当前位置: 首页>>代码示例>>PHP>>正文


PHP StringUtil::parseSimpleTokens方法代码示例

本文整理汇总了PHP中StringUtil::parseSimpleTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::parseSimpleTokens方法的具体用法?PHP StringUtil::parseSimpleTokens怎么用?PHP StringUtil::parseSimpleTokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringUtil的用法示例。


在下文中一共展示了StringUtil::parseSimpleTokens方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $this->Template->content = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     if (TL_MODE == 'FE' && BE_USER_LOGGED_IN) {
         $objNewsletter = \NewsletterModel::findByIdOrAlias(\Input::get('items'));
     } else {
         $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
     }
     if ($objNewsletter === null) {
         // Do not index or cache the page
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         // Send a 404 header
         header('HTTP/1.1 404 Not Found');
         $this->Template->content = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>';
         return;
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objNewsletter->subject != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objNewsletter->subject));
     }
     // Add enclosure
     if ($objNewsletter->addFile) {
         $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files');
     }
     if (!$objNewsletter->sendText) {
         $nl2br = $objPage->outputFormat == 'xhtml' ? 'nl2br_xhtml' : 'nl2br_html5';
         $strContent = '';
         $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter');
         if ($objContentElements !== null) {
             if (!defined('NEWSLETTER_CONTENT_PREVIEW')) {
                 define('NEWSLETTER_CONTENT_PREVIEW', true);
             }
             foreach ($objContentElements as $objContentElement) {
                 $strContent .= $this->getContentElement($objContentElement->id);
             }
         }
         // 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;
     } else {
         $strContent = str_ireplace(' align="center"', '', $objNewsletter->content);
     }
     // Convert relative URLs
     $strContent = $this->convertRelativeUrls($strContent);
     // 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;
 }
开发者ID:davidenke,项目名称:newsletter_content,代码行数:62,代码来源:ModuleNewsletterReader.php

示例2: prepareFileName

 /**
  * Prepare file name
  *
  * @param string $strName   File name
  * @param array  $arrTokens Simple tokens (optional)
  * @param string $strPath   Path (optional)
  *
  * @return string Sanitized file name
  */
 protected function prepareFileName($strName, $arrTokens = array(), $strPath = '')
 {
     // Replace simple tokens
     $strName = \StringUtil::parseSimpleTokens($strName, $arrTokens);
     $strName = $this->sanitizeFileName($strName);
     if ($strPath) {
         // Make sure the path contains a trailing slash
         $strPath = preg_replace('/([^\\/]+)$/', '$1/', $strPath);
         $strName = $strPath . $strName;
     }
     return $strName;
 }
开发者ID:ralfhartmann,项目名称:isotope_core,代码行数:21,代码来源:Document.php

示例3: recursiveReplaceTokensAndTags

 /**
  * 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
  */
 public static function recursiveReplaceTokensAndTags($strText, $arrTokens, $intTextFlags = 0)
 {
     if ($intTextFlags > 0) {
         $arrTokens = static::convertToText($arrTokens, $intTextFlags);
     }
     // PHP 7 compatibility
     // See #309 (https://github.com/contao/core-bundle/issues/309)
     if (version_compare(VERSION . '.' . BUILD, '3.5.1', '>=')) {
         // Must decode, tokens could be encoded
         $strText = \StringUtil::decodeEntities($strText);
     } else {
         // 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 = 'HASTE-TAG-OPEN-' . $strHash;
     $strTagCloseReplacement = 'HASTE-TAG-CLOSE-' . $strHash;
     $arrOriginal = array('<', '>');
     $arrReplacement = array($strTagOpenReplacement, $strTagCloseReplacement);
     $strBuffer = str_replace($arrOriginal, $arrReplacement, $strText);
     // PHP 7 compatibility
     // See #309 (https://github.com/contao/core-bundle/issues/309)
     if (version_compare(VERSION . '.' . BUILD, '3.5.1', '>=')) {
         // first parse the tokens as they might have if-else clauses
         $strBuffer = \StringUtil::parseSimpleTokens($strBuffer, $arrTokens);
     } else {
         // first parse the tokens as they might have if-else clauses
         $strBuffer = \String::parseSimpleTokens($strBuffer, $arrTokens);
     }
     $strBuffer = str_replace($arrReplacement, $arrOriginal, $strBuffer);
     // then replace the insert tags
     $strBuffer = \Controller::replaceInsertTags($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);
     }
     // PHP 7 compatibility
     // See #309 (https://github.com/contao/core-bundle/issues/309)
     if (version_compare(VERSION . '.' . BUILD, '3.5.1', '>=')) {
         $strBuffer = \StringUtil::restoreBasicEntities($strBuffer);
     } else {
         $strBuffer = \String::restoreBasicEntities($strBuffer);
     }
     if ($intTextFlags > 0) {
         $strBuffer = static::convertToText($strBuffer, $intTextFlags);
     }
     return $strBuffer;
 }
