server/onyx/modules/templates/smarty/sysplugins/smarty_internal_compile_extends.php

86 lines
2.8 KiB
PHP
Raw Normal View History

2013-10-09 13:40:23 +00:00
<?php
/**
2013-10-09 17:08:38 +00:00
* Smarty Internal Plugin Compile extend
* Compiles the {extends} tag
*
2015-01-14 10:28:47 +00:00
* @package Smarty
2013-10-09 17:08:38 +00:00
* @subpackage Compiler
2015-01-14 10:28:47 +00:00
* @author Uwe Tews
2013-10-09 17:08:38 +00:00
*/
2013-10-09 13:40:23 +00:00
/**
2013-10-09 17:08:38 +00:00
* Smarty Internal Plugin Compile extend Class
*
2015-01-14 10:28:47 +00:00
* @package Smarty
2013-10-09 17:08:38 +00:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
{
2013-10-09 13:40:23 +00:00
/**
2013-10-09 17:08:38 +00:00
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
2013-10-09 13:40:23 +00:00
public $required_attributes = array('file');
/**
2013-10-09 17:08:38 +00:00
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
2013-10-09 13:40:23 +00:00
public $shorttag_order = array('file');
/**
2013-10-09 17:08:38 +00:00
* Compiles code for the {extends} tag
*
2015-01-14 10:28:47 +00:00
* @param array $args array with attributes from parser
2013-10-09 17:08:38 +00:00
* @param object $compiler compiler object
2015-01-14 10:28:47 +00:00
*
2013-10-09 17:08:38 +00:00
* @return string compiled code
*/
2013-10-09 13:40:23 +00:00
public function compile($args, $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
}
if (strpos($_attr['file'], '$_tmp') !== false) {
$compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
}
2013-10-09 17:08:38 +00:00
2015-01-14 10:28:47 +00:00
$name = $_attr['file'];
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
eval("\$tpl_name = $name;");
2013-10-09 17:08:38 +00:00
// create template object
2015-01-14 10:28:47 +00:00
$_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
2013-10-09 17:08:38 +00:00
// check for recursion
$uid = $_template->source->uid;
if (isset($compiler->extends_uid[$uid])) {
2015-01-14 10:28:47 +00:00
$compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
2013-10-09 13:40:23 +00:00
}
2013-10-09 17:08:38 +00:00
$compiler->extends_uid[$uid] = true;
if (empty($_template->source->components)) {
array_unshift($compiler->sources, $_template->source);
} else {
foreach ($_template->source->components as $source) {
array_unshift($compiler->sources, $source);
$uid = $source->uid;
if (isset($compiler->extends_uid[$uid])) {
2015-01-14 10:28:47 +00:00
$compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
2013-10-09 13:40:23 +00:00
}
2013-10-09 17:08:38 +00:00
$compiler->extends_uid[$uid] = true;
2013-10-09 13:40:23 +00:00
}
}
2013-10-09 17:08:38 +00:00
unset ($_template);
$compiler->inheritance_child = true;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
2013-10-09 13:40:23 +00:00
return '';
}
}