mailwolt/app/Helpers/helpers.php

71 lines
1.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

<?php
if (! function_exists('settings')) {
function settings(string $key, $default = null) {
return app(\App\Support\SettingsRepository::class)->get($key, $default);
}
}
if (!function_exists('domain_host')) {
function domain_host(string $sub = null): string
{
$base = env('BASE_DOMAIN', 'example.com');
return $sub ? "{$sub}.{$base}" : $base;
}
}
if (!function_exists('ui_host')) {
function ui_host(): string
{
return domain_host(env('UI_SUB', 'ui'));
}
}
if (!function_exists('webmail_host')) {
function webmail_host(): string
{
return domain_host(env('WEBMAIL_SUB', 'webmail'));
}
}
if (!function_exists('mta_host')) {
function mta_host(?int $domainId = null): string
{
// 1⃣ Vorrang: Datenbankwert (z. B. aus der domains-Tabelle)
if ($domainId) {
try {
$domain = \App\Models\Domain::find($domainId);
if ($domain && !empty($domain->mta_host)) {
return $domain->mta_host;
}
} catch (\Throwable $e) {
// DB evtl. noch nicht migriert — fallback auf env
}
}
// 2⃣ ENV-Variante (z. B. MTA_SUB=mail01)
$sub = env('MTA_SUB');
if ($sub) {
return domain_host($sub);
}
// 3⃣ Notfall: statischer Fallback
return domain_host('mx');
}
}
if (! function_exists('countryFlag')) {
/**
* Gibt das Flag-Emoji eines Landes zurück anhand des ISO-Codes (z. B. "de" → 🇩🇪).
*/
function countryFlag(string $code): string
{
$code = strtoupper($code);
// Unicode-Magic: A -> 🇦, B -> 🇧 etc.
return implode('', array_map(
fn($char) => mb_chr(ord($char) + 127397, 'UTF-8'),
str_split($code)
));
}
}