本文整理汇总了PHP中XenForo_Template_Compiler::compileParsed方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Template_Compiler::compileParsed方法的具体用法?PHP XenForo_Template_Compiler::compileParsed怎么用?PHP XenForo_Template_Compiler::compileParsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Template_Compiler
的用法示例。
在下文中一共展示了XenForo_Template_Compiler::compileParsed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public static function parse($raw)
{
$compiler = new XenForo_Template_Compiler(sprintf('<xen:if is="%s">%s</xen:if>', $raw, md5($raw)));
$compiler->addFunctionHandler('helper', new WidgetFramework_Helper_Conditional_Function_Helper());
$parsed = $compiler->lexAndParse();
$compiler->setFollowExternal(false);
$parsed = $compiler->compileParsed($parsed, __CLASS__, 0, 0);
return $parsed;
}
示例2: compileAndInsertParsedTemplate
/**
* Compiles the specified parsed template and updates the compiled table
* and included templates list.
*
* @param integer $templateMapId The map ID of the template being compiled (for includes)
* @param string|array $parsedTemplate Parsed form of the template
* @param string $title Title of the template
* @param integer $compileStyleId Style ID of the template
* @param boolean $doDbWrite If non null, controls whether the DB write/template cache is written
*
* @return array|bool
*/
public function compileAndInsertParsedTemplate($templateMapId, $parsedTemplate, $title, $compileStyleId, $doDbWrite = null)
{
$isCss = substr($title, -4) == '.css';
if ($doDbWrite === null) {
$doDbWrite = $isCss || $compileStyleId;
}
$compiler = new XenForo_Template_Compiler('');
$languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages();
$db = $this->_getDb();
$compiledCache = array();
if ($isCss) {
$compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, $compileStyleId, 0);
$compiledCache[0] = $compiledTemplate;
if ($doDbWrite) {
$this->_insertCompiledTemplateRecord($compileStyleId, 0, $title, $compiledTemplate);
}
} else {
foreach ($languages as $language) {
$compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, $compileStyleId, $language['language_id']);
$compiledCache[$language['language_id']] = $compiledTemplate;
if ($doDbWrite) {
$this->_insertCompiledTemplateRecord($compileStyleId, $language['language_id'], $title, $compiledTemplate);
}
}
}
$mapIdQuoted = $db->quote($templateMapId);
$ins = array();
$includedTemplateIds = array();
foreach ($compiler->getIncludedTemplates() as $includedMapId) {
$ins[] = '(' . $mapIdQuoted . ', ' . $db->quote($includedMapId) . ')';
$includedTemplateIds[] = $includedMapId;
}
if ($doDbWrite) {
$db->delete('xf_template_include', 'source_map_id = ' . $db->quote($templateMapId));
if ($ins) {
$db->query("\r\n\t\t\t\t\tINSERT IGNORE INTO xf_template_include\r\n\t\t\t\t\t\t(source_map_id, target_map_id)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t" . implode(',', $ins));
}
}
$ins = array();
$includedPhraseTitles = array();
foreach ($compiler->getIncludedPhrases() as $includedPhrase) {
if (strlen($includedPhrase) > 75) {
continue;
// too long, can't be a valid phrase
}
$ins[] = '(' . $mapIdQuoted . ', ' . $db->quote($includedPhrase) . ')';
$includedPhraseTitles[] = $includedPhrase;
}
if ($doDbWrite) {
$db->delete('xf_template_phrase', 'template_map_id = ' . $db->quote($templateMapId));
if ($ins) {
$db->query("\r\n\t\t\t\t\tINSERT IGNORE INTO xf_template_phrase\r\n\t\t\t\t\t\t(template_map_id, phrase_title)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t" . implode(',', $ins));
}
}
return array('includedTemplateIds' => $includedTemplateIds, 'failedTemplateIncludes' => $compiler->getFailedTemplateIncludes(), 'includedPhraseTitles' => $includedPhraseTitles, 'compiledCache' => $compiledCache, 'doDbWrite' => $doDbWrite);
}
示例3: _verifyPrepareTemplate
/**
* 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)
{
$standardParse = true;
$parsed = null;
if (!$this->get('disable_modifications')) {
$templateWithModifications = $this->_getModificationModel()->applyModificationsToTemplate($this->get('title'), $template, $modificationStatuses);
} else {
$modificationStatuses = null;
$templateWithModifications = $template;
}
if ($modificationStatuses) {
try {
$compiler = new XenForo_Template_Compiler($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($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;
}
示例4: compileAndInsertParsedTemplate
/**
* Compiles the specified parsed template and updates the compiled table
* and included templates list.
*
* @param integer $templateMapId The map ID of the template being compiled (for includes)
* @param string|array $parsedTemplate Parsed form of the template
* @param string $title Title of the template
* @param integer $compileStyleId Style ID of the template
*/
public function compileAndInsertParsedTemplate($templateMapId, $parsedTemplate, $title, $compileStyleId)
{
$isCss = substr($title, -4) == '.css';
if (!$compileStyleId && !$isCss) {
return;
// skip compiling master templates, but compile css we need it
}
$compiler = new XenForo_Template_Compiler('');
$languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages();
$db = $this->_getDb();
if ($isCss) {
$compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, $compileStyleId, 0);
$db->query('
INSERT INTO xf_template_compiled
(style_id, language_id, title, template_compiled)
VALUES
(?, ?, ?, ?)
ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
', array($compileStyleId, 0, $title, $compiledTemplate));
} else {
foreach ($languages as $language) {
$compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, $compileStyleId, $language['language_id']);
$db->query('
INSERT INTO xf_template_compiled
(style_id, language_id, title, template_compiled)
VALUES
(?, ?, ?, ?)
ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
', array($compileStyleId, $language['language_id'], $title, $compiledTemplate));
}
}
$db->delete('xf_template_include', 'source_map_id = ' . $db->quote($templateMapId));
foreach ($compiler->getIncludedTemplates() as $includedMapId) {
$db->insert('xf_template_include', array('source_map_id' => $templateMapId, 'target_map_id' => $includedMapId));
//TODO: this system doesn't handle includes for templates that don't exist yet
}
$db->delete('xf_template_phrase', 'template_map_id = ' . $db->quote($templateMapId));
foreach ($compiler->getIncludedPhrases() as $includedPhrase) {
$db->insert('xf_template_phrase', array('template_map_id' => $templateMapId, 'phrase_title' => $includedPhrase));
}
}
示例5: VerifyTemplate
protected static function VerifyTemplate(array $option, &$value, &$error)
{
try {
$compiler = new XenForo_Template_Compiler($value);
$parsed = $compiler->lexAndParse();
$compiler->setFollowExternal(false);
$compiler->compileParsed($parsed, '', 0, 0);
} catch (XenForo_Template_Compiler_Exception $e) {
$error = $e->getMessage();
return false;
}
return true;
}
示例6: _verifyPrepareTemplate
/**
* 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($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;
}