/** * 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; } }
/** * Returns a MessageDraft * @param Message * @param array * @param string * @return MessageDraftInterface|null (if no draft could be found) */ public function createDraft(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 null; } return new PostmarkMessageDraft($objMessage, $objLanguage, $arrTokens); }