Skip to content

Commit

Permalink
refactor: simplified code and renamed translation keys
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 8, 2024
1 parent fdcb346 commit 28771ca
Show file tree
Hide file tree
Showing 47 changed files with 235 additions and 245 deletions.
35 changes: 10 additions & 25 deletions phpmyfaq/admin/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@
$faqConfig = Configuration::getConfigurationInstance();
$faqTableInfo = $faqConfig->getDb()->getTableStatus(Database::getTablePrefix());
$user = CurrentUser::getCurrentUser($faqConfig);
$userId = $user->getUserId();
$faqSystem = new System();
$faqSession = new Session($faqConfig);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$template = $twig->loadTemplate('./admin/dashboard.twig');

$templateVars = [
'adminHeaderDashboard' => Translation::get('admin_mainmenu_home'),
'isDebugMode' => DEBUG,
'isMaintenanceMode' => $faqConfig->get('main.maintenanceMode'),
'adminDashboardMaintenance' => Translation::get('msgMaintenanceMode'),
'adminDashboardOnline' => Translation::get('msgOnlineMode'),
'isDevelopmentVersion' => System::isDevelopmentVersion(),
'currentVersionApp' => System::getVersion(),
'adminDashboardInfoVisits' => Translation::get('ad_start_visits'),
'adminDashboardHeaderTopTen' => Translation::get('msgTopTen'),
'msgAdminWarningDevelopmentVersion' => sprintf(
Translation::get('msgAdminWarningDevelopmentVersion'),
System::getVersion(),
System::getGitHubIssuesUrl()
),
'adminDashboardInfoNumVisits' => $faqSession->getNumberOfSessions(),
'adminDashboardInfoFaqs' => Translation::get('ad_start_articles'),
'adminDashboardInfoNumFaqs' => $faqTableInfo[Database::getTablePrefix() . 'faqdata'],
Expand All @@ -62,10 +64,11 @@
'adminDashboardInfoNumQuestions' => $faqTableInfo[Database::getTablePrefix() . 'faqquestions'],
'adminDashboardInfoUser' => Translation::get('msgNews'),
'adminDashboardInfoNumUser' => $faqTableInfo[Database::getTablePrefix() . 'faquser'] - 1,
'adminDashboardHeaderVisits' => Translation::get('ad_stat_report_visits'),
'hasUserTracking' => $faqConfig->get('main.enableUserTracking'),
'adminDashboardHeaderInactiveFaqs' => Translation::get('ad_record_inactive'),
'adminDashboardInactiveFaqs' => $faq->getInactiveFaqsData(),
'hasPermissionEditConfig' => $user->perm->hasPermission($user->getUserId(), PermissionType::CONFIGURATION_EDIT->value),
'hasPermissionEditConfig' => $user->perm->hasPermission($userId, PermissionType::CONFIGURATION_EDIT->value),
'showVersion' => $faqConfig->get('main.enableAutoUpdateHint'),
];

Expand All @@ -77,21 +80,7 @@
];
}

if (System::isDevelopmentVersion()) {
$templateVars = [
...$templateVars,
'isDevelopmentVersion' => true
];
}

if ($faqConfig->get('main.enableUserTracking')) {
$templateVars = [
...$templateVars,
'adminDashboardHeaderVisits' => Translation::get('ad_stat_report_visits')
];
}

