['name' => 'čeština', 'locale' => 'cs_CZ', 'flag' => '🇨🇿', 'show_in_menu' => true, 'dir' => 'ltr'], 'de' => ['name' => 'Deutsch', 'locale' => 'de_DE', 'flag' => '🇩🇪', 'show_in_menu' => true, 'dir' => 'ltr'], 'en' => ['name' => 'English', 'locale' => 'en_GB', 'flag' => '🇬🇧', 'show_in_menu' => true, 'dir' => 'ltr'], 'pl' => ['name' => 'Polski', 'locale' => 'pl_PL', 'flag' => '🇵🇱', 'show_in_menu' => true, 'dir' => 'ltr'], 'ru' => ['name' => 'Русский', 'locale' => 'ru_RU', 'flag' => '🇷🇺', 'show_in_menu' => true, 'dir' => 'ltr'], 'tr' => ['name' => 'Türkçe', 'locale' => 'tr_TR', 'flag' => '🇹🇷', 'show_in_menu' => true, 'dir' => 'ltr'], 'uk' => ['name' => 'Українська', 'locale' => 'uk_UA', 'flag' => '🇺🇦', 'show_in_menu' => true, 'dir' => 'ltr'], ]; $language = 'en'; $locale = 'en_GB'; $dir = 'ltr'; if(isset($_REQUEST['lang']) && isset(LANGUAGES[$_REQUEST['lang']])){ $locale = LANGUAGES[$_REQUEST['lang']]['locale']; $language = $_REQUEST['lang']; $dir = LANGUAGES[$_REQUEST['lang']]['dir']; setcookie('language', $_REQUEST['lang'], ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']); }elseif(isset($_COOKIE['language']) && isset(LANGUAGES[$_COOKIE['language']])){ $locale = LANGUAGES[$_COOKIE['language']]['locale']; $language = $_COOKIE['language']; $dir = LANGUAGES[$_COOKIE['language']]['dir']; }elseif(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ $prefLocales = array_reduce( explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']), function (array $res, string $el) { list($l, $q) = array_merge(explode(';q=', $el), [1]); $res[$l] = (float) $q; return $res; }, []); arsort($prefLocales); foreach($prefLocales as $l => $q){ $lang = locale_lookup(array_keys(LANGUAGES), $l); if(!empty($lang)){ $locale = LANGUAGES[$lang]['locale']; $language = $lang; $dir = LANGUAGES[$lang]['dir']; setcookie('language', $lang, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']); break; } } } putenv('LC_ALL='.$locale); setlocale(LC_ALL, $locale); bindtextdomain('mail-hosting', __DIR__.'/locale'); bind_textdomain_codeset('mail-hosting', 'UTF-8'); textdomain('mail-hosting'); require_once( 'vendor/autoload.php' ); function get_db_instance(): PDO { static $db = null; if ( $db !== null ) { return $db; } try { $db = new PDO( 'mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => PERSISTENT ] ); } catch ( PDOException ) { http_response_code( 500 ); die( _('No Connection to MySQL database!') ); } return $db; } function z_base32_encode( string $input ): string { $map = [ 'y', 'b', 'n', 'd', 'r', 'f', 'g', '8', // 7 'e', 'j', 'k', 'm', 'c', 'p', 'q', 'x', // 15 'o', 't', '1', 'u', 'w', 'i', 's', 'z', // 23 'a', '3', '4', '5', 'h', '7', '6', '9', // 31 ]; if ( empty( $input ) ) { return ''; } $input = str_split( $input ); $binaryString = ''; $c = count( $input ); for ( $i = 0; $i < $c; ++$i ) { $binaryString .= str_pad( decbin( ord( $input[ $i ] ) ), 8, '0', STR_PAD_LEFT ); } $fiveBitBinaryArray = str_split( $binaryString, 5 ); $base32 = ''; $i = 0; $c = count( $fiveBitBinaryArray ); while ( $i < $c ) { $base32 .= $map[ bindec( $fiveBitBinaryArray[ $i ] ) ]; ++$i; } return $base32; } function send_captcha(): void { if ( CAPTCHA_DIFFICULTY === 0 || ! extension_loaded( 'gd' ) ) { return; } $db = get_db_instance(); $captchachars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $length = strlen( $captchachars ) - 1; $code = ''; for ( $i = 0; $i < 5; ++$i ) { $code .= $captchachars[ mt_rand( 0, $length ) ]; } $randid = mt_rand(); $time = time(); $stmt = $db->prepare( 'INSERT INTO captcha (id, time, code) VALUES (?, ?, ?);' ); $stmt->execute( [ $randid, $time, $code ] ); echo '