diff --git a/Settings.php b/Settings.php index 969905c..ae8eb24 100644 --- a/Settings.php +++ b/Settings.php @@ -1,277 +1,277 @@ -userService = app(UserService::class); - $this->treeService = app(TreeService::class); - - $users = []; - foreach ($this->userService->all() as $u) $users[$u->username()] = $u->username(); - $this->allUsers = $users; - - $trees = []; - foreach ($this->treeService->all() as $t) $trees[$t->name()] = $t->name(); - $this->allTrees = $trees; - - $formats = []; - foreach (["png", "svg"] as $f) $formats[$f] = $f; - $this->allImageFormat = $formats; - } - - #region General - - public function getUsers(): array - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_USERS'); - if (empty($pref)) return $this->getAllUsers(); - return explode(",", $pref); - } - - public function getAllUsers(): array { return $this->allUsers; } - - public function setUsers($value) { Site::setPreference('EVANG_MAILSYSTEM_USERS', implode(',', $value)); } - - public function getTrees(): array - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_TREES'); - if (empty($pref)) return $this->getAllTrees(); - return explode(",", $pref); - } - - public function getAllTrees(): array { return $this->allTrees; } - - public function setTrees($value) { Site::setPreference('EVANG_MAILSYSTEM_TREES', implode(',', $value)); } - - - public function getEmpty(): bool - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_EMPTY'); - if (empty($pref)) return false; - return (bool)$pref; - } - - public function setEmpty($value) { Site::setPreference('EVANG_MAILSYSTEM_EMPTY', $value); } - - public function setDays($value) { Site::setPreference('EVANG_MAILSYSTEM_DAYS', $value); } - - public function getAllImageDataType(): array - { - return [ - "link" => I18N::translate("Direct URLs"), - "data" => I18N::translate("Data URLs"), - "none" => I18N::translate("No images") - ]; - } - - public function getImageDataType(): string - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_IMAGEDATA'); - if (empty($pref)) return "data"; - return $pref; - } - - public function setImageDataType($value) { Site::setPreference('EVANG_MAILSYSTEM_IMAGEDATA', $value); } - - public function getAllImageFormat(): array { return $this->allImageFormat; } - - public function getImageFormat(): string - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_IMAGEFORMAT'); - if (empty($pref)) return "png"; - return $pref; - } - - public function setImageFormat($value) { Site::setPreference('EVANG_MAILSYSTEM_IMAGEFORMAT', $value); } - - #endregion - - - #region News - - public function getNewsEnabled(): bool - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_NEWS_ENABLED'); - if (!isset($pref)) return true; - return (bool)$pref; - } - - public function setNewsEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_NEWS_ENABLED', $value); } - - #endregion - - - #region Change-list - - public function getChangelistEnabled(): bool - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_CHANGE_ENABLED'); - if (!isset($pref)) return true; - return (bool)$pref; - } - - public function setChangelistEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_CHANGE_ENABLED', $value); } - - public function getAllChangelistTags(): array - { - return [ - Individual::RECORD_TYPE => I18N::translate("Individual"), - Family::RECORD_TYPE => I18N::translate("Family"), - Media::RECORD_TYPE => I18N::translate("Media"), - Note::RECORD_TYPE => I18N::translate("Note"), - Source::RECORD_TYPE => I18N::translate("Source"), - Submitter::RECORD_TYPE => I18N::translate("Submitter"), - Repository::RECORD_TYPE => I18N::translate("Repository")]; - } - - public function getChangelistTags(): array - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_CHANGE_TAGS'); - if (empty($pref)) return [Individual::RECORD_TYPE, Family::RECORD_TYPE]; - return explode(",", $pref); - } - - public function setChangelistTags($value) { Site::setPreference('EVANG_MAILSYSTEM_CHANGE_TAGS', implode(',', $value)); } - - #endregion - - #region Anniversaries - - public function getAnniversariesEnabled(): bool - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_ENABLED'); - if (!isset($pref)) return true; - return (bool)$pref; - } - - public function setAnniversariesEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_ENABLED', $value); } - - public function getAnniversariesDeceased(): bool - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_DECEASED'); - if (!isset($pref)) return false; - return (bool)$pref; - } - - public function setAnniversariesDeceased($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_DECEASED', $value); } - - public function getAllAnniversariesTags(): array - { - $data = []; - foreach (array_merge(Gedcom::BIRTH_EVENTS, Gedcom::DEATH_EVENTS) as $tag) $data[$tag] = Registry::elementFactory()->make("INDI:" . $tag)->label(); - foreach (array_merge(Gedcom::MARRIAGE_EVENTS) as $tag) $data[$tag] = Registry::elementFactory()->make("FAM:" . $tag)->label(); - return $data; - } - - public function getAnniversariesTags(): array - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_TAGS'); - if (empty($pref)) return ["BIRT"]; - return explode(",", $pref); - } - - public function setAnniversariesTags($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_TAGS', implode(',', $value)); } - - #endregion - - - #region Infos - - public function setLastSend(?DateTimeImmutable $date) - { - Site::setPreference('EVANG_MAILSYSTEM_LASTCRONDATE', $date == null ? "" : $date->format("Y-m-d")); - } - - public function getNextSend(): DateTimeImmutable - { - try { - return $this->getThisSend()->add(new DateInterval("P" . $this->getDays() . "D")); - } catch (Exception $e) { - return $this->getThisSend(); - } - } - - public function getThisSend(): DateTimeImmutable - { - $lastCronDate = $this->getLastSend(); - $today = new DateTimeImmutable("midnight"); - if ($lastCronDate == null) return $today; - try { - return $lastCronDate->add(new DateInterval('P' . $this->getDays() . 'D')); - } catch (Exception $e) { - return $today; - } - } - - public function getLastSend(): ?DateTimeImmutable - { - $lastCronTxt = Site::getPreference('EVANG_MAILSYSTEM_LASTCRONDATE'); - if (empty($lastCronTxt)) return null; - try { - return new DateTimeImmutable($lastCronTxt); - } catch (Exception $e) { - /* The date of the last send couldn't be understood, so we send the mails to give it a known value */ - return null; - } - } - - public function getDays(): int - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_DAYS'); - if (empty($pref)) return 7; - return (int)$pref; - } - - #endregion - - - #region Footer - - public function getFooterEnabled(): string - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_FOOTER_ENABLED'); - if (!isset($pref)) return true; - return $pref; - } - - public function setFooterEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_FOOTER_ENABLED', $value); } - - public function getFooterMessage(): string - { - $pref = Site::getPreference('EVANG_MAILSYSTEM_FOOTER_MESSAGE'); - if (empty($pref)) return sprintf("This email was autogenerated by Webtrees and programmed with ❤ by %s", - "Evan Galli"); - return $pref; - } - - public function setFooterMessage($value) { Site::setPreference('EVANG_MAILSYSTEM_FOOTER_MESSAGE', $value); } - - #endregion +userService = app(UserService::class); + $this->treeService = app(TreeService::class); + + $users = []; + foreach ($this->userService->all() as $u) $users[$u->username()] = $u->username(); + $this->allUsers = $users; + + $trees = []; + foreach ($this->treeService->all() as $t) $trees[$t->name()] = $t->name(); + $this->allTrees = $trees; + + $formats = []; + foreach (["png", "svg"] as $f) $formats[$f] = $f; + $this->allImageFormat = $formats; + } + + #region General + + public function getUsers(): array + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_USERS'); + if (empty($pref)) return $this->getAllUsers(); + return explode(",", $pref); + } + + public function getAllUsers(): array { return $this->allUsers; } + + public function setUsers($value) { Site::setPreference('EVANG_MAILSYSTEM_USERS', implode(',', $value)); } + + public function getTrees(): array + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_TREES'); + if (empty($pref)) return $this->getAllTrees(); + return explode(",", $pref); + } + + public function getAllTrees(): array { return $this->allTrees; } + + public function setTrees($value) { Site::setPreference('EVANG_MAILSYSTEM_TREES', implode(',', $value)); } + + + public function getEmpty(): bool + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_EMPTY'); + if (empty($pref)) return false; + return (bool)$pref; + } + + public function setEmpty($value) { Site::setPreference('EVANG_MAILSYSTEM_EMPTY', $value); } + + public function setDays($value) { Site::setPreference('EVANG_MAILSYSTEM_DAYS', $value); } + + public function getAllImageDataType(): array + { + return [ + "link" => I18N::translate("Direct URLs"), + "data" => I18N::translate("Data URLs"), + "none" => I18N::translate("No images") + ]; + } + + public function getImageDataType(): string + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_IMAGEDATA'); + if (empty($pref)) return "data"; + return $pref; + } + + public function setImageDataType($value) { Site::setPreference('EVANG_MAILSYSTEM_IMAGEDATA', $value); } + + public function getAllImageFormat(): array { return $this->allImageFormat; } + + public function getImageFormat(): string + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_IMAGEFORMAT'); + if (empty($pref)) return "png"; + return $pref; + } + + public function setImageFormat($value) { Site::setPreference('EVANG_MAILSYSTEM_IMAGEFORMAT', $value); } + + #endregion + + + #region News + + public function getNewsEnabled(): bool + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_NEWS_ENABLED'); + if (!isset($pref)) return true; + return (bool)$pref; + } + + public function setNewsEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_NEWS_ENABLED', $value); } + + #endregion + + + #region Change-list + + public function getChangelistEnabled(): bool + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_CHANGE_ENABLED'); + if (!isset($pref)) return true; + return (bool)$pref; + } + + public function setChangelistEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_CHANGE_ENABLED', $value); } + + public function getAllChangelistTags(): array + { + return [ + Individual::RECORD_TYPE => I18N::translate("Individual"), + Family::RECORD_TYPE => I18N::translate("Family"), + Media::RECORD_TYPE => I18N::translate("Media"), + Note::RECORD_TYPE => I18N::translate("Note"), + Source::RECORD_TYPE => I18N::translate("Source"), + Submitter::RECORD_TYPE => I18N::translate("Submitter"), + Repository::RECORD_TYPE => I18N::translate("Repository")]; + } + + public function getChangelistTags(): array + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_CHANGE_TAGS'); + if (empty($pref)) return [Individual::RECORD_TYPE, Family::RECORD_TYPE]; + return explode(",", $pref); + } + + public function setChangelistTags($value) { Site::setPreference('EVANG_MAILSYSTEM_CHANGE_TAGS', implode(',', $value)); } + + #endregion + + #region Anniversaries + + public function getAnniversariesEnabled(): bool + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_ENABLED'); + if (!isset($pref)) return true; + return (bool)$pref; + } + + public function setAnniversariesEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_ENABLED', $value); } + + public function getAnniversariesDeceased(): bool + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_DECEASED'); + if (!isset($pref)) return false; + return (bool)$pref; + } + + public function setAnniversariesDeceased($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_DECEASED', $value); } + + public function getAllAnniversariesTags(): array + { + $data = []; + foreach (array_merge(Gedcom::BIRTH_EVENTS, Gedcom::DEATH_EVENTS) as $tag) $data[$tag] = Registry::elementFactory()->make("INDI:" . $tag)->label(); + foreach (array_merge(Gedcom::MARRIAGE_EVENTS) as $tag) $data[$tag] = Registry::elementFactory()->make("FAM:" . $tag)->label(); + return $data; + } + + public function getAnniversariesTags(): array + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_ANNIV_TAGS'); + if (empty($pref)) return ["BIRT"]; + return explode(",", $pref); + } + + public function setAnniversariesTags($value) { Site::setPreference('EVANG_MAILSYSTEM_ANNIV_TAGS', implode(',', $value)); } + + #endregion + + + #region Infos + + public function setLastSend(?DateTimeImmutable $date) + { + Site::setPreference('EVANG_MAILSYSTEM_LASTCRONDATE', $date == null ? "" : $date->format("Y-m-d")); + } + + public function getNextSend(): DateTimeImmutable + { + try { + return $this->getThisSend()->add(new DateInterval("P" . $this->getDays() . "D")); + } catch (Exception $e) { + return $this->getThisSend(); + } + } + + public function getThisSend(): DateTimeImmutable + { + $lastCronDate = $this->getLastSend(); + $today = new DateTimeImmutable("midnight"); + if ($lastCronDate == null) return $today; + try { + return $lastCronDate->add(new DateInterval('P' . $this->getDays() . 'D')); + } catch (Exception $e) { + return $today; + } + } + + public function getLastSend(): ?DateTimeImmutable + { + $lastCronTxt = Site::getPreference('EVANG_MAILSYSTEM_LASTCRONDATE'); + if (empty($lastCronTxt)) return null; + try { + return new DateTimeImmutable($lastCronTxt); + } catch (Exception $e) { + /* The date of the last send couldn't be understood, so we send the mails to give it a known value */ + return null; + } + } + + public function getDays(): int + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_DAYS'); + if (empty($pref)) return 7; + return (int)$pref; + } + + #endregion + + + #region Footer + + public function getFooterEnabled(): string + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_FOOTER_ENABLED'); + if (!isset($pref)) return true; + return $pref; + } + + public function setFooterEnabled($value) { Site::setPreference('EVANG_MAILSYSTEM_FOOTER_ENABLED', $value); } + + public function getFooterMessage(): string + { + $pref = Site::getPreference('EVANG_MAILSYSTEM_FOOTER_MESSAGE'); + if (empty($pref)) return I18N::translate("This email was autogenerated by Webtrees and programmed with ❤ by %s", + "Evan Galli"); + return $pref; + } + + public function setFooterMessage($value) { Site::setPreference('EVANG_MAILSYSTEM_FOOTER_MESSAGE', $value); } + + #endregion } \ No newline at end of file diff --git a/module.php b/module.php index 03557f1..74dda74 100644 --- a/module.php +++ b/module.php @@ -1,67 +1,68 @@ -settings; } - - public function __construct() - { - $loader = new ClassLoader(); - $loader->addPsr4('EvanG\\Modules\\MailSystem\\', __DIR__); - $loader->register(); - $this->settings = new Settings(); - } - - public function boot(): void - { - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); - - /** @var RouterContainer $router */ $router = app(RouterContainer::class); - - $map = $router->getMap(); - $module = $this; - $map->get(RequestHandler::class, RequestHandler::ROUTE_PREFIX . '/{action}', new RequestHandler($module)); - - $map->attach('', '/admin', static function (Map $router) use ($module) { - $router->extras([ - 'middleware' => [ - AuthAdministrator::class, - ], - ]); - $router->get(AdminPage::class, '/mail-sys', new AdminPage($module)); - $router->get(AdminAction::class, '/mail-sys/save', new AdminAction($module)); - }); - } - - public function title(): string { return 'Mail System'; } - public function description(): string { return 'Sends out newsletters at regular intervals'; } - public function customModuleAuthorName(): string { return 'EvanG'; } - public function customModuleSupportUrl(): string { return 'https://github.com/06Games/Webtrees-MailSystem'; } - public function customModuleVersion(): string { return '2.3.5'; } - public function customModuleLatestVersionUrl(): string { return 'https://github.com/06Games/Webtrees-MailSystem/raw/main/version.txt'; } - public function resourcesFolder(): string { return __DIR__ . '/resources/'; } - public function getConfigLink(): string { return route(AdminPage::class); } - public function customTranslations(string $language): array - { - $languageFile = $this->resourcesFolder() . 'lang/' . $language . '.mo'; - return file_exists($languageFile) ? (new Translation($languageFile))->asArray() : []; - } -} -return new MailSystem(); +settings; } + + public function __construct() + { + $loader = new ClassLoader(); + $loader->addPsr4('EvanG\\Modules\\MailSystem\\', __DIR__); + $loader->register(); + $this->settings = new Settings(); + } + + public function boot(): void + { + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); + + /** @var RouterContainer $router */ $router = app(RouterContainer::class); + + $map = $router->getMap(); + $module = $this; + $map->get(RequestHandler::class, RequestHandler::ROUTE_PREFIX . '/{action}', new RequestHandler($module)); + + $map->attach('', '/admin', static function (Map $router) use ($module) { + $router->extras([ + 'middleware' => [ + AuthAdministrator::class, + ], + ]); + $router->get(AdminPage::class, '/mail-sys', new AdminPage($module)); + $router->get(AdminAction::class, '/mail-sys/save', new AdminAction($module)); + }); + } + + public function title(): string { return 'Mail System'; } + public function description(): string { return I18N::translate('Sends out newsletters at regular intervals'); } + public function customModuleAuthorName(): string { return 'EvanG'; } + public function customModuleSupportUrl(): string { return 'https://github.com/06Games/Webtrees-MailSystem'; } + public function customModuleVersion(): string { return '2.3.5'; } + public function customModuleLatestVersionUrl(): string { return 'https://github.com/06Games/Webtrees-MailSystem/raw/main/version.txt'; } + public function resourcesFolder(): string { return __DIR__ . '/resources/'; } + public function getConfigLink(): string { return route(AdminPage::class); } + public function customTranslations(string $language): array + { + $languageFile = $this->resourcesFolder() . 'lang/' . $language . '.mo'; + return file_exists($languageFile) ? (new Translation($languageFile))->asArray() : []; + } +} +return new MailSystem(); diff --git a/resources/lang/en.po b/resources/lang/en.po index 83fc7a4..0be41ab 100644 --- a/resources/lang/en.po +++ b/resources/lang/en.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: Webtrees Mail System\n" -"POT-Creation-Date: 2023-09-14 22:27+0200\n" +"POT-Creation-Date: 2024-01-30 21:22+0100\n" "PO-Revision-Date: \n" "Last-Translator: Evan Galli \n" "Language-Team: \n" @@ -10,7 +10,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Poedit 3.3.2\n" +"X-Generator: Poedit 3.4.1\n" "X-Poedit-Basepath: ../..\n" "X-Poedit-KeywordsList: plural:1,2;translate;translatePlural:1,2\n" "X-Poedit-SearchPath-0: AdminAction.php\n" @@ -19,6 +19,7 @@ msgstr "" "X-Poedit-SearchPath-3: resources/views\n" "X-Poedit-SearchPath-4: Settings.php\n" "X-Poedit-SearchPath-5: Helpers\n" +"X-Poedit-SearchPath-6: module.php\n" #: AdminAction.php:49 msgid "The Mail System preferences have been updated." @@ -72,6 +73,15 @@ msgstr "Submitter" msgid "Repository" msgstr "Repository" +#: Settings.php:269 +#, php-format +msgid "This email was autogenerated by Webtrees and programmed with ❤ by %s" +msgstr "This email was autogenerated by Webtrees and programmed with ❤ by %s" + +#: module.php:55 +msgid "Sends out newsletters at regular intervals" +msgstr "Sends out newsletters at regular intervals" + #: resources/views/admin.phtml:19 msgid "Control panel" msgstr "Control panel" diff --git a/resources/lang/fr.po b/resources/lang/fr.po index c9c2c53..a05ad04 100644 --- a/resources/lang/fr.po +++ b/resources/lang/fr.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: webtrees-mail-system\n" -"POT-Creation-Date: 2023-09-14 22:27+0200\n" -"PO-Revision-Date: 2023-09-14 22:28+0200\n" +"POT-Creation-Date: 2024-01-30 21:22+0100\n" +"PO-Revision-Date: 2024-01-30 21:25+0100\n" "Last-Translator: Evan Galli \n" "Language-Team: French\n" "Language: fr\n" @@ -10,7 +10,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -"X-Generator: Poedit 3.3.2\n" +"X-Generator: Poedit 3.4.1\n" #: AdminAction.php:49 msgid "The Mail System preferences have been updated." @@ -64,6 +64,15 @@ msgstr "Fournisseur de données" msgid "Repository" msgstr "Dépôt d’archives" +#: Settings.php:269 +#, php-format +msgid "This email was autogenerated by Webtrees and programmed with ❤ by %s" +msgstr "Cet email a été autogénéré par Webtrees et programmé avec ❤ par %s" + +#: module.php:55 +msgid "Sends out newsletters at regular intervals" +msgstr "Envoi régulier de bulletins d'information" + #: resources/views/admin.phtml:19 msgid "Control panel" msgstr "Panneau de contrôle"