/**
  * Create file
  *
  * @param   Message
  * @param   array
  * @param   string
  * @return  bool
  */
 public function send(Message $objMessage, array $arrTokens, $strLanguage = '')
 {
     if ($strLanguage == '') {
         $strLanguage = $GLOBALS['TL_LANGUAGE'];
     }
     if (($objLanguage = Language::findByMessageAndLanguageOrFallback($objMessage, $strLanguage)) === null) {
         \System::log(sprintf('Could not find matching language or fallback for message ID "%s" and language "%s".', $objMessage->id, $strLanguage), __METHOD__, TL_ERROR);
         return false;
     }
     $strFileName = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($objLanguage->file_name, $arrTokens, String::NO_TAGS | String::NO_BREAKS);
     // Escape quotes and line breaks for CSV files
     if ($this->objModel->file_type == 'csv') {
         array_walk($arrTokens, function (&$varValue) {
             $varValue = str_replace(array('"', "\r\n", "\r"), array('""', "\n", "\n"), $varValue);
         });
     }
     // Preserve all tags here as this is pretty useful in XML :-)
     $strContent = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($objLanguage->file_content, $arrTokens);
     try {
         return $this->save($strFileName, $strContent, (string) $objLanguage->file_storage_mode);
     } catch (\Exception $e) {
         \System::log('Notification Center gateway error: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         return false;
     }
 }
 /**
  * Generate label for this record.
  *
  * @param array
  * @param string
  *
  * @return string
  */
 public function getLabel($row, $label)
 {
     $objForm = \FormModel::findById($row['master_id']);
     if ($objForm != null && $objForm->encryptLeadsData) {
         $arrTokens = array('created' => \Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $row['created']));
         $objData = \Database::getInstance()->prepare("SELECT * FROM tl_lead_data WHERE pid=?")->execute($row['id']);
         while ($objData->next()) {
             Haste\Util\StringUtil::flatten(deserialize(\Encryption::decrypt($objData->value)), $objData->name, $arrTokens);
         }
         return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($objForm->leadLabel, $arrTokens);
     }
     return parent::getLabel($row, $label);
 }
Example #3
0
 /**
  * Generate label for this record.
  *
  * @param array
  * @param string
  *
  * @return string
  */
 public function getLabel($row, $label)
 {
     $objForm = \Database::getInstance()->prepare("SELECT * FROM tl_form WHERE id=?")->execute($row['master_id']);
     // No form found, we can't format the label
     if (!$objForm->numRows) {
         return $label;
     }
     $arrTokens = array('created' => \Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $row['created']));
     $objData = \Database::getInstance()->prepare("SELECT * FROM tl_lead_data WHERE pid=?")->execute($row['id']);
     while ($objData->next()) {
         Haste\Util\StringUtil::flatten(deserialize($objData->value), $objData->name, $arrTokens);
     }
     return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($objForm->leadLabel, $arrTokens);
 }
 /**
  * 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;
 }
 /**
  * Generate the tokens
  *
  * @param array $arrData
  * @param array $arrForm
  * @param array $arrFiles
  * @param array $arrLabels
  *
  * @return array
  */
 public function generateTokens(array $arrData, array $arrForm, array $arrFiles, array $arrLabels)
 {
     $arrTokens = array();
     $arrTokens['raw_data'] = '';
     foreach ($arrData as $k => $v) {
         \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) {
         \Haste\Util\StringUtil::flatten($v, 'formconfig_' . $k, $arrTokens);
     }
     // Administrator e-mail
     $arrTokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL'];
     // Upload fields
     foreach ($arrFiles as $fieldName => $file) {
         $arrTokens['form_' . $fieldName] = Form::getFileUploadPathForToken($file);
     }
     return $arrTokens;
 }
 /**
  * @deprecated Use \Haste\Util\StringUtil::convertToText()
  */
 protected function convertToText($varValue, $options)
 {
     return \Haste\Util\StringUtil::convertToText($varValue, $options);
 }
 /**
  * Returns the html body as a string
  * @return  string
  */
 public function getHtmlBody()
 {
     if ($this->objLanguage->email_mode == 'textAndHtml') {
         $objTemplate = new \FrontendTemplate($this->objMessage->email_template);
         $objTemplate->body = $this->objLanguage->email_html;
         $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet'];
         // 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 = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strHtml, $this->arrTokens);
         $strHtml = \Controller::convertRelativeUrls($strHtml, '', true);
         $strHtml = str_replace('<DOCTYPE', '<!DOCTYPE', $strHtml);
         return $strHtml;
     }
     return '';
 }
Example #8
0
 /**
  * @param mixed  $value
  * @param string $key
  * @param array  $data
  * @param array  $expected
  *
  * @dataProvider flattenDataProvider
  */
 public function testFlatten($value, $key, array $data, array $expected)
 {
     StringUtil::flatten($value, $key, $data);
     $this->assertEquals($expected, $data);
 }