if ($user->perm->hasPermission($user->getUserId(), PermissionType::CONFIGURATION_EDIT->value)) {
if ($user->perm->hasPermission($userId, PermissionType::CONFIGURATION_EDIT->value)) {
$api = new Api($faqConfig);

$version = Filter::filterInput(INPUT_POST, 'param', FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down Expand Up @@ -174,10 +163,6 @@
$templateVars = [
...$templateVars,
'showVersion' => $faqConfig->get('main.enableAutoUpdateHint') || ($version === 'version'),
'adminDashboardHeaderOnlineInfo' => Translation::get('ad_online_info'),
'adminDashboardButtonGetLatestVersion' => Translation::get('ad_xmlrpc_button'),
'adminDashboardHeaderVerification' => Translation::get('ad_online_verification'),
'adminDashboardButtonVerification' => Translation::get('ad_verification_button')
];
}

Expand Down
24 changes: 10 additions & 14 deletions phpmyfaq/assets/templates/admin/dashboard.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-speedometer"></i>
{{ adminHeaderDashboard }}
{{ 'adminHeaderDashboard' | translate }}
</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<a href="?action=config">
{% if isMaintenanceMode %}
<button class="btn btn-outline-danger">{{ adminDashboardMaintenance }}</button>
<button class="btn btn-outline-danger">{{ 'msgMaintenanceMode' | translate }}</button>
{% else %}
<button class="btn btn-outline-success">{{ adminDashboardOnline }}</button>
<button class="btn btn-outline-success">{{ 'msgOnlineMode' | translate }}</button>
{% endif %}
</a>
</div>
Expand Down Expand Up @@ -51,11 +51,7 @@
<section class="row">
<div class="col">
<div class="alert alert-danger" role="alert">
phpMyFAQ is currently in development ({{ currentVersionApp }}).
And therefore not yet ready for production.
Please <a target="_blank" href="https://github.com/thorsten/phpMyFAQ/issues" class="alert-link">report all
issues on GitHub</a>.
Thank you very much!
{{ msgAdminWarningDevelopmentVersion | raw }}
</div>
</div>
</section>
Expand All @@ -68,7 +64,7 @@
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold mb-1">{{ adminDashboardInfoVisits }}</div>
<div class="text-xs font-weight-bold mb-1">{{ 'msgVisits' | translate }}</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ adminDashboardInfoNumVisits }}</div>
</div>
<div class="col-auto">
Expand Down Expand Up @@ -146,7 +142,7 @@
<div class="col-4 mb-4">
<div class="card shadow h-100 mb-4">
<h5 class="card-header py-3">
<i aria-hidden="true" class="bi bi-bar-chart"></i> {{ adminDashboardHeaderTopTen }}
<i aria-hidden="true" class="bi bi-bar-chart"></i> {{ 'msgTopTen' | translate }}
</h5>
<div class="card-body">
<div class="pmf-charts">
Expand Down Expand Up @@ -186,7 +182,7 @@
<div class="col-3 mb-4">
<div class="card shadow mb-4">
<h5 class="card-header py-3">
<i aria-hidden="true" class="bi bi-check"></i> {{ adminDashboardHeaderOnlineInfo }}
<i aria-hidden="true" class="bi bi-check"></i> {{ 'msgOnlineVersionCheck' | translate }}
</h5>
<div class="card-body">
{% if showVersion %}
Expand All @@ -200,7 +196,7 @@
method="post" accept-charset="utf-8">
<input type="hidden" name="param" value="version" />
<button class="btn btn-info" type="submit">
{{ adminDashboardButtonGetLatestVersion }}
{{ 'msgButtonFetchLatestVersion' | translate }}
</button>
</form>
{% if adminDashboardShouldUpdateMessage %}
Expand All @@ -225,7 +221,7 @@
<div class="col-3 mb-4">
<div class="card shadow mb-4">
<h5 class="card-header py-3">
<i aria-hidden="true" class="bi bi-check bi-fw"></i> {{ adminDashboardHeaderVerification }}
<i aria-hidden="true" class="bi bi-check bi-fw"></i> {{ 'msgOnlineVerificationCheck' | translate }}
</h5>
<div class="card-body">
{% if showVerificationResult %}
Expand Down Expand Up @@ -263,7 +259,7 @@
<form action="./index.php" method="post" accept-charset="utf-8">
<input type="hidden" name="getJson" value="verify">
<button class="btn btn-info" type="submit">
{{ adminDashboardButtonVerification }}
{{ 'msgOnlineVerificationCheckButton' | translate }}
</button>
</form>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use phpMyFAQ\Administration\Report;
use phpMyFAQ\Auth;
use phpMyFAQ\Category;
use phpMyFAQ\Component\Alert;
use phpMyFAQ\Configuration;
use phpMyFAQ\Controller\AbstractController;
use phpMyFAQ\Core\Exception;
Expand Down
20 changes: 15 additions & 5 deletions phpmyfaq/src/phpMyFAQ/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class System
*/
final public const PHPMYFAQ_URL = 'https://www.phpmyfaq.de/';

/**
* GitHub Issues URL
*/
final public const GITHUB_ISSUES_URL = 'https://github.com/thorsten/phpMyFAQ/issues';

