diff --git a/CHANGELOG.md b/CHANGELOG.md index 7173e3d6..23e224e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Notification Center Changelog =========================== +Version 1.3.5 (2016-03-02) +-------------------------- + +### Fixed +- The extension is now compatible with PHP7 (see #86) + + Version 1.3.3 (2016-01-15) -------------------------- diff --git a/library/NotificationCenter/Gateway/Base.php b/library/NotificationCenter/Gateway/Base.php index 8064eba9..d640ccd7 100644 --- a/library/NotificationCenter/Gateway/Base.php +++ b/library/NotificationCenter/Gateway/Base.php @@ -11,7 +11,7 @@ namespace NotificationCenter\Gateway; use NotificationCenter\Model\Gateway; -use NotificationCenter\Util\String; +use NotificationCenter\Util\StringUtil; /** * No need no extend Controller but left here for BC @@ -52,19 +52,19 @@ public function getModel() } /** - * @deprecated Use String::getTokenAttachments() + * @deprecated Use StringUtil::getTokenAttachments() */ protected function getTokenAttachments($strAttachmentTokens, array $arrTokens) { - return String::getTokenAttachments($strAttachmentTokens, $arrTokens); + return StringUtil::getTokenAttachments($strAttachmentTokens, $arrTokens); } /** - * @deprecated Use String::compileRecipients() + * @deprecated Use StringUtil::compileRecipients() */ protected function compileRecipients($strRecipients, $arrTokens) { - return String::compileRecipients($strRecipients, $arrTokens); + return StringUtil::compileRecipients($strRecipients, $arrTokens); } /** diff --git a/library/NotificationCenter/Gateway/File.php b/library/NotificationCenter/Gateway/File.php index 1bb94b0e..be632dab 100644 --- a/library/NotificationCenter/Gateway/File.php +++ b/library/NotificationCenter/Gateway/File.php @@ -12,7 +12,7 @@ use NotificationCenter\Model\Language; use NotificationCenter\Model\Message; -use NotificationCenter\Util\String; +use NotificationCenter\Util\StringUtil; class File extends Base implements GatewayInterface @@ -47,7 +47,7 @@ public function send(Message $objMessage, array $arrTokens, $strLanguage = '') $strFileName = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags( $objLanguage->file_name, $arrTokens, - String::NO_TAGS | String::NO_BREAKS + StringUtil::NO_TAGS | StringUtil::NO_BREAKS ); // Escape quotes and line breaks for CSV files diff --git a/library/NotificationCenter/MessageDraft/EmailMessageDraft.php b/library/NotificationCenter/MessageDraft/EmailMessageDraft.php index 51514aa3..a7ab22f9 100644 --- a/library/NotificationCenter/MessageDraft/EmailMessageDraft.php +++ b/library/NotificationCenter/MessageDraft/EmailMessageDraft.php @@ -13,7 +13,7 @@ use NotificationCenter\Model\Language; use NotificationCenter\Model\Message; -use NotificationCenter\Util\String; +use NotificationCenter\Util\StringUtil; class EmailMessageDraft implements MessageDraftInterface { @@ -56,7 +56,7 @@ public function getSenderEmail() { $strSenderAddress = $this->objLanguage->email_sender_address ?: $GLOBALS['TL_ADMIN_EMAIL']; - return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderAddress, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS); + return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderAddress, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_BREAKS); } /** @@ -67,7 +67,7 @@ public function getSenderName() { $strSenderName = $this->objLanguage->email_sender_name ?: $GLOBALS['TL_ADMIN_NAME']; - return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderName, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS); + return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderName, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_BREAKS); } /** @@ -76,7 +76,7 @@ public function getSenderName() */ public function getRecipientEmails() { - return String::compileRecipients($this->objLanguage->recipients, $this->arrTokens); + return StringUtil::compileRecipients($this->objLanguage->recipients, $this->arrTokens); } /** @@ -85,7 +85,7 @@ public function getRecipientEmails() */ public function getCcRecipientEmails() { - return String::compileRecipients($this->objLanguage->email_recipient_cc, $this->arrTokens); + return StringUtil::compileRecipients($this->objLanguage->email_recipient_cc, $this->arrTokens); } /** @@ -94,7 +94,7 @@ public function getCcRecipientEmails() */ public function getBccRecipientEmails() { - return String::compileRecipients($this->objLanguage->email_recipient_bcc, $this->arrTokens); + return StringUtil::compileRecipients($this->objLanguage->email_recipient_bcc, $this->arrTokens); } /** @@ -104,7 +104,7 @@ public function getBccRecipientEmails() public function getReplyToEmail() { if ($this->objLanguage->email_replyTo) { - return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_replyTo, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS); + return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_replyTo, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_BREAKS); } return ''; @@ -116,7 +116,7 @@ public function getReplyToEmail() */ public function getSubject() { - return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_subject, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS); + return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_subject, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_BREAKS); } /** @@ -140,7 +140,7 @@ public function getPriority() public function getTextBody() { $strText = $this->objLanguage->email_text; - $strText = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $this->arrTokens, String::NO_TAGS); + $strText = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $this->arrTokens, StringUtil::NO_TAGS); return \Controller::convertRelativeUrls($strText, '', true); } @@ -176,7 +176,7 @@ public function getHtmlBody() public function getAttachments() { // Token attachments - $arrAttachments = String::getTokenAttachments($this->objLanguage->attachment_tokens, $this->arrTokens); + $arrAttachments = StringUtil::getTokenAttachments($this->objLanguage->attachment_tokens, $this->arrTokens); // Add static attachments $arrStaticAttachments = deserialize($this->objLanguage->attachments, true); diff --git a/library/NotificationCenter/Util/String.php b/library/NotificationCenter/Util/String.php index 445a36c9..9078cfa2 100644 --- a/library/NotificationCenter/Util/String.php +++ b/library/NotificationCenter/Util/String.php @@ -10,106 +10,17 @@ namespace NotificationCenter\Util; - use Haste\Haste; -class String -{ - /** - * Text filter options - */ - const NO_TAGS = 1; - const NO_BREAKS = 2; - const NO_EMAILS = 4; - - - /** - * Recursively replace simple tokens and insert tags - * - * @param string $strText - * @param array $arrTokens Array of Tokens - * @param int $intTextFlags Filters the tokens and the text for a given set of options - * - * @return string - * - * @deprecated Deprecated since version 1.3.1, to be removed in version 2. - * Use Haste\Util\StringUtil::recursiveReplaceTokensAndTags() instead. - */ - public static function recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags = 0) - { - return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags); - } - - /** - * Convert the given array or string to plain text using given options - * - * @deprecated Deprecated since version 1.3.1, to be removed in version 2. - * Use Haste\Util\StringUtil::convertToText() instead. - * - * @param mixed $varValue - * @param int $options - * - * @return mixed - */ - public static function convertToText($varValue, $options) - { - return \Haste\Util\StringUtil::convertToText($varValue, $options); - } - - /** - * Gets an array of valid attachments of a token field - * - * @param string $strAttachmentTokens - * @param array $arrTokens - * - * @return array - */ - public static function getTokenAttachments($strAttachmentTokens, array $arrTokens) - { - $arrAttachments = array(); - - if ($strAttachmentTokens == '') { - return $arrAttachments; - } - - foreach (trimsplit(',', $strAttachmentTokens) as $strToken) { - $strFile = TL_ROOT . '/' . \String::parseSimpleTokens($strToken, $arrTokens); - - if (is_file($strFile)) { - $arrAttachments[$strToken] = $strFile; - } - } +if (version_compare(PHP_VERSION, '7.0', '>=')) { + throw new \RuntimeException( + 'The String class cannot be used in PHP ' . PHP_VERSION . '. Use the StringUtil class instead.' + ); +} - return $arrAttachments; - } - - /** - * Generate CC or BCC recipients from comma separated string - * - * @param string $strRecipients - * @param array $arrTokens - * - * @return array - */ - public static function compileRecipients($strRecipients, $arrTokens) - { - // Replaces tokens first so that tokens can contain a list of recipients. - $strRecipients = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strRecipients, $arrTokens, static::NO_TAGS | static::NO_BREAKS); - $arrRecipients = array(); - - foreach ((array) trimsplit(',', $strRecipients) as $strAddress) { - if ($strAddress != '') { - list($strName, $strEmail) = \String::splitFriendlyEmail($strAddress); - - // Address could become empty through invalid insert tag - if ($strAddress == '' || !\Validator::isEmail($strEmail)) { - continue; - } - - $arrRecipients[] = $strAddress; - } - } - - return $arrRecipients; - } +/** + * @deprecated Use the StringUtil class instead + */ +class String extends StringUtil +{ } diff --git a/library/NotificationCenter/Util/StringUtil.php b/library/NotificationCenter/Util/StringUtil.php new file mode 100644 index 00000000..e7624443 --- /dev/null +++ b/library/NotificationCenter/Util/StringUtil.php @@ -0,0 +1,123 @@ +<?php + +/** + * notification_center extension for Contao Open Source CMS + * + * @copyright Copyright (c) 2008-2015, terminal42 + * @author terminal42 gmbh <info@terminal42.ch> + * @license LGPL + */ + +namespace NotificationCenter\Util; + + +use Haste\Haste; + +class StringUtil +{ + /** + * Text filter options + */ + const NO_TAGS = 1; + const NO_BREAKS = 2; + const NO_EMAILS = 4; + + + /** + * Recursively replace simple tokens and insert tags + * + * @param string $strText + * @param array $arrTokens Array of Tokens + * @param int $intTextFlags Filters the tokens and the text for a given set of options + * + * @return string + * + * @deprecated Deprecated since version 1.3.1, to be removed in version 2. + * Use Haste\Util\StringUtil::recursiveReplaceTokensAndTags() instead. + */ + public static function recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags = 0) + { + return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags); + } + + /** + * Convert the given array or string to plain text using given options + * + * @deprecated Deprecated since version 1.3.1, to be removed in version 2. + * Use Haste\Util\StringUtil::convertToText() instead. + * + * @param mixed $varValue + * @param int $options + * + * @return mixed + */ + public static function convertToText($varValue, $options) + { + return \Haste\Util\StringUtil::convertToText($varValue, $options); + } + + /** + * Gets an array of valid attachments of a token field + * + * @param string $strAttachmentTokens + * @param array $arrTokens + * + * @return array + */ + public static function getTokenAttachments($strAttachmentTokens, array $arrTokens) + { + $arrAttachments = array(); + + if ($strAttachmentTokens == '') { + return $arrAttachments; + } + + foreach (trimsplit(',', $strAttachmentTokens) as $strToken) { + if (version_compare(VERSION . '.' . BUILD, '3.5.1', '<')) { + $strFile = TL_ROOT.'/'.\String::parseSimpleTokens($strToken, $arrTokens); + } else { + $strFile = TL_ROOT.'/'.\StringUtil::parseSimpleTokens($strToken, $arrTokens); + } + + if (is_file($strFile)) { + $arrAttachments[$strToken] = $strFile; + } + } + + return $arrAttachments; + } + + /** + * Generate CC or BCC recipients from comma separated string + * + * @param string $strRecipients + * @param array $arrTokens + * + * @return array + */ + public static function compileRecipients($strRecipients, $arrTokens) + { + // Replaces tokens first so that tokens can contain a list of recipients. + $strRecipients = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strRecipients, $arrTokens, static::NO_TAGS | static::NO_BREAKS); + $arrRecipients = array(); + + foreach ((array) trimsplit(',', $strRecipients) as $strAddress) { + if ($strAddress != '') { + if (version_compare(VERSION . '.' . BUILD, '3.5.1', '<')) { + list($strName, $strEmail) = \String::splitFriendlyEmail($strAddress); + } else { + list($strName, $strEmail) = \StringUtil::splitFriendlyEmail($strAddress); + } + + // Address could become empty through invalid insert tag + if ($strAddress == '' || !\Validator::isEmail($strEmail)) { + continue; + } + + $arrRecipients[] = $strAddress; + } + } + + return $arrRecipients; + } +}