From 6a0a323270840ee24f2340f6e418fa623cb1b4f6 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Wed, 25 Sep 2024 11:29:12 +0000 Subject: [PATCH 01/10] Remove *-custom.tpl from repo Those should only be provided by the user. --- lang/du_nl/AccountCreation-custom.tpl | 11 ----------- lang/en_us/AccountCreation-custom.tpl | 11 ----------- lang/es/AccountCreation-custom.tpl | 11 ----------- lang/fr_fr/AccountCreation-custom.tpl | 11 ----------- lang/pt_br/AccountCreation-custom.tpl | 18 ------------------ 5 files changed, 62 deletions(-) delete mode 100644 lang/du_nl/AccountCreation-custom.tpl delete mode 100644 lang/en_us/AccountCreation-custom.tpl delete mode 100644 lang/es/AccountCreation-custom.tpl delete mode 100644 lang/fr_fr/AccountCreation-custom.tpl delete mode 100644 lang/pt_br/AccountCreation-custom.tpl diff --git a/lang/du_nl/AccountCreation-custom.tpl b/lang/du_nl/AccountCreation-custom.tpl deleted file mode 100644 index 0e237d69c..000000000 --- a/lang/du_nl/AccountCreation-custom.tpl +++ /dev/null @@ -1,11 +0,0 @@ -

{$To},

- -

Een nieuwe gebruiker is geregistreerd met de volgende informatie:
-Email: {$EmailAddress}
-Naam: {$FullName}
-Telefoonnummer: {$Phone}
-Organisatie: {$Organization}
-Positie: {$Position}

-{if !empty($CreatedBy)} - Gemaakt door: {$CreatedBy} -{/if} diff --git a/lang/en_us/AccountCreation-custom.tpl b/lang/en_us/AccountCreation-custom.tpl deleted file mode 100644 index d814a8a22..000000000 --- a/lang/en_us/AccountCreation-custom.tpl +++ /dev/null @@ -1,11 +0,0 @@ -

{$To},

- -

A new user has registered with the following information:
-Email: {$EmailAddress}
-Name: {$FullName}
-Phone: {$Phone}
-Organization: {$Organization}
-Position: {$Position}

-{if !empty($CreatedBy)} - Created by: {$CreatedBy} -{/if} \ No newline at end of file diff --git a/lang/es/AccountCreation-custom.tpl b/lang/es/AccountCreation-custom.tpl deleted file mode 100644 index 19c5317f6..000000000 --- a/lang/es/AccountCreation-custom.tpl +++ /dev/null @@ -1,11 +0,0 @@ -

{$To},

- -

Se ha registrado un nuevo usuario con la siguiente información:
-Correo electrónico: {$EmailAddress}
-Nombre: {$FullName}
-Teléfono: {$Phone}
-Organización: {$Organization}
-Cargo: {$Position}

-{if !empty($CreatedBy)} - Creado por: {$CreatedBy} -{/if} \ No newline at end of file diff --git a/lang/fr_fr/AccountCreation-custom.tpl b/lang/fr_fr/AccountCreation-custom.tpl deleted file mode 100644 index 3920effd2..000000000 --- a/lang/fr_fr/AccountCreation-custom.tpl +++ /dev/null @@ -1,11 +0,0 @@ -

{$To},

- -

Un nouvel utilisateur s'est enregistré avec les informations suivantes:
-Email: {$EmailAddress}
-Nom: {$FullName}
-Téléphone: {$Phone}
-Organisation: {$Organization}
-Position: {$Position}

-{if !empty($CreatedBy)} - Créé par: {$CreatedBy} -{/if} \ No newline at end of file diff --git a/lang/pt_br/AccountCreation-custom.tpl b/lang/pt_br/AccountCreation-custom.tpl deleted file mode 100644 index 20fb80b9b..000000000 --- a/lang/pt_br/AccountCreation-custom.tpl +++ /dev/null @@ -1,18 +0,0 @@ -

- {$To}, -
-

- -

