/** * Compiles the given email template data and inserts the compiled output. This * template is assumed to be the effective value for a given title. * * @param array $template Template info */ public function compileAndInsertEmailTemplate(array $template) { $languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages(); $languages[0] = array('language_id' => 0); $db = $this->_getDb(); $compiler = new XenForo_Template_Compiler_Email(''); $templateId = $template['template_id']; $title = $template['title']; $subjectParsed = unserialize($template['subject_parsed']); $bodyTextParsed = unserialize($template['body_text_parsed']); $bodyHtmlParsed = unserialize($template['body_html_parsed']); $phrases = array(); $checkPhrases = true; foreach ($languages as $language) { $compiler->setOutputVar('__subject'); $compiledTemplate = $compiler->compileParsedPlainText($subjectParsed, $title, 0, $language['language_id']); if ($checkPhrases) { $phrases = array_merge($phrases, $compiler->getIncludedPhrases()); } $compiler->setOutputVar('__bodyText'); $compiledTemplate .= $compiler->compileParsedPlainText($bodyTextParsed, $title, 0, $language['language_id']); if ($checkPhrases) { $phrases = array_merge($phrases, $compiler->getIncludedPhrases()); } $compiler->setOutputVar('__bodyHtml'); $compiledTemplate .= $compiler->compileParsed($bodyHtmlParsed, $title, 0, $language['language_id']); if ($checkPhrases) { $phrases = array_merge($phrases, $compiler->getIncludedPhrases()); } $db->query(' INSERT INTO xf_email_template_compiled (language_id, title, template_compiled) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled) ', array($language['language_id'], $title, $compiledTemplate)); $checkPhrases = false; } $phrases = array_unique($phrases); $db->delete('xf_email_template_phrase', 'title = ' . $db->quote($title)); foreach ($phrases as $includedPhrase) { $db->insert('xf_email_template_phrase', array('title' => $title, 'phrase_title' => $includedPhrase)); } }