开发者ID:codefog,项目名称:contao-haste,代码行数:59,代码来源:StringUtil.php

示例4: getTokenAttachments

 /**
  * 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', '<')) {
             $strParsedToken = \String::parseSimpleTokens($strToken, $arrTokens);
         } else {
             $strParsedToken = \StringUtil::parseSimpleTokens($strToken, $arrTokens);
         }
         foreach (trimsplit(',', $strParsedToken) as $strFile) {
             $strFileFull = TL_ROOT . '/' . str_replace($arrTokens['env_url'] . '/', '', $strFile);
             if (is_file($strFileFull)) {
                 $arrAttachments[$strFile] = $strFileFull;
             }
         }
     }
     return $arrAttachments;
 }
开发者ID:heimrichhannot,项目名称:contao-notification_center_plus,代码行数:29,代码来源:StringUtil.php

示例5: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var Message|\Model\Collection $objMessages */
     /** @noinspection PhpUndefinedMethodInspection */
     $objMessages = Message::findBy(array('pid IN (' . implode(',', $this->nc_member_customizable_notifications) . ') AND member_customizable<>\'\''), array());
     $arrOptions = array();
     $arrSelected = array();
     while ($objMessages->next()) {
         if (MemberMessages::memberHasSelected(\FrontendUser::getInstance()->id, $objMessages->id)) {
             $arrSelected[$objMessages->pid][] = $objMessages->id;
         }
         // Fetch tokens for parsing the option labels
         $objNotification = $objMessages->getRelated('pid');
         $objGateway = $objMessages->getRelated('gateway');
         $arrTokens = array_merge(array_combine(array_map(function ($key) {
             return 'message_' . $key;
         }, array_keys($objMessages->row())), $objMessages->row()), array_combine(array_map(function ($key) {
             return 'notification_' . $key;
         }, array_keys($objNotification->row())), $objNotification->row()), array_combine(array_map(function ($key) {
             return 'gateway_' . $key;
         }, array_keys($objGateway->row())), $objGateway->row()));
         $arrOptions[$objMessages->pid][$objMessages->id] = \StringUtil::parseSimpleTokens($this->nc_member_customizable_label ?: '##message_title## (##gateway_title##)', $arrTokens);
     }
     $objForm = new Form('tl_select_notifications', 'POST', function ($objHaste) {
         /** @noinspection PhpUndefinedMethodInspection */
         return \Input::post('FORM_SUBMIT') === $objHaste->getFormId();
     });
     foreach ($arrOptions as $k => $options) {
         /** @noinspection PhpUndefinedMethodInspection */
         $objForm->addFormField('notification_' . $k, array('label' => Notification::findByPk($objMessages->pid)->title, 'inputType' => $this->nc_member_customizable_inputType, 'options' => $options, 'eval' => array('mandatory' => $this->nc_member_customizable_mandatory), 'value' => !empty($arrSelected[$k]) ? $arrSelected[$k] : array()));
         // Add a validator
         // We check whether it is possible to send the message to the recipient by means of the gateway
         // E.g. a sms message requires a phone number set by the member which is not default
         $objForm->addValidator('notification_' . $k, function ($varValue, $objWidget, $objForm) use($k, $arrOptions) {
             if (empty($varValue)) {
                 return $varValue;
             }
             foreach ($varValue as $msg) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 /** @var Message|\Model $objMessage */
                 $objMessage = Message::findByPk($msg);
                 /** @noinspection PhpUndefinedMethodInspection */
                 /** @var GatewayInterface|MessageDraftCheckSendInterface $objGateway */
                 $objGateway = $objMessage->getRelated('gateway')->getGateway();
                 if (!$objGateway instanceof MessageDraftCheckSendInterface) {
                     continue;
                 }
                 // Throw the error message as exception if the method has not yet
                 if (!$objGateway->canSendDraft($objMessage)) {
                     throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['messageNotSelectable'], $arrOptions[$k][$msg]));
                 }
             }
             return $varValue;
         });
     }
     $objForm->addSubmitFormField('submit', $GLOBALS['TL_LANG']['MSC']['saveSettings']);
     // Process form submit
     if ($objForm->validate()) {
         $arrData = $objForm->fetchAll();
         foreach ($arrData as $field => $notification) {
             if (strpos($field, 'notification_') !== 0) {
                 continue;
             }
             list(, $notificationId) = trimsplit('_', $field);
             // Delete
             foreach (array_diff((array) $arrSelected[$notificationId], (array) $notification) as $msg) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 MemberMessages::findByMemberAndMessage(\FrontendUser::getInstance()->id, $msg)->delete();
             }
             // Create
             foreach (array_diff((array) $notification, (array) $arrSelected[$notificationId]) as $msg) {
                 /** @var MemberMessages|\Model $objMemberMessage */
                 $objMemberMessage = new MemberMessages();
                 $objMemberMessage->member_id = \FrontendUser::getInstance()->id;
                 $objMemberMessage->message_id = $msg;
                 $objMemberMessage->save();
             }
         }
     }
     $this->Template->form = $objForm->generate();
 }
