From 90e1a949623ead173c0952f802d7b5c5487251b1 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 5 Oct 2018 15:35:14 +0200 Subject: Make application name configurable * Added app_name configuration option * Extended `EngelsystemMailer` to prepend the application name to all mails Closes #426 --- config/config.default.php | 5 ++- includes/engelsystem.php | 4 +- includes/mailer/shifts_mailer.php | 8 ++-- includes/mailer/users_mailer.php | 7 ++- includes/pages/guest_login.php | 5 ++- includes/pages/user_atom.php | 2 +- includes/pages/user_ical.php | 2 +- includes/view/EventConfig_view.php | 3 +- includes/view/User_view.php | 5 ++- resources/lang/de_DE.UTF-8/LC_MESSAGES/default.mo | Bin 45040 -> 44968 bytes resources/lang/de_DE.UTF-8/LC_MESSAGES/default.po | 22 ++++++---- resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.mo | Bin 41310 -> 41256 bytes resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.po | 17 +++++--- resources/views/emails/mail.twig | 4 +- resources/views/layouts/app.twig | 2 +- resources/views/layouts/maintenance.html | 6 +-- resources/views/layouts/parts/navbar.twig | 2 +- src/Mail/EngelsystemMailer.php | 40 +++++++++++++++++ src/Mail/MailerServiceProvider.php | 3 +- tests/Unit/Mail/EngelsystemMailerTest.php | 50 ++++++++++++++++++++++ tests/Unit/Mail/MailerServiceProviderTest.php | 4 +- 21 files changed, 153 insertions(+), 38 deletions(-) diff --git a/config/config.default.php b/config/config.default.php index 56ac6e6a..4207754b 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -17,6 +17,9 @@ return [ // Enable maintenance mode (show a static page) 'maintenance' => (bool)env('MAINTENANCE', false), + // Application name (not the event name!) + 'app_name' => env('APP_NAME', 'Engelsystem'), + // Set to development to enable debugging messages 'environment' => env('ENVIRONMENT', 'production'), @@ -36,7 +39,7 @@ return [ 'from' => [ // From address of all emails 'address' => env('MAIL_FROM_ADDRESS', 'noreply@engelsystem.de'), - 'name' => env('MAIL_FROM_NAME', 'Engelsystem') + 'name' => env('MAIL_FROM_NAME', env('APP_NAME', 'Engelsystem')) ], 'host' => env('MAIL_HOST', 'localhost'), diff --git a/includes/engelsystem.php b/includes/engelsystem.php index a5dee186..caebe09b 100644 --- a/includes/engelsystem.php +++ b/includes/engelsystem.php @@ -16,7 +16,9 @@ require __DIR__ . '/includes.php'; * Check for maintenance */ if ($app->get('config')->get('maintenance')) { - echo file_get_contents(__DIR__ . '/../resources/views/layouts/maintenance.html'); + $maintenance = file_get_contents(__DIR__ . '/../resources/views/layouts/maintenance.html'); + $maintenance = str_replace('%APP_NAME%', $app->get('config')->get('app_name'), $maintenance); + echo $maintenance; die(); } diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index 4dd430d3..0c4e381c 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -65,7 +65,7 @@ function mail_shift_change($old_shift, $new_shift) if ($user['email_shiftinfo']) { engelsystem_email_to_user( $user, - '[engelsystem] ' . __('Your Shift has changed'), + __('Your Shift has changed'), $message, true ); @@ -90,7 +90,7 @@ function mail_shift_delete($shift) foreach ($users as $user) { if ($user['email_shiftinfo']) { - engelsystem_email_to_user($user, '[engelsystem] ' . __('Your Shift was deleted'), $message, true); + engelsystem_email_to_user($user, __('Your Shift was deleted'), $message, true); } } } @@ -113,7 +113,7 @@ function mail_shift_assign($user, $shift) $message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n"; $message .= $room['Name'] . "\n"; - engelsystem_email_to_user($user, '[engelsystem] ' . __('Assigned to Shift'), $message, true); + engelsystem_email_to_user($user, __('Assigned to Shift'), $message, true); } /** @@ -134,5 +134,5 @@ function mail_shift_removed($user, $shift) $message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n"; $message .= $room['Name'] . "\n"; - engelsystem_email_to_user($user, '[engelsystem] ' . __('Removed from Shift'), $message, true); + engelsystem_email_to_user($user, __('Removed from Shift'), $message, true); } diff --git a/includes/mailer/users_mailer.php b/includes/mailer/users_mailer.php index 5f1e6e79..23a13806 100644 --- a/includes/mailer/users_mailer.php +++ b/includes/mailer/users_mailer.php @@ -8,7 +8,10 @@ function mail_user_delete($user) { return engelsystem_email_to_user( $user, - '[engelsystem] ' . __('Your account has been deleted'), - __('Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven.') + __('Your account has been deleted'), + __( + 'Your %s account has been deleted. If you have any questions regarding your account deletion, please contact heaven.', + [config('app_name')] + ) ); } diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 797aaea7..95e63bbc 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -309,7 +309,10 @@ function guest_register() form_email('mail', __('E-Mail') . ' ' . entry_required(), $mail), form_checkbox( 'email_shiftinfo', - __('The engelsystem is allowed to send me an email (e.g. when my shifts change)'), + __( + 'The %s is allowed to send me an email (e.g. when my shifts change)', + [config('app_name')] + ), $email_shiftinfo ), form_checkbox( diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index 9934fb92..f6a67a15 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -47,7 +47,7 @@ function make_atom_entries_from_news($news_entries) $request = app('request'); $html = ' - Engelsystem + ' . config('app_name') . ' ' . $request->getHttpHost() . htmlspecialchars(preg_replace( '#[&?]key=[a-f\d]{32}#', diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php index 3430c3b3..f7ed64dd 100644 --- a/includes/pages/user_ical.php +++ b/includes/pages/user_ical.php @@ -36,7 +36,7 @@ function send_ical_from_shifts($shifts) { header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=shifts.ics'); - $output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n"; + $output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//" . config('app_name') . "//DE\r\nCALSCALE:GREGORIAN\r\n"; foreach ($shifts as $shift) { $output .= make_ical_entry_from_shift($shift); } diff --git a/includes/view/EventConfig_view.php b/includes/view/EventConfig_view.php index cd657c67..730593b1 100644 --- a/includes/view/EventConfig_view.php +++ b/includes/view/EventConfig_view.php @@ -1,6 +1,7 @@ ENGELSYSTEM' + $name . ' ' . Str::upper(config('app_name')) ), 2) ]); diff --git a/includes/view/User_view.php b/includes/view/User_view.php index ddf49885..fb541619 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -54,7 +54,10 @@ function User_settings_view( form_text('mail', __('E-Mail') . ' ' . entry_required(), $user_source['email']), form_checkbox( 'email_shiftinfo', - __('The engelsystem is allowed to send me an email (e.g. when my shifts change)'), + __( + 'The %s is allowed to send me an email (e.g. when my shifts change)', + [config('app_name')] + ), $user_source['email_shiftinfo'] ), form_checkbox( diff --git a/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.mo b/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.mo index 4909145a..a1765a6b 100644 Binary files a/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.mo and b/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.mo differ diff --git a/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.po b/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.po index 54e819c8..263d1641 100644 --- a/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.po +++ b/resources/lang/de_DE.UTF-8/LC_MESSAGES/default.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Engelsystem 2.0\n" "POT-Creation-Date: 2017-12-29 19:01+0100\n" -"PO-Revision-Date: 2018-09-17 12:10+0200\n" +"PO-Revision-Date: 2018-10-05 15:35+0200\n" "Last-Translator: msquare \n" "Language-Team: \n" "Language: de_DE\n" @@ -669,16 +669,18 @@ msgid "Hi %s," msgstr "Hallo %s," #: /Users/msquare/workspace/projects/engelsystem/includes/helper/email_helper.php:21 -msgid "here is a message for you from the engelsystem:" -msgstr "hier ist eine Nachricht aus dem Engelsystem für Dich:" +#, php-format +msgid "here is a message for you from the %s:" +msgstr "hier ist eine Nachricht aus dem %s für Dich:" #: /Users/msquare/workspace/projects/engelsystem/includes/helper/email_helper.php:23 +#, php-format msgid "" "This email is autogenerated and has not been signed. You got this email " -"because you are registered in the engelsystem." +"because you are registered in the %s." msgstr "" "Diese E-Mail wurde automatisch generiert und muss daher nicht unterschrieben " -"werden. Du hast diese E-Mail bekommen, weil Du im Engelsystem registriert " +"werden. Du hast diese E-Mail bekommen, weil Du im %s registriert " "bist." #: /Users/msquare/workspace/projects/engelsystem/includes/mailer/shifts_mailer.php:15 @@ -747,11 +749,12 @@ msgid "Your account has been deleted" msgstr "Dein Konto wurde gelöscht." #: /Users/msquare/workspace/projects/engelsystem/includes/mailer/users_mailer.php:12 +#, php-format msgid "" -"Your angelsystem account has been deleted. If you have any questions " +"Your %s account has been deleted. If you have any questions " "regarding your account deletion, please contact heaven." msgstr "" -"Dein Engelsystem-Konto wurde gelöscht. Wenn Du dazu Fragen hast, kontaktiere " +"Dein %s-Konto wurde gelöscht. Wenn Du dazu Fragen hast, kontaktiere " "bitte den Himmel." #: /Users/msquare/workspace/projects/engelsystem/includes/pages/admin_active.php:10 @@ -1591,10 +1594,11 @@ msgstr "" #: /Users/msquare/workspace/projects/engelsystem/includes/pages/guest_login.php:316 #: /Users/msquare/workspace/projects/engelsystem/includes/view/User_view.php:55 +#, php-format msgid "" -"The engelsystem is allowed to send me an email (e.g. when my shifts change)" +"The %s is allowed to send me an email (e.g. when my shifts change)" msgstr "" -"Das Engelsystem darf mir E-Mails senden (z.B. wenn sich meine Schichten " +"Das %s darf mir E-Mails senden (z.B. wenn sich meine Schichten " "ändern)" #: /Users/msquare/workspace/projects/engelsystem/includes/pages/guest_login.php:321 diff --git a/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.mo b/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.mo index 5ad48984..95251feb 100644 Binary files a/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.mo and b/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.mo differ diff --git a/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.po b/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.po index 19b08ad7..e7307e5d 100644 --- a/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.po +++ b/resources/lang/pt_BR.UTF.8/LC_MESSAGES/pt_BR.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Engelsystem 2.0\n" "POT-Creation-Date: 2017-04-25 05:23+0200\n" -"PO-Revision-Date: 2018-09-17 12:11+0200\n" +"PO-Revision-Date: 2018-10-05 15:35+0200\n" "Last-Translator: samba \n" "Language-Team: \n" "Language: pt_BR\n" @@ -560,14 +560,16 @@ msgid "Hi %s," msgstr "Oi %s," #: includes/helper/email_helper.php:12 -msgid "here is a message for you from the engelsystem:" -msgstr "aqui está uma mensagem do engelsystem para você:" +#, php-format +msgid "here is a message for you from the %s:" +msgstr "aqui está uma mensagem do %s para você:" #: includes/helper/email_helper.php:12 +#, php-format msgid "" "This email is autogenerated and has not been signed. You got this email " -"because you are registered in the engelsystem." -msgstr "Você recebeu esse email porque está registrado no engelsystem." +"because you are registered in the %s." +msgstr "Você recebeu esse email porque está registrado no %s." #: includes/mailer/shifts_mailer.php:10 msgid "A Shift you are registered on has changed:" @@ -1344,10 +1346,11 @@ msgstr "" "Esse script criará uma conta no sistema." #: includes/pages/guest_login.php:229 includes/view/User_view.php:50 +#, php-format msgid "" -"The engelsystem is allowed to send me an email (e.g. when my shifts change)" +"The %s is allowed to send me an email (e.g. when my shifts change)" msgstr "" -"Permito que o engelsystem me envie emails (por exemplo, quando meus turnos " +"Permito que o %s me envie emails (por exemplo, quando meus turnos " "mudam)" #: includes/pages/guest_login.php:230 includes/view/User_view.php:51 diff --git a/resources/views/emails/mail.twig b/resources/views/emails/mail.twig index f5ac5860..c99fc104 100644 --- a/resources/views/emails/mail.twig +++ b/resources/views/emails/mail.twig @@ -1,6 +1,6 @@ {{ __('Hi %s,', [user]) }} -{{ __('here is a message for you from the engelsystem:') }} +{{ __('here is a message for you from the %s:', [config('app_name')]) }} {{ message|raw }} -{{ __('This email is autogenerated and has not been signed. You got this email because you are registered in the engelsystem.') }} +{{ __('This email is autogenerated and has not been signed. You got this email because you are registered in the %s.', [config('app_name')]) }} diff --git a/resources/views/layouts/app.twig b/resources/views/layouts/app.twig index d8f8d10f..ed0d96af 100644 --- a/resources/views/layouts/app.twig +++ b/resources/views/layouts/app.twig @@ -3,7 +3,7 @@ {% block head %} - {% block title %}{{ title }}{% endblock %} - Engelsystem + {% block title %}{{ title }}{% endblock %} - {{ config('app_name') }} diff --git a/resources/views/layouts/maintenance.html b/resources/views/layouts/maintenance.html index f7ab5772..85b95168 100644 --- a/resources/views/layouts/maintenance.html +++ b/resources/views/layouts/maintenance.html @@ -1,7 +1,7 @@ - Maintenance - Engelsystem + Maintenance - %APP_NAME% @@ -19,7 +19,7 @@ - ENGELSYSTEM + %APP_NAME%