Skip to content

Commit

Permalink
Merge branch 'hotfix/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Oct 9, 2015
2 parents 13e5d8b + ea2febd commit e062363
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 124 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ Thumbs.db
nbproject/

# Transifex
.tx/
.tx/

# Composer
vendor/
11 changes: 10 additions & 1 deletion bin/queue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
*/

define('TL_MODE', 'FE');
require __DIR__ . '/../../../initialize.php';

if (file_exists(__DIR__ . '/../../../initialize.php')) {
// Regular way
require_once(__DIR__ . '/../../../initialize.php');
} else {
// Try composer location (see #77)
require_once(__DIR__ . '/../../../../../system/initialize.php');
}


$queueManager = $GLOBALS['NOTIFICATION_CENTER']['QUEUE_MANAGER'];

$queueManager->sendFromQueue($argv[2], $argv[4]);
7 changes: 5 additions & 2 deletions classes/tl_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public function generateTokens(array $arrData, array $arrForm, array $arrFiles,
$arrTokens['raw_data'] = '';

foreach ($arrData as $k => $v) {
$this->flatten($v, 'form_'.$k, $arrTokens);
\Haste\Util\StringUtil::flatten($v, 'form_'.$k, $arrTokens);
$arrTokens['raw_data'] .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n";
}

foreach ($arrForm as $k => $v) {
$this->flatten($v, 'formconfig_'.$k, $arrTokens);
\Haste\Util\StringUtil::flatten($v, 'formconfig_'.$k, $arrTokens);
}

// Administrator e-mail
Expand All @@ -104,6 +104,9 @@ public function generateTokens(array $arrData, array $arrForm, array $arrFiles,
* @param mixed $varValue
* @param string $strKey
* @param array $arrData
*
* @deprecated Deprecated since version 1.3.1, to be removed in version 2.
* Use Haste\Util\StringUtil::flatten() instead.
*/
public function flatten($varValue, $strKey, &$arrData)
{
Expand Down
2 changes: 1 addition & 1 deletion classes/tl_nc_language.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function validateEmailList($varValue, \DataContainer $dc)
foreach ($chunks as $chunk) {

// Skip string with tokens or inserttags
if (strpos($chunk, '##') !== false || strpos($chunk, '{{') !== false) {
if (strpos($chunk, '##') !== false || strpos($chunk, '{{') !== false|| strpos($chunk, '{if') !== false) {
continue;
}

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
"php":">=5.3.2",
"contao/core":"^3.2",
"contao-community-alliance/composer-plugin":"2.*",
"terminal42/contao-namespace-class-loader":"^1.0.1",
"codefog/contao-haste":"4.*",
"codefog/contao-haste":"^4.10.0",
"terminal42/dcawizard":"2.*"
},
"autoload":{
"psr-0": {
"NotificationCenter\\": [
"/library"
"library/"
]
}
},
"classmap": [
"classes/"
]
},
"replace": {
"contao-legacy/notification_center": "self.version"
Expand Down
30 changes: 17 additions & 13 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
/**
* Register PSR-0 namespace
*/
NamespaceClassLoader::add('NotificationCenter', 'system/modules/notification_center/library');
if (class_exists('NamespaceClassLoader')) {
NamespaceClassLoader::add('NotificationCenter', 'system/modules/notification_center/library');
}


/**
* Register classes outside the namespace folder
*/
NamespaceClassLoader::addClassMap(array
(
// DCA Helpers
'NotificationCenter\tl_form' => 'system/modules/notification_center/classes/tl_form.php',
'NotificationCenter\tl_member' => 'system/modules/notification_center/classes/tl_member.php',
'NotificationCenter\tl_module' => 'system/modules/notification_center/classes/tl_module.php',
'NotificationCenter\tl_nc_gateway' => 'system/modules/notification_center/classes/tl_nc_gateway.php',
'NotificationCenter\tl_nc_notification' => 'system/modules/notification_center/classes/tl_nc_notification.php',
'NotificationCenter\tl_nc_language' => 'system/modules/notification_center/classes/tl_nc_language.php',
'NotificationCenter\tl_nc_message' => 'system/modules/notification_center/classes/tl_nc_message.php',
'NotificationCenter\tl_nc_queue' => 'system/modules/notification_center/classes/tl_nc_queue.php'
));
if (class_exists('NamespaceClassLoader')) {
NamespaceClassLoader::addClassMap(array
(
// DCA Helpers
'NotificationCenter\tl_form' => 'system/modules/notification_center/classes/tl_form.php',
'NotificationCenter\tl_member' => 'system/modules/notification_center/classes/tl_member.php',
'NotificationCenter\tl_module' => 'system/modules/notification_center/classes/tl_module.php',
'NotificationCenter\tl_nc_gateway' => 'system/modules/notification_center/classes/tl_nc_gateway.php',
'NotificationCenter\tl_nc_notification' => 'system/modules/notification_center/classes/tl_nc_notification.php',
'NotificationCenter\tl_nc_language' => 'system/modules/notification_center/classes/tl_nc_language.php',
'NotificationCenter\tl_nc_message' => 'system/modules/notification_center/classes/tl_nc_message.php',
'NotificationCenter\tl_nc_queue' => 'system/modules/notification_center/classes/tl_nc_queue.php'
));
}


/**
Expand Down
8 changes: 7 additions & 1 deletion languages/en/tl_nc_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@
<br><blockquote>5 * * * * /path/to/contao/system/modules/notification_center/bin/queue -s {gateway_id} -n 30</blockquote><br>
If you don\'t have access to real cronjobs then you can enable the poor man\'s cron. Note that it doesn\'t provide the same
flexibility in terms of interval settings and it is subject to the web execution context and thus certainly affected by
PHP configurations such as the maximum execution time. Thus, try to keep the number of messages sent per invocation as low as possible.';
PHP configurations such as the maximum execution time. Thus, try to keep the number of messages sent per invocation as low as possible.
<br><br>
<strong>Note: </strong>When you installed the notification center using Composer, the path to the binary differs:
<blockquote>
/path/to/contao/composer/vendor/terminal42/notification_center/bin/queue
</blockquote>
';
8 changes: 4 additions & 4 deletions library/NotificationCenter/Gateway/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ protected function compileRecipients($strRecipients, $arrTokens)
}

/**
* @deprecated Use String::recursiveReplaceTokensAndTags()
* @deprecated Use \Haste\Util\StringUtil::recursiveReplaceTokensAndTags()
*/
protected function recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags = 0)
{
return String::recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags);
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags);
}

/**
* @deprecated Use String::convertToText()
* @deprecated Use \Haste\Util\StringUtil::convertToText()
*/
protected function convertToText($varValue, $options)
{
return String::convertToText($varValue, $options);
return \Haste\Util\StringUtil::convertToText($varValue, $options);
}
}
4 changes: 2 additions & 2 deletions library/NotificationCenter/Gateway/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function send(Message $objMessage, array $arrTokens, $strLanguage = '')
return false;
}