开发者ID:richardhj,项目名称:contao-notification_center_member_selectable,代码行数:84,代码来源:MemberCustomizeMessages.php

示例6: 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) {
         /** @var \PageError404 $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objNewsletter->subject != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($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) {
         $nl2br = $objPage->outputFormat == 'xhtml' ? 'nl2br_xhtml' : 'nl2br_html5';
         $strContent = $nl2br($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;
 }
开发者ID:StephenGWills,项目名称:sample-contao-app,代码行数:39,代码来源:ModuleNewsletterReader.php

示例7: 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') . (\Config::get('disableAlias') || 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 . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
     // Check whether there is a jumpTo page
     if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->jumpToOrReload($objJumpTo->row());
     }
     $this->reload();
 }
开发者ID:rheintechnology,项目名称:core,代码行数:30,代码来源:ModulePassword.php

示例8: addRecipient

 /**
  * Add a new recipient
  */
 protected function addRecipient()
 {
     $arrChannels = \Input::post('channels');
     if (!is_array($arrChannels)) {
         $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels'];
         $this->reload();
     }
     $arrChannels = array_intersect($arrChannels, $this->nl_channels);
     // see #3240
     // Check the selection
     if (!is_array($arrChannels) || empty($arrChannels)) {
         $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels'];
         $this->reload();
     }
     $varInput = \Idna::encodeEmail(\Input::post('email', true));
     // Validate the e-mail address
     if (!\Validator::isEmail($varInput)) {
         $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['email'];
         $this->reload();
     }
     $arrSubscriptions = array();
     // Get the existing active subscriptions
     if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) {
         $arrSubscriptions = $objSubscription->fetchEach('pid');
     }
     $arrNew = array_diff($arrChannels, $arrSubscriptions);
     // Return if there are no new subscriptions
     if (!is_array($arrNew) || empty($arrNew)) {
         $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['subscribed'];
         $this->reload();
     }
     // Remove old subscriptions that have not been activated yet
     if (($objOld = \NewsletterRecipientsModel::findBy(array("email=? AND active=''"), $varInput)) !== 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 = $varInput;
         $objRecipient->active = '';
         $objRecipient->addedOn = $time;
         $objRecipient->ip = $this->anonymizeIp(\Environment::get('ip'));
         $objRecipient->token = $strToken;
         $objRecipient->confirmed = '';
         $objRecipient->save();
     }
     // Get the channels
     $objChannel = \NewsletterChannelModel::findByIds($arrChannels);
     // 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') . (\Config::get('disableAlias') || 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($varInput);
     // Redirect to the jumpTo page
     if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->redirect($this->generateFrontendUrl($objTarget->row()));
     }
     $_SESSION['SUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_confirm'];
     $this->reload();
 }
