/** * Compiles a single admin template * * @param array Template */ public function compileParsedAdminTemplate($templateId, array $parsedTemplate, $title) { $isCss = substr($title, -4) == '.css'; $languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages(); $db = $this->_getDb(); $compiler = new XenForo_Template_Compiler_Admin(''); if ($isCss) { $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, 0); $db->query(' INSERT INTO xf_admin_template_compiled (language_id, title, template_compiled) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled) ', array(0, $title, $compiledTemplate)); } else { foreach ($languages as $language) { $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, $language['language_id']); $db->query(' INSERT INTO xf_admin_template_compiled (language_id, title, template_compiled) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled) ', array($language['language_id'], $title, $compiledTemplate)); } } $ins = array(); foreach ($compiler->getIncludedTemplates() as $includedId) { $ins[] = '(' . $db->quote($templateId) . ', ' . $db->quote($includedId) . ')'; //TODO: this system doesn't handle includes for templates that don't exist yet } $db->delete('xf_admin_template_include', 'source_id = ' . $db->quote($templateId)); if ($ins) { $db->query("\r\n\t\t\t\tINSERT IGNORE INTO xf_admin_template_include\r\n\t\t\t\t\t(source_id, target_id)\r\n\t\t\t\tVALUES\r\n\t\t\t\t\t" . implode(',', $ins)); } $ins = array(); foreach ($compiler->getIncludedPhrases() as $includedPhrase) { if (strlen($includedPhrase) > 75) { continue; // too long, can't be a valid phrase } $ins[] = '(' . $db->quote($templateId) . ', ' . $db->quote($includedPhrase) . ')'; } $db->delete('xf_admin_template_phrase', 'template_id = ' . $db->quote($templateId)); if ($ins) { $db->query(' INSERT IGNORE INTO xf_admin_template_phrase (template_id, phrase_title) VALUES ' . implode(',', $ins)); } }
/** * Verification callback to prepare a template. This isn't actually a verifier; * it just automatically compiles the template. * * @param string $string Uncompiled template * * @return boolean */ protected function _verifyPrepareTemplate(&$template) { $templateWithModifications = $this->_getModificationModel()->applyModificationsToTemplate($this->get('title'), $template, $modificationStatuses); $standardParse = true; $parsed = null; if ($modificationStatuses) { try { $compiler = new XenForo_Template_Compiler_Admin($templateWithModifications); $parsed = $compiler->lexAndParse(); if ($this->getOption(self::OPTION_TEST_COMPILE)) { $compiler->setFollowExternal(false); $compiler->compileParsed($parsed, $this->get('title'), 0, 0); } $standardParse = false; } catch (XenForo_Template_Compiler_Exception $e) { foreach ($modificationStatuses as &$status) { if (is_int($status)) { $status = 'error_compile'; } } } } if ($standardParse) { try { $compiler = new XenForo_Template_Compiler_Admin($template); $parsed = $compiler->lexAndParse(); if ($this->getOption(self::OPTION_TEST_COMPILE)) { $compiler->setFollowExternal(false); $compiler->compileParsed($parsed, $this->get('title'), 0, 0); } } catch (XenForo_Template_Compiler_Exception $e) { $this->error($e->getMessage(), 'template'); return false; } } $this->set('template_parsed', serialize($parsed)); $this->_modificationStatuses = $modificationStatuses; return true; }
/** * Verification callback to prepare a template. This isn't actually a verifier; * it just automatically compiles the template. * * @param string Uncompiled template * * @return true */ protected function _verifyPrepareTemplate($template) { try { $compiler = new XenForo_Template_Compiler_Admin($template); $parsed = $compiler->lexAndParse(); if ($this->getOption(self::OPTION_TEST_COMPILE)) { $compiler->setFollowExternal(false); $compiler->compileParsed($parsed, $this->get('title'), 0, 0); } } catch (XenForo_Template_Compiler_Exception $e) { $this->error($e->getMessage(), 'template'); return false; } $this->set('template_parsed', serialize($parsed)); return true; }
/** * Compiles a single admin template * * @param array Template */ public function compileParsedAdminTemplate($templateId, array $parsedTemplate, $title) { $isCss = substr($title, -4) == '.css'; $languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages(); $db = $this->_getDb(); $compiler = new XenForo_Template_Compiler_Admin(''); if ($isCss) { $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, 0); $db->query(' INSERT INTO xf_admin_template_compiled (language_id, title, template_compiled) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled) ', array(0, $title, $compiledTemplate)); } else { foreach ($languages as $language) { $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, $language['language_id']); $db->query(' INSERT INTO xf_admin_template_compiled (language_id, title, template_compiled) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled) ', array($language['language_id'], $title, $compiledTemplate)); } } $db->delete('xf_admin_template_include', 'source_id = ' . $db->quote($templateId)); foreach ($compiler->getIncludedTemplates() as $includedId) { $db->insert('xf_admin_template_include', array('source_id' => $templateId, 'target_id' => $includedId)); //TODO: this system doesn't handle includes for templates that don't exist yet } $db->delete('xf_admin_template_phrase', 'template_id = ' . $db->quote($templateId)); foreach ($compiler->getIncludedPhrases() as $includedPhrase) { $db->insert('xf_admin_template_phrase', array('template_id' => $templateId, 'phrase_title' => $includedPhrase)); } }