Skip to content

Commit

Permalink
Merge branch 'hotfix/1.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Mar 2, 2016
2 parents e1ddacf + f6002a4 commit 00c83f4
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 116 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
--------------------------

Expand Down
10 changes: 5 additions & 5 deletions library/NotificationCenter/Gateway/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions library/NotificationCenter/Gateway/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions library/NotificationCenter/MessageDraft/EmailMessageDraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use NotificationCenter\Model\Language;
use NotificationCenter\Model\Message;
use NotificationCenter\Util\String;
use NotificationCenter\Util\StringUtil;

class EmailMessageDraft implements MessageDraftInterface
{
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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 '';
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
109 changes: 10 additions & 99 deletions library/NotificationCenter/Util/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
123 changes: 123 additions & 0 deletions library/NotificationCenter/Util/StringUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

/**
* notification_center extension for Contao Open Source CMS
*
* @copyright Copyright (c) 2008-2015, terminal42
* @author terminal42 gmbh <[email protected]>
* @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;
}
}

0 comments on commit 00c83f4

Please sign in to comment.