/**
* Array of required PHP extensions.
*
Expand Down Expand Up @@ -100,20 +105,20 @@ class System
private array $supportedDatabases = [
'mysqli' => [
self::VERSION_MINIMUM_PHP,
'MySQL v8 / MariaDB v10 / Percona Server v8 / Galera Cluster v4 for MySQL'
'MySQL v8 / MariaDB v10 / Percona Server v8 / Galera Cluster v4 for MySQL',
],
'pgsql' => [
self::VERSION_MINIMUM_PHP,
'PostgreSQL v10 or later'
'PostgreSQL v10 or later',
],
'sqlite3' => [
self::VERSION_MINIMUM_PHP,
'SQLite 3'
'SQLite 3',
],
'sqlsrv' => [
self::VERSION_MINIMUM_PHP,
'MS SQL Server 2016 or later'
]
'MS SQL Server 2016 or later',
],
];

/**
Expand Down Expand Up @@ -171,6 +176,11 @@ public static function getDocumentationUrl(): string
return sprintf('%sdocs/%s', self::PHPMYFAQ_URL, self::getMajorVersion());
}

public static function getGitHubIssuesUrl(): string
{
return self::GITHUB_ISSUES_URL;
}

/**
* Returns true or false on SQLite3.
*
Expand Down
8 changes: 4 additions & 4 deletions phpmyfaq/translations/language_ar.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
$PMF_LANG['ad_log_usde'] = 'تم حذف المستخدم التالي: ';
$PMF_LANG['ad_log_beed'] = 'تحرير نموذج المستخدم التالي: ';
$PMF_LANG['ad_log_bede'] = 'تم حذف السؤال التالية: ';
$PMF_LANG['ad_start_visits'] = 'زيارات';
$PMF_LANG['msgVisits'] = 'زيارات';
$PMF_LANG['ad_start_articles'] = 'مواضيع';
$PMF_LANG['ad_start_comments'] = 'تعليقات';
$PMF_LANG['ad_categ_paste'] = 'لصق';
Expand Down Expand Up @@ -467,7 +467,7 @@
$PMF_LANG['lostpwd_text_1'] = 'شكراً لطلبك معلومات حسابك';
$PMF_LANG['lostpwd_text_2'] = 'من فضلك ضع كلمة سر جديدة في قسم الإشراف بالبرنامج';
$PMF_LANG['lostpwd_mail_okay'] = 'تم إرسال البريد ';
$PMF_LANG['ad_xmlrpc_button'] = 'احصل على رقم أحدث إصدار من البرنامج عن طريق الويب ';
$PMF_LANG['msgButtonFetchLatestVersion'] = 'احصل على رقم أحدث إصدار من البرنامج عن طريق الويب ';
$PMF_LANG['ad_xmlrpc_latest'] = 'أحدث إصدار متوفر على';
$PMF_LANG['ad_categ_select'] = 'اختار لغة التصنيف';
$PMF_LANG['msgSitemap'] = 'خريطة الموقع';
Expand Down Expand Up @@ -567,7 +567,7 @@
$PMF_LANG['newsWriteComment'] = 'التعليق على هذة المداخلة';
$PMF_LANG['newsCommentDate'] = 'أضيفت إلي :';
$PMF_LANG['ad_record_expiration_window'] = ' نافذة تسجيل وقت الإنتهاء (اختياري)';
$PMF_LANG['admin_mainmenu_home'] = 'الرئيسية';
$PMF_LANG['adminHeaderDashboard'] = 'الرئيسية';
$PMF_LANG['admin_mainmenu_users'] = 'المستخدمين';
$PMF_LANG['admin_mainmenu_content'] = 'المحتوى';
$PMF_LANG['admin_mainmenu_statistics'] = 'إحصائيات';
Expand Down Expand Up @@ -807,7 +807,7 @@
$PMF_LANG['msgAllCatArticles'] = 'Records in this category';
$PMF_LANG['msgTagSearch'] = 'Tagged entries';
$PMF_LANG['ad_pmf_info'] = 'phpMyFAQ Information';
$PMF_LANG['ad_online_info'] = 'Online version check';
$PMF_LANG['msgOnlineVersionCheck'] = 'Online version check';
$PMF_LANG['ad_system_info'] = 'System Information';
$PMF_LANG['msgRegisterUser'] = 'سجل هنا';
$LANG_CONF['records.orderby'] = array('select', 'Record sorting (according to property)');
Expand Down
8 changes: 4 additions & 4 deletions phpmyfaq/translations/language_bn.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
$PMF_LANG["ad_log_beed"] = "Edit form for the following user: ";
$PMF_LANG["ad_log_bede"] = "Deleted the following entry: ";

$PMF_LANG["ad_start_visits"] = "Visits";
$PMF_LANG["msgVisits"] = "Visits";
$PMF_LANG["ad_start_articles"] = "Articles";
$PMF_LANG["ad_start_comments"] = "Comments";

Expand Down Expand Up @@ -579,7 +579,7 @@
$PMF_LANG["lostpwd_text_2"] = "অনুগ্রহ করে প্রশাসকের বিভাগে একটি নতুন গোপন সংকেত প্রদান করুন।";
$PMF_LANG["lostpwd_mail_okay"] = "ই-মেইল পাঠানো হয়েছে";

$PMF_LANG["ad_xmlrpc_button"] = "Get latest phpMyFAQ version number by web service";
$PMF_LANG["msgButtonFetchLatestVersion"] = "Get latest phpMyFAQ version number by web service";
$PMF_LANG["ad_xmlrpc_latest"] = "Latest version available on";

// added v1.5.0 - 2005-07-31 by Thorsten
Expand Down Expand Up @@ -703,7 +703,7 @@

// added v2.0.0 - 2006-07-29 by Matteo & Thorsten
$PMF_LANG['ad_record_expiration_window'] = 'Record expiration time window (optional)';
$PMF_LANG['admin_mainmenu_home'] = 'Home';
$PMF_LANG['adminHeaderDashboard'] = 'Home';
$PMF_LANG['admin_mainmenu_users'] = 'Users';
$PMF_LANG['admin_mainmenu_content'] = 'Content';
$PMF_LANG['admin_mainmenu_statistics'] = 'Statistics';
Expand Down Expand Up @@ -821,7 +821,7 @@
$PMF_LANG['msgAllCatArticles'] = 'এই বিভাগের প্রশ্ন';
$PMF_LANG['msgTagSearch'] = 'ট্যাগ';
$PMF_LANG['ad_pmf_info'] = 'phpMyFAQ Information';
$PMF_LANG['ad_online_info'] = 'Online version check';
$PMF_LANG['msgOnlineVersionCheck'] = 'Online version check';
$PMF_LANG['ad_system_info'] = 'System Information';

return $PMF_LANG;
8 changes: 4 additions & 4 deletions phpmyfaq/translations/language_bs.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
$PMF_LANG["ad_log_beed"] = "Edit forma za korisnika: ";
$PMF_LANG["ad_log_bede"] = "Obrisan unos: ";

$PMF_LANG["ad_start_visits"] = "Poseta";
$PMF_LANG["msgVisits"] = "Poseta";
$PMF_LANG["ad_start_articles"] = "&#268;lanaka";
$PMF_LANG["ad_start_comments"] = "Komentara";

Expand Down Expand Up @@ -579,7 +579,7 @@
$PMF_LANG["lostpwd_text_2"] = "Podesite novu lozinku u admin delu Va&scaron;eg FAQ.";
$PMF_LANG["lostpwd_mail_okay"] = "E-Mail je poslat.";

$PMF_LANG["ad_xmlrpc_button"] = "Pogledaj najnoviju phpMyFAQ verziju na internetu";
$PMF_LANG["msgButtonFetchLatestVersion"] = "Pogledaj najnoviju phpMyFAQ verziju na internetu";
$PMF_LANG["ad_xmlrpc_latest"] = "Najnovija dostupna verzija je";

// added v1.5.0 - 2005-07-31 by Thorsten
Expand Down Expand Up @@ -703,7 +703,7 @@

// added v2.0.0 - 2006-07-29 by Matteo & Thorsten
$PMF_LANG['ad_record_expiration_window'] = 'Pode&scaron;avanje trajanja unosa (opciono)';
$PMF_LANG['admin_mainmenu_home'] = 'Home';
$PMF_LANG['adminHeaderDashboard'] = 'Home';
$PMF_LANG['admin_mainmenu_users'] = 'Korisnici';
$PMF_LANG['admin_mainmenu_content'] = 'Sadr&#382;aj';
$PMF_LANG['admin_mainmenu_statistics'] = 'Statistika';
Expand Down Expand Up @@ -821,7 +821,7 @@
$PMF_LANG['msgAllCatArticles'] = 'Unosi u ovoj kategoriji';
$PMF_LANG['msgTagSearch'] = 'Oznaceni unosi';
$PMF_LANG['ad_pmf_info'] = 'phpMyFAQ Informacije';
$PMF_LANG['ad_online_info'] = 'Provera Verzije';
$PMF_LANG['msgOnlineVersionCheck'] = 'Provera Verzije';
$PMF_LANG['ad_system_info'] = 'Informacije Sistema';

return $PMF_LANG;
8 changes: 4 additions & 4 deletions phpmyfaq/translations/language_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
$PMF_LANG['ad_log_usde'] = 'Smazat uživatele: ';
$PMF_LANG['ad_log_beed'] = 'Formulář pro editaci uživatele: ';
$PMF_LANG['ad_log_bede'] = 'Smazán záznam: ';
$PMF_LANG['ad_start_visits'] = 'Návštěv';
$PMF_LANG['msgVisits'] = 'Návštěv';
$PMF_LANG['ad_start_articles'] = 'Článků';
$PMF_LANG['ad_start_comments'] = 'Komentářů';
$PMF_LANG['ad_categ_paste'] = 'vložit';
Expand Down Expand Up @@ -477,7 +477,7 @@
$PMF_LANG['lostpwd_text_1'] = 'Děkujeme, že jste si vyžádali vaše přihlašovací údaje.';
$PMF_LANG['lostpwd_text_2'] = 'Prosíme, nastavete si nové helso v admin sekci vašcih FAQ.';
$PMF_LANG['lostpwd_mail_okay'] = 'E-mail byl odeslán.';
$PMF_LANG['ad_xmlrpc_button'] = 'Získejte poslední verzi systému';
$PMF_LANG['msgButtonFetchLatestVersion'] = 'Získejte poslední verzi systému';
$PMF_LANG['ad_xmlrpc_latest'] = 'Poslední dostupná verze';
$PMF_LANG['ad_categ_select'] = 'Zvolte jazyk sekce';
$PMF_LANG['msgSitemap'] = 'Mapa stránek';
Expand Down Expand Up @@ -578,7 +578,7 @@
$PMF_LANG['newsWriteComment'] = 'komentář k záznamu';
$PMF_LANG['newsCommentDate'] = 'Přidáno: ';
$PMF_LANG['ad_record_expiration_window'] = 'Čas expirace záznamu (volitelné)';
$PMF_LANG['admin_mainmenu_home'] = 'Úvod';
$PMF_LANG['adminHeaderDashboard'] = 'Úvod';
$PMF_LANG['admin_mainmenu_users'] = 'Uživatelé';
$PMF_LANG['admin_mainmenu_content'] = 'Obsah';
$PMF_LANG['admin_mainmenu_statistics'] = 'Statistiky';
Expand Down Expand Up @@ -666,7 +666,7 @@
$PMF_LANG['msgAllCatArticles'] = 'Záznamů v této kategorii';
$PMF_LANG['msgTagSearch'] = 'Označkovaných záznamů';
$PMF_LANG['ad_pmf_info'] = 'Informace';
$PMF_LANG['ad_online_info'] = 'Online ověření verze';
$PMF_LANG['msgOnlineVersionCheck'] = 'Online ověření verze';
$PMF_LANG['ad_system_info'] = 'Systémové informace';
$PMF_LANG['msgRegisterUser'] = 'Registrovat';
$PMF_LANG['ad_user_loginname'] = 'Uživatelské jméno:';
Expand Down
4 changes: 2 additions & 2 deletions phpmyfaq/translations/language_cy.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
$PMF_LANG["ad_log_beed"] = "Golygu ffurflen ar gyfer y defnyddiwr canlynol: ";
$PMF_LANG["ad_log_bede"] = "Dilëwyd y cofnod canlynol: ";

$PMF_LANG["ad_start_visits"] = "Ymweliadau";
$PMF_LANG["msgVisits"] = "Ymweliadau";
$PMF_LANG["ad_start_articles"] = "Erthyglau";
$PMF_LANG["ad_start_comments"] = "Sylwadau";

Expand Down Expand Up @@ -579,7 +579,7 @@
$PMF_LANG["lostpwd_text_2"] = "Gosodwch gyfrinair personol newydd yn adran weinyddol eich Cwestiynau Cyffredin.";
$PMF_LANG["lostpwd_mail_okay"] = "Anfonwyd yr e-bost.";

$PMF_LANG["ad_xmlrpc_button"] = "Cael rhif fersiwn phpMyFAQ diweddaraf drwy wasanaeth gwe";
$PMF_LANG["msgButtonFetchLatestVersion"] = "Cael rhif fersiwn phpMyFAQ diweddaraf drwy wasanaeth gwe";
$PMF_LANG["ad_xmlrpc_latest"] = "Y fersiwn ddiweddaraf ar gael ar";

// added v1.5.0 - 2005-07-31 by Thorsten
Expand Down
Loading

0 comments on commit 28771ca

Please sign in to comment.