Skip to content

Commit

Permalink
Some methods have been moved to Haste 4.10
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Oct 9, 2015
1 parent 03209ec commit ea2febd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 103 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/
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php":">=5.3.2",
"contao/core":"^3.2",
"contao-community-alliance/composer-plugin":"2.*",
"codefog/contao-haste":"4.*",
"codefog/contao-haste":"^4.10.0",
"terminal42/dcawizard":"2.*"
},
"autoload":{
Expand Down
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
118 changes: 31 additions & 87 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,12 +85,16 @@ 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) {
Expand Down

0 comments on commit ea2febd

Please sign in to comment.