$strFileName = String::recursiveReplaceTokensAndTags(
$strFileName = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags(
$objLanguage->file_name,
$arrTokens,
String::NO_TAGS | String::NO_BREAKS
Expand All @@ -58,7 +58,7 @@ public function send(Message $objMessage, array $arrTokens, $strLanguage = '')
}

// Preserve all tags here as this is pretty useful in XML :-)
$strContent = String::recursiveReplaceTokensAndTags(
$strContent = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags(
$objLanguage->file_content,
$arrTokens
);
Expand Down
12 changes: 6 additions & 6 deletions library/NotificationCenter/MessageDraft/EmailMessageDraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getSenderEmail()
{
$strSenderAddress = $this->objLanguage->email_sender_address ?: $GLOBALS['TL_ADMIN_EMAIL'];

return String::recursiveReplaceTokensAndTags($strSenderAddress, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderAddress, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
}

/**
Expand All @@ -67,7 +67,7 @@ public function getSenderName()
{
$strSenderName = $this->objLanguage->email_sender_name ?: $GLOBALS['TL_ADMIN_NAME'];

return String::recursiveReplaceTokensAndTags($strSenderName, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strSenderName, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ public function getBccRecipientEmails()
public function getReplyToEmail()
{
if ($this->objLanguage->email_replyTo) {
return String::recursiveReplaceTokensAndTags($this->objLanguage->email_replyTo, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_replyTo, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
}

return '';
Expand All @@ -116,7 +116,7 @@ public function getReplyToEmail()
*/
public function getSubject()
{
return String::recursiveReplaceTokensAndTags($this->objLanguage->email_subject, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->email_subject, $this->arrTokens, String::NO_TAGS | String::NO_BREAKS);
}

/**
Expand All @@ -140,7 +140,7 @@ public function getPriority()
public function getTextBody()
{
$strText = $this->objLanguage->email_text;
$strText = String::recursiveReplaceTokensAndTags($strText, $this->arrTokens, String::NO_TAGS);
$strText = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $this->arrTokens, String::NO_TAGS);

return \Controller::convertRelativeUrls($strText, '', true);
}
Expand All @@ -159,7 +159,7 @@ public function getHtmlBody()
// Prevent parseSimpleTokens from stripping important HTML tags
$GLOBALS['TL_CONFIG']['allowedTags'] .= '<doctype><html><head><meta><style><body>';
$strHtml = str_replace('<!DOCTYPE', '<DOCTYPE', $objTemplate->parse());
$strHtml = String::recursiveReplaceTokensAndTags($strHtml, $this->arrTokens);
$strHtml = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strHtml, $this->arrTokens);
$strHtml = \Controller::convertRelativeUrls($strHtml, '', true);
$strHtml = str_replace('<DOCTYPE', '<!DOCTYPE', $strHtml);

Expand Down
120 changes: 31 additions & 89 deletions library/NotificationCenter/Util/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace NotificationCenter\Util;


use Haste\Haste;

class String
{
/**
Expand All @@ -23,106 +25,44 @@ class String

/**
* 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
* @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)
{
if ($intTextFlags > 0) {
$arrTokens = static::convertToText($arrTokens, $intTextFlags);
}

// Must decode, tokens could be encoded
$strText = \String::decodeEntities($strText);

// Replace all opening and closing tags with a hash so they don't get stripped
// by parseSimpleTokens() - this is useful e.g. for XML content
$strHash = md5($strText);
$strTagOpenReplacement = 'NC-TAG-OPEN-' . $strHash;
$strTagCloseReplacement = 'NC-TAG-CLOSE-' . $strHash;
$arrOriginal = array('<', '>');
$arrReplacement = array($strTagOpenReplacement, $strTagCloseReplacement);

$strText = str_replace($arrOriginal, $arrReplacement, $strText);

// first parse the tokens as they might have if-else clauses
$strBuffer = \String::parseSimpleTokens($strText, $arrTokens);

$strBuffer = str_replace($arrReplacement, $arrOriginal, $strBuffer);

// then replace the insert tags
$strBuffer = \Haste\Haste::getInstance()->call('replaceInsertTags', array($strBuffer, false));

// check if the inserttags have returned a simple token or an insert tag to parse
if ((strpos($strBuffer, '##') !== false || strpos($strBuffer, '{{') !== false) && $strBuffer != $strText) {
$strBuffer = static::recursiveReplaceTokensAndTags($strBuffer, $arrTokens, $intTextFlags);
}

$strBuffer = \String::restoreBasicEntities($strBuffer);

if ($intTextFlags > 0) {
$strBuffer = static::convertToText($strBuffer, $intTextFlags);
}

return $strBuffer;
return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags);
}

/**
* Convert the given array or string to plain text using given options
* @param mixed
* @param int
* @return mixed
*
* @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)
{
if (is_array($varValue)) {
foreach ($varValue as $k => $v) {
$varValue[$k] = static::convertToText($v, $options);
}

return $varValue;
}

// Replace friendly email before stripping tags
if (!($options & static::NO_EMAILS)) {
$arrEmails = array();
preg_match_all('{<.+@.+\.[A-Za-z]{2,6}>}', $varValue, $arrEmails);

if (!empty($arrEmails[0])) {
foreach ($arrEmails[0] as $k => $v) {
$varValue = str_replace($v, '%email' . $k . '%', $varValue);
}
}
}

// Remove HTML tags but keep line breaks for <br> and <p>
if ($options & static::NO_TAGS) {
$varValue = strip_tags(preg_replace('{(?!^)<(br|p|/p).*?/?>\n?(?!$)}is', "\n", $varValue));
}

// Remove line breaks (e.g. for subject)
if ($options & static::NO_BREAKS) {
$varValue = str_replace(array("\r", "\n"), '', $varValue);
}

// Restore friendly email after stripping tags
if (!($options & static::NO_EMAILS) && !empty($arrEmails[0])) {
foreach ($arrEmails[0] as $k => $v) {
$varValue = str_replace('%email' . $k . '%', $v, $varValue);
}
}

return $varValue;
return \Haste\Util\StringUtil::convertToText($varValue, $options);
}

/**
* Gets an array of valid attachments of a token field
* @param string
* @param array Tokens
* @return array
*
* @param string $strAttachmentTokens
* @param array $arrTokens
*
* @return array
*/
public static function getTokenAttachments($strAttachmentTokens, array $arrTokens)
{
Expand All @@ -145,18 +85,20 @@ public static function getTokenAttachments($strAttachmentTokens, array $arrToken

/**
* Generate CC or BCC recipients from comma separated string
* @param 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 = static::recursiveReplaceTokensAndTags($strRecipients, $arrTokens, static::NO_TAGS | static::NO_BREAKS);
$strRecipients = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strRecipients, $arrTokens, static::NO_TAGS | static::NO_BREAKS);
$arrRecipients = array();

foreach ((array) trimsplit(',', $strRecipients) as $strAddress) {
if ($strAddress != '') {
$strAddress = static::recursiveReplaceTokensAndTags($strAddress, $arrTokens, static::NO_TAGS | static::NO_BREAKS);

list($strName, $strEmail) = \String::splitFriendlyEmail($strAddress);

// Address could become empty through invalid insert tag
Expand Down

0 comments on commit e062363

Please sign in to comment.