开发者ID:Jobu,项目名称:core,代码行数:77,代码来源:ModuleSubscribe.php

示例9: removeRecipient

 /**
  * Remove the recipient
  */
 protected function removeRecipient()
 {
     $arrChannels = \Input::post('channels');
     if (!is_array($arrChannels)) {
         $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels'];
         $this->reload();
     }
     $arrChannels = array_intersect($arrChannels, $this->nl_channels);
     // see #3240
     // Check the selection
     if (!is_array($arrChannels) || empty($arrChannels)) {
         $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels'];
         $this->reload();
     }
     $varInput = \Idna::encodeEmail(\Input::post('email', true));
     // Validate e-mail address
     if (!\Validator::isEmail($varInput)) {
         $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['email'];
         $this->reload();
     }
     $arrSubscriptions = array();
     // Get the existing active subscriptions
     if (($objSubscription = \NewsletterRecipientsModel::findBy(array("email=? AND active=1"), $varInput)) !== null) {
         $arrSubscriptions = $objSubscription->fetchEach('pid');
     }
     $arrRemove = array_intersect($arrChannels, $arrSubscriptions);
     // Return if there are no subscriptions to remove
     if (!is_array($arrRemove) || empty($arrRemove)) {
         $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['unsubscribed'];
         $this->reload();
     }
     // Remove the subscriptions
     if (($objRemove = \NewsletterRecipientsModel::findByEmailAndPids($varInput, $arrRemove)) !== null) {
         while ($objRemove->next()) {
             $objRemove->delete();
         }
     }
     // Get the channels
     $objChannels = \NewsletterChannelModel::findByIds($arrRemove);
     $arrChannels = $objChannels->fetchEach('title');
     // Log activity
     $this->log($varInput . ' unsubscribed from ' . implode(', ', $arrChannels), __METHOD__, TL_NEWSLETTER);
     // 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]($varInput, $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($varInput);
     // Redirect to the jumpTo page
     if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->redirect($this->generateFrontendUrl($objTarget->row()));
     }
     $_SESSION['UNSUBSCRIBE_CONFIRM'] = $GLOBALS['TL_LANG']['MSC']['nl_removed'];
     $this->reload();
 }
开发者ID:Jobu,项目名称:core,代码行数:70,代码来源:ModuleUnsubscribe.php

示例10: generate

 /**
  * Return formatted address (hCard)
  *
  * @param array $arrFields
  *
  * @return string
  */
 public function generate($arrFields = null)
 {
     // We need a country to format the address, use default country if none is available
     $strCountry = $this->country ?: Isotope::getConfig()->country;
     // Use generic format if no country specific format is available
     $strFormat = $GLOBALS['ISO_ADR'][$strCountry] ?: $GLOBALS['ISO_ADR']['generic'];
     $arrTokens = $this->getTokens($arrFields);
     $strAddress = \StringUtil::parseSimpleTokens($strFormat, $arrTokens);
     return $strAddress;
 }
开发者ID:bytehead,项目名称:core,代码行数:17,代码来源:Address.php

示例11: 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 Use StringUtil::parseSimpleTokens() instead
  */
 protected function parseSimpleTokens($strBuffer, $arrData)
 {
     return \StringUtil::parseSimpleTokens($strBuffer, $arrData);
 }
开发者ID:StephenGWills,项目名称:sample-contao-app,代码行数:14,代码来源:Controller.php

