本文整理汇总了PHP中Contao\StringUtil::parseSimpleTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::parseSimpleTokens方法的具体用法?PHP StringUtil::parseSimpleTokens怎么用?PHP StringUtil::parseSimpleTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contao\StringUtil
的用法示例。
在下文中一共展示了StringUtil::parseSimpleTokens方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendActivationMail
/**
* Send the activation mail
*
* @param array $arrData
*/
protected function sendActivationMail($arrData)
{
// Prepare the simple token data
$arrTokenData = $arrData;
$arrTokenData['domain'] = \Idna::decode(\Environment::get('host'));
$arrTokenData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'];
$arrTokenData['channels'] = '';
$bundles = \System::getContainer()->getParameter('kernel.bundles');
if (isset($bundles['ContaoNewsletterBundle'])) {
// Make sure newsletter is an array
if (!is_array($arrData['newsletter'])) {
if ($arrData['newsletter'] != '') {
$arrData['newsletter'] = array($arrData['newsletter']);
} else {
$arrData['newsletter'] = array();
}
}
// Replace the wildcard
if (!empty($arrData['newsletter'])) {
$objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']);
if ($objChannels !== null) {
$arrTokenData['channels'] = implode("\n", $objChannels->fetchEach('title'));
}
}
}
// Deprecated since Contao 4.0, to be removed in Contao 5.0
$arrTokenData['channel'] = $arrTokenData['channels'];
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = \StringUtil::parseSimpleTokens($this->reg_text, $arrTokenData);
$objEmail->sendTo($arrData['email']);
}
示例2: sendPasswordLink
/**
* Create a new user and redirect
*
* @param MemberModel $objMember
*/
protected function sendPasswordLink($objMember)
{
$confirmationId = md5(uniqid(mt_rand(), true));
// Store the confirmation ID
$objMember = \MemberModel::findByPk($objMember->id);
$objMember->activation = $confirmationId;
$objMember->save();
// Prepare the simple token data
$arrData = $objMember->row();
$arrData['domain'] = \Idna::decode(\Environment::get('host'));
$arrData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
// Send e-mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['passwordSubject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = \StringUtil::parseSimpleTokens($this->reg_password, $arrData);
$objEmail->sendTo($objMember->email);
$this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . \Idna::decodeEmail($objMember->email) . ')', __METHOD__, TL_ACCESS);
// Check whether there is a jumpTo page
if (($objJumpTo = $this->objModel->getRelated('jumpTo')) instanceof PageModel) {
$this->jumpToOrReload($objJumpTo->row());
}
$this->reload();
}
示例3: testParseSimpleTokensInvalidComparison
/**
* Tests that the parseSimpleTokens() method fails for invalid comparisons.
*
* @param $string
*
* @dataProvider parseSimpleTokensInvalidComparison
*
* @expectedException \InvalidArgumentException
*/
public function testParseSimpleTokensInvalidComparison($string)
{
StringUtil::parseSimpleTokens($string, ['foo' => 'bar']);
}
示例4: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$this->Template->content = '';
$this->Template->referer = 'javascript:history.go(-1)';
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
$objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
if (null === $objNewsletter) {
throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
}
// Overwrite the page title (see #2853 and #4955)
if ($objNewsletter->subject != '') {
$objPage->pageTitle = strip_tags(\StringUtil::stripInsertTags($objNewsletter->subject));
}
// Add enclosure
if ($objNewsletter->addFile) {
$this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files');
}
// Support plain text newsletters (thanks to Hagen Klemp)
if ($objNewsletter->sendText) {
$strContent = nl2br_html5($objNewsletter->text);
} else {
$strContent = str_ireplace(' align="center"', '', $objNewsletter->content);
}
// Parse simple tokens and insert tags
$strContent = $this->replaceInsertTags($strContent);
$strContent = \StringUtil::parseSimpleTokens($strContent, array());
// Encode e-mail addresses
$strContent = \StringUtil::encodeEmail($strContent);
$this->Template->content = $strContent;
$this->Template->subject = $objNewsletter->subject;
}
示例5: sendNewsletter
/**
* Compile the newsletter and send it
*
* @param Email $objEmail
* @param Database\Result|object $objNewsletter
* @param array $arrRecipient
* @param string $text
* @param string $html
* @param string $css
*
* @return string
*/
protected function sendNewsletter(Email $objEmail, Database\Result $objNewsletter, $arrRecipient, $text, $html, $css = null)
{
// Prepare the text content
$objEmail->text = \StringUtil::parseSimpleTokens($text, $arrRecipient);
if (!$objNewsletter->sendText) {
// Default template
if ($objNewsletter->template == '') {
$objNewsletter->template = 'mail_default';
}
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate($objNewsletter->template);
$objTemplate->setData($objNewsletter->row());
$objTemplate->title = $objNewsletter->subject;
$objTemplate->body = \StringUtil::parseSimpleTokens($html, $arrRecipient);
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->recipient = $arrRecipient['email'];
// Deprecated since Contao 4.0, to be removed in Contao 5.0
$objTemplate->css = $css;
// Parse template
$objEmail->html = $objTemplate->parse();
$objEmail->imageDir = TL_ROOT . '/';
}
// Deactivate invalid addresses
try {
$objEmail->sendTo($arrRecipient['email']);
} catch (\Swift_RfcComplianceException $e) {
$_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
}
// Rejected recipients
if ($objEmail->hasFailures()) {
$_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email'];
}
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['sendNewsletter']) && is_array($GLOBALS['TL_HOOKS']['sendNewsletter'])) {
foreach ($GLOBALS['TL_HOOKS']['sendNewsletter'] as $callback) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($objEmail, $objNewsletter, $arrRecipient, $text, $html);
}
}
}
示例6: removeRecipient
/**
* Remove the recipient
*
* @param string $strEmail
* @param array $arrRemove
*/
protected function removeRecipient($strEmail, $arrRemove)
{
// Remove the subscriptions
if (($objRemove = \NewsletterRecipientsModel::findByEmailAndPids($strEmail, $arrRemove)) !== null) {
while ($objRemove->next()) {
$strHash = md5($objRemove->email);
// Add a blacklist entry (see #4999)
if (($objBlacklist = \NewsletterBlacklistModel::findByHashAndPid($strHash, $objRemove->pid)) === null) {
$objBlacklist = new \NewsletterBlacklistModel();
$objBlacklist->pid = $objRemove->pid;
$objBlacklist->hash = $strHash;
$objBlacklist->save();
}
$objRemove->delete();
}
}
// Get the channels
$objChannels = \NewsletterChannelModel::findByIds($arrRemove);
$arrChannels = $objChannels->fetchEach('title');
// HOOK: post unsubscribe callback
if (isset($GLOBALS['TL_HOOKS']['removeRecipient']) && is_array($GLOBALS['TL_HOOKS']['removeRecipient'])) {
foreach ($GLOBALS['TL_HOOKS']['removeRecipient'] as $callback) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($strEmail, $arrRemove);
}
}
// Prepare the simple token data
$arrData = array();
$arrData['domain'] = \Idna::decode(\Environment::get('host'));
$arrData['channel'] = $arrData['channels'] = implode("\n", $arrChannels);
// Confirmation e-mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = \StringUtil::parseSimpleTokens($this->nl_unsubscribe, $arrData);
$objEmail->sendTo($strEmail);
// Redirect to the jumpTo page
if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
$this->redirect($this->generateFrontendUrl($objTarget->row()));
}
\System::getContainer()->get('session')->getFlashBag()->set('nl_removed', $GLOBALS['TL_LANG']['MSC']['nl_removed']);
$this->reload();
}
示例7: parseSimpleTokens
/**
* Parse simple tokens that can be used to personalize newsletters
*
* @param string $strBuffer The text with the tokens to be replaced
* @param array $arrData The replacement data as array
*
* @return string The text with the replaced tokens
*
* @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
* Use StringUtil::parseSimpleTokens() instead.
*/
protected function parseSimpleTokens($strBuffer, $arrData)
{
trigger_error('Using Controller::parseSimpleTokens() has been deprecated and will no longer work in Contao 5.0. Use StringUtil::parseSimpleTokens() instead.', E_USER_DEPRECATED);
return \StringUtil::parseSimpleTokens($strBuffer, $arrData);
}
示例8: parseSimpleTokens
/**
* Parse simple tokens that can be used to personalize newsletters.
*
* @param string $strString The string to be parsed.
*
* @param array $arrData The replacement data.
*
* @return string The converted string
*
* @throws \Exception If $strString cannot be parsed.
*/
public static function parseSimpleTokens($strString, $arrData)
{
if (self::isStringUtilAvailable()) {
return StringUtil::parseSimpleTokens($strString, $arrData);
}
return \Contao\String::parseSimpleTokens($strString, $arrData);
}
示例9: addRecipient
/**
* Add a new recipient
*
* @param string $strEmail
* @param array $arrNew
*/
protected function addRecipient($strEmail, $arrNew)
{
// Remove old subscriptions that have not been activated yet
if (($objOld = \NewsletterRecipientsModel::findBy(array("email=? AND active=''"), $strEmail)) !== null) {
while ($objOld->next()) {
$objOld->delete();
}
}
$time = time();
$strToken = md5(uniqid(mt_rand(), true));
// Add the new subscriptions
foreach ($arrNew as $id) {
$objRecipient = new \NewsletterRecipientsModel();
$objRecipient->pid = $id;
$objRecipient->tstamp = $time;
$objRecipient->email = $strEmail;
$objRecipient->active = '';
$objRecipient->addedOn = $time;
$objRecipient->ip = $this->anonymizeIp(\Environment::get('ip'));
$objRecipient->token = $strToken;
$objRecipient->confirmed = '';
$objRecipient->save();
// Remove the blacklist entry (see #4999)
if (($objBlacklist = \NewsletterBlacklistModel::findByHashAndPid(md5($strEmail), $id)) !== null) {
$objBlacklist->delete();
}
}
// Get the channels
$objChannel = \NewsletterChannelModel::findByIds($arrNew);
// Prepare the simple token data
$arrData = array();
$arrData['token'] = $strToken;
$arrData['domain'] = \Idna::decode(\Environment::get('host'));
$arrData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $strToken;
$arrData['channel'] = $arrData['channels'] = implode("\n", $objChannel->fetchEach('title'));
// Activation e-mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = \StringUtil::parseSimpleTokens($this->nl_subscribe, $arrData);
$objEmail->sendTo($strEmail);
// Redirect to the jumpTo page
if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) {
/** @var PageModel $objTarget */
$this->redirect($objTarget->getFrontendUrl());
}
\System::getContainer()->get('session')->getFlashBag()->set('nl_confirm', $GLOBALS['TL_LANG']['MSC']['nl_confirm']);
$this->reload();
}