- Um novo usuário se registrou com as seguintes informações: -
- E-mail: {$EmailAddress} -
- Nome: {$FullName} -
- Organização: {$Organization} - {if !empty($CreatedBy)} -
- Criada por: {$CreatedBy} - {/if} -

From 30e10c984a4fdc4e0415df3a8439845856bd91c4 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Wed, 25 Sep 2024 11:32:08 +0000 Subject: [PATCH 02/10] Ignore custom translation files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9d45268ea..9f49b1740 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ # Customization Files /Web/custom-favicon.png /Web/img/custom-logo.png +lang/*/*-custom.tpl # Upload Directories /uploads/* From 15731551fc67b0731cc6c50ef5458c7b925a5f7b Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Wed, 25 Sep 2024 12:32:03 +0000 Subject: [PATCH 03/10] defaultPath is a fallback path The name is misleading, as it's not the default.language setting --- lib/Common/SmartyPage.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Common/SmartyPage.php b/lib/Common/SmartyPage.php index 52159c55b..ef536e5e7 100644 --- a/lib/Common/SmartyPage.php +++ b/lib/Common/SmartyPage.php @@ -107,15 +107,15 @@ public function FetchLocalized($templateName, $languageCode = null) $languageCode = $this->getTemplateVars('CurrentLanguage'); } $localizedPath = ROOT_DIR . 'lang/' . $languageCode; - $defaultPath = ROOT_DIR . 'lang/en_us/'; $customTemplateName = str_replace('.tpl', '-custom.tpl', $templateName); if (file_exists($localizedPath . '/' . $templateName) || file_exists($localizedPath . '/' . $customTemplateName)) { $path = $localizedPath; $this->AddTemplateDirectory($localizedPath); } else { - $path = $defaultPath; - $this->AddTemplateDirectory($defaultPath); + // Fallback path + $path = ROOT_DIR . 'lang/en_us/'; + $this->AddTemplateDirectory($path); } if (file_exists($path . '/' . $customTemplateName)) { From 62fecff46c9109b64846ec1e44c66835c33884c2 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sat, 28 Sep 2024 17:14:49 +0000 Subject: [PATCH 04/10] Remove dead code DisplayLocalized in SmartyPage was never called DisplayLocalized in Page was only a copy, which is still called, but the languageCode parameter is not used. --- Pages/HelpPage.php | 15 --------------- Pages/Page.php | 7 ++----- lib/Common/SmartyPage.php | 21 --------------------- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/Pages/HelpPage.php b/Pages/HelpPage.php index 89d967579..d6783b4d4 100644 --- a/Pages/HelpPage.php +++ b/Pages/HelpPage.php @@ -18,20 +18,5 @@ public function PageLoad() $this->Set('ServerTimezone', date_default_timezone_get()); $this->DisplayLocalized('support-and-credits.tpl'); - - // $helpType = $this->GetQuerystring('ht'); -// -// if ($helpType == 'about') -// { -// -// } -// else if ($helpType == 'admin') -// { -// $this->DisplayLocalized('help-admin.tpl'); -// } -// else -// { -// $this->DisplayLocalized('help.tpl'); -// } } } diff --git a/Pages/Page.php b/Pages/Page.php index a2897ce70..cd9ee3440 100644 --- a/Pages/Page.php +++ b/Pages/Page.php @@ -393,13 +393,10 @@ protected function DisplayCsv($templateName, $fileName) /** * @param string $templateName - * @param null $languageCode uses current language is nothing is passed in */ - protected function DisplayLocalized($templateName, $languageCode = null) + protected function DisplayLocalized($templateName) { - if (empty($languageCode)) { - $languageCode = $this->GetVar('CurrentLanguage'); - } + $languageCode = $this->GetVar('CurrentLanguage'); $localizedPath = ROOT_DIR . 'lang/' . $languageCode; $defaultPath = ROOT_DIR . 'lang/en_us/'; diff --git a/lib/Common/SmartyPage.php b/lib/Common/SmartyPage.php index ef536e5e7..d5008e871 100644 --- a/lib/Common/SmartyPage.php +++ b/lib/Common/SmartyPage.php @@ -75,27 +75,6 @@ public function AddTemplateDirectory($templateDirectory) $this->addTemplateDir($templateDirectory); } - /** - * @param string $templateName - * @param null $languageCode uses current language is nothing is passed in - */ - public function DisplayLocalized($templateName, $languageCode = null) - { - if (empty($languageCode)) { - $languageCode = $this->getTemplateVars('CurrentLanguage'); - } - $localizedPath = ROOT_DIR . 'lang/' . $languageCode; - $defaultPath = ROOT_DIR . 'lang/en_us/' . $templateName; - - if (file_exists($localizedPath . '/' . $templateName)) { - $this->AddTemplateDirectory($localizedPath); - } else { - $this->AddTemplateDirectory($defaultPath); - } - - $this->Display($templateName); - } - /** * @param string $templateName * @param null $languageCode uses current language is nothing is passed in From 6e3d756b8833dc16f3db326a1e3dceb416e40610 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sun, 29 Sep 2024 08:09:38 +0000 Subject: [PATCH 05/10] Fix save custom email template for selected language fixes #424 --- Pages/Admin/ManageEmailTemplatesPage.php | 7 +++++ .../Admin/ManageEmailTemplatesPresenter.php | 2 +- lib/Server/FormKeys.php | 1 + .../Configuration/manage_email_templates.tpl | 26 +++++++++---------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Pages/Admin/ManageEmailTemplatesPage.php b/Pages/Admin/ManageEmailTemplatesPage.php index c9e07a47b..9605f08ac 100644 --- a/Pages/Admin/ManageEmailTemplatesPage.php +++ b/Pages/Admin/ManageEmailTemplatesPage.php @@ -44,6 +44,8 @@ public function SetSaveResult($saveResult); * @return string */ public function GetUpdatedTemplateName(); + + public function GetUpdatedLanguage(): string; } class ManageEmailTemplatesPage extends ActionPage implements IManageEmailTemplatesPage @@ -75,6 +77,11 @@ public function ProcessPageLoad() $this->Display('Admin/Configuration/manage_email_templates.tpl'); } + public function GetUpdatedLanguage(): string + { + return $this->GetForm(FormKeys::EMAIL_TEMPLATE_LANGUAGE); + } + public function GetLanguage() { return $this->GetQuerystring(QueryStringKeys::LANGUAGE); diff --git a/Presenters/Admin/ManageEmailTemplatesPresenter.php b/Presenters/Admin/ManageEmailTemplatesPresenter.php index 5a09b8e28..b5a44afbd 100644 --- a/Presenters/Admin/ManageEmailTemplatesPresenter.php +++ b/Presenters/Admin/ManageEmailTemplatesPresenter.php @@ -117,7 +117,7 @@ public function UpdateEmailTemplate() try { Log::Debug('Updating email template. Template=%s', $templateName); - $templatePath = Paths::EmailTemplates($this->GetSelectedLanguage()); + $templatePath = Paths::EmailTemplates($this->page->GetUpdatedLanguage()); $saveResult = $this->filesystem->Save($templatePath, str_replace('.tpl', '-custom.tpl', $templateName), $this->page->GetTemplateContents()); $this->filesystem->FlushSmartyCache(); diff --git a/lib/Server/FormKeys.php b/lib/Server/FormKeys.php index 631a3d9fb..1dc168259 100644 --- a/lib/Server/FormKeys.php +++ b/lib/Server/FormKeys.php @@ -89,6 +89,7 @@ private function __construct() public const ENABLE_AUTO_RELEASE = 'ENABLE_AUTO_RELEASE'; public const EMAIL_CONTENTS = 'EMAIL_CONTENTS'; public const EMAIL_TEMPLATE_NAME = 'EMAIL_TEMPLATE_NAME'; + public const EMAIL_TEMPLATE_LANGUAGE = 'EMAIL_TEMPLATE_LANGUAGE'; public const FIRST_NAME = 'fname'; public const FAVICON_FILE = 'FAVICON_FILE'; diff --git a/tpl/Admin/Configuration/manage_email_templates.tpl b/tpl/Admin/Configuration/manage_email_templates.tpl index 9a99cd4b5..e53b77cd8 100644 --- a/tpl/Admin/Configuration/manage_email_templates.tpl +++ b/tpl/Admin/Configuration/manage_email_templates.tpl @@ -15,18 +15,18 @@ -
- -
+
+
+ +
-
-
- +
+
@@ -41,8 +41,8 @@ {csrf_token} - -
+
+ -
-
- -
+ +
+ +
From 6059360af6ae8f3e706200c8b8afdfbdc173f4c6 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sun, 29 Sep 2024 09:29:57 +0000 Subject: [PATCH 09/10] Change ReservationShareMail property name It conflicts with the now protected email property --- lib/Email/Messages/ReservationShareEmail.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Email/Messages/ReservationShareEmail.php b/lib/Email/Messages/ReservationShareEmail.php index bba5460cd..5d6b0adb1 100644 --- a/lib/Email/Messages/ReservationShareEmail.php +++ b/lib/Email/Messages/ReservationShareEmail.php @@ -7,7 +7,7 @@ class ReservationShareEmail extends ReservationEmailMessage /** * @var string */ - private $email; + private $emailToShare; public function __construct(User $reservationOwner, $emailToShare, ReservationSeries $reservationSeries, IAttributeRepository $attributeRepository, IUserRepository $userRepository) { @@ -16,12 +16,12 @@ public function __construct(User $reservationOwner, $emailToShare, ReservationSe $this->reservationOwner = $reservationOwner; $this->reservationSeries = $reservationSeries; $this->timezone = $reservationOwner->Timezone(); - $this->email = $emailToShare; + $this->emailToShare = $emailToShare; } public function To() { - return [new EmailAddress($this->email)]; + return [new EmailAddress($this->emailToShare)]; } public function Subject() From d294f8adc141c8257a46ce5fc4e31b819a604e5e Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sun, 29 Sep 2024 09:30:43 +0000 Subject: [PATCH 10/10] Fix unit test for updating email template refs #424 --- .../Admin/ManageEmailTemplatesPresenterTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Presenters/Admin/ManageEmailTemplatesPresenterTest.php b/tests/Presenters/Admin/ManageEmailTemplatesPresenterTest.php index f90f5e306..ed428b983 100644 --- a/tests/Presenters/Admin/ManageEmailTemplatesPresenterTest.php +++ b/tests/Presenters/Admin/ManageEmailTemplatesPresenterTest.php @@ -74,11 +74,12 @@ public function testUpdatesEmailTemplate() $this->page->_UpdatedTemplateName = $templateName; $this->page->_TemplateContents = $contents; $this->page->_Language = 'en_us'; + $this->page->_UpdatedLanguage = 'cz'; $this->presenter->UpdateEmailTemplate(); $this->assertEquals($contents, $this->fileSystem->_AddedFileContents); - $this->assertEquals(Paths::EmailTemplates('en_us'), $this->fileSystem->_AddedFilePath); + $this->assertEquals(Paths::EmailTemplates('cz'), $this->fileSystem->_AddedFilePath); $this->assertEquals('template-custom.tpl', $this->fileSystem->_AddedFileName); } } @@ -91,6 +92,7 @@ class FakeManageEmailTemplatesPage extends ManageEmailTemplatesPage public $_BoundTemplateContents; public $_TemplateContents; public $_Language; + public $_UpdatedLanguage; public $_SaveResult = true; public function BindTemplateNames($templates) @@ -123,6 +125,11 @@ public function GetLanguage() return $this->_Language; } + public function GetUpdatedLanguage(): string + { + return $this->_UpdatedLanguage; + } + public function SetSaveResult($saveResult) { $this->_SaveResult = $saveResult;