示例12: sendNewsletter

 /**
  * Compile the newsletter and send it
  * @param \Email
  * @param \Database\Result
  * @param array
  * @param string
  * @param string
  * @param string
  * @return string
  */
 protected function sendNewsletter(\Email $objEmail, \Database\Result $objNewsletter, $arrRecipient, $text, $body, $css = null)
 {
     // Prepare the text content
     $objEmail->text = \StringUtil::parseSimpleTokens($text, $arrRecipient);
     // Add the HTML content
     if (!$objNewsletter->sendText) {
         // Default template
         if ($objNewsletter->template == '') {
             $objNewsletter->template = 'mail_default';
         }
         // Load the mail template
         $objTemplate = new \BackendTemplate($objNewsletter->template);
         $objTemplate->setData($objNewsletter->row());
         $objTemplate->title = $objNewsletter->subject;
         $objTemplate->body = $body;
         $objTemplate->charset = \Config::get('characterSet');
         $objTemplate->css = $css;
         // Backwards compatibility
         $objTemplate->recipient = $arrRecipient['email'];
         // Parse template
         $html = $objTemplate->parse();
         $html = $this->convertRelativeUrls($html);
         $html = $this->replaceInsertTags($html);
         $html = $this->prepareLinkTracking($html, $objNewsletter->id, $arrRecipient['email'], $arrRecipient['extra'] ?: '');
         $html = $this->parseSimpleTokens($html, $arrRecipient);
         // Append to mail object
         $objEmail->html = $html;
         $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);
         }
     }
 }
开发者ID:davidenke,项目名称:newsletter_content,代码行数:57,代码来源:NewsletterContent.php

示例13: createNewUser

 /**
  * Create a new user and redirect
  *
  * @param array $arrData
  */
 protected function createNewUser($arrData)
 {
     $arrData['tstamp'] = time();
     $arrData['login'] = $this->reg_allowLogin;
     $arrData['activation'] = md5(uniqid(mt_rand(), true));
     $arrData['dateAdded'] = $arrData['tstamp'];
     // Set default groups
     if (!array_key_exists('groups', $arrData)) {
         $arrData['groups'] = $this->reg_groups;
     }
     // Disable account
     $arrData['disable'] = 1;
     // Send activation e-mail
     if ($this->reg_activate) {
         // Prepare the simple token data
         $arrTokenData = $arrData;
         $arrTokenData['domain'] = \Idna::decode(\Environment::get('host'));
         $arrTokenData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'];
         $arrTokenData['channels'] = '';
         if (in_array('newsletter', \ModuleLoader::getActive())) {
             // 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'));
                 }
             }
         }
         // Backwards compatibility
         $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']);
     }
     // Make sure newsletter is an array
     if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) {
         $arrData['newsletter'] = array($arrData['newsletter']);
     }
     // Create the user
     $objNewUser = new \MemberModel();
     $objNewUser->setRow($arrData);
     $objNewUser->save();
     // Assign home directory
     if ($this->reg_assignDir) {
         $objHomeDir = \FilesModel::findByUuid($this->reg_homeDir);
         if ($objHomeDir !== null) {
             $this->import('Files');
             $strUserDir = standardize($arrData['username']) ?: 'user_' . $objNewUser->id;
             // Add the user ID if the directory exists
             while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) {
                 $strUserDir .= '_' . $objNewUser->id;
             }
             // Create the user folder
             new \Folder($objHomeDir->path . '/' . $strUserDir);
             $objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir);
             // Save the folder ID
             $objNewUser->assignDir = 1;
             $objNewUser->homeDir = $objUserDir->uuid;
             $objNewUser->save();
         }
     }
     // HOOK: send insert ID and user data
     if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) {
         foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objNewUser->id, $arrData, $this);
         }
     }
     // Create the initial version (see #7816)
     $objVersions = new \Versions('tl_member', $objNewUser->id);
     $objVersions->setUsername($objNewUser->username);
     $objVersions->setUserId(0);
     $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1');
     $objVersions->initialize();
     // Inform admin if no activation link is sent
     if (!$this->reg_activate) {
         $this->sendAdminNotification($objNewUser->id, $arrData);
     }
     // Check whether there is a jumpTo page
     if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->jumpToOrReload($objJumpTo->row());
     }
     $this->reload();
 }
