diff --git a/customer_mysql.php b/customer_mysql.php index d231aa99..6b91714d 100644 --- a/customer_mysql.php +++ b/customer_mysql.php @@ -67,11 +67,6 @@ if ($page == 'overview' || $page == 'mysqls') { Response::dynamicError($e->getMessage()); } - Database::needSqlData(); - $sql = Database::getSqlData(); - // FIXME: setting translation on the fly is currently not supported; do we want this; alternatives - // $lng['mysql']['description'] = str_replace('', $sql['host'], lng('mysql.description')); - $actions_links = false; if ($userinfo['mysqls_used'] < $userinfo['mysqls'] || $userinfo['mysqls'] == '-1') { $actions_links = [ diff --git a/lib/Froxlor/Config/ConfigDaemon.php b/lib/Froxlor/Config/ConfigDaemon.php index e31479e6..0e9cde33 100644 --- a/lib/Froxlor/Config/ConfigDaemon.php +++ b/lib/Froxlor/Config/ConfigDaemon.php @@ -113,13 +113,12 @@ class ConfigDaemon if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) { return Settings::Get($match[1]); } elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) { - global $lng; if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') { - return $lng[$match[1]][$match[2]][$match[3]]; + return lng($match[1] . '.' . $match[2] . '.' . $match[3]); } elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') { - return $lng[$match[1]][$match[2]]; + return lng($match[1] . '.' . $match[2]); } elseif (isset($match[1]) && $match[1] != '') { - return $lng[$match[1]]; + return lng($match[1]); } return ''; } elseif (preg_match('/^const\.(.*)$/', $matches[1], $match)) { @@ -196,7 +195,7 @@ class ConfigDaemon $preparsed[] = $include; } break; - // The next 3 are groupings, MUST come first in this to work properly + // The next 3 are groupings, MUST come first in this to work properly case "commands": case "files": case "installs": diff --git a/lib/Froxlor/Config/ConfigService.php b/lib/Froxlor/Config/ConfigService.php index 157c4250..799630f7 100644 --- a/lib/Froxlor/Config/ConfigService.php +++ b/lib/Froxlor/Config/ConfigService.php @@ -93,13 +93,12 @@ class ConfigService if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) { return Settings::Get($match[1]); } elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) { - global $lng; if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') { - return $lng[$match[1]][$match[2]][$match[3]]; + return lng($match[1] . '.' . $match[2] . '.' . $match[3]); } elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') { - return $lng[$match[1]][$match[2]]; + return lng($match[1] . '.' . $match[2]); } elseif (isset($match[1]) && $match[1] != '') { - return $lng[$match[1]]; + return lng($match[1]); } return ''; } diff --git a/lib/Froxlor/Cron/MasterCron.php b/lib/Froxlor/Cron/MasterCron.php index 46178f91..f58f3be6 100644 --- a/lib/Froxlor/Cron/MasterCron.php +++ b/lib/Froxlor/Cron/MasterCron.php @@ -209,6 +209,7 @@ class MasterCron extends FroxlorCron unset($sql['root_password']); } + require Froxlor::getInstallDir() . '/lib/functions.php'; // Includes the MySQL-Tabledefinitions etc. require Froxlor::getInstallDir() . '/lib/tables.inc.php'; fwrite(self::$debugHandler, 'Table definitions included' . "\n"); diff --git a/lib/Froxlor/Cron/Traffic/ReportsCron.php b/lib/Froxlor/Cron/Traffic/ReportsCron.php index be549f09..f8aa6eaf 100644 --- a/lib/Froxlor/Cron/Traffic/ReportsCron.php +++ b/lib/Froxlor/Cron/Traffic/ReportsCron.php @@ -40,6 +40,7 @@ use Froxlor\PhpHelper; use Froxlor\Settings; use Froxlor\System\Mailer; use Froxlor\User; +use Froxlor\Language; use PDO; class ReportsCron extends FroxlorCron @@ -98,29 +99,8 @@ class ReportsCron extends FroxlorCron 'MAX_PERCENT' => Settings::Get('system.report_trafficmax') ]; - $lngfile_stmt = Database::prepare(" - SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` = :deflang - "); - $lngfile = Database::pexecute_first($lngfile_stmt, [ - 'deflang' => $row['def_language'] - ]); - - if ($lngfile !== null) { - $langfile = $lngfile['file']; - } else { - $lngfile = Database::pexecute_first($lngfile_stmt, [ - 'deflang' => Settings::Get('panel.standardlanguage') - ]); - $langfile = $lngfile['file']; - } - - // include english language file (fallback) - include FileDir::makeCorrectFile(Froxlor::getInstallDir() . '/lng/english.lng.php'); - // include admin/customer language file - if ($lngfile != 'lng/english.lng.php') { - include FileDir::makeCorrectFile(Froxlor::getInstallDir() . '/' . $langfile); - } + // set target user language + Language::setLanguage($row['def_language']); // Get mail templates from database; the ones from 'admin' are fetched for fallback $result2_stmt = Database::prepare(" @@ -135,11 +115,11 @@ class ReportsCron extends FroxlorCron 'varname' => 'trafficmaxpercent_subject' ]; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['subject']), $replace_arr)); + $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.trafficmaxpercent.subject')), $replace_arr)); $result2_data['varname'] = 'trafficmaxpercent_mailbody'; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['mailbody']), $replace_arr)); + $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.trafficmaxpercent.mailbody')), $replace_arr)); $_mailerror = false; $mailerr_msg = ""; @@ -241,11 +221,11 @@ class ReportsCron extends FroxlorCron 'varname' => 'trafficmaxpercent_subject' ]; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['subject']), $replace_arr)); + $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.trafficmaxpercent.subject')), $replace_arr)); $result2_data['varname'] = 'trafficmaxpercent_mailbody'; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['mailbody']), $replace_arr)); + $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.trafficmaxpercent.mailbody')), $replace_arr)); $_mailerror = false; $mailerr_msg = ""; @@ -447,11 +427,11 @@ class ReportsCron extends FroxlorCron 'varname' => 'diskmaxpercent_subject' ]; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['diskmaxpercent']['subject']), $replace_arr)); + $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.diskmaxpercent.subject')), $replace_arr)); $result2_data['varname'] = 'diskmaxpercent_mailbody'; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['diskmaxpercent']['mailbody']), $replace_arr)); + $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.diskmaxpercent.mailbody')), $replace_arr)); $_mailerror = false; $mailerr_msg = ""; @@ -544,11 +524,11 @@ class ReportsCron extends FroxlorCron 'varname' => 'diskmaxpercent_subject' ]; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['diskmaxpercent']['subject']), $replace_arr)); + $mail_subject = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.diskmaxpercent.subject')), $replace_arr)); $result2_data['varname'] = 'diskmaxpercent_mailbody'; $result2 = Database::pexecute_first($result2_stmt, $result2_data); - $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : $lng['mails']['diskmaxpercent']['mailbody']), $replace_arr)); + $mail_body = html_entity_decode(PhpHelper::replaceVariables((($result2 !== false && $result2['value'] != '') ? $result2['value'] : lng('mails.diskmaxpercent.mailbody')), $replace_arr)); $_mailerror = false; $mailerr_msg = ""; @@ -580,8 +560,6 @@ class ReportsCron extends FroxlorCron Database::pexecute($upd_stmt, [ 'adminid' => $row['adminid'] ]); - - unset($lng); } } } // webmax > 0 diff --git a/lib/Froxlor/Domain/Domain.php b/lib/Froxlor/Domain/Domain.php index 69aeb270..c5dd7f9d 100644 --- a/lib/Froxlor/Domain/Domain.php +++ b/lib/Froxlor/Domain/Domain.php @@ -135,8 +135,6 @@ class Domain */ public static function getRedirectCodes($add_desc = true) { - global $lng; - $sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC"; $result_stmt = Database::query($sql); @@ -144,7 +142,7 @@ class Domain while ($rc = $result_stmt->fetch(PDO::FETCH_ASSOC)) { $codes[$rc['id']] = $rc['code']; if ($add_desc) { - $codes[$rc['id']] .= ' (' . $lng['redirect_desc'][$rc['desc']] . ')'; + $codes[$rc['id']] .= ' (' . lng('redirect_desc.' . $rc['desc']) . ')'; } } diff --git a/lib/Froxlor/Domain/IpAddr.php b/lib/Froxlor/Domain/IpAddr.php index 3ce52fad..5bc76f44 100644 --- a/lib/Froxlor/Domain/IpAddr.php +++ b/lib/Froxlor/Domain/IpAddr.php @@ -53,9 +53,8 @@ class IpAddr public static function getSslIpPortCombinations() { - global $lng; return [ - '' => $lng['panel']['none_value'] + '' => lng('panel.none_value') ] + self::getIpPortCombinations(true); } diff --git a/lib/Froxlor/FileDir.php b/lib/Froxlor/FileDir.php index 0d001d15..d2aa346e 100644 --- a/lib/Froxlor/FileDir.php +++ b/lib/Froxlor/FileDir.php @@ -424,8 +424,6 @@ class FileDir */ public static function makePathfield($path, $uid, $gid, $value = '', $dom = false) { - global $lng; - $value = str_replace($path, '', $value); $field = []; @@ -471,20 +469,17 @@ class FileDir // remove starting slash we added // for the Dropdown, #225 $value = substr($value, 1); - // $field = $lng['panel']['toomanydirs']; $field = [ 'type' => 'text', 'value' => htmlspecialchars($value), - 'note' => $lng['panel']['toomanydirs'] + 'note' => lng('panel.toomanydirs') ]; } } else { - // $field = $lng['panel']['dirsmissing']; - // $field = ''; $field = [ 'type' => 'hidden', 'value' => '/', - 'note' => $lng['panel']['dirsmissing'] + 'note' => lng('panel.dirsmissing') ]; } } diff --git a/lib/Froxlor/System/Crypt.php b/lib/Froxlor/System/Crypt.php index 391a3782..05be41f5 100644 --- a/lib/Froxlor/System/Crypt.php +++ b/lib/Froxlor/System/Crypt.php @@ -89,11 +89,9 @@ class Crypt */ public static function getAvailablePasswordHashes() { - global $lng; - // get available pwd-hases $available_pwdhashes = [ - PASSWORD_DEFAULT => $lng['serversettings']['systemdefault'] + PASSWORD_DEFAULT => lng('serversettings.systemdefault') ]; if (defined('PASSWORD_BCRYPT')) { $available_pwdhashes[PASSWORD_BCRYPT] = 'Bcrypt/Blowfish'; diff --git a/lib/Froxlor/UI/Form.php b/lib/Froxlor/UI/Form.php index 63f1ad52..5fdc6677 100644 --- a/lib/Froxlor/UI/Form.php +++ b/lib/Froxlor/UI/Form.php @@ -93,8 +93,6 @@ class Form public static function getFormOverviewGroupOutput($groupname, $groupdetails) { - global $lng; - $activated = true; if (isset($groupdetails['fields'])) { foreach ($groupdetails['fields'] as $fielddetails) { @@ -125,7 +123,7 @@ class Form if (isset($groupdetails['websrv_avail']) && is_array($groupdetails['websrv_avail'])) { $websrv = Settings::Get('system.webserver'); if (!in_array($websrv, $groupdetails['websrv_avail'])) { - $item['info'] = sprintf($lng['serversettings']['option_unavailable_websrv'], implode(", ", $groupdetails['websrv_avail'])); + $item['info'] = lng('serversettings.option_unavailable_websrv', [implode(", ", $groupdetails['websrv_avail'])]); $item['visible'] = false; } } @@ -135,8 +133,6 @@ class Form public static function getFormFieldOutput($fieldname, $fielddata): array { - global $lng; - $returnvalue = []; if (is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '') { if (!isset($fielddata['value'])) { @@ -170,7 +166,7 @@ class Form $websrv = Settings::Get('system.webserver'); if (!in_array($websrv, $fielddata['websrv_avail'])) { $do_show = false; - $fielddata['note'] = sprintf($lng['serversettings']['option_unavailable_websrv'], implode(", ", $fielddata['websrv_avail'])); + $fielddata['note'] = lng('serversettings.option_unavailable_websrv', [implode(", ", $fielddata['websrv_avail'])]); } } @@ -180,7 +176,7 @@ class Form if (isset($fielddata['visible']) && $do_show) { $do_show = $fielddata['visible']; if (!$do_show) { - $fielddata['note'] = $lng['serversettings']['option_unavailable']; + $fielddata['note'] = lng('serversettings.option_unavailable'); } } diff --git a/lib/Froxlor/UI/HTML.php b/lib/Froxlor/UI/HTML.php index 6fece703..6c6ae243 100644 --- a/lib/Froxlor/UI/HTML.php +++ b/lib/Froxlor/UI/HTML.php @@ -186,15 +186,7 @@ class HTML */ public static function askYesNo(string $text, string $yesfile, array $params = [], string $replacer = '', array $back_link = []) { - global $lng; - - if (isset($lng['question'][$text])) { - $text = $lng['question'][$text]; - } - - $text = strtr($text, [ - '%s' => htmlspecialchars($replacer) - ]); + $text = lng('question.' . $text, [htmlspecialchars($replacer)]); Panel\UI::view('form/yesnoquestion.html.twig', [ 'action' => $yesfile, @@ -207,18 +199,8 @@ class HTML public static function askYesNoWithCheckbox(string $text, string $chk_text, string $yesfile, array $params = [], string $replacer = '', bool $show_checkbox = true) { - global $lng; - - if (isset($lng['question'][$text])) { - $text = $lng['question'][$text]; - } - $text = strtr($text, [ - '%s' => htmlspecialchars($replacer) - ]); - - if (isset($lng['question'][$chk_text])) { - $chk_text = $lng['question'][$chk_text]; - } + $text = lng('question.' . $text, [htmlspecialchars($replacer)]); + $chk_text = lng('question.' . $chk_text); Panel\UI::view('form/yesnoquestion.html.twig', [ 'action' => $yesfile, diff --git a/lib/Froxlor/UI/Response.php b/lib/Froxlor/UI/Response.php index fa2d622d..8882eca8 100644 --- a/lib/Froxlor/UI/Response.php +++ b/lib/Froxlor/UI/Response.php @@ -98,8 +98,6 @@ class Response */ public static function standardError($errors = '', $replacer = '', $throw_exception = false) { - global $lng; - $_SESSION['requestData'] = $_POST; $replacer = htmlentities($replacer); @@ -116,7 +114,7 @@ class Response $error = ''; foreach ($errors as $single_error) { - $single_error = lng('error.'.$single_error, [htmlentities($replacer)]); + $single_error = lng('error.' . $single_error, [htmlentities($replacer)]); if (empty($error)) { $error = $single_error; } else { @@ -130,7 +128,7 @@ class Response UI::view('misc/alert.html.twig', [ 'type' => 'danger', 'btntype' => 'light', - 'heading' => $lng['error']['error'], + 'heading' => lng('error.error'), 'alert_msg' => $error, 'redirect_link' => $link_ref ]); @@ -139,7 +137,6 @@ class Response public static function dynamicError($message) { - global $lng; $_SESSION['requestData'] = $_POST; $link_ref = ''; if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false) { @@ -149,7 +146,7 @@ class Response UI::view('misc/alert.html.twig', [ 'type' => 'danger', 'btntype' => 'light', - 'heading' => $lng['error']['error'], + 'heading' => lng('error.error'), 'alert_msg' => $message, 'redirect_link' => $link_ref ]); @@ -170,9 +167,7 @@ class Response */ public static function standardSuccess($success_message = '', $replacer = '', $params = [], $throw_exception = false) { - global $lng; - - $success_message = lng('success.'.$success_message, [htmlentities($replacer)]); + $success_message = lng('success.' . $success_message, [htmlentities($replacer)]); if ($throw_exception) { throw new Exception(strip_tags($success_message), 200); @@ -198,7 +193,7 @@ class Response UI::view('misc/alert.html.twig', [ 'type' => 'success', 'btntype' => 'light', - 'heading' => $lng['success']['success'], + 'heading' => lng('success.success'), 'alert_msg' => $success_message, 'redirect_link' => $redirect_url ]); diff --git a/lib/init.php b/lib/init.php index 7c12f2e5..cf78dd9d 100644 --- a/lib/init.php +++ b/lib/init.php @@ -247,12 +247,12 @@ if (AREA == 'admin' || AREA == 'customer') { $navigation_data = [ 'admin' => [ 'server' => [ - 'label' => $lng['admin']['server'], + 'label' => lng('admin.server'), 'required_resources' => 'change_serversettings', 'elements' => [ [ 'url' => 'admin_updates.php?page=overview', - 'label' => $lng['update']['update'], + 'label' => lng('update.update'), 'required_resources' => 'change_serversettings' ] ]