/** * @return string The generated mailing body. */ protected function getEmailBody() { $template = FrontendMailmotorModel::getTemplate($this->mailing['language'], $this->mailing['template']); // define the key/value replacements to assign in to the mailing body $replacements = array('{$siteURL}' => SITE_URL, 'src="/"' => 'src="' . SITE_URL . '/'); // build the mailing body $mailing = new MailingBodyBuilder(); $mailing->setTemplateContent($template['content']); $mailing->setEditorContent($this->mailing['content_html']); $mailing->setCSS($template['css']); $mailing->setUTMParameters($this->mailing['name']); if ($this->type === 'plain') { $mailing->enablePlaintext(); } $body = $mailing->buildBody($replacements); // Handle the online preview link if (preg_match_all('/<a.*?id="onlineVersionURL".*?>.*?<\\/a>/', $body, $matches)) { // loop the matches foreach ($matches[0] as $match) { // replace the match $body = str_replace('href="#', 'href="' . FrontendMailmotorModel::getMailingPreviewURL($this->id, $this->type), $body); } } // Handle CM-related content substitutions, such as the unsubscribe link if ($this->forCM) { // replace the unsubscribe if (preg_match_all('/<a.*?id="unsubscribeURL".*?>.*?<\\/a>/', $body, $matches)) { // loop the matches foreach ($matches[0] as $match) { // get style attribute if one is provided preg_match('/style=".*?"/is', $match, $styleAttribute); // replace the match $body = str_replace($match, '<unsubscribe' . (isset($styleAttribute[0]) ? ' ' . $styleAttribute[0] : '') . '>' . strip_tags($match) . '</unsubscribe>', $body); } } } return $body; }
/** * Parse the data into the template * * @return void */ private function parse() { // add into breadcrumb $this->breadcrumb->addElement($this->record['name']); // set meta $this->header->setPageTitle($this->record['name']); // set the content to parse $content = $this->type == 'html' ? $this->record['data']['full_content_html'] : $this->record['content_plain']; // cm is asking the info if ($this->forCM) { // replace the unsubscribe if (preg_match_all('/<a id="unsubscribeURL".*?>.*?<\\/a>/is', $content, $matches)) { // loop the matches foreach ($matches[0] as $match) { // get style attribute if one is provided preg_match('/style=".*?"/is', $match, $styleAttribute); // replace the match $content = str_replace($match, '<unsubscribe' . (isset($styleAttribute[0]) ? ' ' . $styleAttribute[0] : '') . '>' . strip_tags($match) . '</unsubscribe>', $content); } } // online preview links if (preg_match_all('/<a id="onlineVersionURL".*?>.*?<\\/a>/is', $content, $matches)) { // loop the matches foreach ($matches[0] as $match) { // replace the match $content = str_replace('href="#', 'href="' . FrontendMailmotorModel::getMailingPreviewURL($this->id, $this->type), $content); } } } // assign article $this->tpl->assign('mailingContent', $content); }