add smarty lib
Dieser Commit ist enthalten in:
Ursprung
833f88731f
Commit
df675e403f
55 geänderte Dateien mit 12775 neuen und 0 gelöschten Zeilen
40
libs/sysplugins/smarty_internal_method_unregistercacheresource.php
Normale Datei
40
libs/sysplugins/smarty_internal_method_unregistercacheresource.php
Normale Datei
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Method UnregisterCacheResource
|
||||
*
|
||||
* Smarty::unregisterCacheResource() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Method_UnregisterCacheResource
|
||||
{
|
||||
/**
|
||||
* Valid for Smarty and template object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $objMap = 3;
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @api Smarty::unregisterCacheResource()
|
||||
* @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
|
||||
* @param $name
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
if (isset($smarty->registered_cache_resources[ $name ])) {
|
||||
unset($smarty->registered_cache_resources[ $name ]);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
42
libs/sysplugins/smarty_internal_method_unregisterfilter.php
Normale Datei
42
libs/sysplugins/smarty_internal_method_unregisterfilter.php
Normale Datei
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Method UnregisterFilter
|
||||
*
|
||||
* Smarty::unregisterFilter() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_RegisterFilter
|
||||
{
|
||||
/**
|
||||
* Unregisters a filter function
|
||||
*
|
||||
* @api Smarty::unregisterFilter()
|
||||
*
|
||||
* @link http://www.smarty.net/docs/en/api.unregister.filter.tpl
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
|
||||
* @param string $type filter type
|
||||
* @param callback|string $callback
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
$this->_checkFilterType($type);
|
||||
if (isset($smarty->registered_filters[ $type ])) {
|
||||
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
|
||||
if (isset($smarty->registered_filters[ $type ][ $name ])) {
|
||||
unset($smarty->registered_filters[ $type ][ $name ]);
|
||||
if (empty($smarty->registered_filters[ $type ])) {
|
||||
unset($smarty->registered_filters[ $type ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
40
libs/sysplugins/smarty_internal_method_unregisterobject.php
Normale Datei
40
libs/sysplugins/smarty_internal_method_unregisterobject.php
Normale Datei
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Method UnregisterObject
|
||||
*
|
||||
* Smarty::unregisterObject() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Method_UnregisterObject
|
||||
{
|
||||
/**
|
||||
* Valid for Smarty and template object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $objMap = 3;
|
||||
|
||||
/**
|
||||
* Registers plugin to be used in templates
|
||||
*
|
||||
* @api Smarty::unregisterObject()
|
||||
* @link http://www.smarty.net/docs/en/api.unregister.object.tpl
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
|
||||
* @param string $object_name name of object
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function unregisterObject(Smarty_Internal_TemplateBase $obj, $object_name)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
if (isset($smarty->registered_objects[ $object_name ])) {
|
||||
unset($smarty->registered_objects[ $object_name ]);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
41
libs/sysplugins/smarty_internal_method_unregisterplugin.php
Normale Datei
41
libs/sysplugins/smarty_internal_method_unregisterplugin.php
Normale Datei
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Method UnregisterPlugin
|
||||
*
|
||||
* Smarty::unregisterPlugin() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Method_UnregisterPlugin
|
||||
{
|
||||
/**
|
||||
* Valid for Smarty and template object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $objMap = 3;
|
||||
|
||||
/**
|
||||
* Registers plugin to be used in templates
|
||||
*
|
||||
* @api Smarty::unregisterPlugin()
|
||||
* @link http://www.smarty.net/docs/en/api.unregister.plugin.tpl
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
|
||||
* @param string $type plugin type
|
||||
* @param string $name name of template tag
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function unregisterPlugin(Smarty_Internal_TemplateBase $obj, $type, $name)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
|
||||
unset($smarty->registered_plugins[ $type ][ $name ]);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
40
libs/sysplugins/smarty_internal_method_unregisterresource.php
Normale Datei
40
libs/sysplugins/smarty_internal_method_unregisterresource.php
Normale Datei
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Method UnregisterResource
|
||||
*
|
||||
* Smarty::unregisterResource() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Method_UnregisterResource
|
||||
{
|
||||
/**
|
||||
* Valid for Smarty and template object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $objMap = 3;
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @api Smarty::unregisterResource()
|
||||
* @link http://www.smarty.net/docs/en/api.unregister.resource.tpl
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
|
||||
* @param string $type name of resource type
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function unregisterResource(Smarty_Internal_TemplateBase $obj, $type)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
if (isset($smarty->registered_resources[ $type ])) {
|
||||
unset($smarty->registered_resources[ $type ]);
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
53
libs/sysplugins/smarty_internal_nocache_insert.php
Normale Datei
53
libs/sysplugins/smarty_internal_nocache_insert.php
Normale Datei
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Nocache Insert
|
||||
* Compiles the {insert} tag into the cache file
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Nocache_Insert
|
||||
{
|
||||
/**
|
||||
* Compiles code for the {insert} tag into cache file
|
||||
*
|
||||
* @param string $_function insert function name
|
||||
* @param array $_attr array with parameter
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $_script script name to load or 'null'
|
||||
* @param string $_assign optional variable name
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public static function compile($_function, $_attr, $_template, $_script, $_assign = null)
|
||||
{
|
||||
$_output = '<?php ';
|
||||
if ($_script != 'null') {
|
||||
// script which must be included
|
||||
// code for script file loading
|
||||
$_output .= "require_once '{$_script}';";
|
||||
}
|
||||
// call insert
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) .
|
||||
",\$_smarty_tpl), true);?>";
|
||||
} else {
|
||||
$_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>";
|
||||
}
|
||||
$_tpl = $_template;
|
||||
while ($_tpl->_isSubTpl()) {
|
||||
$_tpl = $_tpl->parent;
|
||||
}
|
||||
|
||||
return "/*%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/" . $_output .
|
||||
"/*/%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/";
|
||||
}
|
||||
}
|
54
libs/sysplugins/smarty_internal_parsetree.php
Normale Datei
54
libs/sysplugins/smarty_internal_parsetree.php
Normale Datei
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
abstract class Smarty_Internal_ParseTree
|
||||
{
|
||||
|
||||
/**
|
||||
* Buffer content
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Subtree array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = array();
|
||||
|
||||
/**
|
||||
* Return buffer
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string buffer content
|
||||
*/
|
||||
abstract public function to_smarty_php(Smarty_Internal_Templateparser $parser);
|
||||
|
||||
/**
|
||||
* Template data object destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->data = null;
|
||||
$this->subtrees = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
42
libs/sysplugins/smarty_internal_parsetree_code.php
Normale Datei
42
libs/sysplugins/smarty_internal_parsetree_code.php
Normale Datei
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parse Tree
|
||||
* These are classes to build parse trees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Code fragment inside a tag .
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for code fragment
|
||||
*
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
}
|
95
libs/sysplugins/smarty_internal_parsetree_dq.php
Normale Datei
95
libs/sysplugins/smarty_internal_parsetree_dq.php
Normale Datei
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for double quoted string subtrees
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
|
||||
*/
|
||||
public function __construct($parser, Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
$this->subtrees[] = $subtree;
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$parser->block_nesting_level = count($parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
|
||||
*/
|
||||
public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
$last_subtree = count($this->subtrees) - 1;
|
||||
if ($last_subtree >= 0 && $this->subtrees[ $last_subtree ] instanceof Smarty_Internal_ParseTree_Tag &&
|
||||
$this->subtrees[ $last_subtree ]->saved_block_nesting < $parser->block_nesting_level
|
||||
) {
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
|
||||
$this->subtrees[ $last_subtree ]->data =
|
||||
$parser->compiler->appendCode($this->subtrees[ $last_subtree ]->data,
|
||||
'<?php echo ' . $subtree->data . ';?>');
|
||||
} elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
|
||||
$this->subtrees[ $last_subtree ]->data =
|
||||
$parser->compiler->appendCode($this->subtrees[ $last_subtree ]->data,
|
||||
'<?php echo "' . $subtree->data . '";?>');
|
||||
} else {
|
||||
$this->subtrees[ $last_subtree ]->data =
|
||||
$parser->compiler->appendCode($this->subtrees[ $last_subtree ]->data, $subtree->data);
|
||||
}
|
||||
} else {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$parser->block_nesting_level = count($parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge subtree buffer content together
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
if ($code !== "") {
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$more_php = $subtree->assign_to_var($parser);
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php($parser);
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
|
||||
$parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
42
libs/sysplugins/smarty_internal_parsetree_dqcontent.php
Normale Datei
42
libs/sysplugins/smarty_internal_parsetree_dqcontent.php
Normale Datei
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parse Tree
|
||||
* These are classes to build parse tree in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Raw chars as part of a double quoted string.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer with string content
|
||||
*
|
||||
* @param string $data string section
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
}
|
69
libs/sysplugins/smarty_internal_parsetree_tag.php
Normale Datei
69
libs/sysplugins/smarty_internal_parsetree_tag.php
Normale Datei
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parse Tree
|
||||
* These are classes to build parse tree in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* A complete smarty tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
|
||||
{
|
||||
|
||||
/**
|
||||
* Saved block nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $saved_block_nesting;
|
||||
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct(Smarty_Internal_Templateparser $parser, $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return complied code that loads the evaluated output of buffer content into a temporary variable
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string template code
|
||||
*/
|
||||
public function assign_to_var(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
$var = $parser->compiler->getNewPrefixVariable();
|
||||
$tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data);
|
||||
$tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
|
||||
$parser->compiler->prefix_code[] = sprintf("%s", $tmp);
|
||||
|
||||
return $var;
|
||||
}
|
||||
}
|
128
libs/sysplugins/smarty_internal_parsetree_template.php
Normale Datei
128
libs/sysplugins/smarty_internal_parsetree_template.php
Normale Datei
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parse Tree
|
||||
* These are classes to build parse tree in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Template element
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
||||
{
|
||||
|
||||
/**
|
||||
* Array of template elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = Array();
|
||||
|
||||
/**
|
||||
* Create root of parse tree for template elements
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @param Smarty_Internal_ParseTree $subtree
|
||||
*/
|
||||
public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
if (!empty($subtree->subtrees)) {
|
||||
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
|
||||
} else {
|
||||
if ($subtree->data !== '') {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append array to subtree
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @param \Smarty_Internal_ParseTree[] $array
|
||||
*/
|
||||
public function append_array(Smarty_Internal_Templateparser $parser, $array = array())
|
||||
{
|
||||
if (!empty($array)) {
|
||||
$this->subtrees = array_merge($this->subtrees, (array) $array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend array to subtree
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @param \Smarty_Internal_ParseTree[] $array
|
||||
*/
|
||||
public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array())
|
||||
{
|
||||
if (!empty($array)) {
|
||||
$this->subtrees = array_merge((array) $array, $this->subtrees);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and merge subtree buffers together
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
|
||||
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
|
||||
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
|
||||
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Text ||
|
||||
$this->subtrees[ $key + 1 ]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[ $key ]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$subtree .= $this->subtrees[ $key ]->to_smarty_php($parser);
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n",
|
||||
$subtree);
|
||||
continue;
|
||||
}
|
||||
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
|
||||
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Tag ||
|
||||
$this->subtrees[ $key + 1 ]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[ $key ]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$subtree = $parser->compiler->appendCode($subtree, $this->subtrees[ $key ]->to_smarty_php($parser));
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= $subtree;
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[ $key ]->to_smarty_php($parser);
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
}
|
40
libs/sysplugins/smarty_internal_parsetree_text.php
Normale Datei
40
libs/sysplugins/smarty_internal_parsetree_text.php
Normale Datei
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parse Tree
|
||||
* These are classes to build parse tree in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
* *
|
||||
* template text
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create template text buffer
|
||||
*
|
||||
* @param string $data text
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string text
|
||||
*/
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
95
libs/sysplugins/smarty_internal_resource_eval.php
Normale Datei
95
libs/sysplugins/smarty_internal_resource_eval.php
Normale Datei
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Eval
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Eval
|
||||
* Implements the strings as resource for Smarty template
|
||||
* {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}}
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->uid = $source->filepath = sha1($source->name);
|
||||
$source->timestamp = $source->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from $resource_name into current template object
|
||||
*
|
||||
* @uses decode() to decode base64 and urlencoded template_resources
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
return $this->decode($source->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode base64 and urlencode
|
||||
*
|
||||
* @param string $string template_resource to decode
|
||||
*
|
||||
* @return string decoded template_resource
|
||||
*/
|
||||
protected function decode($string)
|
||||
{
|
||||
// decode if specified
|
||||
if (($pos = strpos($string, ':')) !== false) {
|
||||
if (!strncmp($string, 'base64', 6)) {
|
||||
return base64_decode(substr($string, 7));
|
||||
} elseif (!strncmp($string, 'urlencode', 9)) {
|
||||
return urldecode(substr($string, 10));
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
return get_class($this) . '#' . $this->decode($resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
125
libs/sysplugins/smarty_internal_resource_extends.php
Normale Datei
125
libs/sysplugins/smarty_internal_resource_extends.php
Normale Datei
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Extends
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Extends
|
||||
* Implements the file system as resource for Smarty which {extend}s a chain of template files templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* mbstring.overload flag
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $mbstring_overload = 0;
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$uid = '';
|
||||
$sources = array();
|
||||
$components = explode('|', $source->name);
|
||||
$smarty = &$source->smarty;
|
||||
$exists = true;
|
||||
foreach ($components as $component) {
|
||||
/* @var \Smarty_Template_Source $_s */
|
||||
$_s = Smarty_Template_Source::load(null, $smarty, $component);
|
||||
if ($_s->type == 'php') {
|
||||
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
|
||||
}
|
||||
$sources[ $_s->uid ] = $_s;
|
||||
$uid .= $_s->filepath;
|
||||
if ($_template) {
|
||||
$exists = $exists && $_s->exists;
|
||||
}
|
||||
}
|
||||
$source->components = $sources;
|
||||
$source->filepath = $_s->filepath;
|
||||
$source->uid = sha1($uid . $source->smarty->_joined_template_dir);
|
||||
$source->exists = $exists;
|
||||
if ($_template) {
|
||||
$source->timestamp = $_s->timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
$source->exists = true;
|
||||
/* @var \Smarty_Template_Source $_s */
|
||||
foreach ($source->components as $_s) {
|
||||
$source->exists = $source->exists && $_s->exists;
|
||||
}
|
||||
$source->timestamp = $source->exists ? $_s->getTimeStamp() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from files into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if (!$source->exists) {
|
||||
throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'");
|
||||
}
|
||||
|
||||
$_components = array_reverse($source->components);
|
||||
|
||||
$_content = '';
|
||||
/* @var \Smarty_Template_Source $_s */
|
||||
foreach ($_components as $_s) {
|
||||
// read content
|
||||
$_content .= $_s->getContent();
|
||||
}
|
||||
return $_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return str_replace(':', '.', basename($source->filepath));
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for extends resource.
|
||||
* The individual source components will be checked.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
176
libs/sysplugins/smarty_internal_resource_file.php
Normale Datei
176
libs/sysplugins/smarty_internal_resource_file.php
Normale Datei
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
* Implements the file system as resource for Smarty templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* build template filepath by traversing the template_dir array
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string fully qualified filepath
|
||||
* @throws SmartyException
|
||||
*/
|
||||
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$file = $source->name;
|
||||
// absolute file ?
|
||||
if ($file[ 0 ] == '/' || $file[ 1 ] == ':') {
|
||||
$file = $source->smarty->_realpath($file, true);
|
||||
return is_file($file) ? $file : false;
|
||||
}
|
||||
// go relative to a given template?
|
||||
if ($file[ 0 ] == '.' && $_template && $_template->_isSubTpl() &&
|
||||
preg_match('#^[.]{1,2}[\\\/]#', $file)
|
||||
) {
|
||||
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' &&
|
||||
!isset($_template->parent->_cache[ 'allow_relative_path' ])
|
||||
) {
|
||||
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
|
||||
}
|
||||
// normalize path
|
||||
$path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . $source->smarty->ds . $file);
|
||||
// files relative to a template only get one shot
|
||||
return is_file($path) ? $path : false;
|
||||
}
|
||||
// normalize $source->smarty->ds
|
||||
if (strpos($file, $source->smarty->ds == '/' ? '\\' : '/') !== false) {
|
||||
$file = str_replace($source->smarty->ds == '/' ? '\\' : '/', $source->smarty->ds, $file);
|
||||
}
|
||||
|
||||
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
||||
// template_dir index?
|
||||
if ($file[ 0 ] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
|
||||
$file = $fileMatch[ 2 ];
|
||||
$_indices = explode(',', $fileMatch[ 1 ]);
|
||||
$_index_dirs = array();
|
||||
foreach ($_indices as $index) {
|
||||
$index = trim($index);
|
||||
// try string indexes
|
||||
if (isset($_directories[ $index ])) {
|
||||
$_index_dirs[] = $_directories[ $index ];
|
||||
} elseif (is_numeric($index)) {
|
||||
// try numeric index
|
||||
$index = (int) $index;
|
||||
if (isset($_directories[ $index ])) {
|
||||
$_index_dirs[] = $_directories[ $index ];
|
||||
} else {
|
||||
// try at location index
|
||||
$keys = array_keys($_directories);
|
||||
if (isset($_directories[ $keys[ $index ] ])) {
|
||||
$_index_dirs[] = $_directories[ $keys[ $index ] ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($_index_dirs)) {
|
||||
// index not found
|
||||
return false;
|
||||
} else {
|
||||
$_directories = $_index_dirs;
|
||||
}
|
||||
}
|
||||
|
||||
// relative file name?
|
||||
foreach ($_directories as $_directory) {
|
||||
$path = $_directory . $file;
|
||||
if (is_file($path)) {
|
||||
return (strpos($path, '.' . $source->smarty->ds) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
}
|
||||
}
|
||||
if (!isset($_index_dirs)) {
|
||||
// Could be relative to cwd
|
||||
$path = $source->smarty->_realpath($file, true);
|
||||
if (is_file($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
// Use include path ?
|
||||
if ($source->smarty->use_include_path) {
|
||||
return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->filepath = $this->buildFilepath($source, $_template);
|
||||
|
||||
if ($source->filepath !== false) {
|
||||
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
||||
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
|
||||
}
|
||||
$source->exists = true;
|
||||
$source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir :
|
||||
$source->smarty->_joined_template_dir));
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
} else {
|
||||
$source->timestamp = $source->exists = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
if (!$source->exists) {
|
||||
$source->timestamp = $source->exists = is_file($source->filepath);
|
||||
}
|
||||
if ($source->exists) {
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if ($source->exists) {
|
||||
return file_get_contents($source->filepath);
|
||||
}
|
||||
throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') .
|
||||
" {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename($source->filepath);
|
||||
}
|
||||
}
|
111
libs/sysplugins/smarty_internal_resource_php.php
Normale Datei
111
libs/sysplugins/smarty_internal_resource_php.php
Normale Datei
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource PHP
|
||||
* Implements the file system as resource for PHP templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
|
||||
{
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* container for short_open_tag directive's value before executing PHP templates
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $short_open_tag;
|
||||
|
||||
/**
|
||||
* Create a new PHP Resource
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if ($source->exists) {
|
||||
return '';
|
||||
}
|
||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object (is ignored)
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array($compiled->filepath,
|
||||
$compiled->timestamp,
|
||||
$_template->source->type,);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render and output the template (without using the compiler)
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
|
||||
*/
|
||||
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$source->smarty->allow_php_templates) {
|
||||
throw new SmartyException("PHP templates are disabled");
|
||||
}
|
||||
if (!$source->exists) {
|
||||
throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
|
||||
($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
|
||||
}
|
||||
|
||||
// prepare variables
|
||||
extract($_template->getTemplateVars());
|
||||
|
||||
// include PHP template with short open tags enabled
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', '1');
|
||||
}
|
||||
/** @var Smarty_Internal_Template $_smarty_template
|
||||
* used in included file
|
||||
*/
|
||||
$_smarty_template = $_template;
|
||||
include($source->filepath);
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', $this->short_open_tag);
|
||||
}
|
||||
}
|
||||
}
|
99
libs/sysplugins/smarty_internal_resource_registered.php
Normale Datei
99
libs/sysplugins/smarty_internal_resource_registered.php
Normale Datei
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Registered
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Registered
|
||||
* Implements the registered resource for Smarty template
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @deprecated
|
||||
*/
|
||||
class Smarty_Internal_Resource_Registered extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->filepath = $source->type . ':' . $source->name;
|
||||
$source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir);
|
||||
$source->timestamp = $this->getTemplateTimestamp($source);
|
||||
$source->exists = !!$source->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
$source->timestamp = $this->getTemplateTimestamp($source);
|
||||
$source->exists = !!$source->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp (epoch) the template source was modified
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
|
||||
*/
|
||||
public function getTemplateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
// return timestamp
|
||||
$time_stamp = false;
|
||||
call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ],
|
||||
array($source->name, &$time_stamp, $source->smarty));
|
||||
|
||||
return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source by invoking the registered callback into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
// return template string
|
||||
$content = null;
|
||||
$t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ],
|
||||
array($source->name, &$content, $source->smarty));
|
||||
if (is_bool($t) && !$t) {
|
||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename($source->name);
|
||||
}
|
||||
}
|
80
libs/sysplugins/smarty_internal_resource_stream.php
Normale Datei
80
libs/sysplugins/smarty_internal_resource_stream.php
Normale Datei
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @link http://php.net/streams
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
if (strpos($source->resource, '://') !== false) {
|
||||
$source->filepath = $source->resource;
|
||||
} else {
|
||||
$source->filepath = str_replace(':', '://', $source->resource);
|
||||
}
|
||||
$source->uid = false;
|
||||
$source->content = $this->getContent($source);
|
||||
$source->timestamp = $source->exists = !!$source->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from stream into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
$t = '';
|
||||
// the availability of the stream has already been checked in Smarty_Resource::fetch()
|
||||
$fp = fopen($source->filepath, 'r+');
|
||||
if ($fp) {
|
||||
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
|
||||
$t .= $current_line;
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
return $t;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
return get_class($this) . '#' . $resource_name;
|
||||
}
|
||||
}
|
107
libs/sysplugins/smarty_internal_resource_string.php
Normale Datei
107
libs/sysplugins/smarty_internal_resource_string.php
Normale Datei
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
* Implements the strings as resource for Smarty template
|
||||
* {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_String extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
|
||||
$source->timestamp = $source->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from $resource_name into current template object
|
||||
*
|
||||
* @uses decode() to decode base64 and urlencoded template_resources
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
return $this->decode($source->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode base64 and urlencode
|
||||
*
|
||||
* @param string $string template_resource to decode
|
||||
*
|
||||
* @return string decoded template_resource
|
||||
*/
|
||||
protected function decode($string)
|
||||
{
|
||||
// decode if specified
|
||||
if (($pos = strpos($string, ':')) !== false) {
|
||||
if (!strncmp($string, 'base64', 6)) {
|
||||
return base64_decode(substr($string, 7));
|
||||
} elseif (!strncmp($string, 'urlencode', 9)) {
|
||||
return urldecode(substr($string, 10));
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
return get_class($this) . '#' . $this->decode($resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
* Always returns an empty string.
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for string resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
68
libs/sysplugins/smarty_internal_runtime_cachemodify.php
Normale Datei
68
libs/sysplugins/smarty_internal_runtime_cachemodify.php
Normale Datei
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Inline Runtime Methods render, setSourceByUid, setupSubTemplate
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
**/
|
||||
class Smarty_Internal_Runtime_CacheModify
|
||||
{
|
||||
/**
|
||||
* check client side cache
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param string $content
|
||||
*/
|
||||
public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
|
||||
$_last_modified_date =
|
||||
@substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3);
|
||||
if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
|
||||
switch (PHP_SAPI) {
|
||||
case 'cgi': // php-cgi < 5.3
|
||||
case 'cgi-fcgi': // php-cgi >= 5.3
|
||||
case 'fpm-fcgi': // php-fpm >= 5.3.3
|
||||
header('Status: 304 Not Modified');
|
||||
break;
|
||||
|
||||
case 'cli':
|
||||
if ( /* ^phpunit */
|
||||
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
|
||||
) {
|
||||
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( /* ^phpunit */
|
||||
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
|
||||
) {
|
||||
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
|
||||
} else {
|
||||
header($_SERVER[ 'SERVER_PROTOCOL' ] . ' 304 Not Modified');
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (PHP_SAPI) {
|
||||
case 'cli':
|
||||
if ( /* ^phpunit */
|
||||
!empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
|
||||
) {
|
||||
$_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] =
|
||||
'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
|
||||
break;
|
||||
}
|
||||
echo $content;
|
||||
}
|
||||
}
|
||||
}
|
142
libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php
Normale Datei
142
libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php
Normale Datei
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty cache resource file clear method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Runtime Cache Resource File Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Runtime_CacheResourceFile
|
||||
{
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param Smarty $smarty
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer $exp_time expiration time (number of seconds, not timestamp)
|
||||
*
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
|
||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w]+!', '_', $compile_id) : null;
|
||||
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
|
||||
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
|
||||
$_dir = $smarty->getCacheDir();
|
||||
if ($_dir == '/') { //We should never want to delete this!
|
||||
return 0;
|
||||
}
|
||||
$_dir_length = strlen($_dir);
|
||||
if (isset($_cache_id)) {
|
||||
$_cache_id_parts = explode('|', $_cache_id);
|
||||
$_cache_id_parts_count = count($_cache_id_parts);
|
||||
if ($smarty->use_sub_dirs) {
|
||||
foreach ($_cache_id_parts as $id_part) {
|
||||
$_dir .= $id_part . $smarty->ds;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = true;
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
$smarty->caching = $_save_stat;
|
||||
|
||||
// remove from template cache
|
||||
$tpl->source; // have the template registered before unset()
|
||||
|
||||
if ($tpl->source->exists) {
|
||||
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
$_count = 0;
|
||||
$_time = time();
|
||||
if (file_exists($_dir)) {
|
||||
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_cache as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.') {
|
||||
continue;
|
||||
}
|
||||
$_filepath = (string) $_file;
|
||||
// directory ?
|
||||
if ($_file->isDir()) {
|
||||
if (!$_cache->isDot()) {
|
||||
// delete folder if empty
|
||||
@rmdir($_file->getPathname());
|
||||
}
|
||||
} else {
|
||||
// delete only php files
|
||||
if (substr($_filepath, - 4) !== '.php') {
|
||||
continue;
|
||||
}
|
||||
$_parts = explode($_dir_sep, str_replace('\\', '/', substr($_filepath, $_dir_length)));
|
||||
$_parts_count = count($_parts);
|
||||
// check name
|
||||
if (isset($resource_name)) {
|
||||
if ($_parts[ $_parts_count - 1 ] != $_resourcename_parts) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// check compile id
|
||||
if (isset($_compile_id) && (!isset($_parts[ $_parts_count - 2 - $_compile_id_offset ]) ||
|
||||
$_parts[ $_parts_count - 2 - $_compile_id_offset ] != $_compile_id)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// check cache id
|
||||
if (isset($_cache_id)) {
|
||||
// count of cache id parts
|
||||
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset :
|
||||
$_parts_count - 1 - $_compile_id_offset;
|
||||
if ($_parts_count < $_cache_id_parts_count) {
|
||||
continue;
|
||||
}
|
||||
for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
|
||||
if ($_parts[ $i ] != $_cache_id_parts[ $i ]) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_file($_filepath)) {
|
||||
// expired ?
|
||||
if (isset($exp_time)) {
|
||||
if ($exp_time < 0) {
|
||||
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_filepath), $match);
|
||||
if ($_time < (@filemtime($_filepath) + $match[ 1 ])) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ($_time - @filemtime($_filepath) < $exp_time) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count += @unlink($_filepath) ? 1 : 0;
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||
) {
|
||||
opcache_invalidate($_filepath, true);
|
||||
} elseif (function_exists('apc_delete_file')) {
|
||||
apc_delete_file($_filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $_count;
|
||||
}
|
||||
}
|
169
libs/sysplugins/smarty_internal_runtime_capture.php
Normale Datei
169
libs/sysplugins/smarty_internal_runtime_capture.php
Normale Datei
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Runtime Extension Capture
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Runtime_Capture
|
||||
{
|
||||
/**
|
||||
* Flag that this instance will not be cached
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isPrivateExtension = true;
|
||||
|
||||
/**
|
||||
* Stack of capture parameter
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $captureStack = array();
|
||||
|
||||
/**
|
||||
* Current open capture sections
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $captureCount = 0;
|
||||
|
||||
/**
|
||||
* Count stack
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private $countStack = array();
|
||||
|
||||
/**
|
||||
* Named buffer
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $namedBuffer = array();
|
||||
|
||||
/**
|
||||
* Flag if callbacks are registered
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isRegistered = false;
|
||||
|
||||
/**
|
||||
* Open capture section
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param string $buffer capture name
|
||||
* @param string $assign variable name
|
||||
* @param string $append variable name
|
||||
*/
|
||||
public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append)
|
||||
{
|
||||
if (!$this->isRegistered) {
|
||||
$this->register($_template);
|
||||
}
|
||||
$this->captureStack[] = array($buffer,
|
||||
$assign,
|
||||
$append);
|
||||
$this->captureCount ++;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register callbacks in template class
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*/
|
||||
private function register(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_template->startRenderCallbacks[] = array($this,
|
||||
'startRender');
|
||||
$_template->endRenderCallbacks[] = array($this,
|
||||
'endRender');
|
||||
$this->startRender($_template);
|
||||
$this->isRegistered = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start render callback
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*/
|
||||
public function startRender(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$this->countStack[] = $this->captureCount;
|
||||
$this->captureCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close capture section
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function close(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if ($this->captureCount) {
|
||||
list($buffer, $assign, $append) = array_pop($this->captureStack);
|
||||
$this->captureCount --;
|
||||
if (isset($assign)) {
|
||||
$_template->assign($assign, ob_get_contents());
|
||||
}
|
||||
if (isset($append)) {
|
||||
$_template->append($append, ob_get_contents());
|
||||
}
|
||||
$this->namedBuffer[ $buffer ] = ob_get_clean();
|
||||
} else {
|
||||
$this->error($_template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error exception on not matching {capture}{/capture}
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function error(Smarty_Internal_Template $_template)
|
||||
{
|
||||
throw new SmartyException("Not matching {capture}{/capture} in \"{$_template->template_resource}\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content of named capture buffer by key or as array
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return string|string[]|null
|
||||
*/
|
||||
public function getBuffer(Smarty_Internal_Template $_template, $name = null)
|
||||
{
|
||||
if (isset($name)) {
|
||||
return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null;
|
||||
} else {
|
||||
return $this->namedBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End render callback
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function endRender(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if ($this->captureCount) {
|
||||
$this->error($_template);
|
||||
} else {
|
||||
$this->captureCount = array_pop($this->countStack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
98
libs/sysplugins/smarty_internal_runtime_codeframe.php
Normale Datei
98
libs/sysplugins/smarty_internal_runtime_codeframe.php
Normale Datei
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Extension
|
||||
* This file contains the Smarty template extension to create a code frame
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Smarty_Internal_Extension_CodeFrame
|
||||
* Create code frame for compiled and cached templates
|
||||
*/
|
||||
class Smarty_Internal_Runtime_CodeFrame
|
||||
{
|
||||
/**
|
||||
* Create code frame for compiled and cached templates
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
* @param string $content optional template content
|
||||
* @param string $functions compiled template function and block code
|
||||
* @param bool $cache flag for cache file
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false,
|
||||
Smarty_Internal_TemplateCompilerBase $compiler = null)
|
||||
{
|
||||
// build property code
|
||||
$properties[ 'version' ] = Smarty::SMARTY_VERSION;
|
||||
$properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
if (!$cache) {
|
||||
$properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
|
||||
$properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
|
||||
$properties[ 'includes' ] = $_template->compiled->includes;
|
||||
} else {
|
||||
$properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code;
|
||||
$properties[ 'file_dependency' ] = $_template->cached->file_dependency;
|
||||
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/* Smarty version {Smarty::SMARTY_VERSION}, created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
||||
"\n from \"" . str_replace('*/','* /',$_template->source->filepath) . "\" */\n\n";
|
||||
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
||||
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
||||
($cache ? 'true' : 'false') . ")";
|
||||
$output .= "if ({$dec}) {\n";
|
||||
$output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||
if (!$cache && !empty($compiler->tpl_function)) {
|
||||
$output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
|
||||
var_export($compiler->tpl_function, true) . ");\n";
|
||||
}
|
||||
if ($cache && isset($_template->smarty->ext->_tplFunction)) {
|
||||
$output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
|
||||
var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
|
||||
|
||||
}
|
||||
// include code for plugins
|
||||
if (!$cache) {
|
||||
if (!empty($_template->compiled->required_plugins[ 'compiled' ])) {
|
||||
foreach ($_template->compiled->required_plugins[ 'compiled' ] as $tmp) {
|
||||
foreach ($tmp as $data) {
|
||||
$file = addslashes($data[ 'file' ]);
|
||||
if (is_array($data[ 'function' ])) {
|
||||
$output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
|
||||
} else {
|
||||
$output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_template->caching && !empty($_template->compiled->required_plugins[ 'nocache' ])) {
|
||||
$_template->compiled->has_nocache_code = true;
|
||||
$output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
||||
foreach ($_template->compiled->required_plugins[ 'nocache' ] as $tmp) {
|
||||
foreach ($tmp as $data) {
|
||||
$file = addslashes($data[ 'file' ]);
|
||||
if (is_array($data[ 'function' ])) {
|
||||
$output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
|
||||
} else {
|
||||
$output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
$output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
|
||||
}
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$output .= $content;
|
||||
$output .= "<?php }\n?>";
|
||||
$output .= $functions;
|
||||
$output .= "<?php }\n";
|
||||
// remove unneeded PHP tags
|
||||
return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output);
|
||||
}
|
||||
}
|
69
libs/sysplugins/smarty_internal_runtime_filterhandler.php
Normale Datei
69
libs/sysplugins/smarty_internal_runtime_filterhandler.php
Normale Datei
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Filter Handler
|
||||
* Smarty filter handler class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for filter processing
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Runtime_FilterHandler
|
||||
{
|
||||
/**
|
||||
* Run filters over content
|
||||
* The filters will be lazy loaded if required
|
||||
* class name format: Smarty_FilterType_FilterName
|
||||
* plugin filename format: filtertype.filtername.php
|
||||
* Smarty2 filter plugins could be used
|
||||
*
|
||||
* @param string $type the type of filter ('pre','post','output') which shall run
|
||||
* @param string $content the content which shall be processed by the filters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string the filtered content
|
||||
*/
|
||||
public function runFilter($type, $content, Smarty_Internal_Template $template)
|
||||
{
|
||||
// loop over autoload filters of specified type
|
||||
if (!empty($template->smarty->autoload_filters[ $type ])) {
|
||||
foreach ((array) $template->smarty->autoload_filters[ $type ] as $name) {
|
||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||
if (function_exists($plugin_name)) {
|
||||
$callback = $plugin_name;
|
||||
} elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) {
|
||||
$callback = array($plugin_name, 'execute');
|
||||
} elseif ($template->smarty->loadPlugin($plugin_name, false)) {
|
||||
if (function_exists($plugin_name)) {
|
||||
// use loaded Smarty2 style plugin
|
||||
$callback = $plugin_name;
|
||||
} elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) {
|
||||
// loaded class of filter plugin
|
||||
$callback = array($plugin_name, 'execute');
|
||||
} else {
|
||||
throw new SmartyException("Auto load {$type}-filter plugin method \"{$plugin_name}::execute\" not callable");
|
||||
}
|
||||
} else {
|
||||
// nothing found, throw exception
|
||||
throw new SmartyException("Unable to auto load {$type}-filter plugin \"{$plugin_name}\"");
|
||||
}
|
||||
$content = call_user_func($callback, $content, $template);
|
||||
}
|
||||
}
|
||||
// loop over registered filters of specified type
|
||||
if (!empty($template->smarty->registered_filters[ $type ])) {
|
||||
foreach ($template->smarty->registered_filters[ $type ] as $key => $name) {
|
||||
$content = call_user_func($template->smarty->registered_filters[ $type ][ $key ], $content, $template);
|
||||
}
|
||||
}
|
||||
// return filtered output
|
||||
return $content;
|
||||
}
|
||||
}
|
151
libs/sysplugins/smarty_internal_runtime_foreach.php
Normale Datei
151
libs/sysplugins/smarty_internal_runtime_foreach.php
Normale Datei
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Foreach Runtime Methods count(), init(), restore()
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
*/
|
||||
class Smarty_Internal_Runtime_Foreach
|
||||
{
|
||||
|
||||
/**
|
||||
* Stack of saved variables
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $stack = array();
|
||||
|
||||
/**
|
||||
* Init foreach loop
|
||||
* - save item and key variables, named foreach property data if defined
|
||||
* - init item and key variables, named foreach property data if required
|
||||
* - count total if required
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param mixed $from values to loop over
|
||||
* @param string $item variable name
|
||||
* @param bool $needTotal flag if we need to count values
|
||||
* @param null|string $key variable name
|
||||
* @param null|string $name of named foreach
|
||||
* @param array $properties of named foreach
|
||||
*
|
||||
* @return mixed $from
|
||||
*/
|
||||
public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null,
|
||||
$properties = array())
|
||||
{
|
||||
$saveVars = array();
|
||||
$total = null;
|
||||
if (!is_array($from)) {
|
||||
if (is_object($from)) {
|
||||
$total = $this->count($from);
|
||||
} else {
|
||||
settype($from, 'array');
|
||||
}
|
||||
}
|
||||
if (!isset($total)) {
|
||||
$total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1);
|
||||
}
|
||||
if (isset($tpl->tpl_vars[ $item ])) {
|
||||
$saveVars[ 'item' ] = array($item,
|
||||
$tpl->tpl_vars[ $item ]);
|
||||
}
|
||||
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
if ($total === 0) {
|
||||
$from = null;
|
||||
} else {
|
||||
if ($key) {
|
||||
if (isset($tpl->tpl_vars[ $key ])) {
|
||||
$saveVars[ 'key' ] = array($key,
|
||||
$tpl->tpl_vars[ $key ]);
|
||||
}
|
||||
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
}
|
||||
}
|
||||
if ($needTotal) {
|
||||
$tpl->tpl_vars[ $item ]->total = $total;
|
||||
}
|
||||
if ($name) {
|
||||
$namedVar = "__smarty_foreach_{$name}";
|
||||
if (isset($tpl->tpl_vars[ $namedVar ])) {
|
||||
$saveVars[ 'named' ] = array($namedVar,
|
||||
$tpl->tpl_vars[ $namedVar ]);
|
||||
}
|
||||
$namedProp = array();
|
||||
if (isset($properties[ 'total' ])) {
|
||||
$namedProp[ 'total' ] = $total;
|
||||
}
|
||||
if (isset($properties[ 'iteration' ])) {
|
||||
$namedProp[ 'iteration' ] = 0;
|
||||
}
|
||||
if (isset($properties[ 'index' ])) {
|
||||
$namedProp[ 'index' ] = - 1;
|
||||
}
|
||||
if (isset($properties[ 'show' ])) {
|
||||
$namedProp[ 'show' ] = ($total > 0);
|
||||
}
|
||||
$tpl->tpl_vars[ $namedVar ] = new Smarty_Variable($namedProp);
|
||||
}
|
||||
$this->stack[] = $saveVars;
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
|
||||
* for empty elements
|
||||
*/
|
||||
public function count($value)
|
||||
{
|
||||
if ($value instanceof IteratorAggregate) {
|
||||
// Note: getIterator() returns a Traversable, not an Iterator
|
||||
// thus rewind() and valid() methods may not be present
|
||||
return iterator_count($value->getIterator());
|
||||
} elseif ($value instanceof Iterator) {
|
||||
return $value instanceof Generator ? 1 : iterator_count($value);
|
||||
} elseif ($value instanceof Countable) {
|
||||
return count($value);
|
||||
} elseif ($value instanceof PDOStatement) {
|
||||
return $value->rowCount();
|
||||
} elseif ($value instanceof Traversable) {
|
||||
return iterator_count($value);
|
||||
}
|
||||
return count((array) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore saved variables
|
||||
*
|
||||
* will be called by {break n} or {continue n} for the required number of levels
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param int $levels number of levels
|
||||
*/
|
||||
public function restore(Smarty_Internal_Template $tpl, $levels = 1)
|
||||
{
|
||||
while ($levels) {
|
||||
$saveVars = array_pop($this->stack);
|
||||
if (!empty($saveVars)) {
|
||||
if (isset($saveVars[ 'item' ])) {
|
||||
$item = &$saveVars[ 'item' ];
|
||||
$tpl->tpl_vars[ $item[ 0 ] ]->value = $item[ 1 ]->value;
|
||||
}
|
||||
if (isset($saveVars[ 'key' ])) {
|
||||
$tpl->tpl_vars[ $saveVars[ 'key' ][ 0 ] ] = $saveVars[ 'key' ][ 1 ];
|
||||
}
|
||||
if (isset($saveVars[ 'named' ])) {
|
||||
$tpl->tpl_vars[ $saveVars[ 'named' ][ 0 ] ] = $saveVars[ 'named' ][ 1 ];
|
||||
}
|
||||
}
|
||||
$levels --;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
182
libs/sysplugins/smarty_internal_runtime_getincludepath.php
Normale Datei
182
libs/sysplugins/smarty_internal_runtime_getincludepath.php
Normale Datei
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty read include path plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Monte Ohrt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Read Include Path Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Runtime_GetIncludePath
|
||||
{
|
||||
/**
|
||||
* include path cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_include_path = '';
|
||||
|
||||
/**
|
||||
* include path directory cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_include_dirs = array();
|
||||
|
||||
/**
|
||||
* include path directory cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_user_dirs = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $isFile = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $isPath = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
public $number = array();
|
||||
|
||||
/**
|
||||
* status cache
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $_has_stream_include = null;
|
||||
|
||||
/**
|
||||
* Number for array index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $counter = 0;
|
||||
|
||||
/**
|
||||
* Check if include path was updated
|
||||
*
|
||||
* @param \Smarty $smarty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNewIncludePath(Smarty $smarty)
|
||||
{
|
||||
$_i_path = get_include_path();
|
||||
if ($this->_include_path != $_i_path) {
|
||||
$this->_include_dirs = array();
|
||||
$this->_include_path = $_i_path;
|
||||
$_dirs = (array) explode(PATH_SEPARATOR, $_i_path);
|
||||
foreach ($_dirs as $_path) {
|
||||
if (is_dir($_path)) {
|
||||
$this->_include_dirs[] = $smarty->_realpath($_path . $smarty->ds, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* return array with include path directories
|
||||
*
|
||||
* @param \Smarty $smarty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIncludePathDirs(Smarty $smarty)
|
||||
{
|
||||
$this->isNewIncludePath($smarty);
|
||||
return $this->_include_dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return full file path from PHP include_path
|
||||
*
|
||||
* @param string[] $dirs
|
||||
* @param string $file
|
||||
* @param \Smarty $smarty
|
||||
*
|
||||
* @return bool|string full filepath or false
|
||||
*
|
||||
*/
|
||||
public function getIncludePath($dirs, $file, Smarty $smarty)
|
||||
{
|
||||
//if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) {
|
||||
if (!(isset($this->_has_stream_include) ? $this->_has_stream_include :
|
||||
$this->_has_stream_include = function_exists('stream_resolve_include_path'))
|
||||
) {
|
||||
$this->isNewIncludePath($smarty);
|
||||
}
|
||||
// try PHP include_path
|
||||
foreach ($dirs as $dir) {
|
||||
$dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter ++;
|
||||
if (isset($this->isFile[ $dir_n ][ $file ])) {
|
||||
if ($this->isFile[ $dir_n ][ $file ]) {
|
||||
return $this->isFile[ $dir_n ][ $file ];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isset($this->_user_dirs[ $dir_n ])) {
|
||||
if (false === $this->_user_dirs[ $dir_n ]) {
|
||||
continue;
|
||||
} else {
|
||||
$dir = $this->_user_dirs[ $dir_n ];
|
||||
}
|
||||
} else {
|
||||
if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') {
|
||||
$dir = str_ireplace(getcwd(), '.', $dir);
|
||||
if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') {
|
||||
$this->_user_dirs[ $dir_n ] = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$dir = substr($dir, 2);
|
||||
$this->_user_dirs[ $dir_n ] = $dir;
|
||||
}
|
||||
if ($this->_has_stream_include) {
|
||||
$path = stream_resolve_include_path($dir . (isset($file) ? $file : ''));
|
||||
if ($path) {
|
||||
return $this->isFile[ $dir_n ][ $file ] = $path;
|
||||
}
|
||||
} else {
|
||||
foreach ($this->_include_dirs as $key => $_i_path) {
|
||||
$path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] :
|
||||
$this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false;
|
||||
if ($path === false) {
|
||||
continue;
|
||||
}
|
||||
if (isset($file)) {
|
||||
$_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false;
|
||||
if ($_file) {
|
||||
return $_file;
|
||||
}
|
||||
} else {
|
||||
// no file was given return directory path
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
241
libs/sysplugins/smarty_internal_runtime_inheritance.php
Normale Datei
241
libs/sysplugins/smarty_internal_runtime_inheritance.php
Normale Datei
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Inheritance Runtime Methods processBlock, endChild, init
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
**/
|
||||
class Smarty_Internal_Runtime_Inheritance
|
||||
{
|
||||
|
||||
/**
|
||||
* State machine
|
||||
* - 0 idle next extends will create a new inheritance tree
|
||||
* - 1 processing child template
|
||||
* - 2 wait for next inheritance template
|
||||
* - 3 assume parent template, if child will loaded goto state 1
|
||||
* a call to a sub template resets the state to 0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $state = 0;
|
||||
|
||||
/**
|
||||
* Array of root child {block} objects
|
||||
*
|
||||
* @var Smarty_Internal_Block[]
|
||||
*/
|
||||
public $childRoot = array();
|
||||
|
||||
/**
|
||||
* inheritance template nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $inheritanceLevel = 0;
|
||||
|
||||
/**
|
||||
* inheritance template index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tplIndex = - 1;
|
||||
|
||||
/**
|
||||
* Array of template source objects
|
||||
* - key template index
|
||||
*
|
||||
* @var Smarty_Template_Source[]
|
||||
*/
|
||||
public $sources = array();
|
||||
|
||||
/**
|
||||
* Stack of source objects while executing block code
|
||||
*
|
||||
* @var Smarty_Template_Source[]
|
||||
*/
|
||||
public $sourceStack = array();
|
||||
|
||||
/**
|
||||
* Initialize inheritance
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl template object of caller
|
||||
* @param bool $initChild if true init for child template
|
||||
* @param array $blockNames outer level block name
|
||||
*
|
||||
*/
|
||||
public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = array())
|
||||
{
|
||||
// if called while executing parent template it must be a sub-template with new inheritance root
|
||||
if ($initChild && $this->state == 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
|
||||
$tpl->inheritance = new Smarty_Internal_Runtime_Inheritance();
|
||||
$tpl->inheritance->init($tpl, $initChild, $blockNames);
|
||||
return;
|
||||
}
|
||||
$this->tplIndex ++;
|
||||
$this->sources[ $this->tplIndex ] = $tpl->source;
|
||||
|
||||
// start of child sub template(s)
|
||||
if ($initChild) {
|
||||
$this->state = 1;
|
||||
if (!$this->inheritanceLevel) {
|
||||
//grab any output of child templates
|
||||
ob_start();
|
||||
}
|
||||
$this->inheritanceLevel ++;
|
||||
// $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
|
||||
// $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
|
||||
}
|
||||
// if state was waiting for parent change state to parent
|
||||
if ($this->state == 2) {
|
||||
$this->state = 3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End of child template(s)
|
||||
* - if outer level is reached flush output buffer and switch to wait for parent template state
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param null|string $template optional name of inheritance parent template
|
||||
* @param null|string $uid uid of inline template
|
||||
* @param null|string $func function call name of inline template
|
||||
*/
|
||||
public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null)
|
||||
{
|
||||
$this->inheritanceLevel --;
|
||||
if (!$this->inheritanceLevel) {
|
||||
ob_end_clean();
|
||||
$this->state = 2;
|
||||
}
|
||||
if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends') || $tpl->smarty->extends_recursion)) {
|
||||
$tpl->_subTemplateRender($template, $tpl->cache_id, $tpl->compile_id, $tpl->caching ? 9999 : 0,
|
||||
$tpl->cache_lifetime, array(), 2, false, $uid, $func);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty_Internal_Block constructor.
|
||||
* - if outer level {block} of child template ($state == 1) save it as child root block
|
||||
* - otherwise process inheritance and render
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param $className
|
||||
* @param string $name
|
||||
* @param int|null $tplIndex index of outer level {block} if nested
|
||||
*/
|
||||
public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null)
|
||||
{
|
||||
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
|
||||
if (isset($this->childRoot[ $name ])) {
|
||||
$block->child = $this->childRoot[ $name ];
|
||||
}
|
||||
if ($this->state == 1) {
|
||||
$this->childRoot[ $name ] = $block;
|
||||
return;
|
||||
}
|
||||
// make sure we got child block of child template of current block
|
||||
while ($block->child && $block->tplIndex <= $block->child->tplIndex) {
|
||||
$block->child = $block->child->child;
|
||||
}
|
||||
$this->process($tpl, $block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Goto child block or render this
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param \Smarty_Internal_Block $block
|
||||
* @param \Smarty_Internal_Block|null $parent
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block,
|
||||
Smarty_Internal_Block $parent = null)
|
||||
{
|
||||
if ($block->hide && !isset($block->child)) {
|
||||
return;
|
||||
}
|
||||
if (isset($block->child) && $block->child->hide && !isset($block->child->child)) {
|
||||
$block->child = null;
|
||||
}
|
||||
$block->parent = $parent;
|
||||
if ($block->append && !$block->prepend && isset($parent)) {
|
||||
$this->callParent($tpl, $block);
|
||||
}
|
||||
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
|
||||
$this->callBlock($block, $tpl);
|
||||
} else {
|
||||
$this->process($tpl, $block->child, $block);
|
||||
}
|
||||
if ($block->prepend && isset($parent)) {
|
||||
$this->callParent($tpl, $block);
|
||||
if ($block->append) {
|
||||
if ($block->callsChild || !isset($block->child) ||
|
||||
($block->child->hide && !isset($block->child->child))
|
||||
) {
|
||||
$this->callBlock($block, $tpl);
|
||||
} else {
|
||||
$this->process($tpl, $block->child, $block);
|
||||
}
|
||||
}
|
||||
}
|
||||
$block->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render child on {$smarty.block.child}
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param \Smarty_Internal_Block $block
|
||||
*/
|
||||
public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
|
||||
{
|
||||
if (isset($block->child)) {
|
||||
$this->process($tpl, $block->child, $block);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render parent on {$smarty.block.parent} or {block append/prepend} *
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param \Smarty_Internal_Block $block
|
||||
*
|
||||
* @param null $name
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $name = null)
|
||||
{
|
||||
if (isset($name)) {
|
||||
$block = $block->parent;
|
||||
while (isset($block)) {
|
||||
if (isset($block->subBlocks[ $name ])) {
|
||||
} else {
|
||||
$block = $block->parent;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (isset($block->parent)) {
|
||||
$this->callBlock($block->parent, $tpl);
|
||||
} else {
|
||||
throw new SmartyException("inheritance: illegal {\$smarty.block.parent} or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Smarty_Internal_Block $block
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
*/
|
||||
public function callBlock(Smarty_Internal_Block $block, Smarty_Internal_Template $tpl)
|
||||
{
|
||||
$this->sourceStack[] = $tpl->source;
|
||||
$tpl->source = $this->sources[ $block->tplIndex ];
|
||||
$block->callBlock($tpl);
|
||||
$tpl->source = array_pop($this->sourceStack);
|
||||
}
|
||||
}
|
56
libs/sysplugins/smarty_internal_runtime_make_nocache.php
Normale Datei
56
libs/sysplugins/smarty_internal_runtime_make_nocache.php
Normale Datei
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* {make_nocache} Runtime Methods save(), store()
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
*/
|
||||
class Smarty_Internal_Runtime_Make_Nocache
|
||||
{
|
||||
|
||||
/**
|
||||
* Save current variable value while rendering compiled template and inject nocache code to
|
||||
* assign variable value in cahed template
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param string $var variable name
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function save(Smarty_Internal_Template $tpl, $var)
|
||||
{
|
||||
if (isset($tpl->tpl_vars[ $var ])) {
|
||||
$export =
|
||||
preg_replace('/^Smarty_Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[ $var ], true));
|
||||
if (preg_match('/(\w+)::__set_state/', $export, $match)) {
|
||||
throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
|
||||
}
|
||||
echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " .
|
||||
addcslashes("\$_smarty_tpl->smarty->ext->_make_nocache->store(\$_smarty_tpl, '{$var}', ", '\\') .
|
||||
$export . ");?>\n/*/%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store variable value saved while rendering compiled template in cached template context
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param string $var variable name
|
||||
* @param array $properties
|
||||
*/
|
||||
public function store(Smarty_Internal_Template $tpl, $var, $properties)
|
||||
{
|
||||
// do not overwrite existing nocache variables
|
||||
if (!isset($tpl->tpl_vars[ $var ]) || !$tpl->tpl_vars[ $var ]->nocache) {
|
||||
$newVar = new Smarty_Variable();
|
||||
unset($properties[ 'nocache' ]);
|
||||
foreach ($properties as $k => $v) {
|
||||
$newVar->$k = $v;
|
||||
}
|
||||
$tpl->tpl_vars[ $var ] = $newVar;
|
||||
}
|
||||
}
|
||||
}
|
171
libs/sysplugins/smarty_internal_runtime_tplfunction.php
Normale Datei
171
libs/sysplugins/smarty_internal_runtime_tplfunction.php
Normale Datei
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* TplFunction Runtime Methods callTemplateFunction
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
**/
|
||||
class Smarty_Internal_Runtime_TplFunction
|
||||
{
|
||||
/**
|
||||
* Call template function
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl template object
|
||||
* @param string $name template function name
|
||||
* @param array $params parameter array
|
||||
* @param bool $nocache true if called nocache
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache)
|
||||
{
|
||||
$funcParam = isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] :
|
||||
(isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : null);
|
||||
if (isset($funcParam)) {
|
||||
if (!$tpl->caching || ($tpl->caching && $nocache)) {
|
||||
$function = $funcParam[ 'call_name' ];
|
||||
} else {
|
||||
if (isset($funcParam[ 'call_name_caching' ])) {
|
||||
$function = $funcParam[ 'call_name_caching' ];
|
||||
} else {
|
||||
$function = $funcParam[ 'call_name' ];
|
||||
}
|
||||
}
|
||||
if (function_exists($function)) {
|
||||
$this->saveTemplateVariables($tpl, $name);
|
||||
$function ($tpl, $params);
|
||||
$this->restoreTemplateVariables($tpl, $name);
|
||||
return;
|
||||
}
|
||||
// try to load template function dynamically
|
||||
if ($this->addTplFuncToCache($tpl, $name, $function)) {
|
||||
$this->saveTemplateVariables($tpl, $name);
|
||||
$function ($tpl, $params);
|
||||
$this->restoreTemplateVariables($tpl, $name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("Unable to find template function '{$name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register template functions defined by template
|
||||
*
|
||||
* @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $obj
|
||||
* @param array $tplFunctions source information array of template functions defined in template
|
||||
* @param bool $override if true replace existing functions with same name
|
||||
*/
|
||||
public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tplFunctions, $override = true)
|
||||
{
|
||||
$obj->tplFunctions =
|
||||
$override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions);
|
||||
// make sure that the template functions are known in parent templates
|
||||
if ($obj->_isSubTpl()) {
|
||||
$obj->smarty->ext->_tplFunction->registerTplFunctions($obj->parent, $tplFunctions, false);
|
||||
} else {
|
||||
$obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->tplFunctions, $tplFunctions) :
|
||||
array_merge($tplFunctions, $obj->smarty->tplFunctions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return source parameter array for single or all template functions
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl template object
|
||||
* @param null|string $name template function name
|
||||
*
|
||||
* @return array|bool|mixed
|
||||
*/
|
||||
public function getTplFunction(Smarty_Internal_Template $tpl, $name = null)
|
||||
{
|
||||
if (isset($name)) {
|
||||
return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] :
|
||||
(isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : false);
|
||||
} else {
|
||||
return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Add template function to cache file for nocache calls
|
||||
*
|
||||
* @param Smarty_Internal_Template $tpl
|
||||
* @param string $_name template function name
|
||||
* @param string $_function PHP function name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function)
|
||||
{
|
||||
$funcParam = $tpl->tplFunctions[ $_name ];
|
||||
if (is_file($funcParam[ 'compiled_filepath' ])) {
|
||||
// read compiled file
|
||||
$code = file_get_contents($funcParam[ 'compiled_filepath' ]);
|
||||
// grab template function
|
||||
if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) {
|
||||
// grab source info from file dependency
|
||||
preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
|
||||
unset($code);
|
||||
// make PHP function known
|
||||
eval($match[ 0 ]);
|
||||
if (function_exists($_function)) {
|
||||
// search cache file template
|
||||
$tplPtr = $tpl;
|
||||
while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
|
||||
$tplPtr = $tplPtr->parent;
|
||||
}
|
||||
// add template function code to cache file
|
||||
if (isset($tplPtr->cached)) {
|
||||
/* @var Smarty_Template_Cached $cache */
|
||||
$cache = $tplPtr->cached;
|
||||
$content = $cache->read($tplPtr);
|
||||
if ($content) {
|
||||
// check if we must update file dependency
|
||||
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
|
||||
$content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content);
|
||||
}
|
||||
$tplPtr->smarty->ext->_updateCache->write($cache, $tplPtr,
|
||||
preg_replace('/\s*\?>\s*$/', "\n", $content) .
|
||||
"\n" . preg_replace(array('/^\s*<\?php\s+/',
|
||||
'/\s*\?>\s*$/',), "\n",
|
||||
$match[ 0 ]));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current template variables on stack
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param string $name stack name
|
||||
*/
|
||||
public function saveTemplateVariables(Smarty_Internal_Template $tpl, $name)
|
||||
{
|
||||
$tpl->_cache[ 'varStack' ][] =
|
||||
array('tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore saved variables into template objects
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param string $name stack name
|
||||
*/
|
||||
public function restoreTemplateVariables(Smarty_Internal_Template $tpl, $name)
|
||||
{
|
||||
if (isset($tpl->_cache[ 'varStack' ])) {
|
||||
$vars = array_pop($tpl->_cache[ 'varStack' ]);
|
||||
$tpl->tpl_vars = $vars[ 'tpl' ];
|
||||
$tpl->config_vars = $vars[ 'config' ];
|
||||
}
|
||||
}
|
||||
}
|
165
libs/sysplugins/smarty_internal_runtime_updatecache.php
Normale Datei
165
libs/sysplugins/smarty_internal_runtime_updatecache.php
Normale Datei
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Inline Runtime Methods render, setSourceByUid, setupSubTemplate
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
**/
|
||||
class Smarty_Internal_Runtime_UpdateCache
|
||||
{
|
||||
/**
|
||||
* check client side cache
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param Smarty_Internal_Template $_template
|
||||
* @param string $content
|
||||
*/
|
||||
public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize content and write it to cache resource
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param Smarty_Internal_Template $_template
|
||||
* @param bool $no_output_filter
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function removeNoCacheHash(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template,
|
||||
$no_output_filter)
|
||||
{
|
||||
$content = ob_get_clean();
|
||||
unset($cached->hashes[ $_template->compiled->nocache_hash ]);
|
||||
if (!empty($cached->hashes)) {
|
||||
$hash_array = array();
|
||||
foreach ($cached->hashes as $hash => $foo) {
|
||||
$hash_array[] = "/{$hash}/";
|
||||
}
|
||||
$content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content);
|
||||
}
|
||||
$_template->cached->has_nocache_code = false;
|
||||
// get text between non-cached items
|
||||
$cache_split =
|
||||
preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
|
||||
$content);
|
||||
// get non-cached items
|
||||
preg_match_all("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
|
||||
$content, $cache_parts);
|
||||
$content = '';
|
||||
// loop over items, stitch back together
|
||||
foreach ($cache_split as $curr_idx => $curr_split) {
|
||||
// escape PHP tags in template content
|
||||
$content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/',
|
||||
"<?php echo '\$1'; ?>\n", $curr_split);
|
||||
if (isset($cache_parts[ 0 ][ $curr_idx ])) {
|
||||
$_template->cached->has_nocache_code = true;
|
||||
$content .= $cache_parts[ 1 ][ $curr_idx ];
|
||||
}
|
||||
}
|
||||
if (!$no_output_filter && !$_template->cached->has_nocache_code &&
|
||||
(isset($_template->smarty->autoload_filters[ 'output' ]) ||
|
||||
isset($_template->smarty->registered_filters[ 'output' ]))
|
||||
) {
|
||||
$content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template);
|
||||
}
|
||||
// write cache file content
|
||||
$this->writeCachedContent($cached, $_template, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache was invalid , so render from compiled and write to cache
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param $no_output_filter
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter)
|
||||
{
|
||||
ob_start();
|
||||
if (!isset($_template->compiled)) {
|
||||
$_template->loadCompiled();
|
||||
}
|
||||
$_template->compiled->render($_template);
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->start_cache($_template);
|
||||
}
|
||||
$this->removeNoCacheHash($cached, $_template, $no_output_filter);
|
||||
$compile_check = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
if ($_template->_isSubTpl()) {
|
||||
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
|
||||
}
|
||||
if (!$_template->cached->processed) {
|
||||
$_template->cached->process($_template, true);
|
||||
}
|
||||
$_template->smarty->compile_check = $compile_check;
|
||||
$cached->getRenderedTemplateCode($_template);
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_cache($_template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content to cache resource
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param Smarty_Internal_Template $_template
|
||||
* @param string $content
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function writeCachedContent(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
|
||||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED)
|
||||
) {
|
||||
// don't write cache file
|
||||
return false;
|
||||
}
|
||||
$content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true);
|
||||
return $this->write($cached, $_template, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this cache object to handler
|
||||
*
|
||||
* @param \Smarty_Template_Cached $cached
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
if ($cached->handler->writeCachedContent($_template, $content)) {
|
||||
$cached->content = null;
|
||||
$cached->timestamp = time();
|
||||
$cached->exists = true;
|
||||
$cached->valid = true;
|
||||
$cached->cache_lifetime = $_template->cache_lifetime;
|
||||
$cached->processed = false;
|
||||
if ($_template->smarty->cache_locking) {
|
||||
$cached->handler->releaseLock($_template->smarty, $cached);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
$cached->content = null;
|
||||
$cached->timestamp = false;
|
||||
$cached->exists = false;
|
||||
$cached->valid = false;
|
||||
$cached->processed = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
115
libs/sysplugins/smarty_internal_runtime_updatescope.php
Normale Datei
115
libs/sysplugins/smarty_internal_runtime_updatescope.php
Normale Datei
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Runtime Extension updateScope
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*
|
||||
**/
|
||||
class Smarty_Internal_Runtime_UpdateScope
|
||||
{
|
||||
|
||||
/**
|
||||
* Update new assigned template or config variable in other effected scopes
|
||||
*
|
||||
* @param Smarty_Internal_Template $tpl data object
|
||||
* @param string|null $varName variable name
|
||||
* @param int $tagScope tag scope to which bubble up variable value
|
||||
*
|
||||
*/
|
||||
public function _updateScope(Smarty_Internal_Template $tpl, $varName, $tagScope = 0)
|
||||
{
|
||||
if ($tagScope) {
|
||||
$this->_updateVarStack($tpl, $varName);
|
||||
$tagScope = $tagScope & ~Smarty::SCOPE_LOCAL;
|
||||
if (!$tpl->scope && !$tagScope) return;
|
||||
}
|
||||
$mergedScope = $tagScope | $tpl->scope;
|
||||
if ($mergedScope) {
|
||||
if ($mergedScope & Smarty::SCOPE_GLOBAL && $varName) {
|
||||
Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
||||
}
|
||||
// update scopes
|
||||
foreach ($this->_getAffectedScopes($tpl, $mergedScope) as $ptr) {
|
||||
$this->_updateVariableInOtherScope($ptr->tpl_vars, $tpl, $varName);
|
||||
if($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) {
|
||||
$this->_updateVarStack($ptr, $varName); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of objects which needs to be updated by given scope value
|
||||
*
|
||||
* @param Smarty_Internal_Template $tpl
|
||||
* @param int $mergedScope merged tag and template scope to which bubble up variable value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getAffectedScopes(Smarty_Internal_Template $tpl, $mergedScope)
|
||||
{
|
||||
$_stack = array();
|
||||
$ptr = $tpl->parent;
|
||||
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
|
||||
$_stack[] = $ptr;
|
||||
$mergedScope = $mergedScope & ~Smarty::SCOPE_PARENT;
|
||||
if (!$mergedScope) {
|
||||
// only parent was set, we are done
|
||||
return $_stack;
|
||||
}
|
||||
$ptr = $ptr->parent;
|
||||
}
|
||||
while (isset($ptr) && $ptr->_isTplObj()) {
|
||||
$_stack[] = $ptr;
|
||||
$ptr = $ptr->parent;
|
||||
}
|
||||
if ($mergedScope & Smarty::SCOPE_SMARTY) {
|
||||
if (isset($tpl->smarty)) {
|
||||
$_stack[] = $tpl->smarty;
|
||||
}
|
||||
} elseif ($mergedScope & Smarty::SCOPE_ROOT) {
|
||||
while (isset($ptr)) {
|
||||
if (!$ptr->_isTplObj()) {
|
||||
$_stack[] = $ptr;
|
||||
break;
|
||||
}
|
||||
$ptr = $ptr->parent;
|
||||
}
|
||||
}
|
||||
return $_stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update variable in other scope
|
||||
*
|
||||
* @param array $tpl_vars template variable array
|
||||
* @param \Smarty_Internal_Template $from
|
||||
* @param string $varName variable name
|
||||
*/
|
||||
public function _updateVariableInOtherScope(&$tpl_vars, Smarty_Internal_Template $from, $varName)
|
||||
{
|
||||
if (!isset($tpl_vars[ $varName ])) {
|
||||
$tpl_vars[ $varName ] = clone $from->tpl_vars[ $varName ];
|
||||
} else {
|
||||
$tpl_vars[ $varName ] = clone $tpl_vars[ $varName ];
|
||||
$tpl_vars[ $varName ]->value = $from->tpl_vars[ $varName ]->value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update variable in template local variable stack
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param string|null $varName variable name or null for config variables
|
||||
*/
|
||||
public function _updateVarStack(Smarty_Internal_Template $tpl, $varName)
|
||||
{
|
||||
$i = 0;
|
||||
while (isset($tpl->_cache[ 'varStack' ][ $i ])) {
|
||||
$this->_updateVariableInOtherScope($tpl->_cache[ 'varStack' ][ $i ][ 'tpl' ], $tpl, $varName);
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
}
|
105
libs/sysplugins/smarty_internal_runtime_writefile.php
Normale Datei
105
libs/sysplugins/smarty_internal_runtime_writefile.php
Normale Datei
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty write file plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Monte Ohrt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Write File Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Runtime_WriteFile
|
||||
{
|
||||
/**
|
||||
* Writes file in a safe way to disk
|
||||
*
|
||||
* @param string $_filepath complete filepath
|
||||
* @param string $_contents file content
|
||||
* @param Smarty $smarty smarty instance
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return boolean true
|
||||
*/
|
||||
public function writeFile($_filepath, $_contents, Smarty $smarty)
|
||||
{
|
||||
$_error_reporting = error_reporting();
|
||||
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||
$_file_perms = property_exists($smarty, '_file_perms') ? $smarty->_file_perms : 0644;
|
||||
$_dir_perms =
|
||||
property_exists($smarty, '_dir_perms') ? (isset($smarty->_dir_perms) ? $smarty->_dir_perms : 0777) : 0771;
|
||||
if ($_file_perms !== null) {
|
||||
$old_umask = umask(0);
|
||||
}
|
||||
|
||||
$_dirpath = dirname($_filepath);
|
||||
|
||||
// if subdirs, create dir structure
|
||||
if ($_dirpath !== '.') {
|
||||
$i=0;
|
||||
// loop if concurrency problem occurs
|
||||
// see https://bugs.php.net/bug.php?id=35326
|
||||
while (!is_dir($_dirpath)) {
|
||||
if (@mkdir($_dirpath, $_dir_perms, true)) {
|
||||
break;
|
||||
}
|
||||
clearstatcache();
|
||||
if (++$i === 3) {
|
||||
error_reporting($_error_reporting);
|
||||
throw new SmartyException("unable to create directory {$_dirpath}");
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
// write to tmp file, then move to overt file lock race condition
|
||||
$_tmp_file = $_dirpath . $smarty->ds . str_replace(array('.', ','), '_', uniqid('wrt', true));
|
||||
if (!file_put_contents($_tmp_file, $_contents)) {
|
||||
error_reporting($_error_reporting);
|
||||
throw new SmartyException("unable to write file {$_tmp_file}");
|
||||
}
|
||||
|
||||
/*
|
||||
* Windows' rename() fails if the destination exists,
|
||||
* Linux' rename() properly handles the overwrite.
|
||||
* Simply unlink()ing a file might cause other processes
|
||||
* currently reading that file to fail, but linux' rename()
|
||||
* seems to be smart enough to handle that for us.
|
||||
*/
|
||||
if (Smarty::$_IS_WINDOWS) {
|
||||
// remove original file
|
||||
if (is_file($_filepath)) {
|
||||
@unlink($_filepath);
|
||||
}
|
||||
// rename tmp file
|
||||
$success = @rename($_tmp_file, $_filepath);
|
||||
} else {
|
||||
// rename tmp file
|
||||
$success = @rename($_tmp_file, $_filepath);
|
||||
if (!$success) {
|
||||
// remove original file
|
||||
if (is_file($_filepath)) {
|
||||
@unlink($_filepath);
|
||||
}
|
||||
// rename tmp file
|
||||
$success = @rename($_tmp_file, $_filepath);
|
||||
}
|
||||
}
|
||||
if (!$success) {
|
||||
error_reporting($_error_reporting);
|
||||
throw new SmartyException("unable to write file {$_filepath}");
|
||||
}
|
||||
if ($_file_perms !== null) {
|
||||
// set file permissions
|
||||
chmod($_filepath, $_file_perms);
|
||||
umask($old_umask);
|
||||
}
|
||||
error_reporting($_error_reporting);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
174
libs/sysplugins/smarty_internal_smartytemplatecompiler.php
Normale Datei
174
libs/sysplugins/smarty_internal_smartytemplatecompiler.php
Normale Datei
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Smarty Template Compiler Base
|
||||
* This file contains the basic classes and methods for compiling Smarty templates with lexer/parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class SmartyTemplateCompiler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase
|
||||
{
|
||||
/**
|
||||
* Lexer class name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $lexer_class;
|
||||
|
||||
/**
|
||||
* Parser class name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $parser_class;
|
||||
|
||||
/**
|
||||
* array of vars which can be compiled in local scope
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $local_var = array();
|
||||
|
||||
/**
|
||||
* array of callbacks called when the normal compile process of template is finished
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $postCompileCallbacks = array();
|
||||
|
||||
/**
|
||||
* prefix code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $prefixCompiledCode = '';
|
||||
|
||||
/**
|
||||
* postfix code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $postfixCompiledCode = '';
|
||||
|
||||
/**
|
||||
* Initialize compiler
|
||||
*
|
||||
* @param string $lexer_class class name
|
||||
* @param string $parser_class class name
|
||||
* @param Smarty $smarty global instance
|
||||
*/
|
||||
public function __construct($lexer_class, $parser_class, Smarty $smarty)
|
||||
{
|
||||
parent::__construct($smarty);
|
||||
// get required plugins
|
||||
$this->lexer_class = $lexer_class;
|
||||
$this->parser_class = $parser_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* method to compile a Smarty template
|
||||
*
|
||||
* @param mixed $_content template source
|
||||
* @param bool $isTemplateSource
|
||||
*
|
||||
* @return bool true if compiling succeeded, false if it failed
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
protected function doCompile($_content, $isTemplateSource = false)
|
||||
{
|
||||
/* here is where the compiling takes place. Smarty
|
||||
tags in the templates are replaces with PHP code,
|
||||
then written to compiled files. */
|
||||
// init the lexer/parser to compile the template
|
||||
$this->parser =
|
||||
new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n",
|
||||
"\r"), "\n", $_content), $this),
|
||||
$this);
|
||||
if ($isTemplateSource && $this->template->caching) {
|
||||
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n");
|
||||
}
|
||||
if (function_exists('mb_internal_encoding')
|
||||
&& function_exists('ini_get')
|
||||
&& ((int) ini_get('mbstring.func_overload')) & 2
|
||||
) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('ASCII');
|
||||
} else {
|
||||
$mbEncoding = null;
|
||||
}
|
||||
|
||||
if ($this->smarty->_parserdebug) {
|
||||
$this->parser->PrintTrace();
|
||||
$this->parser->lex->PrintTrace();
|
||||
}
|
||||
// get tokens from lexer and parse them
|
||||
while ($this->parser->lex->yylex()) {
|
||||
if ($this->smarty->_parserdebug) {
|
||||
echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
|
||||
htmlentities($this->parser->lex->value) . "</pre>";
|
||||
}
|
||||
$this->parser->doParse($this->parser->lex->token, $this->parser->lex->value);
|
||||
}
|
||||
|
||||
// finish parsing process
|
||||
$this->parser->doParse(0, 0);
|
||||
if ($mbEncoding) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
// check for unclosed tags
|
||||
if (count($this->_tag_stack) > 0) {
|
||||
// get stacked info
|
||||
list($openTag, $_data) = array_pop($this->_tag_stack);
|
||||
$this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag .
|
||||
"{$this->smarty->right_delimiter} tag");
|
||||
}
|
||||
// call post compile callbacks
|
||||
foreach ($this->postCompileCallbacks as $cb) {
|
||||
$parameter = $cb;
|
||||
$parameter[ 0 ] = $this;
|
||||
call_user_func_array($cb[ 0 ], $parameter);
|
||||
}
|
||||
// return compiled code
|
||||
return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a post compile callback
|
||||
* - when the callback is called after template compiling the compiler object will be inserted as first parameter
|
||||
*
|
||||
* @param callback $callback
|
||||
* @param array $parameter optional parameter array
|
||||
* @param string $key optional key for callback
|
||||
* @param bool $replace if true replace existing keyed callback
|
||||
*
|
||||
*/
|
||||
public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
|
||||
{
|
||||
array_unshift($parameter, $callback);
|
||||
if (isset($key)) {
|
||||
if ($replace || !isset($this->postCompileCallbacks[ $key ])) {
|
||||
$this->postCompileCallbacks[ $key ] = $parameter;
|
||||
}
|
||||
} else {
|
||||
$this->postCompileCallbacks[] = $parameter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a post compile callback
|
||||
*
|
||||
* @param string $key callback key
|
||||
*/
|
||||
public function unregisterPostCompileCallback($key)
|
||||
{
|
||||
unset($this->postCompileCallbacks[ $key ]);
|
||||
}
|
||||
}
|
692
libs/sysplugins/smarty_internal_template.php
Normale Datei
692
libs/sysplugins/smarty_internal_template.php
Normale Datei
|
@ -0,0 +1,692 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Template
|
||||
* This file contains the Smarty template engine
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Main class with template data structures and methods
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*
|
||||
* @property Smarty_Template_Compiled $compiled
|
||||
* @property Smarty_Template_Cached $cached
|
||||
* @property Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*
|
||||
* The following methods will be dynamically loaded by the extension handler when they are called.
|
||||
* They are located in a corresponding Smarty_Internal_Method_xxxx class
|
||||
*
|
||||
* @method bool mustCompile()
|
||||
*/
|
||||
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
{
|
||||
/**
|
||||
* This object type (Smarty = 1, template = 2, data = 4)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_objType = 2;
|
||||
|
||||
/**
|
||||
* Global smarty instance
|
||||
*
|
||||
* @var Smarty
|
||||
*/
|
||||
public $smarty = null;
|
||||
|
||||
/**
|
||||
* Source instance
|
||||
*
|
||||
* @var Smarty_Template_Source|Smarty_Template_Config
|
||||
*/
|
||||
public $source = null;
|
||||
|
||||
/**
|
||||
* Inheritance runtime extension
|
||||
*
|
||||
* @var Smarty_Internal_Runtime_Inheritance
|
||||
*/
|
||||
public $inheritance = null;
|
||||
|
||||
/**
|
||||
* Template resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_resource = null;
|
||||
|
||||
/**
|
||||
* flag if compiled template is invalid and must be (re)compiled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $mustCompile = null;
|
||||
|
||||
/**
|
||||
* Template Id
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $templateId = null;
|
||||
|
||||
/**
|
||||
* Scope in which variables shall be assigned
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $scope = 0;
|
||||
|
||||
/**
|
||||
* Flag which is set while rending a cache file
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isRenderingCache = false;
|
||||
|
||||
/**
|
||||
* Callbacks called before rendering template
|
||||
*
|
||||
* @var callback[]
|
||||
*/
|
||||
public $startRenderCallbacks = array();
|
||||
|
||||
/**
|
||||
* Callbacks called after rendering template
|
||||
*
|
||||
* @var callback[]
|
||||
*/
|
||||
public $endRenderCallbacks = array();
|
||||
|
||||
/**
|
||||
* Template object cache
|
||||
*
|
||||
* @var Smarty_Internal_Template[]
|
||||
*/
|
||||
public static $tplObjCache = array();
|
||||
|
||||
/**
|
||||
* Template object cache for Smarty::isCached() == true
|
||||
*
|
||||
* @var Smarty_Internal_Template[]
|
||||
*/
|
||||
public static $isCacheTplObj = array();
|
||||
|
||||
/**
|
||||
* Subtemplate Info Cache
|
||||
*
|
||||
* @var string[]int[]
|
||||
*/
|
||||
public static $subTplInfo = array();
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
* Some of the global Smarty settings copied to template scope
|
||||
* It load the required template resources and caching plugins
|
||||
*
|
||||
* @param string $template_resource template resource string
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent back pointer to parent object
|
||||
* with variables or null
|
||||
* @param mixed $_cache_id cache id or null
|
||||
* @param mixed $_compile_id compile id or null
|
||||
* @param bool|int|null $_caching use caching?
|
||||
* @param int|null $_cache_lifetime cache life-time in seconds
|
||||
* @param bool $_isConfig
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null,
|
||||
$_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null,
|
||||
$_isConfig = false)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
// Smarty parameter
|
||||
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
|
||||
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
|
||||
$this->caching = $_caching === null ? $this->smarty->caching : $_caching;
|
||||
if ($this->caching === true) {
|
||||
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
}
|
||||
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
|
||||
$this->parent = $_parent;
|
||||
// Template resource
|
||||
$this->template_resource = $template_resource;
|
||||
$this->source = $_isConfig ? Smarty_Template_Config::load($this) : Smarty_Template_Source::load($this);
|
||||
parent::__construct();
|
||||
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
|
||||
$smarty->security_policy->registerCallBacks($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* render template
|
||||
*
|
||||
* @param bool $no_output_filter if true do not run output filter
|
||||
* @param null|bool $display true: display, false: fetch null: sub-template
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function render($no_output_filter = true, $display = null)
|
||||
{
|
||||
if ($this->smarty->debugging) {
|
||||
if (!isset($this->smarty->_debug)) {
|
||||
$this->smarty->_debug = new Smarty_Internal_Debug();
|
||||
}
|
||||
$this->smarty->_debug->start_template($this, $display);
|
||||
}
|
||||
// checks if template exists
|
||||
if (!$this->source->exists) {
|
||||
throw new SmartyException("Unable to load template '{$this->source->type}:{$this->source->name}'" .
|
||||
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : ''));
|
||||
}
|
||||
// disable caching for evaluated code
|
||||
if ($this->source->handler->recompiled) {
|
||||
$this->caching = false;
|
||||
}
|
||||
// read from cache or render
|
||||
$isCacheTpl =
|
||||
$this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
||||
if ($isCacheTpl) {
|
||||
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id ||
|
||||
$this->cached->compile_id !== $this->compile_id
|
||||
) {
|
||||
$this->loadCached(true);
|
||||
}
|
||||
$this->cached->render($this, $no_output_filter);
|
||||
} else {
|
||||
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
||||
$this->loadCompiled(true);
|
||||
}
|
||||
$this->compiled->render($this);
|
||||
}
|
||||
|
||||
// display or fetch
|
||||
if ($display) {
|
||||
if ($this->caching && $this->smarty->cache_modified_check) {
|
||||
$this->smarty->ext->_cacheModify->cacheModifiedCheck($this->cached, $this,
|
||||
isset($content) ? $content : ob_get_clean());
|
||||
} else {
|
||||
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
|
||||
!$no_output_filter && (isset($this->smarty->autoload_filters[ 'output' ]) ||
|
||||
isset($this->smarty->registered_filters[ 'output' ]))
|
||||
) {
|
||||
echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
|
||||
} else {
|
||||
echo ob_get_clean();
|
||||
}
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->end_template($this);
|
||||
// debug output
|
||||
$this->smarty->_debug->display_debug($this, true);
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->end_template($this);
|
||||
if ($this->smarty->debugging === 2 && $display === false) {
|
||||
$this->smarty->_debug->display_debug($this, true);
|
||||
}
|
||||
}
|
||||
if ($this->_isSubTpl()) {
|
||||
foreach ($this->compiled->required_plugins as $code => $tmp1) {
|
||||
foreach ($tmp1 as $name => $tmp) {
|
||||
foreach ($tmp as $type => $data) {
|
||||
$this->parent->compiled->required_plugins[ $code ][ $name ][ $type ] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$no_output_filter &&
|
||||
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
|
||||
(isset($this->smarty->autoload_filters[ 'output' ]) ||
|
||||
isset($this->smarty->registered_filters[ 'output' ]))
|
||||
) {
|
||||
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
|
||||
}
|
||||
// return cache content
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime function to render sub-template
|
||||
*
|
||||
* @param string $template template name
|
||||
* @param mixed $cache_id cache id
|
||||
* @param mixed $compile_id compile id
|
||||
* @param integer $caching cache mode
|
||||
* @param integer $cache_lifetime life time of cache data
|
||||
* @param array $data passed parameter template variables
|
||||
* @param int $scope scope in which {include} should execute
|
||||
* @param bool $forceTplCache cache template object
|
||||
* @param string $uid file dependency uid
|
||||
* @param string $content_func function name
|
||||
*
|
||||
*/
|
||||
public function _subTemplateRender($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $scope,
|
||||
$forceTplCache, $uid = null, $content_func = null)
|
||||
{
|
||||
$tpl = clone $this;
|
||||
$tpl->parent = $this;
|
||||
$smarty = &$this->smarty;
|
||||
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
|
||||
// recursive call ?
|
||||
if (isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId() != $_templateId) {
|
||||
// already in template cache?
|
||||
if (isset(self::$tplObjCache[ $_templateId ])) {
|
||||
// copy data from cached object
|
||||
$cachedTpl = &self::$tplObjCache[ $_templateId ];
|
||||
$tpl->templateId = $cachedTpl->templateId;
|
||||
$tpl->template_resource = $cachedTpl->template_resource;
|
||||
$tpl->cache_id = $cachedTpl->cache_id;
|
||||
$tpl->compile_id = $cachedTpl->compile_id;
|
||||
$tpl->source = $cachedTpl->source;
|
||||
if (isset($cachedTpl->compiled)) {
|
||||
$tpl->compiled = $cachedTpl->compiled;
|
||||
} else {
|
||||
unset($tpl->compiled);
|
||||
}
|
||||
if ($caching != 9999 && isset($cachedTpl->cached)) {
|
||||
$tpl->cached = $cachedTpl->cached;
|
||||
} else {
|
||||
unset($tpl->cached);
|
||||
}
|
||||
} else {
|
||||
$tpl->templateId = $_templateId;
|
||||
$tpl->template_resource = $template;
|
||||
$tpl->cache_id = $cache_id;
|
||||
$tpl->compile_id = $compile_id;
|
||||
if (isset($uid)) {
|
||||
// for inline templates we can get all resource information from file dependency
|
||||
list($filepath, $timestamp, $type) = $tpl->compiled->file_dependency[ $uid ];
|
||||
$tpl->source = new Smarty_Template_Source($smarty, $filepath, $type, $filepath);
|
||||
$tpl->source->filepath = $filepath;
|
||||
$tpl->source->timestamp = $timestamp;
|
||||
$tpl->source->exists = true;
|
||||
$tpl->source->uid = $uid;
|
||||
} else {
|
||||
$tpl->source = Smarty_Template_Source::load($tpl);
|
||||
unset($tpl->compiled);
|
||||
}
|
||||
if ($caching != 9999) {
|
||||
unset($tpl->cached);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// on recursive calls force caching
|
||||
$forceTplCache = true;
|
||||
}
|
||||
$tpl->caching = $caching;
|
||||
$tpl->cache_lifetime = $cache_lifetime;
|
||||
// set template scope
|
||||
$tpl->scope = $scope;
|
||||
if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
||||
// check if template object should be cached
|
||||
if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ]) &&
|
||||
self::$subTplInfo[ $tpl->template_resource ] > 1) ||
|
||||
($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ]))
|
||||
) {
|
||||
self::$tplObjCache[ $tpl->templateId ] = $tpl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
// set up variable values
|
||||
foreach ($data as $_key => $_val) {
|
||||
$tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val, $this->isRenderingCache);
|
||||
}
|
||||
}
|
||||
if ($tpl->caching == 9999) {
|
||||
if (!isset($tpl->compiled)) {
|
||||
$this->loadCompiled(true);
|
||||
}
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
$this->cached->hashes[ $tpl->compiled->nocache_hash ] = true;
|
||||
}
|
||||
}
|
||||
$tpl->_cache = array();
|
||||
if (isset($uid)) {
|
||||
if ($smarty->debugging) {
|
||||
if (!isset($smarty->_debug)) {
|
||||
$smarty->_debug = new Smarty_Internal_Debug();
|
||||
}
|
||||
$smarty->_debug->start_template($tpl);
|
||||
$smarty->_debug->start_render($tpl);
|
||||
}
|
||||
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
||||
if ($smarty->debugging) {
|
||||
$smarty->_debug->end_template($tpl);
|
||||
$smarty->_debug->end_render($tpl);
|
||||
}
|
||||
} else {
|
||||
if (isset($tpl->compiled)) {
|
||||
$tpl->compiled->render($tpl);
|
||||
} else {
|
||||
$tpl->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get called sub-templates and save call count
|
||||
*
|
||||
*/
|
||||
public function _subTemplateRegister()
|
||||
{
|
||||
foreach ($this->compiled->includes as $name => $count) {
|
||||
if (isset(self::$subTplInfo[ $name ])) {
|
||||
self::$subTplInfo[ $name ] += $count;
|
||||
} else {
|
||||
self::$subTplInfo[ $name ] = $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this is a sub template
|
||||
*
|
||||
* @return bool true is sub template
|
||||
*/
|
||||
public function _isSubTpl()
|
||||
{
|
||||
return isset($this->parent) && $this->parent->_isTplObj();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign variable in scope
|
||||
*
|
||||
* @param string $varName variable name
|
||||
* @param mixed $value value
|
||||
* @param bool $nocache nocache flag
|
||||
* @param int $scope scope into which variable shall be assigned
|
||||
*
|
||||
*/
|
||||
public function _assignInScope($varName, $value, $nocache = false, $scope = 0)
|
||||
{
|
||||
if (isset($this->tpl_vars[ $varName ])) {
|
||||
$this->tpl_vars[ $varName ] = clone $this->tpl_vars[ $varName ];
|
||||
$this->tpl_vars[ $varName ]->value = $value;
|
||||
if ($nocache || $this->isRenderingCache) {
|
||||
$this->tpl_vars[ $varName ]->nocache = true;
|
||||
}
|
||||
} else {
|
||||
$this->tpl_vars[ $varName ] = new Smarty_Variable($value, $nocache || $this->isRenderingCache);
|
||||
}
|
||||
if ($scope >= 0) {
|
||||
if ($scope > 0 || $this->scope > 0) {
|
||||
$this->smarty->ext->_updateScope->_updateScope($this, $varName, $scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is executed automatically when a compiled or cached template file is included
|
||||
* - Decode saved properties from compiled template and cache files
|
||||
* - Check if compiled or cache file is valid
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param array $properties special template properties
|
||||
* @param bool $cache flag if called from cache file
|
||||
*
|
||||
* @return bool flag if compiled or cache file is valid
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
|
||||
{
|
||||
// on cache resources other than file check version stored in cache code
|
||||
if (!isset($properties[ 'version' ]) || Smarty::SMARTY_VERSION !== $properties[ 'version' ]) {
|
||||
if ($cache) {
|
||||
$tpl->smarty->clearAllCache();
|
||||
} else {
|
||||
$tpl->smarty->clearCompiledTemplate();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$is_valid = true;
|
||||
if (!empty($properties[ 'file_dependency' ]) &&
|
||||
((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
|
||||
) {
|
||||
// check file dependencies at compiled code
|
||||
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
||||
if ($_file_to_check[ 2 ] == 'file' || $_file_to_check[ 2 ] == 'php') {
|
||||
if ($tpl->source->filepath == $_file_to_check[ 0 ]) {
|
||||
// do not recheck current template
|
||||
continue;
|
||||
//$mtime = $tpl->source->getTimeStamp();
|
||||
} else {
|
||||
// file and php types can be checked without loading the respective resource handlers
|
||||
$mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false;
|
||||
}
|
||||
} else {
|
||||
$handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[ 2 ]);
|
||||
if ($handler->checkTimestamps()) {
|
||||
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
|
||||
$mtime = $source->getTimeStamp();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($mtime === false || $mtime > $_file_to_check[ 1 ]) {
|
||||
$is_valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($cache) {
|
||||
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
|
||||
if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0 &&
|
||||
(time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ]))
|
||||
) {
|
||||
$is_valid = false;
|
||||
}
|
||||
$tpl->cached->cache_lifetime = $properties[ 'cache_lifetime' ];
|
||||
$tpl->cached->valid = $is_valid;
|
||||
$resource = $tpl->cached;
|
||||
} else {
|
||||
$tpl->mustCompile = !$is_valid;
|
||||
$resource = $tpl->compiled;
|
||||
$resource->includes = isset($properties[ 'includes' ]) ? $properties[ 'includes' ] : array();
|
||||
}
|
||||
if ($is_valid) {
|
||||
$resource->unifunc = $properties[ 'unifunc' ];
|
||||
$resource->has_nocache_code = $properties[ 'has_nocache_code' ];
|
||||
// $tpl->compiled->nocache_hash = $properties['nocache_hash'];
|
||||
$resource->file_dependency = $properties[ 'file_dependency' ];
|
||||
}
|
||||
return $is_valid && !function_exists($properties[ 'unifunc' ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the template
|
||||
* If the template is not evaluated the compiled template is saved on disk
|
||||
*/
|
||||
public function compileTemplateSource()
|
||||
{
|
||||
return $this->compiled->compileTemplateSource($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content to cache resource
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function writeCachedContent($content)
|
||||
{
|
||||
return $this->smarty->ext->_updateCache->writeCachedContent($this->cached, $this, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique template id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getTemplateId()
|
||||
{
|
||||
return isset($this->templateId) ? $this->templateId : $this->templateId =
|
||||
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* runtime error not matching capture tags
|
||||
*/
|
||||
public function capture_error()
|
||||
{
|
||||
throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load compiled object
|
||||
*
|
||||
* @param bool $force force new compiled object
|
||||
*/
|
||||
public function loadCompiled($force = false)
|
||||
{
|
||||
if ($force || !isset($this->compiled)) {
|
||||
$this->compiled = Smarty_Template_Compiled::load($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load cached object
|
||||
*
|
||||
* @param bool $force force new cached object
|
||||
*/
|
||||
public function loadCached($force = false)
|
||||
{
|
||||
if ($force || !isset($this->cached)) {
|
||||
$this->cached = Smarty_Template_Cached::load($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load inheritance object
|
||||
*
|
||||
*/
|
||||
public function _loadInheritance()
|
||||
{
|
||||
if (!isset($this->inheritance)) {
|
||||
$this->inheritance = new Smarty_Internal_Runtime_Inheritance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload inheritance object
|
||||
*
|
||||
*/
|
||||
public function _cleanUp()
|
||||
{
|
||||
$this->startRenderCallbacks = array();
|
||||
$this->endRenderCallbacks = array();
|
||||
$this->inheritance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load compiler object
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function loadCompiler()
|
||||
{
|
||||
if (!class_exists($this->source->compiler_class)) {
|
||||
$this->smarty->loadPlugin($this->source->compiler_class);
|
||||
}
|
||||
$this->compiler =
|
||||
new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class,
|
||||
$this->smarty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle unknown class methods
|
||||
*
|
||||
* @param string $name unknown method-name
|
||||
* @param array $args argument array
|
||||
*
|
||||
* @return mixed
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function __call($name, $args)
|
||||
{
|
||||
// method of Smarty object?
|
||||
if (method_exists($this->smarty, $name)) {
|
||||
return call_user_func_array(array($this->smarty, $name), $args);
|
||||
}
|
||||
// parent
|
||||
return parent::__call($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* set Smarty property in template context
|
||||
*
|
||||
* @param string $property_name property name
|
||||
* @param mixed $value value
|
||||
*
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'compiled':
|
||||
case 'cached':
|
||||
case 'compiler':
|
||||
$this->$property_name = $value;
|
||||
return;
|
||||
default:
|
||||
// Smarty property ?
|
||||
if (property_exists($this->smarty, $property_name)) {
|
||||
$this->smarty->$property_name = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("invalid template property '$property_name'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* get Smarty property in template context
|
||||
*
|
||||
* @param string $property_name property name
|
||||
*
|
||||
* @return mixed|Smarty_Template_Cached
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function __get($property_name)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'compiled':
|
||||
$this->loadCompiled();
|
||||
return $this->compiled;
|
||||
|
||||
case 'cached':
|
||||
$this->loadCached();
|
||||
return $this->cached;
|
||||
|
||||
case 'compiler':
|
||||
$this->loadCompiler();
|
||||
return $this->compiler;
|
||||
default:
|
||||
// Smarty property ?
|
||||
if (property_exists($this->smarty, $property_name)) {
|
||||
return $this->smarty->$property_name;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("template property '$property_name' does not exist.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Template data object destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
|
||||
$this->cached->handler->releaseLock($this->smarty, $this->cached);
|
||||
}
|
||||
}
|
||||
}
|
354
libs/sysplugins/smarty_internal_templatebase.php
Normale Datei
354
libs/sysplugins/smarty_internal_templatebase.php
Normale Datei
|
@ -0,0 +1,354 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Smarty Template Base
|
||||
* This file contains the basic shared methods for template handling
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class with shared smarty/template methods
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*
|
||||
* @property int $_objType
|
||||
*
|
||||
* The following methods will be dynamically loaded by the extension handler when they are called.
|
||||
* They are located in a corresponding Smarty_Internal_Method_xxxx class
|
||||
*
|
||||
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
|
||||
* @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
|
||||
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
|
||||
* @method array getAutoloadFilters(string $type = null)
|
||||
* @method string getDebugTemplate()
|
||||
* @method array getDefaultModifier()
|
||||
* @method array getTags(mixed $template = null)
|
||||
* @method object getRegisteredObject(string $object_name)
|
||||
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
|
||||
* @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
|
||||
* @method Smarty_Internal_TemplateBase registerDefaultConfigHandler(callback $callback)
|
||||
* @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback)
|
||||
* @method Smarty_Internal_TemplateBase registerDefaultTemplateHandler(callback $callback)
|
||||
* @method Smarty_Internal_TemplateBase registerResource(string $name, mixed $resource_handler)
|
||||
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
|
||||
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
|
||||
* @method Smarty_Internal_TemplateBase setDefaultModifiers(mixed $modifiers)
|
||||
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
|
||||
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
|
||||
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
|
||||
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
|
||||
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
|
||||
* @method Smarty_Internal_TemplateBase unregisterResource(string $name)
|
||||
*/
|
||||
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
||||
{
|
||||
/**
|
||||
* Set this if you want different sets of cache files for the same
|
||||
* templates.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $cache_id = null;
|
||||
|
||||
/**
|
||||
* Set this if you want different sets of compiled files for the same
|
||||
* templates.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compile_id = null;
|
||||
|
||||
/**
|
||||
* caching enabled
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $caching = false;
|
||||
|
||||
/**
|
||||
* cache lifetime in seconds
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $cache_lifetime = 3600;
|
||||
|
||||
/**
|
||||
* Array of source information for known template functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tplFunctions = array();
|
||||
|
||||
/**
|
||||
* universal cache
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
public $_cache = array();
|
||||
|
||||
/**
|
||||
* fetches a rendered Smarty template
|
||||
*
|
||||
* @param string $template the resource handle of the template file or template object
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws SmartyException
|
||||
* @return string rendered template output
|
||||
*/
|
||||
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||
{
|
||||
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
|
||||
return $result === null ? ob_get_clean() : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* displays a Smarty template
|
||||
*
|
||||
* @param string $template the resource handle of the template file or template object
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
*/
|
||||
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||
{
|
||||
// display template
|
||||
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* test if cache is valid
|
||||
*
|
||||
* @api Smarty::isCached()
|
||||
* @link http://www.smarty.net/docs/en/api.is.cached.tpl
|
||||
*
|
||||
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
*
|
||||
* @return boolean cache status
|
||||
*/
|
||||
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||
{
|
||||
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetches a rendered Smarty template
|
||||
*
|
||||
* @param string $template the resource handle of the template file or template object
|
||||
* @param mixed $cache_id cache id to be used with this template
|
||||
* @param mixed $compile_id compile id to be used with this template
|
||||
* @param object $parent next higher level of Smarty variables
|
||||
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
private function _execute($template, $cache_id, $compile_id, $parent, $function)
|
||||
{
|
||||
$smarty = $this->_getSmartyObj();
|
||||
$saveVars = true;
|
||||
if ($template === null) {
|
||||
if (!$this->_isTplObj()) {
|
||||
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
||||
} else {
|
||||
$template = $this;
|
||||
}
|
||||
} elseif (is_object($template)) {
|
||||
/* @var Smarty_Internal_Template $template */
|
||||
if (!isset($template->_objType) || !$template->_isTplObj()) {
|
||||
throw new SmartyException($function . '():Template object expected');
|
||||
}
|
||||
} else {
|
||||
// get template object
|
||||
$saveVars = false;
|
||||
|
||||
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
||||
if ($this->_objType == 1) {
|
||||
// set caching in template object
|
||||
$template->caching = $this->caching;
|
||||
}
|
||||
}
|
||||
// fetch template content
|
||||
$level = ob_get_level();
|
||||
try {
|
||||
$_smarty_old_error_level =
|
||||
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
|
||||
if ($this->_objType == 2) {
|
||||
/* @var Smarty_Internal_Template $this */
|
||||
$template->tplFunctions = $this->tplFunctions;
|
||||
$template->inheritance = $this->inheritance;
|
||||
}
|
||||
/* @var Smarty_Internal_Template $parent */
|
||||
if (isset($parent->_objType) && ($parent->_objType == 2) && !empty($parent->tplFunctions)) {
|
||||
$template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
|
||||
}
|
||||
if ($function == 2) {
|
||||
if ($template->caching) {
|
||||
// return cache status of template
|
||||
if (!isset($template->cached)) {
|
||||
$template->loadCached();
|
||||
}
|
||||
$result = $template->cached->isCached($template);
|
||||
Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($saveVars) {
|
||||
$savedTplVars = $template->tpl_vars;
|
||||
$savedConfigVars = $template->config_vars;
|
||||
}
|
||||
ob_start();
|
||||
$template->_mergeVars();
|
||||
if (!empty(Smarty::$global_tpl_vars)) {
|
||||
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
|
||||
}
|
||||
$result = $template->render(false, $function);
|
||||
$template->_cleanUp();
|
||||
if ($saveVars) {
|
||||
$template->tpl_vars = $savedTplVars;
|
||||
$template->config_vars = $savedConfigVars;
|
||||
} else {
|
||||
if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) {
|
||||
$template->parent = null;
|
||||
$template->tpl_vars = $template->config_vars = array();
|
||||
Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_smarty_old_error_level)) {
|
||||
error_reporting($_smarty_old_error_level);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
if (isset($_smarty_old_error_level)) {
|
||||
error_reporting($_smarty_old_error_level);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers plugin to be used in templates
|
||||
*
|
||||
* @api Smarty::registerPlugin()
|
||||
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl
|
||||
*
|
||||
* @param string $type plugin type
|
||||
* @param string $name name of template tag
|
||||
* @param callback $callback PHP callback to register
|
||||
* @param bool $cacheable if true (default) this function is cache able
|
||||
* @param mixed $cache_attr caching attributes if any
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
* @throws SmartyException when the plugin tag is invalid
|
||||
*/
|
||||
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
|
||||
{
|
||||
return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* load a filter of specified type and name
|
||||
*
|
||||
* @api Smarty::loadFilter()
|
||||
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param string $name filter name
|
||||
*
|
||||
* @return bool
|
||||
* @throws SmartyException if filter could not be loaded
|
||||
*/
|
||||
public function loadFilter($type, $name)
|
||||
{
|
||||
return $this->ext->loadFilter->loadFilter($this, $type, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a filter function
|
||||
*
|
||||
* @api Smarty::registerFilter()
|
||||
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param callback $callback
|
||||
* @param string|null $name optional filter name
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function registerFilter($type, $callback, $name = null)
|
||||
{
|
||||
return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
*
|
||||
* @api Smarty::registerObject()
|
||||
* @link http://www.smarty.net/docs/en/api.register.object.tpl
|
||||
*
|
||||
* @param string $object_name
|
||||
* @param object $object the referenced PHP object to register
|
||||
* @param array $allowed_methods_properties list of allowed methods (empty = all)
|
||||
* @param bool $format smarty argument format, else traditional
|
||||
* @param array $block_methods list of block-methods
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true,
|
||||
$block_methods = array())
|
||||
{
|
||||
return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties,
|
||||
$format, $block_methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $caching
|
||||
*/
|
||||
public function setCaching($caching)
|
||||
{
|
||||
$this->caching = $caching;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cache_lifetime
|
||||
*/
|
||||
public function setCacheLifetime($cache_lifetime)
|
||||
{
|
||||
$this->cache_lifetime = $cache_lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $compile_id
|
||||
*/
|
||||
public function setCompileId($compile_id)
|
||||
{
|
||||
$this->compile_id = $compile_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cache_id
|
||||
*/
|
||||
public function setCacheId($cache_id)
|
||||
{
|
||||
$this->cache_id = $cache_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
1394
libs/sysplugins/smarty_internal_templatecompilerbase.php
Normale Datei
1394
libs/sysplugins/smarty_internal_templatecompilerbase.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
1136
libs/sysplugins/smarty_internal_templatelexer.php
Normale Datei
1136
libs/sysplugins/smarty_internal_templatelexer.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
2764
libs/sysplugins/smarty_internal_templateparser.php
Normale Datei
2764
libs/sysplugins/smarty_internal_templateparser.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
599
libs/sysplugins/smarty_internal_testinstall.php
Normale Datei
599
libs/sysplugins/smarty_internal_testinstall.php
Normale Datei
|
@ -0,0 +1,599 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Internal TestInstall
|
||||
* Test Smarty installation
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Utilities
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* TestInstall class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Utilities
|
||||
*/
|
||||
class Smarty_Internal_TestInstall
|
||||
{
|
||||
/**
|
||||
* diagnose Smarty setup
|
||||
* If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
|
||||
*
|
||||
* @param \Smarty $smarty
|
||||
* @param array $errors array to push results into rather than outputting them
|
||||
*
|
||||
* @return bool status, true if everything is fine, false else
|
||||
*/
|
||||
public static function testInstall(Smarty $smarty, &$errors = null)
|
||||
{
|
||||
$status = true;
|
||||
|
||||
if ($errors === null) {
|
||||
echo "<PRE>\n";
|
||||
echo "Smarty Installation test...\n";
|
||||
echo "Testing template directory...\n";
|
||||
}
|
||||
|
||||
$_stream_resolve_include_path = function_exists('stream_resolve_include_path');
|
||||
|
||||
// test if all registered template_dir are accessible
|
||||
foreach ($smarty->getTemplateDir() as $template_dir) {
|
||||
$_template_dir = $template_dir;
|
||||
$template_dir = realpath($template_dir);
|
||||
// resolve include_path or fail existence
|
||||
if (!$template_dir) {
|
||||
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
|
||||
// try PHP include_path
|
||||
if ($_stream_resolve_include_path) {
|
||||
$template_dir = stream_resolve_include_path($_template_dir);
|
||||
} else {
|
||||
$template_dir = $smarty->ext->_getIncludePath->getIncludePath($_template_dir, null, $smarty);
|
||||
}
|
||||
|
||||
if ($template_dir !== false) {
|
||||
if ($errors === null) {
|
||||
echo "$template_dir is OK.\n";
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
$status = false;
|
||||
$message =
|
||||
"FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['template_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: $_template_dir does not exist";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['template_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_dir($template_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $template_dir is not a directory";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['template_dir'] = $message;
|
||||
}
|
||||
} else if (!is_readable($template_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $template_dir is not readable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['template_dir'] = $message;
|
||||
}
|
||||
} else {
|
||||
if ($errors === null) {
|
||||
echo "$template_dir is OK.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing compile directory...\n";
|
||||
}
|
||||
|
||||
// test if registered compile_dir is accessible
|
||||
$__compile_dir = $smarty->getCompileDir();
|
||||
$_compile_dir = realpath($__compile_dir);
|
||||
if (!$_compile_dir) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$__compile_dir} does not exist";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['compile_dir'] = $message;
|
||||
}
|
||||
} else if (!is_dir($_compile_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_compile_dir} is not a directory";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['compile_dir'] = $message;
|
||||
}
|
||||
} else if (!is_readable($_compile_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_compile_dir} is not readable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['compile_dir'] = $message;
|
||||
}
|
||||
} else if (!is_writable($_compile_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_compile_dir} is not writable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['compile_dir'] = $message;
|
||||
}
|
||||
} else {
|
||||
if ($errors === null) {
|
||||
echo "{$_compile_dir} is OK.\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing plugins directory...\n";
|
||||
}
|
||||
|
||||
// test if all registered plugins_dir are accessible
|
||||
// and if core plugins directory is still registered
|
||||
$_core_plugins_dir = realpath(dirname(__FILE__) . '/../plugins');
|
||||
$_core_plugins_available = false;
|
||||
foreach ($smarty->getPluginsDir() as $plugin_dir) {
|
||||
$_plugin_dir = $plugin_dir;
|
||||
$plugin_dir = realpath($plugin_dir);
|
||||
// resolve include_path or fail existence
|
||||
if (!$plugin_dir) {
|
||||
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
|
||||
// try PHP include_path
|
||||
if ($_stream_resolve_include_path) {
|
||||
$plugin_dir = stream_resolve_include_path($_plugin_dir);
|
||||
} else {
|
||||
$plugin_dir = $smarty->ext->_getIncludePath->getIncludePath($_plugin_dir, null, $smarty);
|
||||
}
|
||||
|
||||
if ($plugin_dir !== false) {
|
||||
if ($errors === null) {
|
||||
echo "$plugin_dir is OK.\n";
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: $_plugin_dir does not exist";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_dir($plugin_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $plugin_dir is not a directory";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins_dir'] = $message;
|
||||
}
|
||||
} else if (!is_readable($plugin_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $plugin_dir is not readable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins_dir'] = $message;
|
||||
}
|
||||
} else if ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
|
||||
$_core_plugins_available = true;
|
||||
if ($errors === null) {
|
||||
echo "$plugin_dir is OK.\n";
|
||||
}
|
||||
} else {
|
||||
if ($errors === null) {
|
||||
echo "$plugin_dir is OK.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$_core_plugins_available) {
|
||||
$status = false;
|
||||
$message = "WARNING: Smarty's own libs/plugins is not available";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else if (!isset($errors['plugins_dir'])) {
|
||||
$errors['plugins_dir'] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing cache directory...\n";
|
||||
}
|
||||
|
||||
// test if all registered cache_dir is accessible
|
||||
$__cache_dir = $smarty->getCacheDir();
|
||||
$_cache_dir = realpath($__cache_dir);
|
||||
if (!$_cache_dir) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$__cache_dir} does not exist";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['cache_dir'] = $message;
|
||||
}
|
||||
} else if (!is_dir($_cache_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_cache_dir} is not a directory";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['cache_dir'] = $message;
|
||||
}
|
||||
} else if (!is_readable($_cache_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_cache_dir} is not readable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['cache_dir'] = $message;
|
||||
}
|
||||
} else if (!is_writable($_cache_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: {$_cache_dir} is not writable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['cache_dir'] = $message;
|
||||
}
|
||||
} else {
|
||||
if ($errors === null) {
|
||||
echo "{$_cache_dir} is OK.\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing configs directory...\n";
|
||||
}
|
||||
|
||||
// test if all registered config_dir are accessible
|
||||
foreach ($smarty->getConfigDir() as $config_dir) {
|
||||
$_config_dir = $config_dir;
|
||||
// resolve include_path or fail existence
|
||||
if (!$config_dir) {
|
||||
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
|
||||
// try PHP include_path
|
||||
if ($_stream_resolve_include_path) {
|
||||
$config_dir = stream_resolve_include_path($_config_dir);
|
||||
} else {
|
||||
$config_dir = $smarty->ext->_getIncludePath->getIncludePath($_config_dir, null, $smarty);
|
||||
}
|
||||
|
||||
if ($config_dir !== false) {
|
||||
if ($errors === null) {
|
||||
echo "$config_dir is OK.\n";
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['config_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: $_config_dir does not exist";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['config_dir'] = $message;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_dir($config_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $config_dir is not a directory";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['config_dir'] = $message;
|
||||
}
|
||||
} else if (!is_readable($config_dir)) {
|
||||
$status = false;
|
||||
$message = "FAILED: $config_dir is not readable";
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['config_dir'] = $message;
|
||||
}
|
||||
} else {
|
||||
if ($errors === null) {
|
||||
echo "$config_dir is OK.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing sysplugin files...\n";
|
||||
}
|
||||
// test if sysplugins are available
|
||||
$source = SMARTY_SYSPLUGINS_DIR;
|
||||
if (is_dir($source)) {
|
||||
$expectedSysplugins = array('smartycompilerexception.php' => true, 'smartyexception.php' => true,
|
||||
'smarty_cacheresource.php' => true, 'smarty_cacheresource_custom.php' => true,
|
||||
'smarty_cacheresource_keyvaluestore.php' => true, 'smarty_data.php' => true,
|
||||
'smarty_internal_block.php' => true,
|
||||
'smarty_internal_cacheresource_file.php' => true,
|
||||
'smarty_internal_compilebase.php' => true,
|
||||
'smarty_internal_compile_append.php' => true,
|
||||
'smarty_internal_compile_assign.php' => true,
|
||||
'smarty_internal_compile_block.php' => true,
|
||||
'smarty_internal_compile_block_child.php' => true,
|
||||
'smarty_internal_compile_block_parent.php' => true,
|
||||
'smarty_internal_compile_break.php' => true,
|
||||
'smarty_internal_compile_call.php' => true,
|
||||
'smarty_internal_compile_capture.php' => true,
|
||||
'smarty_internal_compile_config_load.php' => true,
|
||||
'smarty_internal_compile_continue.php' => true,
|
||||
'smarty_internal_compile_debug.php' => true,
|
||||
'smarty_internal_compile_eval.php' => true,
|
||||
'smarty_internal_compile_extends.php' => true,
|
||||
'smarty_internal_compile_for.php' => true,
|
||||
'smarty_internal_compile_foreach.php' => true,
|
||||
'smarty_internal_compile_function.php' => true,
|
||||
'smarty_internal_compile_if.php' => true,
|
||||
'smarty_internal_compile_include.php' => true,
|
||||
'smarty_internal_compile_include_php.php' => true,
|
||||
'smarty_internal_compile_insert.php' => true,
|
||||
'smarty_internal_compile_ldelim.php' => true,
|
||||
'smarty_internal_compile_make_nocache.php' => true,
|
||||
'smarty_internal_compile_nocache.php' => true,
|
||||
'smarty_internal_compile_private_block_plugin.php' => true,
|
||||
'smarty_internal_compile_private_foreachsection.php' => true,
|
||||
'smarty_internal_compile_private_function_plugin.php' => true,
|
||||
'smarty_internal_compile_private_modifier.php' => true,
|
||||
'smarty_internal_compile_private_object_block_function.php' => true,
|
||||
'smarty_internal_compile_private_object_function.php' => true,
|
||||
'smarty_internal_compile_private_php.php' => true,
|
||||
'smarty_internal_compile_private_print_expression.php' => true,
|
||||
'smarty_internal_compile_private_registered_block.php' => true,
|
||||
'smarty_internal_compile_private_registered_function.php' => true,
|
||||
'smarty_internal_compile_private_special_variable.php' => true,
|
||||
'smarty_internal_compile_rdelim.php' => true,
|
||||
'smarty_internal_compile_section.php' => true,
|
||||
'smarty_internal_compile_setfilter.php' => true,
|
||||
'smarty_internal_compile_shared_inheritance.php' => true,
|
||||
'smarty_internal_compile_while.php' => true,
|
||||
'smarty_internal_configfilelexer.php' => true,
|
||||
'smarty_internal_configfileparser.php' => true,
|
||||
'smarty_internal_config_file_compiler.php' => true,
|
||||
'smarty_internal_data.php' => true, 'smarty_internal_debug.php' => true,
|
||||
'smarty_internal_extension_handler.php' => true,
|
||||
'smarty_internal_method_addautoloadfilters.php' => true,
|
||||
'smarty_internal_method_adddefaultmodifiers.php' => true,
|
||||
'smarty_internal_method_append.php' => true,
|
||||
'smarty_internal_method_appendbyref.php' => true,
|
||||
'smarty_internal_method_assignbyref.php' => true,
|
||||
'smarty_internal_method_assignglobal.php' => true,
|
||||
'smarty_internal_method_clearallassign.php' => true,
|
||||
'smarty_internal_method_clearallcache.php' => true,
|
||||
'smarty_internal_method_clearassign.php' => true,
|
||||
'smarty_internal_method_clearcache.php' => true,
|
||||
'smarty_internal_method_clearcompiledtemplate.php' => true,
|
||||
'smarty_internal_method_clearconfig.php' => true,
|
||||
'smarty_internal_method_compileallconfig.php' => true,
|
||||
'smarty_internal_method_compilealltemplates.php' => true,
|
||||
'smarty_internal_method_configload.php' => true,
|
||||
'smarty_internal_method_createdata.php' => true,
|
||||
'smarty_internal_method_getautoloadfilters.php' => true,
|
||||
'smarty_internal_method_getconfigvariable.php' => true,
|
||||
'smarty_internal_method_getconfigvars.php' => true,
|
||||
'smarty_internal_method_getdebugtemplate.php' => true,
|
||||
'smarty_internal_method_getdefaultmodifiers.php' => true,
|
||||
'smarty_internal_method_getglobal.php' => true,
|
||||
'smarty_internal_method_getregisteredobject.php' => true,
|
||||
'smarty_internal_method_getstreamvariable.php' => true,
|
||||
'smarty_internal_method_gettags.php' => true,
|
||||
'smarty_internal_method_gettemplatevars.php' => true,
|
||||
'smarty_internal_method_loadfilter.php' => true,
|
||||
'smarty_internal_method_loadplugin.php' => true,
|
||||
'smarty_internal_method_mustcompile.php' => true,
|
||||
'smarty_internal_method_registercacheresource.php' => true,
|
||||
'smarty_internal_method_registerclass.php' => true,
|
||||
'smarty_internal_method_registerdefaultconfighandler.php' => true,
|
||||
'smarty_internal_method_registerdefaultpluginhandler.php' => true,
|
||||
'smarty_internal_method_registerdefaulttemplatehandler.php' => true,
|
||||
'smarty_internal_method_registerfilter.php' => true,
|
||||
'smarty_internal_method_registerobject.php' => true,
|
||||
'smarty_internal_method_registerplugin.php' => true,
|
||||
'smarty_internal_method_registerresource.php' => true,
|
||||
'smarty_internal_method_setautoloadfilters.php' => true,
|
||||
'smarty_internal_method_setdebugtemplate.php' => true,
|
||||
'smarty_internal_method_setdefaultmodifiers.php' => true,
|
||||
'smarty_internal_method_unloadfilter.php' => true,
|
||||
'smarty_internal_method_unregistercacheresource.php' => true,
|
||||
'smarty_internal_method_unregisterfilter.php' => true,
|
||||
'smarty_internal_method_unregisterobject.php' => true,
|
||||
'smarty_internal_method_unregisterplugin.php' => true,
|
||||
'smarty_internal_method_unregisterresource.php' => true,
|
||||
'smarty_internal_nocache_insert.php' => true,
|
||||
'smarty_internal_parsetree.php' => true,
|
||||
'smarty_internal_parsetree_code.php' => true,
|
||||
'smarty_internal_parsetree_dq.php' => true,
|
||||
'smarty_internal_parsetree_dqcontent.php' => true,
|
||||
'smarty_internal_parsetree_tag.php' => true,
|
||||
'smarty_internal_parsetree_template.php' => true,
|
||||
'smarty_internal_parsetree_text.php' => true,
|
||||
'smarty_internal_resource_eval.php' => true,
|
||||
'smarty_internal_resource_extends.php' => true,
|
||||
'smarty_internal_resource_file.php' => true,
|
||||
'smarty_internal_resource_php.php' => true,
|
||||
'smarty_internal_resource_registered.php' => true,
|
||||
'smarty_internal_resource_stream.php' => true,
|
||||
'smarty_internal_resource_string.php' => true,
|
||||
'smarty_internal_runtime_cachemodify.php' => true,
|
||||
'smarty_internal_runtime_cacheresourcefile.php' => true,
|
||||
'smarty_internal_runtime_capture.php' => true,
|
||||
'smarty_internal_runtime_codeframe.php' => true,
|
||||
'smarty_internal_runtime_filterhandler.php' => true,
|
||||
'smarty_internal_runtime_foreach.php' => true,
|
||||
'smarty_internal_runtime_getincludepath.php' => true,
|
||||
'smarty_internal_runtime_inheritance.php' => true,
|
||||
'smarty_internal_runtime_make_nocache.php' => true,
|
||||
'smarty_internal_runtime_tplfunction.php' => true,
|
||||
'smarty_internal_runtime_updatecache.php' => true,
|
||||
'smarty_internal_runtime_updatescope.php' => true,
|
||||
'smarty_internal_runtime_writefile.php' => true,
|
||||
'smarty_internal_smartytemplatecompiler.php' => true,
|
||||
'smarty_internal_template.php' => true,
|
||||
'smarty_internal_templatebase.php' => true,
|
||||
'smarty_internal_templatecompilerbase.php' => true,
|
||||
'smarty_internal_templatelexer.php' => true,
|
||||
'smarty_internal_templateparser.php' => true,
|
||||
'smarty_internal_testinstall.php' => true,
|
||||
'smarty_internal_undefined.php' => true, 'smarty_resource.php' => true,
|
||||
'smarty_resource_custom.php' => true, 'smarty_resource_recompiled.php' => true,
|
||||
'smarty_resource_uncompiled.php' => true, 'smarty_security.php' => true,
|
||||
'smarty_template_cached.php' => true, 'smarty_template_compiled.php' => true,
|
||||
'smarty_template_config.php' => true,
|
||||
'smarty_template_resource_base.php' => true,
|
||||
'smarty_template_source.php' => true, 'smarty_undefined_variable.php' => true,
|
||||
'smarty_variable.php' => true,);
|
||||
$iterator = new DirectoryIterator($source);
|
||||
foreach ($iterator as $file) {
|
||||
if (!$file->isDot()) {
|
||||
$filename = $file->getFilename();
|
||||
if (isset($expectedSysplugins[ $filename ])) {
|
||||
unset($expectedSysplugins[ $filename ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($expectedSysplugins) {
|
||||
$status = false;
|
||||
$message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expectedSysplugins));
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['sysplugins'] = $message;
|
||||
}
|
||||
} else if ($errors === null) {
|
||||
echo "... OK\n";
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: " . SMARTY_SYSPLUGINS_DIR . ' is not a directory';
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['sysplugins_dir_constant'] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Testing plugin files...\n";
|
||||
}
|
||||
// test if core plugins are available
|
||||
$source = SMARTY_PLUGINS_DIR;
|
||||
if (is_dir($source)) {
|
||||
$expectedPlugins =
|
||||
array('block.textformat.php' => true, 'function.counter.php' => true, 'function.cycle.php' => true,
|
||||
'function.fetch.php' => true, 'function.html_checkboxes.php' => true,
|
||||
'function.html_image.php' => true, 'function.html_options.php' => true,
|
||||
'function.html_radios.php' => true, 'function.html_select_date.php' => true,
|
||||
'function.html_select_time.php' => true, 'function.html_table.php' => true,
|
||||
'function.mailto.php' => true, 'function.math.php' => true, 'modifier.capitalize.php' => true,
|
||||
'modifier.date_format.php' => true, 'modifier.debug_print_var.php' => true,
|
||||
'modifier.escape.php' => true, 'modifier.mb_wordwrap.php' => true,
|
||||
'modifier.regex_replace.php' => true, 'modifier.replace.php' => true,
|
||||
'modifier.spacify.php' => true, 'modifier.truncate.php' => true,
|
||||
'modifiercompiler.cat.php' => true, 'modifiercompiler.count_characters.php' => true,
|
||||
'modifiercompiler.count_paragraphs.php' => true, 'modifiercompiler.count_sentences.php' => true,
|
||||
'modifiercompiler.count_words.php' => true, 'modifiercompiler.default.php' => true,
|
||||
'modifiercompiler.escape.php' => true, 'modifiercompiler.from_charset.php' => true,
|
||||
'modifiercompiler.indent.php' => true, 'modifiercompiler.lower.php' => true,
|
||||
'modifiercompiler.noprint.php' => true, 'modifiercompiler.string_format.php' => true,
|
||||
'modifiercompiler.strip.php' => true, 'modifiercompiler.strip_tags.php' => true,
|
||||
'modifiercompiler.to_charset.php' => true, 'modifiercompiler.unescape.php' => true,
|
||||
'modifiercompiler.upper.php' => true, 'modifiercompiler.wordwrap.php' => true,
|
||||
'outputfilter.trimwhitespace.php' => true, 'shared.escape_special_chars.php' => true,
|
||||
'shared.literal_compiler_param.php' => true, 'shared.make_timestamp.php' => true,
|
||||
'shared.mb_str_replace.php' => true, 'shared.mb_unicode.php' => true,
|
||||
'variablefilter.htmlspecialchars.php' => true,);
|
||||
$iterator = new DirectoryIterator($source);
|
||||
foreach ($iterator as $file) {
|
||||
if (!$file->isDot()) {
|
||||
$filename = $file->getFilename();
|
||||
if (isset($expectedPlugins[ $filename ])) {
|
||||
unset($expectedPlugins[ $filename ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($expectedPlugins) {
|
||||
$status = false;
|
||||
$message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expectedPlugins));
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins'] = $message;
|
||||
}
|
||||
} else if ($errors === null) {
|
||||
echo "... OK\n";
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
$message = "FAILED: " . SMARTY_PLUGINS_DIR . ' is not a directory';
|
||||
if ($errors === null) {
|
||||
echo $message . ".\n";
|
||||
} else {
|
||||
$errors['plugins_dir_constant'] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors === null) {
|
||||
echo "Tests complete.\n";
|
||||
echo "</PRE>\n";
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
68
libs/sysplugins/smarty_internal_undefined.php
Normale Datei
68
libs/sysplugins/smarty_internal_undefined.php
Normale Datei
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Undefined
|
||||
*
|
||||
* Class to handle undefined method calls or calls to obsolete runtime extensions
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Undefined
|
||||
{
|
||||
|
||||
/**
|
||||
* Name of undefined extension class
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $class = null;
|
||||
|
||||
/**
|
||||
* Smarty_Internal_Undefined constructor.
|
||||
*
|
||||
* @param null|string $class name of undefined extension class
|
||||
*/
|
||||
public function __construct($class = null)
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for obsolete class Smarty_Internal_Runtime_ValidateCompiled
|
||||
*
|
||||
* @param \Smarty_Internal_Template $tpl
|
||||
* @param array $properties special template properties
|
||||
* @param bool $cache flag if called from cache file
|
||||
*
|
||||
* @return bool false
|
||||
*/
|
||||
public function decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
|
||||
{
|
||||
if ($cache) {
|
||||
$tpl->cached->valid = false;
|
||||
} else {
|
||||
$tpl->mustCompile = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call error handler for undefined method
|
||||
*
|
||||
* @param string $name unknown method-name
|
||||
* @param array $args argument array
|
||||
*
|
||||
* @return mixed
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function __call($name, $args)
|
||||
{
|
||||
if (isset($this->class)) {
|
||||
throw new SmartyException("undefined extension class '{$this->class}'");
|
||||
} else {
|
||||
throw new SmartyException(get_class($args[ 0 ]) . "->{$name}() undefined method");
|
||||
}
|
||||
}
|
||||
}
|
254
libs/sysplugins/smarty_resource.php
Normale Datei
254
libs/sysplugins/smarty_resource.php
Normale Datei
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*
|
||||
* @method renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
|
||||
* @method populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
* @method process(Smarty_Internal_Template $_smarty_tpl)
|
||||
*/
|
||||
abstract class Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Source is bypassing compiler
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $uncompiled = false;
|
||||
|
||||
/**
|
||||
* Source must be recompiled on every occasion
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $recompiled = false;
|
||||
|
||||
/**
|
||||
* resource types provided by the core
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $sysplugins = array('file' => 'smarty_internal_resource_file.php',
|
||||
'string' => 'smarty_internal_resource_string.php',
|
||||
'extends' => 'smarty_internal_resource_extends.php',
|
||||
'stream' => 'smarty_internal_resource_stream.php',
|
||||
'eval' => 'smarty_internal_resource_eval.php',
|
||||
'php' => 'smarty_internal_resource_php.php');
|
||||
|
||||
/**
|
||||
* Flag if resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = false;
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
abstract public function getContent(Smarty_Template_Source $source);
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
// intentionally left blank
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
if ($isConfig) {
|
||||
if (!isset($smarty->_joined_config_dir)) {
|
||||
$smarty->getTemplateDir(null, true);
|
||||
}
|
||||
return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
|
||||
} else {
|
||||
if (!isset($smarty->_joined_template_dir)) {
|
||||
$smarty->getTemplateDir();
|
||||
}
|
||||
return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename(preg_replace('![^\w]+!', '_', $source->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Resource Handler
|
||||
*
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $type name of the resource
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return Smarty_Resource Resource Handler
|
||||
*/
|
||||
public static function load(Smarty $smarty, $type)
|
||||
{
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ];
|
||||
}
|
||||
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_resources[ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] =
|
||||
$smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
|
||||
$smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
|
||||
}
|
||||
|
||||
// try sysplugins dir
|
||||
if (isset(self::$sysplugins[ $type ])) {
|
||||
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
}
|
||||
|
||||
// try plugins dir
|
||||
$_resource_class = 'Smarty_Resource_' . ucfirst($type);
|
||||
if ($smarty->loadPlugin($_resource_class)) {
|
||||
if (class_exists($_resource_class, false)) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
} else {
|
||||
$smarty->registerResource($type,
|
||||
array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
|
||||
"smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
|
||||
// give it another try, now that the resource is registered properly
|
||||
return self::load($smarty, $type);
|
||||
}
|
||||
}
|
||||
|
||||
// try streams
|
||||
$_known_stream = stream_get_wrappers();
|
||||
if (in_array($type, $_known_stream)) {
|
||||
// is known stream
|
||||
if (is_object($smarty->security_policy)) {
|
||||
$smarty->security_policy->isTrustedStream($type);
|
||||
}
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream();
|
||||
}
|
||||
|
||||
// TODO: try default_(template|config)_handler
|
||||
|
||||
// give up
|
||||
throw new SmartyException("Unknown resource type '{$type}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* extract resource_type and resource_name from template_resource and config_resource
|
||||
* @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
|
||||
*
|
||||
* @param string $resource_name template_resource or config_resource to parse
|
||||
* @param string $default_resource the default resource_type defined in $smarty
|
||||
*
|
||||
* @return array with parsed resource name and type
|
||||
*/
|
||||
public static function parseResourceName($resource_name, $default_resource)
|
||||
{
|
||||
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
|
||||
$type = $match[ 1 ];
|
||||
$name = substr($resource_name, strlen($match[ 0 ]));
|
||||
} else {
|
||||
// no resource given, use default
|
||||
// or single character before the colon is not a resource type, but part of the filepath
|
||||
$type = $default_resource;
|
||||
$name = $resource_name;
|
||||
}
|
||||
return array($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* modify template_resource according to resource handlers specifications
|
||||
*
|
||||
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
|
||||
* @param string $template_resource template_resource to extract resource handler and name of
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public static function getUniqueTemplateName($obj, $template_resource)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
||||
// TODO: optimize for Smarty's internal resource types
|
||||
$resource = Smarty_Resource::load($smarty, $type);
|
||||
// go relative to a given template?
|
||||
$_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/');
|
||||
if ($obj->_isTplObj() && $_file_is_dotted &&
|
||||
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
|
||||
) {
|
||||
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . $smarty->ds . $name);
|
||||
}
|
||||
return $resource->buildUniqueResourceName($smarty, $name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if resource must check time stamps when when loading complied or cached templates.
|
||||
* Resources like 'extends' which use source components my disable timestamp checks on own resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
* wrapper for backward compatibility to versions < 3.1.22
|
||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $template_resource resource identifier
|
||||
*
|
||||
* @return Smarty_Template_Source Source Object
|
||||
*/
|
||||
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
|
||||
$template_resource = null)
|
||||
{
|
||||
return Smarty_Template_Source::load($_template, $smarty, $template_resource);
|
||||
}
|
||||
}
|
||||
|
95
libs/sysplugins/smarty_resource_custom.php
Normale Datei
95
libs/sysplugins/smarty_resource_custom.php
Normale Datei
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Wrapper Implementation for custom resource plugins
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Custom extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* fetch template and its modification time from data source
|
||||
*
|
||||
* @param string $name template name
|
||||
* @param string &$source template source
|
||||
* @param integer &$mtime template modification timestamp (epoch)
|
||||
*/
|
||||
abstract protected function fetch($name, &$source, &$mtime);
|
||||
|
||||
/**
|
||||
* Fetch template's modification timestamp from data source
|
||||
* {@internal implementing this method is optional.
|
||||
* Only implement it if modification times can be accessed faster than loading the complete template source.}}
|
||||
*
|
||||
* @param string $name template name
|
||||
*
|
||||
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
||||
*/
|
||||
protected function fetchTimestamp($name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->filepath = $source->type . ':' . substr(preg_replace('/[^A-Za-z0-9.]/','',$source->name),0,25);
|
||||
$source->uid = sha1($source->type . ':' . $source->name);
|
||||
|
||||
$mtime = $this->fetchTimestamp($source->name);
|
||||
if ($mtime !== null) {
|
||||
$source->timestamp = $mtime;
|
||||
} else {
|
||||
$this->fetch($source->name, $content, $timestamp);
|
||||
$source->timestamp = isset($timestamp) ? $timestamp : false;
|
||||
if (isset($content)) {
|
||||
$source->content = $content;
|
||||
}
|
||||
}
|
||||
$source->exists = !!$source->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
$this->fetch($source->name, $content, $timestamp);
|
||||
if (isset($content)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename(substr(preg_replace('/[^A-Za-z0-9.]/','',$source->name),0,25));
|
||||
}
|
||||
}
|
92
libs/sysplugins/smarty_resource_recompiled.php
Normale Datei
92
libs/sysplugins/smarty_resource_recompiled.php
Normale Datei
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't compile cache
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Recompiled extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Flag that it's an recompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $recompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* compile template from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
$compiled = &$_smarty_tpl->compiled;
|
||||
$compiled->file_dependency = array();
|
||||
$compiled->includes = array();
|
||||
$compiled->nocache_hash = null;
|
||||
$compiled->unifunc = null;
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
$_smarty_tpl->loadCompiler();
|
||||
// call compiler
|
||||
try {
|
||||
eval("?>" . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
unset($_smarty_tpl->compiler);
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
// release compiler object to free memory
|
||||
unset($_smarty_tpl->compiler);
|
||||
ob_get_clean();
|
||||
$compiled->timestamp = time();
|
||||
$compiled->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Compiled Object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = false;
|
||||
$compiled->timestamp = false;
|
||||
$compiled->exists = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for recompiled resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
49
libs/sysplugins/smarty_resource_uncompiled.php
Normale Datei
49
libs/sysplugins/smarty_resource_uncompiled.php
Normale Datei
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't use the compiler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) {
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array($compiled->filepath, $compiled->timestamp, $_template->source->type,);
|
||||
}
|
||||
}
|
||||
}
|
730
libs/sysplugins/smarty_security.php
Normale Datei
730
libs/sysplugins/smarty_security.php
Normale Datei
|
@ -0,0 +1,730 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Security
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/*
|
||||
* FIXME: Smarty_Security API
|
||||
* - getter and setter instead of public properties would allow cultivating an internal cache properly
|
||||
* - current implementation of isTrustedResourceDir() assumes that Smarty::$template_dir and Smarty::$config_dir are immutable
|
||||
* the cache is killed every time either of the variables change. That means that two distinct Smarty objects with differing
|
||||
* $template_dir or $config_dir should NOT share the same Smarty_Security instance,
|
||||
* as this would lead to (severe) performance penalty! how should this be handled?
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class does contain the security settings
|
||||
*/
|
||||
class Smarty_Security
|
||||
{
|
||||
/**
|
||||
* This determines how Smarty handles "<?php ... ?>" tags in templates.
|
||||
* possible values:
|
||||
* <ul>
|
||||
* <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li>
|
||||
* <li>Smarty::PHP_QUOTE -> escape tags as entities</li>
|
||||
* <li>Smarty::PHP_REMOVE -> remove php tags</li>
|
||||
* <li>Smarty::PHP_ALLOW -> execute php tags</li>
|
||||
* </ul>
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $php_handling = Smarty::PHP_PASSTHRU;
|
||||
|
||||
/**
|
||||
* This is the list of template directories that are considered secure.
|
||||
* $template_dir is in this list implicitly.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $secure_dir = array();
|
||||
|
||||
/**
|
||||
* This is an array of directories where trusted php scripts reside.
|
||||
* {@link $security} is disabled during their inclusion/execution.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_dir = array();
|
||||
|
||||
/**
|
||||
* List of regular expressions (PCRE) that include trusted URIs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_uri = array();
|
||||
|
||||
/**
|
||||
* List of trusted constants names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_constants = array();
|
||||
|
||||
/**
|
||||
* This is an array of trusted static classes.
|
||||
* If empty access to all static classes is allowed.
|
||||
* If set to 'none' none is allowed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $static_classes = array();
|
||||
|
||||
/**
|
||||
* This is an nested array of trusted classes and static methods.
|
||||
* If empty access to all static classes and methods is allowed.
|
||||
* Format:
|
||||
* array (
|
||||
* 'class_1' => array('method_1', 'method_2'), // allowed methods listed
|
||||
* 'class_2' => array(), // all methods of class allowed
|
||||
* )
|
||||
* If set to null none is allowed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_static_methods = array();
|
||||
|
||||
/**
|
||||
* This is an array of trusted static properties.
|
||||
* If empty access to all static classes and properties is allowed.
|
||||
* Format:
|
||||
* array (
|
||||
* 'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
|
||||
* 'class_2' => array(), // all properties of class allowed
|
||||
* )
|
||||
* If set to null none is allowed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_static_properties = array();
|
||||
|
||||
/**
|
||||
* This is an array of trusted PHP functions.
|
||||
* If empty all functions are allowed.
|
||||
* To disable all PHP functions set $php_functions = null.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',);
|
||||
|
||||
/**
|
||||
* This is an array of trusted PHP modifiers.
|
||||
* If empty all modifiers are allowed.
|
||||
* To disable all modifier set $php_modifiers = null.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $php_modifiers = array('escape', 'count', 'nl2br',);
|
||||
|
||||
/**
|
||||
* This is an array of allowed tags.
|
||||
* If empty no restriction by allowed_tags.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $allowed_tags = array();
|
||||
|
||||
/**
|
||||
* This is an array of disabled tags.
|
||||
* If empty no restriction by disabled_tags.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $disabled_tags = array();
|
||||
|
||||
/**
|
||||
* This is an array of allowed modifier plugins.
|
||||
* If empty no restriction by allowed_modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $allowed_modifiers = array();
|
||||
|
||||
/**
|
||||
* This is an array of disabled modifier plugins.
|
||||
* If empty no restriction by disabled_modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $disabled_modifiers = array();
|
||||
|
||||
/**
|
||||
* This is an array of disabled special $smarty variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $disabled_special_smarty_vars = array();
|
||||
|
||||
/**
|
||||
* This is an array of trusted streams.
|
||||
* If empty all streams are allowed.
|
||||
* To disable all streams set $streams = null.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $streams = array('file');
|
||||
|
||||
/**
|
||||
* + flag if constants can be accessed from template
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $allow_constants = true;
|
||||
|
||||
/**
|
||||
* + flag if super globals can be accessed from template
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $allow_super_globals = true;
|
||||
|
||||
/**
|
||||
* max template nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $max_template_nesting = 0;
|
||||
|
||||
/**
|
||||
* current template nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_current_template_nesting = 0;
|
||||
|
||||
/**
|
||||
* Cache for $resource_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_resource_dir = array();
|
||||
|
||||
/**
|
||||
* Cache for $template_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_template_dir = array();
|
||||
|
||||
/**
|
||||
* Cache for $config_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config_dir = array();
|
||||
|
||||
/**
|
||||
* Cache for $secure_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_secure_dir = array();
|
||||
|
||||
/**
|
||||
* Cache for $php_resource_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_php_resource_dir = null;
|
||||
|
||||
/**
|
||||
* Cache for $trusted_dir lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_trusted_dir = null;
|
||||
|
||||
/**
|
||||
* Cache for include path status
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_include_path_status = false;
|
||||
|
||||
/**
|
||||
* Cache for $_include_array lookup
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_include_dir = array();
|
||||
|
||||
/**
|
||||
* @param Smarty $smarty
|
||||
*/
|
||||
public function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
$this->smarty->_cache[ 'template_dir_new' ] = true;
|
||||
$this->smarty->_cache[ 'config_dir_new' ] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PHP function is trusted.
|
||||
*
|
||||
* @param string $function_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if function is trusted
|
||||
* @throws SmartyCompilerException if php function is not trusted
|
||||
*/
|
||||
public function isTrustedPhpFunction($function_name, $compiler)
|
||||
{
|
||||
if (isset($this->php_functions) &&
|
||||
(empty($this->php_functions) || in_array($function_name, $this->php_functions))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$compiler->trigger_template_error("PHP function '{$function_name}' not allowed by security setting");
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if static class is trusted.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if class is trusted
|
||||
* @throws SmartyCompilerException if static class is not trusted
|
||||
*/
|
||||
public function isTrustedStaticClass($class_name, $compiler)
|
||||
{
|
||||
if (isset($this->static_classes) &&
|
||||
(empty($this->static_classes) || in_array($class_name, $this->static_classes))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$compiler->trigger_template_error("access to static class '{$class_name}' not allowed by security setting");
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if static class method/property is trusted.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @param string $params
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if class method is trusted
|
||||
* @throws SmartyCompilerException if static class method is not trusted
|
||||
*/
|
||||
public function isTrustedStaticClassAccess($class_name, $params, $compiler)
|
||||
{
|
||||
if (!isset($params[ 2 ])) {
|
||||
// fall back
|
||||
return $this->isTrustedStaticClass($class_name, $compiler);
|
||||
}
|
||||
if ($params[ 2 ] == 'method') {
|
||||
$allowed = $this->trusted_static_methods;
|
||||
$name = substr($params[ 0 ], 0, strpos($params[ 0 ], '('));
|
||||
} else {
|
||||
$allowed = $this->trusted_static_properties;
|
||||
// strip '$'
|
||||
$name = substr($params[ 0 ], 1);
|
||||
}
|
||||
if (isset($allowed)) {
|
||||
if (empty($allowed)) {
|
||||
// fall back
|
||||
return $this->isTrustedStaticClass($class_name, $compiler);
|
||||
}
|
||||
if (isset($allowed[ $class_name ]) &&
|
||||
(empty($allowed[ $class_name ]) || in_array($name, $allowed[ $class_name ]))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$compiler->trigger_template_error("access to static class '{$class_name}' {$params[2]} '{$name}' not allowed by security setting");
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PHP modifier is trusted.
|
||||
*
|
||||
* @param string $modifier_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if modifier is trusted
|
||||
* @throws SmartyCompilerException if modifier is not trusted
|
||||
*/
|
||||
public function isTrustedPhpModifier($modifier_name, $compiler)
|
||||
{
|
||||
if (isset($this->php_modifiers) &&
|
||||
(empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting");
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tag is trusted.
|
||||
*
|
||||
* @param string $tag_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if tag is trusted
|
||||
* @throws SmartyCompilerException if modifier is not trusted
|
||||
*/
|
||||
public function isTrustedTag($tag_name, $compiler)
|
||||
{
|
||||
// check for internal always required tags
|
||||
if (in_array($tag_name,
|
||||
array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin',
|
||||
'private_object_block_function', 'private_object_function', 'private_registered_function',
|
||||
'private_registered_block', 'private_special_variable', 'private_print_expression',
|
||||
'private_modifier'))) {
|
||||
return true;
|
||||
}
|
||||
// check security settings
|
||||
if (empty($this->allowed_tags)) {
|
||||
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
|
||||
}
|
||||
} elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
|
||||
}
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if special $smarty variable is trusted.
|
||||
*
|
||||
* @param string $var_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if tag is trusted
|
||||
* @throws SmartyCompilerException if modifier is not trusted
|
||||
*/
|
||||
public function isTrustedSpecialSmartyVar($var_name, $compiler)
|
||||
{
|
||||
if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting",
|
||||
null, true);
|
||||
}
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if modifier plugin is trusted.
|
||||
*
|
||||
* @param string $modifier_name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true if tag is trusted
|
||||
* @throws SmartyCompilerException if modifier is not trusted
|
||||
*/
|
||||
public function isTrustedModifier($modifier_name, $compiler)
|
||||
{
|
||||
// check for internal always allowed modifier
|
||||
if (in_array($modifier_name, array('default'))) {
|
||||
return true;
|
||||
}
|
||||
// check security settings
|
||||
if (empty($this->allowed_modifiers)) {
|
||||
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null,
|
||||
true);
|
||||
}
|
||||
} elseif (in_array($modifier_name, $this->allowed_modifiers) &&
|
||||
!in_array($modifier_name, $this->disabled_modifiers)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null,
|
||||
true);
|
||||
}
|
||||
|
||||
return false; // should not, but who knows what happens to the compiler in the future?
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if constants are enabled or trusted
|
||||
*
|
||||
* @param string $const constant name
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isTrustedConstant($const, $compiler)
|
||||
{
|
||||
if (in_array($const, array('true', 'false', 'null'))) {
|
||||
return true;
|
||||
}
|
||||
if (!empty($this->trusted_constants)) {
|
||||
if (!in_array(strtolower($const), $this->trusted_constants)) {
|
||||
$compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($this->allow_constants) {
|
||||
return true;
|
||||
}
|
||||
$compiler->trigger_template_error("Security: access to constants not permitted");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if stream is trusted.
|
||||
*
|
||||
* @param string $stream_name
|
||||
*
|
||||
* @return boolean true if stream is trusted
|
||||
* @throws SmartyException if stream is not trusted
|
||||
*/
|
||||
public function isTrustedStream($stream_name)
|
||||
{
|
||||
if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new SmartyException("stream '{$stream_name}' not allowed by security setting");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param null|bool $isConfig
|
||||
*
|
||||
* @return bool true if directory is trusted
|
||||
* @throws \SmartyException if directory is not trusted
|
||||
*/
|
||||
public function isTrustedResourceDir($filepath, $isConfig = null)
|
||||
{
|
||||
if ($this->_include_path_status !== $this->smarty->use_include_path) {
|
||||
foreach ($this->_include_dir as $directory) {
|
||||
unset($this->_resource_dir[ $directory ]);
|
||||
}
|
||||
if ($this->smarty->use_include_path) {
|
||||
$this->_include_dir = array();
|
||||
$_dirs = $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty);
|
||||
foreach ($_dirs as $directory) {
|
||||
$this->_include_dir[] = $directory;
|
||||
$this->_resource_dir[ $directory ] = true;
|
||||
}
|
||||
}
|
||||
$this->_include_path_status = $this->smarty->use_include_path;
|
||||
}
|
||||
if ($isConfig !== true &&
|
||||
(!isset($this->smarty->_cache[ 'template_dir_new' ]) || $this->smarty->_cache[ 'template_dir_new' ])
|
||||
) {
|
||||
$_dir = $this->smarty->getTemplateDir();
|
||||
if ($this->_template_dir !== $_dir) {
|
||||
foreach ($this->_template_dir as $directory) {
|
||||
unset($this->_resource_dir[ $directory ]);
|
||||
}
|
||||
foreach ($_dir as $directory) {
|
||||
$this->_resource_dir[ $directory ] = true;
|
||||
}
|
||||
$this->_template_dir = $_dir;
|
||||
}
|
||||
$this->smarty->_cache[ 'template_dir_new' ] = false;
|
||||
}
|
||||
if ($isConfig !== false &&
|
||||
(!isset($this->smarty->_cache[ 'config_dir_new' ]) || $this->smarty->_cache[ 'config_dir_new' ])
|
||||
) {
|
||||
$_dir = $this->smarty->getConfigDir();
|
||||
if ($this->_config_dir !== $_dir) {
|
||||
foreach ($this->_config_dir as $directory) {
|
||||
unset($this->_resource_dir[ $directory ]);
|
||||
}
|
||||
foreach ($_dir as $directory) {
|
||||
$this->_resource_dir[ $directory ] = true;
|
||||
}
|
||||
$this->_config_dir = $_dir;
|
||||
}
|
||||
$this->smarty->_cache[ 'config_dir_new' ] = false;
|
||||
}
|
||||
if ($this->_secure_dir !== (array) $this->secure_dir) {
|
||||
foreach ($this->_secure_dir as $directory) {
|
||||
unset($this->_resource_dir[ $directory ]);
|
||||
}
|
||||
foreach ((array) $this->secure_dir as $directory) {
|
||||
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
|
||||
$this->_resource_dir[ $directory ] = true;
|
||||
}
|
||||
$this->_secure_dir = (array) $this->secure_dir;
|
||||
}
|
||||
$this->_resource_dir = $this->_checkDir($filepath, $this->_resource_dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if URI (e.g. {fetch} or {html_image}) is trusted
|
||||
* To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}".
|
||||
* So "http://username:password@hello.world.example.org:8080/some-path?some=query-string"
|
||||
* is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}.
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return boolean true if URI is trusted
|
||||
* @throws SmartyException if URI is not trusted
|
||||
* @uses $trusted_uri for list of patterns to match against $uri
|
||||
*/
|
||||
public function isTrustedUri($uri)
|
||||
{
|
||||
$_uri = parse_url($uri);
|
||||
if (!empty($_uri[ 'scheme' ]) && !empty($_uri[ 'host' ])) {
|
||||
$_uri = $_uri[ 'scheme' ] . '://' . $_uri[ 'host' ];
|
||||
foreach ($this->trusted_uri as $pattern) {
|
||||
if (preg_match($pattern, $_uri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SmartyException("URI '{$uri}' not allowed by security setting");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
*
|
||||
* @return boolean true if directory is trusted
|
||||
* @throws SmartyException if PHP directory is not trusted
|
||||
*/
|
||||
public function isTrustedPHPDir($filepath)
|
||||
{
|
||||
if (empty($this->trusted_dir)) {
|
||||
throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
|
||||
}
|
||||
|
||||
// check if index is outdated
|
||||
if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
|
||||
$this->_php_resource_dir = array();
|
||||
|
||||
$this->_trusted_dir = $this->trusted_dir;
|
||||
foreach ((array) $this->trusted_dir as $directory) {
|
||||
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
|
||||
$this->_php_resource_dir[ $directory ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_php_resource_dir =
|
||||
$this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file is inside a valid directory
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param array $dirs valid directories
|
||||
*
|
||||
* @return array
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
private function _checkDir($filepath, $dirs)
|
||||
{
|
||||
$directory = dirname($filepath) . DIRECTORY_SEPARATOR;
|
||||
$_directory = array();
|
||||
while (true) {
|
||||
// remember the directory to add it to _resource_dir in case we're successful
|
||||
$_directory[ $directory ] = true;
|
||||
// test if the directory is trusted
|
||||
if (isset($dirs[ $directory ])) {
|
||||
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
|
||||
$dirs = array_merge($dirs, $_directory);
|
||||
|
||||
return $dirs;
|
||||
}
|
||||
// abort if we've reached root
|
||||
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
|
||||
break;
|
||||
}
|
||||
// bubble up one level
|
||||
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory);
|
||||
}
|
||||
|
||||
// give up
|
||||
throw new SmartyException("directory '{$filepath}' not allowed by security setting");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads security class and enables security
|
||||
*
|
||||
* @param \Smarty $smarty
|
||||
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
|
||||
*
|
||||
* @return \Smarty current Smarty instance for chaining
|
||||
* @throws \SmartyException when an invalid class name is provided
|
||||
*/
|
||||
public static function enableSecurity(Smarty $smarty, $security_class)
|
||||
{
|
||||
if ($security_class instanceof Smarty_Security) {
|
||||
$smarty->security_policy = $security_class;
|
||||
return;
|
||||
} elseif (is_object($security_class)) {
|
||||
throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
|
||||
}
|
||||
if ($security_class == null) {
|
||||
$security_class = $smarty->security_class;
|
||||
}
|
||||
if (!class_exists($security_class)) {
|
||||
throw new SmartyException("Security class '$security_class' is not defined");
|
||||
} elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
|
||||
throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
|
||||
} else {
|
||||
$smarty->security_policy = new $security_class($smarty);
|
||||
}
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Start template processing
|
||||
*
|
||||
* @param $template
|
||||
*
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function startTemplate($template)
|
||||
{
|
||||
if ($this->max_template_nesting > 0 && $this->_current_template_nesting ++ >= $this->max_template_nesting) {
|
||||
throw new SmartyException("maximum template nesting level of '{$this->max_template_nesting}' exceeded when calling '{$template->template_resource}'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit template processing
|
||||
*
|
||||
*/
|
||||
public function endTemplate()
|
||||
{
|
||||
if ($this->max_template_nesting > 0) {
|
||||
$this->_current_template_nesting --;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register callback functions call at start/end of template rendering
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public function registerCallBacks(Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->startRenderCallbacks[] = array($this, 'startTemplate');
|
||||
$template->endRenderCallbacks[] = array($this, 'endTemplate');
|
||||
}
|
||||
}
|
256
libs/sysplugins/smarty_template_cached.php
Normale Datei
256
libs/sysplugins/smarty_template_cached.php
Normale Datei
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Uwe Tews
|
||||
* Date: 04.12.2014
|
||||
* Time: 06:08
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Cache Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
||||
{
|
||||
/**
|
||||
* Cache Is Valid
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $valid = null;
|
||||
|
||||
/**
|
||||
* CacheResource Handler
|
||||
*
|
||||
* @var Smarty_CacheResource
|
||||
*/
|
||||
public $handler = null;
|
||||
|
||||
/**
|
||||
* Template Cache Id (Smarty_Internal_Template::$cache_id)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $cache_id = null;
|
||||
|
||||
/**
|
||||
* saved cache lifetime in seconds
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $cache_lifetime = 0;
|
||||
|
||||
/**
|
||||
* Id for cache locking
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $lock_id = null;
|
||||
|
||||
/**
|
||||
* flag that cache is locked by this instance
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $is_locked = false;
|
||||
|
||||
/**
|
||||
* Source Object
|
||||
*
|
||||
* @var Smarty_Template_Source
|
||||
*/
|
||||
public $source = null;
|
||||
|
||||
/**
|
||||
* Nocache hash codes of processed compiled templates
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $hashes = array();
|
||||
|
||||
/**
|
||||
* Flag if this is a cache resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isCache = true;
|
||||
|
||||
/**
|
||||
* create Cached Object container
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function __construct(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$this->compile_id = $_template->compile_id;
|
||||
$this->cache_id = $_template->cache_id;
|
||||
$this->source = $_template->source;
|
||||
if (!class_exists('Smarty_CacheResource', false)) {
|
||||
require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
|
||||
}
|
||||
$this->handler = Smarty_CacheResource::load($_template->smarty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return Smarty_Template_Cached
|
||||
*/
|
||||
static function load(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_template->cached = new Smarty_Template_Cached($_template);
|
||||
$_template->cached->handler->populate($_template->cached, $_template);
|
||||
// caching enabled ?
|
||||
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
|
||||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->handler->recompiled
|
||||
) {
|
||||
$_template->cached->valid = false;
|
||||
}
|
||||
return $_template->cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render cache template
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param bool $no_output_filter
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
|
||||
{
|
||||
if ($this->isCached($_template)) {
|
||||
if ($_template->smarty->debugging) {
|
||||
if (!isset($_template->smarty->_debug)) {
|
||||
$_template->smarty->_debug = new Smarty_Internal_Debug();
|
||||
}
|
||||
$_template->smarty->_debug->start_cache($_template);
|
||||
}
|
||||
if (!$this->processed) {
|
||||
$this->process($_template);
|
||||
}
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_cache($_template);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
$_template->smarty->ext->_updateCache->updateCache($this, $_template, $no_output_filter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cache is valid, lock cache if required
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return bool flag true if cache is valid
|
||||
*/
|
||||
public function isCached(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if ($this->valid !== null) {
|
||||
return $this->valid;
|
||||
}
|
||||
while (true) {
|
||||
while (true) {
|
||||
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
|
||||
$this->valid = false;
|
||||
} else {
|
||||
$this->valid = true;
|
||||
}
|
||||
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT &&
|
||||
$_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
|
||||
) {
|
||||
// lifetime expired
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($this->valid && $_template->smarty->compile_check == 1 &&
|
||||
$_template->source->getTimeStamp() > $this->timestamp
|
||||
) {
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($this->valid || !$_template->smarty->cache_locking) {
|
||||
break;
|
||||
}
|
||||
if (!$this->handler->locked($_template->smarty, $this)) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
break 2;
|
||||
}
|
||||
$this->handler->populate($this, $_template);
|
||||
}
|
||||
if ($this->valid) {
|
||||
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
||||
// load cache file for the following checks
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->start_cache($_template);
|
||||
}
|
||||
if ($this->handler->process($_template, $this) === false) {
|
||||
$this->valid = false;
|
||||
} else {
|
||||
$this->processed = true;
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_cache($_template);
|
||||
}
|
||||
} else {
|
||||
$this->is_locked = true;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
return $this->valid;
|
||||
}
|
||||
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED &&
|
||||
$_template->cached->cache_lifetime >= 0 &&
|
||||
(time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
|
||||
) {
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($_template->smarty->cache_locking) {
|
||||
if (!$this->valid) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
} elseif ($this->is_locked) {
|
||||
$this->handler->releaseLock($_template->smarty, $this);
|
||||
}
|
||||
}
|
||||
return $this->valid;
|
||||
}
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process cached template
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param bool $update flag if called because cache update
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, $update = false)
|
||||
{
|
||||
if ($this->handler->process($_template, $this, $update) === false) {
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($this->valid) {
|
||||
$this->processed = true;
|
||||
} else {
|
||||
$this->processed = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cache content from handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string|false content
|
||||
*/
|
||||
public function read(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
return $this->handler->readCachedContent($_template);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
257
libs/sysplugins/smarty_template_compiled.php
Normale Datei
257
libs/sysplugins/smarty_template_compiled.php
Normale Datei
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Meta Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
* @property string $content compiled content
|
||||
*/
|
||||
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
{
|
||||
|
||||
/**
|
||||
* nocache hash
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $nocache_hash = null;
|
||||
|
||||
/**
|
||||
* get a Compiled Object of this source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return Smarty_Template_Compiled compiled object
|
||||
*/
|
||||
static function load($_template)
|
||||
{
|
||||
$compiled = new Smarty_Template_Compiled();
|
||||
if ($_template->source->handler->hasCompiledHandler) {
|
||||
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
|
||||
} else {
|
||||
$compiled->populateCompiledFilepath($_template);
|
||||
}
|
||||
return $compiled;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Compiled Object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
**/
|
||||
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$source = &$_template->source;
|
||||
$smarty = &$_template->smarty;
|
||||
$this->filepath = $smarty->getCompileDir();
|
||||
if (isset($_template->compile_id)) {
|
||||
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
|
||||
($smarty->use_sub_dirs ? $smarty->ds : '^');
|
||||
}
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($smarty->use_sub_dirs) {
|
||||
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] .
|
||||
$source->uid[ 3 ] . $smarty->ds . $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds;
|
||||
}
|
||||
$this->filepath .= $source->uid . '_';
|
||||
if ($source->isConfig) {
|
||||
$this->filepath .= (int) $smarty->config_read_hidden + (int) $smarty->config_booleanize * 2 +
|
||||
(int) $smarty->config_overwrite * 4;
|
||||
} else {
|
||||
$this->filepath .= (int) $smarty->merge_compiled_includes + (int) $smarty->escape_html * 2 +
|
||||
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
|
||||
(int) $smarty->extends_recursion * 4 : 0);
|
||||
}
|
||||
$this->filepath .= '.' . $source->type;
|
||||
$basename = $source->handler->getBasename($source);
|
||||
if (!empty($basename)) {
|
||||
$this->filepath .= '.' . $basename;
|
||||
}
|
||||
if ($_template->caching) {
|
||||
$this->filepath .= '.cache';
|
||||
}
|
||||
$this->filepath .= '.php';
|
||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||
if ($this->exists) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* render compiled template code
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function render(Smarty_Internal_Template $_template)
|
||||
{
|
||||
// checks if template exists
|
||||
if (!$_template->source->exists) {
|
||||
$type = $_template->source->isConfig ? 'config' : 'template';
|
||||
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
if (!isset($_template->smarty->_debug)) {
|
||||
$_template->smarty->_debug = new Smarty_Internal_Debug();
|
||||
}
|
||||
$_template->smarty->_debug->start_render($_template);
|
||||
}
|
||||
if (!$this->processed) {
|
||||
$this->process($_template);
|
||||
}
|
||||
if (isset($_template->cached)) {
|
||||
$_template->cached->file_dependency =
|
||||
array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||
}
|
||||
if ($_template->source->handler->uncompiled) {
|
||||
$_template->source->handler->renderUncompiled($_template->source, $_template);
|
||||
} else {
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
}
|
||||
if ($_template->caching && $this->has_nocache_code) {
|
||||
$_template->cached->hashes[ $this->nocache_hash ] = true;
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_render($_template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load compiled template or compile from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
$source = &$_smarty_tpl->source;
|
||||
$smarty = &$_smarty_tpl->smarty;
|
||||
if ($source->handler->recompiled) {
|
||||
$source->handler->process($_smarty_tpl);
|
||||
} elseif (!$source->handler->uncompiled) {
|
||||
if (!$this->exists || $smarty->force_compile ||
|
||||
($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_smarty_tpl);
|
||||
$compileCheck = $smarty->compile_check;
|
||||
$smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_smarty_tpl);
|
||||
$smarty->compile_check = $compileCheck;
|
||||
} else {
|
||||
$_smarty_tpl->mustCompile = true;
|
||||
@include($this->filepath);
|
||||
if ($_smarty_tpl->mustCompile) {
|
||||
$this->compileTemplateSource($_smarty_tpl);
|
||||
$compileCheck = $smarty->compile_check;
|
||||
$smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_smarty_tpl);
|
||||
$smarty->compile_check = $compileCheck;
|
||||
}
|
||||
}
|
||||
$_smarty_tpl->_subTemplateRegister();
|
||||
$this->processed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* compile template from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function compileTemplateSource(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$this->file_dependency = array();
|
||||
$this->includes = array();
|
||||
$this->nocache_hash = null;
|
||||
$this->unifunc = null;
|
||||
// compile locking
|
||||
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
|
||||
$saved_timestamp = $this->getTimeStamp();
|
||||
touch($this->filepath);
|
||||
}
|
||||
// compile locking
|
||||
try {
|
||||
// call compiler
|
||||
$_template->loadCompiler();
|
||||
$this->write($_template, $_template->compiler->compileTemplate($_template));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// restore old timestamp in case of error
|
||||
if ($saved_timestamp && is_file($this->filepath)) {
|
||||
touch($this->filepath, $saved_timestamp);
|
||||
}
|
||||
unset($_template->compiler);
|
||||
throw $e;
|
||||
}
|
||||
// release compiler object to free memory
|
||||
unset($_template->compiler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write compiled code by handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $code compiled code
|
||||
*
|
||||
* @return boolean success
|
||||
*/
|
||||
public function write(Smarty_Internal_Template $_template, $code)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) {
|
||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||
if ($this->exists) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load fresh compiled template by including the PHP file
|
||||
* HHVM requires a work around because of a PHP incompatibility
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*/
|
||||
private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
if (function_exists('opcache_invalidate')
|
||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||
) {
|
||||
opcache_invalidate($this->filepath, true);
|
||||
} elseif (function_exists('apc_compile_file')) {
|
||||
apc_compile_file($this->filepath);
|
||||
}
|
||||
if (defined('HHVM_VERSION')) {
|
||||
eval("?>" . file_get_contents($this->filepath));
|
||||
} else {
|
||||
include($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read compiled content from handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function read(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
return file_get_contents($this->filepath);
|
||||
}
|
||||
return isset($this->content) ? $this->content : false;
|
||||
}
|
||||
}
|
99
libs/sysplugins/smarty_template_config.php
Normale Datei
99
libs/sysplugins/smarty_template_config.php
Normale Datei
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Smarty Config Source Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Config Resource Data Object
|
||||
* Meta Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
*
|
||||
*/
|
||||
class Smarty_Template_Config extends Smarty_Template_Source
|
||||
{
|
||||
/**
|
||||
* array of section names, single section or null
|
||||
*
|
||||
* @var null|string|array
|
||||
*/
|
||||
public $config_sections = null;
|
||||
|
||||
/**
|
||||
* scope into which the config variables shall be loaded
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $scope = 0;
|
||||
|
||||
/**
|
||||
* Flag that source is a config file
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isConfig = true;
|
||||
|
||||
/**
|
||||
* Name of the Class to compile this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
|
||||
|
||||
/**
|
||||
* Name of the Class to tokenize this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
|
||||
|
||||
/**
|
||||
* Name of the Class to parse this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_parser_class = 'Smarty_Internal_Configfileparser';
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $template_resource resource identifier
|
||||
*
|
||||
* @return Smarty_Template_Config Source Object
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
|
||||
$template_resource = null)
|
||||
{
|
||||
static $_incompatible_resources = array('extends' => true, 'php' => true);
|
||||
if ($_template) {
|
||||
$smarty = $_template->smarty;
|
||||
$template_resource = $_template->template_resource;
|
||||
}
|
||||
if (empty($template_resource)) {
|
||||
throw new SmartyException('Source: Missing name');
|
||||
}
|
||||
// parse resource_name, load resource handler
|
||||
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
|
||||
// make sure configs are not loaded via anything smarty can't handle
|
||||
if (isset($_incompatible_resources[ $type ])) {
|
||||
throw new SmartyException ("Unable to use resource '{$type}' for config");
|
||||
}
|
||||
$source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
|
||||
$source->handler->populate($source, $_template);
|
||||
if (!$source->exists && isset($smarty->default_config_handler_func)) {
|
||||
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
|
||||
$source->handler->populate($source, $_template);
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
}
|
158
libs/sysplugins/smarty_template_resource_base.php
Normale Datei
158
libs/sysplugins/smarty_template_resource_base.php
Normale Datei
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Template Resource Base Object
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
abstract class Smarty_Template_Resource_Base
|
||||
{
|
||||
/**
|
||||
* Compiled Filepath
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $filepath = null;
|
||||
|
||||
/**
|
||||
* Compiled Timestamp
|
||||
*
|
||||
* @var integer|bool
|
||||
*/
|
||||
public $timestamp = false;
|
||||
|
||||
/**
|
||||
* Compiled Existence
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $exists = false;
|
||||
|
||||
/**
|
||||
* Template Compile Id (Smarty_Internal_Template::$compile_id)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compile_id = null;
|
||||
|
||||
/**
|
||||
* Compiled Content Loaded
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $processed = false;
|
||||
|
||||
/**
|
||||
* unique function name for compiled template code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $unifunc = '';
|
||||
|
||||
/**
|
||||
* flag if template does contain nocache code sections
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $has_nocache_code = false;
|
||||
|
||||
/**
|
||||
* resource file dependency
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $file_dependency = array();
|
||||
|
||||
/**
|
||||
* Content buffer
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* required plugins
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $required_plugins = array();
|
||||
|
||||
/**
|
||||
* Included subtemplates
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $includes = array();
|
||||
|
||||
/**
|
||||
* Flag if this is a cache resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isCache = false;
|
||||
|
||||
/**
|
||||
* Process resource
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
abstract public function process(Smarty_Internal_Template $_template);
|
||||
|
||||
/**
|
||||
* get rendered template content by calling compiled or cached template code
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param string $unifunc function with template code
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
|
||||
{
|
||||
$smarty = &$_template->smarty;
|
||||
$_template->isRenderingCache = $this->isCache;
|
||||
$level = ob_get_level();
|
||||
try {
|
||||
if (!isset($unifunc)) {
|
||||
$unifunc = $this->unifunc;
|
||||
}
|
||||
if (empty($unifunc) || !function_exists($unifunc)) {
|
||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||
}
|
||||
if ($_template->startRenderCallbacks) {
|
||||
foreach ($_template->startRenderCallbacks as $callback) {
|
||||
call_user_func($callback, $_template);
|
||||
}
|
||||
}
|
||||
$unifunc($_template);
|
||||
foreach ($_template->endRenderCallbacks as $callback) {
|
||||
call_user_func($callback, $_template);
|
||||
}
|
||||
$_template->isRenderingCache = false;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$_template->isRenderingCache = false;
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
if (isset($smarty->security_policy)) {
|
||||
$smarty->security_policy->endTemplate();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get compiled time stamp
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeStamp()
|
||||
{
|
||||
if ($this->exists && !$this->timestamp) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
}
|
||||
return $this->timestamp;
|
||||
}
|
||||
}
|
210
libs/sysplugins/smarty_template_source.php
Normale Datei
210
libs/sysplugins/smarty_template_source.php
Normale Datei
|
@ -0,0 +1,210 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Meta Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*
|
||||
*/
|
||||
class Smarty_Template_Source
|
||||
{
|
||||
/**
|
||||
* Unique Template ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $uid = null;
|
||||
|
||||
/**
|
||||
* Template Resource (Smarty_Internal_Template::$template_resource)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $resource = null;
|
||||
|
||||
/**
|
||||
* Resource Type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = null;
|
||||
|
||||
/**
|
||||
* Resource Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* Source Filepath
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $filepath = null;
|
||||
|
||||
/**
|
||||
* Source Timestamp
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $timestamp = null;
|
||||
|
||||
/**
|
||||
* Source Existence
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $exists = false;
|
||||
|
||||
/**
|
||||
* Source File Base name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $basename = null;
|
||||
|
||||
/**
|
||||
* The Components an extended template is made of
|
||||
*
|
||||
* @var \Smarty_Template_Source[]
|
||||
*/
|
||||
public $components = null;
|
||||
|
||||
/**
|
||||
* Resource Handler
|
||||
*
|
||||
* @var \Smarty_Resource
|
||||
*/
|
||||
public $handler = null;
|
||||
|
||||
/**
|
||||
* Smarty instance
|
||||
*
|
||||
* @var Smarty
|
||||
*/
|
||||
public $smarty = null;
|
||||
|
||||
/**
|
||||
* Resource is source
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isConfig = false;
|
||||
|
||||
/**
|
||||
* Template source content eventually set by default handler
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* Name of the Class to compile this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
|
||||
/**
|
||||
* Name of the Class to tokenize this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
||||
|
||||
/**
|
||||
* Name of the Class to parse this resource's contents with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||
|
||||
/**
|
||||
* create Source Object container
|
||||
*
|
||||
* @param Smarty_Resource $handler Resource Handler this source object communicates with
|
||||
* @param Smarty $smarty Smarty instance this source object belongs to
|
||||
* @param string $resource full template_resource
|
||||
* @param string $type type of resource
|
||||
* @param string $name resource name
|
||||
*
|
||||
*/
|
||||
public function __construct(Smarty $smarty, $resource, $type, $name)
|
||||
{
|
||||
$this->handler =
|
||||
isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
|
||||
Smarty_Resource::load($smarty, $type);
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $template_resource resource identifier
|
||||
*
|
||||
* @return Smarty_Template_Source Source Object
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
|
||||
$template_resource = null)
|
||||
{
|
||||
if ($_template) {
|
||||
$smarty = $_template->smarty;
|
||||
$template_resource = $_template->template_resource;
|
||||
}
|
||||
if (empty($template_resource)) {
|
||||
throw new SmartyException('Source: Missing name');
|
||||
}
|
||||
// parse resource_name, load resource handler, identify unique resource name
|
||||
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
|
||||
$type = $match[ 1 ];
|
||||
$name = $match[ 2 ];
|
||||
} else {
|
||||
// no resource given, use default
|
||||
// or single character before the colon is not a resource type, but part of the filepath
|
||||
$type = $smarty->default_resource_type;
|
||||
$name = $template_resource;
|
||||
}
|
||||
// create new source object
|
||||
$source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
|
||||
$source->handler->populate($source, $_template);
|
||||
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
|
||||
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
|
||||
$source->handler->populate($source, $_template);
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source time stamp
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeStamp()
|
||||
{
|
||||
if (!isset($this->timestamp)) {
|
||||
$this->handler->populateTimestamp($this);
|
||||
}
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return isset($this->content) ? $this->content : $this->handler->getContent($this);
|
||||
}
|
||||
}
|
37
libs/sysplugins/smarty_undefined_variable.php
Normale Datei
37
libs/sysplugins/smarty_undefined_variable.php
Normale Datei
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* class for undefined variable object
|
||||
* This class defines an object for undefined variable handling
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*/
|
||||
class Smarty_Undefined_Variable
|
||||
{
|
||||
/**
|
||||
* Returns FALSE for 'nocache' and NULL otherwise.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'nocache') {
|
||||
return false;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns an empty string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
48
libs/sysplugins/smarty_variable.php
Normale Datei
48
libs/sysplugins/smarty_variable.php
Normale Datei
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* class for the Smarty variable object
|
||||
* This class defines the Smarty variable object
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*/
|
||||
class Smarty_Variable
|
||||
{
|
||||
/**
|
||||
* template variable
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $value = null;
|
||||
|
||||
/**
|
||||
* if true any output of this variable will be not cached
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $nocache = false;
|
||||
|
||||
/**
|
||||
* create Smarty variable object
|
||||
*
|
||||
* @param mixed $value the value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
*/
|
||||
public function __construct($value = null, $nocache = false)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->nocache = $nocache;
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> String conversion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->value;
|
||||
}
|
||||
}
|
||||
|
42
libs/sysplugins/smartycompilerexception.php
Normale Datei
42
libs/sysplugins/smartycompilerexception.php
Normale Datei
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty compiler exception class
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
class SmartyCompilerException extends SmartyException
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return ' --> Smarty Compiler: ' . $this->message . ' <-- ';
|
||||
}
|
||||
|
||||
/**
|
||||
* The line number of the template error
|
||||
*
|
||||
* @type int|null
|
||||
*/
|
||||
public $line = null;
|
||||
|
||||
/**
|
||||
* The template source snippet relating to the error
|
||||
*
|
||||
* @type string|null
|
||||
*/
|
||||
public $source = null;
|
||||
|
||||
/**
|
||||
* The raw text of the error message
|
||||
*
|
||||
* @type string|null
|
||||
*/
|
||||
public $desc = null;
|
||||
|
||||
/**
|
||||
* The resource identifier or template name
|
||||
*
|
||||
* @type string|null
|
||||
*/
|
||||
public $template = null;
|
||||
}
|
16
libs/sysplugins/smartyexception.php
Normale Datei
16
libs/sysplugins/smartyexception.php
Normale Datei
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Smarty exception class
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
class SmartyException extends Exception
|
||||
{
|
||||
public static $escape = false;
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return ' --> Smarty: ' . (self::$escape ? htmlentities($this->message) : $this->message) . ' <-- ';
|
||||
}
|
||||
}
|
Laden …
In neuem Issue referenzieren