diff --git a/composer.json b/composer.json index 0c995a9..b883865 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,11 @@ "name":"Cliff Parnitzky", "email":"contao@cliff-parnitzky.de", "role":"Developer" + }, + { + "name":"Richard Henkenjohann", + "email":"richardhenkenjohann@googlemail.com", + "role":"Developer" } ], "support":{ @@ -18,10 +23,11 @@ }, "require":{ "php":">=5.3", - "contao/core":">=3.2.0,<3.5", + "contao/core":"~3.2", "contao-community-alliance/composer-plugin":"~2.0", "friends-of-contao/contao-associategroups":"~1.3", - "terminal42/notification_center":"~1.0" + "terminal42/notification_center":"~1.0", + "codefog/contao-haste":"~4.11" }, "conflict": { "contao/core":"3.4.0,3.4.1,3.4.2" @@ -32,9 +38,7 @@ "extra":{ "contao":{ "sources":{ - "system/modules/BirthdayMailer":"system/modules/BirthdayMailer", - "files/tiny_templates/birthdaymailer_default_de.html": "files/tiny_templates/birthdaymailer_default_de.html", - "files/tiny_templates/birthdaymailer_default_en.html": "files/tiny_templates/birthdaymailer_default_en.html" + "system/modules/BirthdayMailer":"system/modules/BirthdayMailer" } }, "branch-alias": { diff --git a/files/tiny_templates/birthdaymailer_default_de.html b/files/tiny_templates/birthdaymailer_default_de.html deleted file mode 100644 index f78b27b..0000000 --- a/files/tiny_templates/birthdaymailer_default_de.html +++ /dev/null @@ -1,4 +0,0 @@ -
##birthdaychild_salutation## ##birthdaychild_firstname## ##birthdaychild_lastname##,
-als Mitglied der Gruppe ##birthdaychild_groupname## gratulieren wir Ihnen recht herzlich zu Ihrem ##birthdaychild_age##. Geburtstag und wünschen Ihnen alles erdenklich Gute, viel Glück und vor allem Gesundheit.
-Genießen Sie Ihren ganz besonderen Ehrentag.
-Viele Grüße, ihr Contao [BirthdayMailer]
\ No newline at end of file diff --git a/files/tiny_templates/birthdaymailer_default_en.html b/files/tiny_templates/birthdaymailer_default_en.html deleted file mode 100644 index 5c67c15..0000000 --- a/files/tiny_templates/birthdaymailer_default_en.html +++ /dev/null @@ -1,4 +0,0 @@ -##welcoming_formally## ##birthdaychild_firstname## ##birthdaychild_lastname##,
-as a member of group ##birthdaymailer_groupname##, we heartily congratulate you on your ##birthdaychild_age##th birthday and wish you all the very best, good luck and health in particular.
-Enjoy your very special day.
-Best regards, yours Contao [BirthdayMailer]
\ No newline at end of file diff --git a/system/modules/BirthdayMailer/assets/.htaccess b/system/modules/BirthdayMailer/assets/.htaccess old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon.png b/system/modules/BirthdayMailer/assets/icon.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_1.png b/system/modules/BirthdayMailer/assets/icon_1.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_execute.png b/system/modules/BirthdayMailer/assets/icon_execute.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/assets/icon_root.png b/system/modules/BirthdayMailer/assets/icon_root.png old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/classes/BirthdayMailSender.php b/system/modules/BirthdayMailer/classes/BirthdayMailSender.php deleted file mode 100644 index 9125518..0000000 --- a/system/modules/BirthdayMailer/classes/BirthdayMailSender.php +++ /dev/null @@ -1,452 +0,0 @@ -. - * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL - */ - -/** - * Run in a custom namespace, so the class can be replaced - */ -namespace BirthdayMailer; - -/** - * Class BirthdayMailSender - * - * Provide methods to send the birthday emails - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - */ -class BirthdayMailSender extends \Backend -{ - // the default language will always be englisch - const DEFAULT_LANGUAGE = 'en'; - - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the sender manually from backend and get a result page. - */ - public function sendBirthdayMailManually() - { - if (TL_MODE == 'BE') - { - $result = $this->sendBirthdayMail(); - - // Create template object - $objTemplate = new \BackendTemplate('be_birthday-mailer'); - - $objTemplate->backLink = ''.$GLOBALS['TL_LANG']['MSC']['backBT'].''; - $objTemplate->headline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['headline']; - $objTemplate->sendingHeadline = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['sendingHeadline']; - $objTemplate->success = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['successMessage'], $result['success']); - - $objTemplate->failed = sizeof($result['failed']) > 0; - $objTemplate->failureMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureMessage'], sizeof($result['failed'])); - $objTemplate->failureTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureTableHead']; - $objTemplate->failures = $result['failed']; - $objTemplate->failureInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['failureInfo']; - - $objTemplate->aborted = sizeof($result['aborted']) > 0; - $objTemplate->abortionMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionMessage'], sizeof($result['aborted'])); - $objTemplate->abortionTableHead = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionTableHead']; - $objTemplate->abortions = $result['aborted']; - $objTemplate->abortionInfo = $GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['abortionInfo']; - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode']) - { - $objTemplate->developerMessage = sprintf($GLOBALS['TL_LANG']['tl_birthdaymailer']['manualExecution']['developerMessage'], $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeEmail']); - } - - return $this->replaceInsertTags($objTemplate->parse()); - } - return; - } - - /** - * Sends the birthday emails. - */ - public function sendBirthdayMail() - { - // first check if required extension 'associategroups' is installed - if (!in_array('associategroups', $this->Config->getActiveModules())) - { - $this->log('BirthdayMailSender: Extension "associategroups" is required!', 'BirthdayMailSender sendBirthdayMail()', TL_ERROR); - return false; - } - - $alreadySendTo = array(); - $notSendCauseOfError = array(); - $notSendCauseOfAbortion = array(); - - $config = $this->Database->prepare("SELECT tl_member.*, " - . "tl_member_group.name as memberGroupName, tl_member_group.disable as memberGroupDisable, tl_member_group.start as memberGroupStart, tl_member_group.stop as memberGroupStop, " - . "tl_birthdaymailer.sender as mailSender, tl_birthdaymailer.senderName as mailSenderName, tl_birthdaymailer.mailCopy as mailCopy, tl_birthdaymailer.mailBlindCopy as mailBlindCopy, " - . "tl_birthdaymailer.mailUseCustomText as mailUseCustomText, tl_birthdaymailer.mailTextKey as mailTextKey " - . "FROM tl_member " - . "JOIN tl_member_to_group ON tl_member_to_group.member_id = tl_member.id " - . "JOIN tl_member_group ON tl_member_group.id = tl_member_to_group.group_id " - . "JOIN tl_birthdaymailer ON tl_birthdaymailer.membergroup = tl_member_group.id " - . "ORDER BY tl_member.id, tl_birthdaymailer.sorting DESC") - ->execute(); - - if($config->numRows < 1) - { - return; - } - - while($config->next()) - { - if( - is_numeric($config->dateOfBirth) - && - ( - ( - $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode'] - && - $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeIgnoreDate'] - ) - || - ( - date("d.m") == date("d.m", $config->dateOfBirth) - ) - ) - && - ( - $this->isMemberActive($config) - && - $this->isMemberGroupActive($config) - && - $this->allowSendingDuplicates($alreadySendTo, $config) - ) - ) - { - // now check via custom hook, if sending should be aborted - $blnAbortSendMail = false; - if (isset($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'])) - { - foreach ($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'] as $callback) - { - $this->import($callback[0]); - $blnAbortSendMail = $this->$callback[0]->$callback[1]($config, $blnAbortSendMail); - } - } - - if (!$blnAbortSendMail) - { - if ($this->sendMail($config)) - { - $alreadySendTo[] = $config->id; - } - else - { - $notSendCauseOfError[] = array('id' => $config->id, 'firstname' => $config->firstname, 'lastname' => $config->lastname, 'email' => $config->email); - } - } - else - { - $notSendCauseOfAbortion[] = array('id' => $config->id, 'firstname' => $config->firstname, 'lastname' => $config->lastname, 'email' => $config->email); - } - } - } - - $this->log('BirthdayMailer: Daily sending of birthday mail finished. Send ' . sizeof($alreadySendTo) . ' emails. ' - . sizeof($notSendCauseOfError) . ' emails could not be send due to errors. ' - . sizeof($notSendCauseOfAbortion) . ' emails were aborted due to custom hooks. See birthdaymails.log for details.', 'BirthdayMailSender sendBirthdayMail()', TL_CRON); - - return array('success' => sizeof($alreadySendTo), 'failed' => $notSendCauseOfError, 'aborted' => $notSendCauseOfAbortion); - } - - /** - * Get the text for specific types for the email. Fallback ist to 'default' if no text is set. - * FALLBACK Chain: - * 1. check, if there is a text for the specified textKey and language (search in system/config/langconfig.php) - * 2. if nothing found, check, if there is a text for the specified textKey and 'en' (search in system/config/langconfig.php) - * 3. if nothing found, get default text in specified language - * 4. if nothing found, get default text in language 'en' - */ - private function getEmailText ($textType, $config, $language) - { - $text = ""; - - if ($config->mailUseCustomText) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][$language]; - - if (strlen($text) == 0 && $language != self::DEFAULT_LANGUAGE) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][self::DEFAULT_LANGUAGE]; - } - } - - if (strlen($text) == 0) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail']['default'][$textType]; - } - - $textReplaced = $this->replaceBirthdayMailerInsertTags($text, $config, $language); - - if ($textReplaced) - { - return $textReplaced; - } - - return $text; - } - - /** - * Send an email. - * @return boolean - */ - private function sendMail($config) - { - $language = $config->language; - if (strlen($language) == 0) - { - $language = self::DEFAULT_LANGUAGE; - } - - $this->loadLanguageFile('BirthdayMailer', $language); - - $emailSubject = $this->getEmailText('subject', $config, $language); - $emailText = $this->getEmailText('text', $config, $language); - $emailHtml = $this->getEmailText('html', $config, $language); - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode'] || $GLOBALS['TL_CONFIG']['birthdayMailerLogDebugInfo']) - { - $mailTextUsageOutput = $config->mailUseCustomText ? 'yes' : 'no'; - $this->log('BirthdayMailer: These are additional debugging information that will only be logged in developer mode or if debugging is enabled.' - . ' | Userlanguage = ' . $config->language - . ' | used language = ' . $language - . ' | mailTextUsage = ' . $mailTextUsageOutput - . ' | mailTextKey = ' . $config->mailTextKey - . ' | email = ' . $config->email - . ' | subject = ' . $emailSubject - . ' | text = ' . $emailText - . ' | html = ' . $emailHtml, 'BirthdayMailSender sendMail()', TL_CRON); - } - - $objEmail = new \Email(); - - $objEmail->logFile = 'birthdaymails.log'; - - $objEmail->from = $config->mailSender; - if (strlen($config->mailSenderName) > 0) - { - $objEmail->fromName = $config->mailSenderName; - } - $objEmail->subject = $emailSubject; - $objEmail->text = $emailText; - $objEmail->html = $emailHtml; - - try - { - $emailTo = $config->email; - - if ($GLOBALS['TL_CONFIG']['birthdayMailerDeveloperMode']) - { - $emailTo = $GLOBALS['TL_CONFIG']['birthdayMailerDeveloperModeEmail']; - } - else - { - if (strlen($config->mailCopy) > 0) - { - $emailCC = trimsplit(',', $config->mailCopy); - $objEmail->sendCc($emailCC); - } - - if (strlen($config->mailBlindCopy) > 0) - { - $emailBCC = trimsplit(',', $config->mailBlindCopy); - $objEmail->sendBcc($emailBCC); - } - - $emailTo = $config->email; - } - return $objEmail->sendTo($emailTo); - } - catch (Swift_RfcComplianceException $e) - { - return false; - } - } - - /** - * Checks if the member is active. - * @return boolean - */ - private function isMemberActive($config) - { - if ($config->disable || - (strlen($config->start) > 0 && - $config->start > time()) || - (strlen($config->stop) > 0 && - $config->stop < time())) - { - return false; - } - return true; - } - - /** - * Checks if the associated group is active. - * @return boolean - */ - private function isMemberGroupActive($config) - { - if ($config->memberGroupDisable || - (strlen($config->memberGroupStart) > 0 && - $config->memberGroupStart > time()) || - (strlen($config->memberGroupStop) > 0 && - $config->memberGroupStop < time())) - { - return false; - } - return true; - } - - /** - * Checks if sending duplicate emails is allowed. - * @return boolean - */ - private function allowSendingDuplicates($alreadySendTo, $config) - { - if (!$GLOBALS['TL_CONFIG']['birthdayMailerAllowDuplicates'] && in_array($config->id, $alreadySendTo)) - { - return false; - } - return true; - } - - /** - * Delete an according configuration, if the member group is deleted. - */ - public function deleteConfiguration(DataContainer $dc) - { - $this->Database->prepare("DELETE FROM tl_birthdaymailer WHERE memberGroup = ?") - ->execute($dc->id); - } - - /** - * Replaces all insert tags for the email text. - */ - private function replaceBirthdayMailerInsertTags ($text, $config, $language) - { - $textArray = preg_split('/\{\{([^\}]+)\}\}/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); - - for ($count = 0; $count < count($textArray); $count++) - { - $parts = explode("::", $textArray[$count]); - switch ($parts[0]) - { - case 'birthdaychild': - switch ($parts[1]) - { - case 'salutation': - $salutation = $this->getSalutation($config, $language, 'salutation_' . $config->gender); - if (strlen($salutation) == 0) - { - $salutation = $this->getSalutation($config, $language, 'salutation'); - } - $textArray[$count] = $salutation; - break; - - case 'name': - $textArray[$count] = trim($config->firstname . ' ' . $config->lastname); - break; - - case 'groupname': - $textArray[$count] = trim($config->memberGroupName); - break; - - case 'password': - // do not allow extracting the password - $textArray[$count] = ""; - break; - - case 'age': - $textArray[$count] = (date("Y") - date("Y", $config->dateOfBirth)); - break; - - default: - $textArray[$count] = $config->$parts[1]; - break; - } - break; - - case 'birthdaymailer': - switch ($parts[1]) - { - case 'email': - $textArray[$count] = trim($config->mailSender); - break; - - case 'name': - $textArray[$count] = trim($config->mailSenderName); - break; - } - break; - } - } - - return implode('', $textArray); - } - - /** - * Get the text for specific types. Fallback ist to 'default' if no text is set. - * FALLBACK Chain: - * 1. check, if there is a text for the specified textKey and language (search in system/config/langconfig.php) - * 2. if nothing found, check, if there is a text for the specified textKey and 'en' (search in system/config/langconfig.php) - * 3. if nothing found, get default text in specified language - * 4. if nothing found, get default text in language 'en' - */ - private function getSalutation($config, $language, $textType) - { - $text = ""; - - if ($config->mailUseCustomText) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][$language]; - - if (strlen($text) == 0 && $language != self::DEFAULT_LANGUAGE) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail'][$config->mailTextKey][$textType][self::DEFAULT_LANGUAGE]; - } - } - - if (strlen($text) == 0) - { - $text = $GLOBALS['TL_LANG']['BirthdayMailer']['mail']['default'][$textType]; - } - - return $text; - } -} - -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/config/autoload.ini b/system/modules/BirthdayMailer/config/autoload.ini old mode 100644 new mode 100755 diff --git a/system/modules/BirthdayMailer/config/autoload.php b/system/modules/BirthdayMailer/config/autoload.php index f4e70e0..43474e8 100644 --- a/system/modules/BirthdayMailer/config/autoload.php +++ b/system/modules/BirthdayMailer/config/autoload.php @@ -3,11 +3,9 @@ /** * Contao Open Source CMS * - * Copyright (c) 2005-2015 Leo Feyer + * Copyright (c) 2005-2016 Leo Feyer * - * @package BirthdayMailer - * @link https://contao.org - * @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL + * @license LGPL-3.0+ */ @@ -26,7 +24,13 @@ ClassLoader::addClasses(array ( // Classes - 'BirthdayMailer\BirthdayMailSender' => 'system/modules/BirthdayMailer/classes/BirthdayMailSender.php', + 'BirthdayMailer\BirthdayMailSender' => 'system/modules/BirthdayMailer/classes/BirthdayMailSender.php', + + // Library + 'BirthdayMailer\Helper\Backend' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Backend.php', + 'BirthdayMailer\Helper\Cron' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Cron.php', + 'BirthdayMailer\Helper\Dca' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Helper/Dca.php', + 'BirthdayMailer\Model\BirthdayMailer' => 'system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php', )); diff --git a/system/modules/BirthdayMailer/config/config.php b/system/modules/BirthdayMailer/config/config.php old mode 100644 new mode 100755 index d30e4e8..0068705 --- a/system/modules/BirthdayMailer/config/config.php +++ b/system/modules/BirthdayMailer/config/config.php @@ -28,73 +28,56 @@ */ /** - * ------------------------------------------------------------------------- - * BACK END MODULES - * ------------------------------------------------------------------------- + * Back end modules */ - -// Add configuration to Backend -> Accounts $GLOBALS['BE_MOD']['accounts']['BirthdayMailer'] = array ( 'tables' => array('tl_birthdaymailer'), 'icon' => 'system/modules/BirthdayMailer/assets/icon.png', - 'sendBirthdayMail' => array('BirthdayMailSender', 'sendBirthdayMailManually'), + 'sendBirthdayMail' => array('BirthdayMailer\Helper\Backend', 'sendBirthdayMailsManually'), ); + /** - * ------------------------------------------------------------------------- - * CRON - * ------------------------------------------------------------------------- + * Models */ +$GLOBALS['TL_MODELS'][BirthdayMailer\Model\BirthdayMailer::getTable()] = 'BirthdayMailer\Model\BirthdayMailer'; + + +/** + * Cron + */ +$GLOBALS['TL_CRON']['daily'][] = array('BirthdayMailer\Helper\Cron', 'sendBirthdayMails'); -// Daily cron job to send birthday mails -$GLOBALS['TL_CRON']['daily'][] = array('BirthdayMailSender', 'sendBirthdayMail'); /** * Notification Center Notification Types */ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['recipients'] = array( - 'birthdaychild_email', // returns the email of the member - 'admin_email' + 'birthdaychild_email', // returns the email of the member + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' -); -$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_text'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' -); -$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_html'] = array( - 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) - 'birthdaychild_name', // returns first and last name of the member - 'birthdaychild_age', // returns the age of the member - 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) - 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) - 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) - 'birthdaymailer_groupname', // returns the name of the member group of the current configuration - 'admin_email' + 'birthdaychild_*', // returns all the values of the current member (replace * with any attribute of the member, e.g. firstname or company, the attribute password is not allowed) + 'birthdaychild_name', // returns first and last name of the member + 'birthdaychild_age', // returns the age of the member + 'birthdaychild_salutation', // returns the salutation of the member (depending on gender) + 'birthdaychild_welcoming_personally', // returns the personally welcoming for the birthday child (depending on gender) + 'birthdaychild_welcoming_formally', // returns the formally welcoming for the birthday child (depending on gender) + 'birthdaymailer_groupname', // returns the name of the member group of the current configuration ); +$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_text'] = + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject']; +$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_html'] = + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_subject']; + $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_recipient_cc'] = array( - 'admin_email' + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_recipient_bcc'] = array( - 'admin_email' + 'admin_email' ); $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['BirthdayMailer']['birthday_mail']['email_replyTo'] = array( - 'admin_email' + 'admin_email' ); -?> \ No newline at end of file diff --git a/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php b/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php old mode 100644 new mode 100755 index ede5f31..bfe0b61 --- a/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php +++ b/system/modules/BirthdayMailer/dca/tl_birthdaymailer.php @@ -1,32 +1,15 @@ . - * - * PHP version 5 - * @copyright Cliff Parnitzky 2011-2015 - * @author Cliff Parnitzky - * @package BirthdayMailer - * @license LGPL + * BirthdayMailer for Contao Open Source CMS + * + * Copyright (c) 2011-2016 Cliff Parnitzky + * + * @package BirthdayMailer + * @author Cliff Parnitzky + * @author Richard Henkenjohann
', $image, $label, $this->getTheme(), $memberGroupImage, $memberGroupTitle, $memberGroupTitle);
- }
-
- /**
- * Return the paste button
- * @param object
- * @param array
- * @param string
- * @param boolean
- * @param array
- * @return string
- */
- public function pasteConfig(DataContainer $dc, $row, $table, $cr, $arrClipboard=false)
- {
- $this->import('BackendUser', 'User');
- $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']));
- $imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id']));
- if ($row['id'] == 0)
- {
- return $cr ? $this->generateImage('pasteinto_.gif').' ' : ''.$imagePasteInto.' ';
- }
- return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif').' ' : ''.$imagePasteAfter.' ';
- }
-
- /**
- * Return the "toggle visibility" button
- * @param array
- * @param string
- * @param string
- * @param string
- * @param string
- * @param string
- * @return string
- */
- public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
- {
- if (strlen(Input::get('tid')))
- {
- $this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null));
- $this->redirect($this->getReferer());
- }
-
- // Check permissions AFTER checking the tid, so hacking attempts are logged
- if (!$this->User->isAdmin && !$this->User->hasAccess('tl_birthdaymailer::disable', 'alexf'))
- {
- return '';
- }
-
- $href .= '&tid='.$row['id'].'&state='.$row['disable'];
-
- if ($row['disable'])
- {
- $icon = 'invisible.gif';
- }
-
- return ''.Image::getHtml($icon, $label).' ';
- }
-
-
- /**
- * Disable/enable a configuration
- * @param integer
- * @param boolean
- * @param \DataContainer
- */
- public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null)
- {
- // Check permissions
- if (!$this->User->isAdmin && !$this->User->hasAccess('tl_birthdaymailer::disable', 'alexf'))
- {
- $this->log('Not enough permissions to activate/deactivate bithday mailer configuration ID "'.$intId.'"', __METHOD__, TL_ERROR);
- $this->redirect('contao/main.php?act=error');
- }
-
- $objVersions = new Versions('tl_birthdaymailer', $intId);
- $objVersions->initialize();
-
- // Trigger the save_callback
- if (is_array($GLOBALS['TL_DCA']['tl_birthdaymailer']['fields']['disable']['save_callback']))
- {
- foreach ($GLOBALS['TL_DCA']['tl_birthdaymailer']['fields']['disable']['save_callback'] as $callback)
- {
- if (is_array($callback))
- {
- $this->import($callback[0]);
- $blnVisible = $this->$callback[0]->$callback[1]($blnVisible, ($dc ?: $this));
- }
- elseif (is_callable($callback))
- {
- $blnVisible = $callback($blnVisible, ($dc ?: $this));
- }
- }
- }
-
- $time = time();
-
- // Update the database
- \Database::getInstance()->prepare("UPDATE tl_birthdaymailer SET tstamp=$time, disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")
- ->execute($intId);
-
- $objVersions->create();
- $this->log('A new version of record "tl_birthdaymailer.id='.$intId.'" has been created'.$this->getParentEntries('tl_birthdaymailer', $intId), __METHOD__, TL_GENERAL);
- }
-
- /**
- * Get notification choices
- *
- * @return array
- */
- public function getNotificationChoices()
- {
- $arrChoices = array();
- $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='birthday_mail' ORDER BY title");
-
- while ($objNotifications->next()) {
- $arrChoices[$objNotifications->id] = $objNotifications->title;
- }
-
- return $arrChoices;
- }
-
- /**
- * Return the edit notification wizard
- * @param \DataContainer
- * @return string
- */
- public function editNotification(DataContainer $dc)
- {
- return ($dc->value < 1) ? '' : ' value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_birthdaymailer']['edit_notification'][0], 'style="vertical-align:top"') . '';
- }
-}
-
-?>
\ No newline at end of file
diff --git a/system/modules/BirthdayMailer/dca/tl_member_group.php b/system/modules/BirthdayMailer/dca/tl_member_group.php
old mode 100644
new mode 100755
index fa269df..418187f
--- a/system/modules/BirthdayMailer/dca/tl_member_group.php
+++ b/system/modules/BirthdayMailer/dca/tl_member_group.php
@@ -1,35 +1,17 @@
.
+ * Copyright (c) 2011-2016 Cliff Parnitzky
*
- * PHP version 5
- * @copyright Cliff Parnitzky 2011-2015
- * @author Cliff Parnitzky
- * @package BirthdayMailer
- * @license LGPL
+ * @package BirthdayMailer
+ * @author Cliff Parnitzky
+ * @author Richard Henkenjohann
', $image, $label, $this->getTheme(), $memberGroupImage, $memberGroupTitle, $memberGroupTitle);
+ }
+
+
+ /**
+ * Return the paste button
+ *
+ * @param \DataContainer $dc
+ * @param $row
+ * @param $table
+ * @param $cr
+ * @param bool $arrClipboard
+ *
+ * @return string
+ */
+ public function pasteConfig(\DataContainer $dc, $row, $table, $cr, $arrClipboard = false)
+ {
+ $this->import('BackendUser', 'User');
+ $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']));
+ $imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id']));
+ if ($row['id'] == 0)
+ {
+ return $cr ? $this->generateImage('pasteinto_.gif') . ' ' : '' . $imagePasteInto . ' ';
+ }
+
+ return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif') . ' ' : '' . $imagePasteAfter . ' ';
+ }
+
+
+ /**
+ * Get notification choices
+ *
+ * @return array
+ */
+ public function getNotificationChoices()
+ {
+ $arrChoices = array();
+ $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='birthday_mail' ORDER BY title");
+
+ while ($objNotifications->next())
+ {
+ $arrChoices[$objNotifications->id] = $objNotifications->title;
+ }
+
+ return $arrChoices;
+ }
+
+
+ /**
+ * Return the edit notification wizard
+ *
+ * @param \DataContainer
+ *
+ * @return string
+ */
+ public function editNotification(\DataContainer $dc)
+ {
+ return ($dc->value < 1) ? '' : ' value))) . '\',\'url\':this.href});return false">' . \Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_birthdaymailer']['edit_notification'][0], 'style="vertical-align:top"') . '';
+ }
+
+
+ /**
+ * Delete an according BirthdayMailer configuration if the member group is deleted.
+ *
+ * @param \DataContainer $dc
+ */
+ public function deleteConfiguration(\DataContainer $dc)
+ {
+ /** @var BirthdayMailer|\Contao\Model $objBirthdayMailer */
+ /** @noinspection PhpUndefinedMethodInspection */
+ $objBirthdayMailer = BirthdayMailer::findBy('memberGroup', $dc->id);
+ $objBirthdayMailer->delete();
+ }
+}
\ No newline at end of file
diff --git a/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php b/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php
new file mode 100644
index 0000000..fe7ae95
--- /dev/null
+++ b/system/modules/BirthdayMailer/library/BirthdayMailer/Model/BirthdayMailer.php
@@ -0,0 +1,187 @@
+
+ */
+
+
+namespace BirthdayMailer\Model;
+
+use Haste\DateTime\DateTime;
+use NotificationCenter\Model\Notification;
+
+
+/**
+ * Class BirthdayMailer
+ * @package BirthdayMailer\Model
+ */
+class BirthdayMailer extends \Model
+{
+
+ /**
+ * The table name
+ *
+ * @var string
+ */
+ protected static $strTable = 'tl_birthdaymailer';
+
+
+ /**
+ * Send the birthday emails for the current configuration
+ *
+ * @return array
+ */
+ public static function sendBirthdayMails()
+ {
+ $arrResult = array
+ (
+ 'success' => array(),
+ 'failed' => array(),
+ 'aborted' => array()
+ );
+
+ $time = time();
+
+ self::synchronizeDatabaseTimeZone();
+
+ /** @noinspection PhpUndefinedMethodInspection */
+ $objResult = \Database::getInstance()->query(sprintf('
+ SELECT%4$s m.*, mg.name as memberGroupName, bm.nc_notification
+ FROM %2$s m
+ JOIN tl_member_to_group m2g ON m2g.member_id=m.id
+ JOIN %3$s mg ON mg.id=m2g.group_id
+ JOIN %1$s bm ON bm.membergroup=mg.id
+ WHERE %5$s%6$s%7$s%8$s
+ ORDER BY m.id, bm.sorting DESC',
+ static::getTable(),
+ \MemberModel::getTable(),
+ \MemberGroupModel::getTable(),
+ // Select distinct
+ \Config::get('birthdayMailerAllowDuplicates') ? "" : " DISTINCT",
+ // Only active BirthdayMail configurations
+ "bm.disable<>1 ",
+ // Only active members
+ "AND m.disable<>1 AND (m.start='' OR m.start<$time) AND (m.stop='' OR m.stop>$time) ",
+ // Only active member groups
+ "AND mg.disable<>1 AND (mg.start='' OR mg.start<$time) AND (mg.stop='' OR mg.stop>$time) ",
+ // Only birthday members if not in developer mode
+ (\Config::get('birthdayMailerDeveloperMode') && \Config::get('birthdayMailerDeveloperModeIgnoreDate')) ? '' : "AND FROM_UNIXTIME(m.dateOfBirth, '%e.%m') = '" . date('d.m', $time) . "' "
+ )
+ );
+
+ if ($objResult->numRows < 1)
+ {
+ return array();
+ }
+
+ while ($objResult->next())
+ {
+ // !HOOK: now check via custom hook if sending should be aborted
+ $blnAbortSendMail = false;
+
+ if (isset($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail']))
+ {
+ foreach ($GLOBALS['TL_HOOKS']['birthdayMailerAbortSendMail'] as $callback)
+ {
+ $objCallback = \System::importStatic($callback[0]);
+ $blnAbortSendMail = $objCallback->{$callback[1]}($objResult, $blnAbortSendMail);
+ }
+ }
+
+ if ($blnAbortSendMail)
+ {
+ $arrResult['aborted'][] = $objResult->row();
+ continue;
+ }
+
+ if (static::sendMail($objResult))
+ {
+ $arrResult['success'][] = $objResult->row();
+ }
+ else
+ {
+ $arrResult['failed'][] = $objResult->row();
+ }
+ }
+
+ return $arrResult;
+ }
+
+
+ /**
+ * Send an email.
+ *
+ * @param \Database\Result|object $objResult
+ *
+ * @return bool
+ */
+ protected static function sendMail($objResult)
+ {
+ /** @var Notification $objNotification */
+ /** @noinspection PhpUndefinedMethodInspection */
+ $objNotification = Notification::findByPk($objResult->nc_notification);
+
+ // Build tokens
+ $arrTokens = array();
+ $objDateOfBirth = new DateTime('@' . $objResult->dateOfBirth);
+
+ foreach ($objResult->row() as $field => $value)
+ {
+ if (in_array($field, ['memberGroupName', 'nc_notification']))
+ {
+ continue;
+ }
+
+ $arrTokens['birthdaychild_' . $field] = $value;
+ }
+
+ $arrTokens['birthdaychild_name'] = trim(sprintf('%s %s', $objResult->firstname, $objResult->lastname));
+ $arrTokens['birthdaychild_age'] = $objDateOfBirth->getAge();
+// $arrTokens['birthdaychild_salutation'] =
+// $arrTokens['birthdaychild_welcoming_personally']
+// $arrTokens['birthdaychild_welcoming_formally']
+// $arrTokens['birthdaymailer_groupname']
+
+ // !HOOK: alter the notification tokens
+ if (isset($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens']) && is_array($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens']))
+ {
+ foreach ($GLOBALS['TL_HOOKS']['birthdayMailerGetNotificationTokens'] as $callback)
+ {
+ $objCallback = \System::importStatic($callback[0]);
+ $arrTokens = $objCallback->{$callback[1]}($arrTokens, $objResult);
+ }
+ }
+
+ if (null !== $objNotification)
+ {
+ $objNotification->send($arrTokens);
+
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Synchronize time zone on database
+ * @see https://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/
+ */
+ private static function synchronizeDatabaseTimeZone() {
+ $now = new DateTime();
+
+ $mins = $now->getOffset() / 60;
+ $sgn = ($mins < 0 ? -1 : 1);
+ $mins = abs($mins);
+ $hrs = floor($mins / 60);
+ $mins -= $hrs * 60;
+ $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
+
+ \Database::getInstance()->query(sprintf('SET time_zone=\'%s\';', $offset));
+ }
+}
diff --git a/system/modules/BirthdayMailer/templates/backend/be_birthday-mailer.html5 b/system/modules/BirthdayMailer/templates/backend/be_birthday-mailer.html5
old mode 100644
new mode 100755