开发者ID:Jobu,项目名称:core,代码行数:100,代码来源:ModuleRegistration.php

示例14: generateTemplate

 /**
  * Generate and return document template
  *
  * @param IsotopeProductCollection $objCollection
  * @param array                    $arrTokens
  *
  * @return string
  */
 protected function generateTemplate(IsotopeProductCollection $objCollection, array $arrTokens)
 {
     $objPage = \PageModel::findWithDetails($objCollection->page_id);
     $objTemplate = new \Isotope\Template($this->documentTpl);
     $objTemplate->setData($this->arrData);
     $objTemplate->title = \StringUtil::parseSimpleTokens($this->documentTitle, $arrTokens);
     $objTemplate->collection = $objCollection;
     $objTemplate->config = $objCollection->getRelated('config_id');
     $objTemplate->page = $objPage;
     $objTemplate->dateFormat = $objPage->dateFormat ?: $GLOBALS['TL_CONFIG']['dateFormat'];
     $objTemplate->timeFormat = $objPage->timeFormat ?: $GLOBALS['TL_CONFIG']['timeFormat'];
     $objTemplate->datimFormat = $objPage->datimFormat ?: $GLOBALS['TL_CONFIG']['datimFormat'];
     // Render the collection
     $objCollectionTemplate = new \Isotope\Template($this->collectionTpl);
     $objCollection->addToTemplate($objCollectionTemplate, array('gallery' => $this->gallery, 'sorting' => $objCollection->getItemsSortingCallable($this->orderCollectionBy)));
     $objTemplate->products = $objCollectionTemplate->parse();
     // !HOOK: customize the document template
     if (isset($GLOBALS['ISO_HOOKS']['generateDocumentTemplate']) && is_array($GLOBALS['ISO_HOOKS']['generateDocumentTemplate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['generateDocumentTemplate'] as $callback) {
             \System::importStatic($callback[0])->{$callback}[1]($objTemplate, $objCollection, $this);
         }
     }
     // Generate template and fix PDF issues, see Contao's ModuleArticle
     $strBuffer = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false));
     $strBuffer = html_entity_decode($strBuffer, ENT_QUOTES, $GLOBALS['TL_CONFIG']['characterSet']);
     $strBuffer = \Controller::convertRelativeUrls($strBuffer, '', true);
     // Remove form elements and JavaScript links
     $arrSearch = array('@<form.*</form>@Us', '@<a [^>]*href="[^"]*javascript:[^>]+>.*</a>@Us');
     $strBuffer = preg_replace($arrSearch, '', $strBuffer);
     // URL decode image paths (see contao/core#6411)
     // Make image paths absolute
     $strBuffer = preg_replace_callback('@(src=")([^"]+)(")@', function ($args) {
         if (preg_match('@^(http://|https://)@', $args[2])) {
             return $args[2];
         }
         return $args[1] . TL_ROOT . '/' . rawurldecode($args[2]) . $args[3];
     }, $strBuffer);
     // Handle line breaks in preformatted text
     $strBuffer = preg_replace_callback('@(<pre.*</pre>)@Us', 'nl2br_callback', $strBuffer);
     // Default PDF export using TCPDF
     $arrSearch = array('@<span style="text-decoration: ?underline;?">(.*)</span>@Us', '@(<img[^>]+>)@', '@(<div[^>]+block[^>]+>)@', '@[\\n\\r\\t]+@', '@<br( /)?><div class="mod_article@', '@href="([^"]+)(pdf=[0-9]*(&|&amp;)?)([^"]*)"@');
     $arrReplace = array('<u>$1</u>', '<br>$1', '<br>$1', ' ', '<div class="mod_article', 'href="$1$4"');
     $strBuffer = preg_replace($arrSearch, $arrReplace, $strBuffer);
     return $strBuffer;
 }
开发者ID:ralfhartmann,项目名称:isotope_core,代码行数:53,代码来源:Standard.php


注:本文中的StringUtil::parseSimpleTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。