update smarty from 3.0.7 to 3.1.5
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1288 a1433add-5e2c-0410-b055-b7f2511e0802pull/2/head
parent
7773c537cc
commit
35d91d4b0c
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,460 @@
|
||||
<?php
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: SmartyBC.class.php
|
||||
* SVN: $Id$
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Smarty mailing list. Send a blank e-mail to
|
||||
* smarty-discussion-subscribe@googlegroups.com
|
||||
*
|
||||
* @link http://www.smarty.net/
|
||||
* @copyright 2008 New Digital Group, Inc.
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
* @package Smarty
|
||||
*/
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
require(dirname(__FILE__) . '/Smarty.class.php');
|
||||
|
||||
/**
|
||||
* Smarty Backward Compatability Wrapper Class
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
class SmartyBC extends Smarty {
|
||||
|
||||
/**
|
||||
* Smarty 2 BC
|
||||
* @var string
|
||||
*/
|
||||
public $_version = self::SMARTY_VERSION;
|
||||
|
||||
/**
|
||||
* Initialize new SmartyBC object
|
||||
*
|
||||
* @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
|
||||
*/
|
||||
public function __construct(array $options=array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
// register {php} tag
|
||||
$this->registerPlugin('block', 'php', 'smarty_php_tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for assign_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to assign
|
||||
*/
|
||||
public function assign_by_ref($tpl_var, &$value)
|
||||
{
|
||||
$this->assignByRef($tpl_var, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for append_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
*/
|
||||
public function append_by_ref($tpl_var, &$value, $merge = false)
|
||||
{
|
||||
$this->appendByRef($tpl_var, $value, $merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the given assigned template variable.
|
||||
*
|
||||
* @param string $tpl_var the template variable to clear
|
||||
*/
|
||||
public function clear_assign($tpl_var)
|
||||
{
|
||||
$this->clearAssign($tpl_var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers custom function to be used in templates
|
||||
*
|
||||
* @param string $function the name of the template function
|
||||
* @param string $function_impl the name of the PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*/
|
||||
public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
|
||||
{
|
||||
$this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters custom function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('function', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
*
|
||||
* @param string $object name of template object
|
||||
* @param object $object_impl the referenced PHP object to register
|
||||
* @param array $allowed list of allowed methods (empty = all)
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param array $block_functs list of methods that are block format
|
||||
*/
|
||||
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
{
|
||||
settype($allowed, 'array');
|
||||
settype($smarty_args, 'boolean');
|
||||
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters object
|
||||
*
|
||||
* @param string $object name of template object
|
||||
*/
|
||||
public function unregister_object($object)
|
||||
{
|
||||
$this->unregisterObject($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers block function to be used in templates
|
||||
*
|
||||
* @param string $block name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*/
|
||||
public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
|
||||
{
|
||||
$this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters block function
|
||||
*
|
||||
* @param string $block name of template function
|
||||
*/
|
||||
public function unregister_block($block)
|
||||
{
|
||||
$this->unregisterPlugin('block', $block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
* @param string $function_impl name of PHP function to register
|
||||
* @param bool $cacheable
|
||||
*/
|
||||
public function register_compiler_function($function, $function_impl, $cacheable=true)
|
||||
{
|
||||
$this->registerPlugin('compiler', $function, $function_impl, $cacheable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_compiler_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('compiler', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers modifier to be used in templates
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
* @param string $modifier_impl name of PHP function to register
|
||||
*/
|
||||
public function register_modifier($modifier, $modifier_impl)
|
||||
{
|
||||
$this->registerPlugin('modifier', $modifier, $modifier_impl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters modifier
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
*/
|
||||
public function unregister_modifier($modifier)
|
||||
{
|
||||
$this->unregisterPlugin('modifier', $modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @param string $type name of resource
|
||||
* @param array $functions array of functions to handle resource
|
||||
*/
|
||||
public function register_resource($type, $functions)
|
||||
{
|
||||
$this->registerResource($type, $functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a resource
|
||||
*
|
||||
* @param string $type name of resource
|
||||
*/
|
||||
public function unregister_resource($type)
|
||||
{
|
||||
$this->unregisterResource($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a prefilter function to apply
|
||||
* to a template before compiling
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_prefilter($function)
|
||||
{
|
||||
$this->registerFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a prefilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_prefilter($function)
|
||||
{
|
||||
$this->unregisterFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a postfilter function to apply
|
||||
* to a compiled template after compilation
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_postfilter($function)
|
||||
{
|
||||
$this->registerFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a postfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_postfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an output filter function to apply
|
||||
* to a template output
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_outputfilter($function)
|
||||
{
|
||||
$this->registerFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an outputfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_outputfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* load a filter of specified type and name
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param string $name filter name
|
||||
*/
|
||||
public function load_filter($type, $name)
|
||||
{
|
||||
$this->loadFilter($type, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear cached content for the given template and cache id
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id name of cache_id
|
||||
* @param string $compile_id name of compile_id
|
||||
* @param string $exp_time expiration time
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the entire contents of cache (all templates)
|
||||
*
|
||||
* @param string $exp_time expire time
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_all_cache($exp_time = null)
|
||||
{
|
||||
return $this->clearCache(null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* test to see if valid cache exists for this template
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id
|
||||
* @param string $compile_id
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
return $this->isCached($tpl_file, $cache_id, $compile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all the assigned template variables.
|
||||
*/
|
||||
public function clear_all_assign()
|
||||
{
|
||||
$this->clearAllAssign();
|
||||
}
|
||||
|
||||
/**
|
||||
* clears compiled version of specified template resource,
|
||||
* or all compiled template files if one is not specified.
|
||||
* This function is for advanced use only, not normally needed.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @param string $compile_id
|
||||
* @param string $exp_time
|
||||
* @return boolean results of {@link smarty_core_rm_auto()}
|
||||
*/
|
||||
public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether requested template exists.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @return boolean
|
||||
*/
|
||||
public function template_exists($tpl_file)
|
||||
{
|
||||
return $this->templateExists($tpl_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing template variables
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function get_template_vars($name=null)
|
||||
{
|
||||
return $this->getTemplateVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing config variables
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function get_config_vars($name=null)
|
||||
{
|
||||
return $this->getConfigVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* load configuration values
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $section
|
||||
* @param string $scope
|
||||
*/
|
||||
public function config_load($file, $section = null, $scope = 'global')
|
||||
{
|
||||
$this->ConfigLoad($file, $section, $scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a reference to a registered object
|
||||
*
|
||||
* @param string $name
|
||||
* @return object
|
||||
*/
|
||||
public function get_registered_object($name)
|
||||
{
|
||||
return $this->getRegisteredObject($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear configuration values
|
||||
*
|
||||
* @param string $var
|
||||
*/
|
||||
public function clear_config($var = null)
|
||||
{
|
||||
$this->clearConfig($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type
|
||||
*/
|
||||
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Smarty error: $error_msg", $error_type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty {php}{/php} block function
|
||||
*
|
||||
* @param array $params parameter list
|
||||
* @param string $content contents of the block
|
||||
* @param object $template template object
|
||||
* @param boolean &$repeat repeat flag
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_php_tag($params, $content, $template, &$repeat)
|
||||
{
|
||||
eval($content);
|
||||
return '';
|
||||
}
|
||||
|
||||
?>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin to execute PHP code
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsBlock
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {php}{/php} block plugin
|
||||
*
|
||||
* @param string $content contents of the block
|
||||
* @param object $template template object
|
||||
* @param boolean $ &$repeat repeat flag
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_block_php($params, $content, $template, &$repeat)
|
||||
{
|
||||
if (!$template->allow_php_tag) {
|
||||
throw new SmartyException("{php} is deprecated, set allow_php_tag = true to enable");
|
||||
}
|
||||
eval($content);
|
||||
return '';
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
require_once( SMARTY_PLUGINS_DIR .'shared.literal_compiler_param.php' );
|
||||
|
||||
/**
|
||||
* Smarty escape modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: escape<br>
|
||||
* Purpose: escape string for output
|
||||
*
|
||||
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
|
||||
* @author Rodney Rehm
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_escape($params, $compiler)
|
||||
{
|
||||
try {
|
||||
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
|
||||
$char_set = smarty_literal_compiler_param($params, 2, SMARTY_RESOURCE_CHAR_SET);
|
||||
$double_encode = smarty_literal_compiler_param($params, 3, true);
|
||||
|
||||
if (!$char_set) {
|
||||
$char_set = SMARTY_RESOURCE_CHAR_SET;
|
||||
}
|
||||
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
return 'htmlspecialchars('
|
||||
. $params[0] .', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true) . ')';
|
||||
|
||||
case 'htmlall':
|
||||
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||
return 'mb_convert_encoding(htmlspecialchars('
|
||||
. $params[0] .', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true)
|
||||
. '), "HTML-ENTITIES", '
|
||||
. var_export($char_set, true) . ')';
|
||||
}
|
||||
|
||||
// no MBString fallback
|
||||
return 'htmlentities('
|
||||
. $params[0] .', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true) . ')';
|
||||
|
||||
case 'url':
|
||||
return 'rawurlencode(' . $params[0] . ')';
|
||||
|
||||
case 'urlpathinfo':
|
||||
return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))';
|
||||
|
||||
case 'quotes':
|
||||
// escape unescaped single quotes
|
||||
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')';
|
||||
|
||||
case 'javascript':
|
||||
// escape quotes and backslashes, newlines, etc.
|
||||
return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
|
||||
|
||||
}
|
||||
} catch(SmartyException $e) {
|
||||
// pass through to regular plugin fallback
|
||||
}
|
||||
|
||||
// could not optimize |escape call, so fallback to regular plugin
|
||||
if ($compiler->tag_nocache | $compiler->nocache) {
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php';
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php';
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
}
|
||||
return 'smarty_modifier_escape(' . join( ', ', $params ) . ')';
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty from_charset modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: from_charset<br>
|
||||
* Purpose: convert character encoding from $charset to internal encoding
|
||||
*
|
||||
* @author Rodney Rehm
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_from_charset($params, $compiler)
|
||||
{
|
||||
if (!SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||
// FIXME: (rodneyrehm) shouldn't this throw an error?
|
||||
return $params[0];
|
||||
}
|
||||
|
||||
if (!isset($params[1])) {
|
||||
$params[1] = '"ISO-8859-1"';
|
||||
}
|
||||
|
||||
return 'mb_convert_encoding(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET, ' . $params[1] . ')';
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty to_charset modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: to_charset<br>
|
||||
* Purpose: convert character encoding from internal encoding to $charset
|
||||
*
|
||||
* @author Rodney Rehm
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_to_charset($params, $compiler)
|
||||
{
|
||||
if (!SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||
// FIXME: (rodneyrehm) shouldn't this throw an error?
|
||||
return $params[0];
|
||||
}
|
||||
|
||||
if (!isset($params[1])) {
|
||||
$params[1] = '"ISO-8859-1"';
|
||||
}
|
||||
|
||||
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', SMARTY_RESOURCE_CHAR_SET)';
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty unescape modifier plugin
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: unescape<br>
|
||||
* Purpose: unescape html entities
|
||||
*
|
||||
* @author Rodney Rehm
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_unescape($params, $compiler)
|
||||
{
|
||||
if (!isset($params[1])) {
|
||||
$params[1] = 'html';
|
||||
}
|
||||
if (!isset($params[2])) {
|
||||
$params[2] = "SMARTY_RESOURCE_CHAR_SET";
|
||||
} else {
|
||||
$params[2] = "'" . $params[2] . "'";
|
||||
}
|
||||
|
||||
switch (trim($params[1], '"\'')) {
|
||||
case 'entity':
|
||||
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
|
||||
case 'htmlall':
|
||||
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||
return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
|
||||
}
|
||||
return 'html_entity_decode(' . $params[0] . ', ENT_QUOTES, ' . $params[2] . ')';
|
||||
|
||||
case 'html':
|
||||
return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
|
||||
|
||||
default:
|
||||
return $params[0];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* evaluate compiler parameter
|
||||
*
|
||||
* @param array $params parameter array as given to the compiler function
|
||||
* @param integer $index array index of the parameter to convert
|
||||
* @param mixed $default value to be returned if the parameter is not present
|
||||
* @return mixed evaluated value of parameter or $default
|
||||
* @throws SmartyException if parameter is not a literal (but an expression, variable, …)
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_literal_compiler_param($params, $index, $default=null)
|
||||
{
|
||||
// not set, go default
|
||||
if (!isset($params[$index])) {
|
||||
return $default;
|
||||
}
|
||||
// test if param is a literal
|
||||
if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $params[$index])) {
|
||||
throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time');
|
||||
}
|
||||
|
||||
$t = null;
|
||||
eval("\$t = " . $params[$index] . ";");
|
||||
return $t;
|
||||
}
|
@ -1,38 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty shared plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
if (!function_exists('smarty_mb_str_replace')) {
|
||||
|
||||
if(!function_exists('smarty_mb_str_replace')) {
|
||||
function smarty_mb_str_replace($search, $replace, $subject, &$count=0) {
|
||||
if (!is_array($search) && is_array($replace)) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($subject)) {
|
||||
// call mb_replace for each single string in $subject
|
||||
foreach ($subject as &$string) {
|
||||
$string = &smarty_mb_str_replace($search, $replace, $string, $c);
|
||||
$count += $c;
|
||||
}
|
||||
} elseif (is_array($search)) {
|
||||
if (!is_array($replace)) {
|
||||
foreach ($search as &$string) {
|
||||
$subject = smarty_mb_str_replace($string, $replace, $subject, $c);
|
||||
$count += $c;
|
||||
}
|
||||
} else {
|
||||
$n = max(count($search), count($replace));
|
||||
while ($n--) {
|
||||
$subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
|
||||
$count += $c;
|
||||
next($search);
|
||||
next($replace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$parts = mb_split(preg_quote($search), $subject);
|
||||
$count = count($parts)-1;
|
||||
$subject = implode($replace, $parts);
|
||||
}
|
||||
return $subject;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Multibyte string replace
|
||||
*
|
||||
* @param string $search the string to be searched
|
||||
* @param string $replace the replacement string
|
||||
* @param string $subject the source string
|
||||
* @param int &$count number of matches found
|
||||
* @return string replaced string
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_mb_str_replace($search, $replace, $subject, &$count=0)
|
||||
{
|
||||
if (!is_array($search) && is_array($replace)) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($subject)) {
|
||||
// call mb_replace for each single string in $subject
|
||||
foreach ($subject as &$string) {
|
||||
$string = &smarty_mb_str_replace($search, $replace, $string, $c);
|
||||
$count += $c;
|
||||
}
|
||||
} elseif (is_array($search)) {
|
||||
if (!is_array($replace)) {
|
||||
foreach ($search as &$string) {
|
||||
$subject = smarty_mb_str_replace($string, $replace, $subject, $c);
|
||||
$count += $c;
|
||||
}
|
||||
} else {
|
||||
$n = max(count($search), count($replace));
|
||||
while ($n--) {
|
||||
$subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
|
||||
$count += $c;
|
||||
next($search);
|
||||
next($replace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$parts = mb_split(preg_quote($search), $subject);
|
||||
$count = count($parts) - 1;
|
||||
$subject = implode($replace, $parts);
|
||||
}
|
||||
return $subject;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty shared plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
/**
|
||||
* convert characters to their decimal unicode equivalents
|
||||
*
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
* @param string $string characters to calculate unicode of
|
||||
* @param string $encoding encoding of $string, if null mb_internal_encoding() is used
|
||||
* @return array sequence of unicodes
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_mb_to_unicode($string, $encoding=null) {
|
||||
if ($encoding) {
|
||||
$expanded = mb_convert_encoding($string, "UTF-32BE", $encoding);
|
||||
} else {
|
||||
$expanded = mb_convert_encoding($string, "UTF-32BE");
|
||||
}
|
||||
return unpack("N*", $expanded);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert unicodes to the character of given encoding
|
||||
*
|
||||
* @link http://www.ibm.com/developerworks/library/os-php-unicode/index.html#listing3 for inspiration
|
||||
* @param integer|array $unicode single unicode or list of unicodes to convert
|
||||
* @param string $encoding encoding of returned string, if null mb_internal_encoding() is used
|
||||
* @return string unicode as character sequence in given $encoding
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_mb_from_unicode($unicode, $encoding=null) {
|
||||
$t = '';
|
||||
if (!$encoding) {
|
||||
$encoding = mb_internal_encoding();
|
||||
}
|
||||
foreach((array) $unicode as $utf32be) {
|
||||
$character = pack("N*", $utf32be);
|
||||
$t .= mb_convert_encoding($character, $encoding, "UTF-32BE");
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty shared plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsShared
|
||||
*/
|
||||
|
||||
if(!function_exists('smarty_mb_wordwrap')) {
|
||||
|
||||
/**
|
||||
* Wrap a string to a given number of characters
|
||||
*
|
||||
* @link http://php.net/manual/en/function.wordwrap.php for similarity
|
||||
* @param string $str the string to wrap
|
||||
* @param int $width the width of the output
|
||||
* @param string $break the character used to break the line
|
||||
* @param boolean $cut ignored parameter, just for the sake of
|
||||
* @return string wrapped string
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_mb_wordwrap($str, $width=75, $break="\n", $cut=false)
|
||||
{
|
||||
// break words into tokens using white space as a delimiter
|
||||
$tokens = preg_split('!(\s)!uS', $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
||||
$length = 0;
|
||||
$t = '';
|
||||
$_previous = false;
|
||||
|
||||
foreach ($tokens as $_token) {
|
||||
$token_length = mb_strlen($_token, SMARTY_RESOURCE_CHAR_SET);
|
||||
$_tokens = array($_token);
|
||||
if ($token_length > $width) {
|
||||
// remove last space
|
||||
$t = mb_substr($t, 0, -1, SMARTY_RESOURCE_CHAR_SET);
|
||||
$_previous = false;
|
||||
$length = 0;
|
||||
|
||||
if ($cut) {
|
||||
$_tokens = preg_split('!(.{' . $width . '})!uS', $_token, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
||||
// broken words go on a new line
|
||||
$t .= $break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_tokens as $token) {
|
||||
$_space = !!preg_match('!^\s$!uS', $token);
|
||||
$token_length = mb_strlen($token, SMARTY_RESOURCE_CHAR_SET);
|
||||
$length += $token_length;
|
||||
|
||||
if ($length > $width) {
|
||||
// remove space before inserted break
|
||||
if ($_previous && $token_length < $width) {
|
||||
$t = mb_substr($t, 0, -1, SMARTY_RESOURCE_CHAR_SET);
|
||||
}
|
||||
|
||||
// add the break before the token
|
||||
$t .= $break;
|
||||
$length = $token_length;
|
||||
|
||||
// skip space after inserting a break
|
||||
if ($_space) {
|
||||
$length = 0;
|
||||
continue;
|
||||
}
|
||||
} else if ($token == "\n") {
|
||||
// hard break must reset counters
|
||||
$_previous = 0;
|
||||
$length = 0;
|
||||
} else {
|
||||
// remember if we had a space or not
|
||||
$_previous = $_space;
|
||||
}
|
||||
// add the token
|
||||
$t .= $token;
|
||||
}
|
||||
}
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,380 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Handler API
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
abstract class Smarty_CacheResource {
|
||||
/**
|
||||
* cache for Smarty_CacheResource instances
|
||||
* @var array
|
||||
*/
|
||||
public static $resources = array();
|
||||
|
||||
/**
|
||||
* resource types provided by the core
|
||||
* @var array
|
||||
*/
|
||||
protected static $sysplugins = array(
|
||||
'file' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* populate Cached Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @return void
|
||||
*/
|
||||
public abstract function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
|
||||
|
||||
/**
|
||||
* populate Cached Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $source cached object
|
||||
* @return void
|
||||
*/
|
||||
public abstract function populateTimestamp(Smarty_Template_Cached $cached);
|
||||
|
||||
/**
|
||||
* Read the cached template and process header
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return booelan true or false if the cached content does not exist
|
||||
*/
|
||||
public abstract function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null);
|
||||
|
||||
/**
|
||||
* Write the rendered template output to cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
* @return boolean success
|
||||
*/
|
||||
public abstract function writeCachedContent(Smarty_Internal_Template $_template, $content);
|
||||
|
||||
/**
|
||||
* Return cached content
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content of cache
|
||||
*/
|
||||
public function getCachedContent(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if ($_template->cached->handler->process($_template)) {
|
||||
ob_start();
|
||||
$_template->properties['unifunc']($_template);
|
||||
return ob_get_clean();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param integer $exp_time expiration time (number of seconds, not timestamp)
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
public abstract function clearAll(Smarty $smarty, $exp_time=null);
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @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 abstract function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time);
|
||||
|
||||
|
||||
public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
// theoretically locking_timeout should be checked against time_limit (max_execution_time)
|
||||
$start = microtime(true);
|
||||
$hadLock = null;
|
||||
while ($this->hasLock($smarty, $cached)) {
|
||||
$hadLock = true;
|
||||
if (microtime(true) - $start > $smarty->locking_timeout) {
|
||||
// abort waiting for lock release
|
||||
return false;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
return $hadLock;
|
||||
}
|
||||
|
||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
// check if lock exists
|
||||
return false;
|
||||
}
|
||||
|
||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
// create lock
|
||||
return true;
|
||||
}
|
||||
|
||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
// release lock
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load Cache Resource Handler
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param string $type name of the cache resource
|
||||
* @return Smarty_CacheResource Cache Resource Handler
|
||||
*/
|
||||
public static function load(Smarty $smarty, $type = null)
|
||||
{
|
||||
if (!isset($type)) {
|
||||
$type = $smarty->caching_type;
|
||||
}
|
||||
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cacheresource_handlers[$type])) {
|
||||
return $smarty->_cacheresource_handlers[$type];
|
||||
}
|
||||
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_cache_resources[$type])) {
|
||||
// do not cache these instances as they may vary from instance to instance
|
||||
return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
|
||||
}
|
||||
// try sysplugins dir
|
||||
if (isset(self::$sysplugins[$type])) {
|
||||
if (!isset(self::$resources[$type])) {
|
||||
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
|
||||
self::$resources[$type] = new $cache_resource_class();
|
||||
}
|
||||
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
|
||||
}
|
||||
// try plugins dir
|
||||
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
|
||||
if ($smarty->loadPlugin($cache_resource_class)) {
|
||||
if (!isset(self::$resources[$type])) {
|
||||
self::$resources[$type] = new $cache_resource_class();
|
||||
}
|
||||
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
|
||||
}
|
||||
// give up
|
||||
throw new SmartyException("Unable to load cache resource '{$type}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid Loaded Cache Files
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
*/
|
||||
public static function invalidLoadedCache(Smarty $smarty)
|
||||
{
|
||||
foreach ($smarty->template_objects as $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
$tpl->cached->valid = false;
|
||||
$tpl->cached->processed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
*
|
||||
* Cache Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Template_Cached {
|
||||
/**
|
||||
* Source Filepath
|
||||
* @var string
|
||||
*/
|
||||
public $filepath = false;
|
||||
|
||||
/**
|
||||
* Source Content
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* Source Timestamp
|
||||
* @var integer
|
||||
*/
|
||||
public $timestamp = false;
|
||||
|
||||
/**
|
||||
* Source Existance
|
||||
* @var boolean
|
||||
*/
|
||||
public $exists = false;
|
||||
|
||||
/**
|
||||
* Cache Is Valid
|
||||
* @var boolean
|
||||
*/
|
||||
public $valid = false;
|
||||
|
||||
/**
|
||||
* Cache was processed
|
||||
* @var boolean
|
||||
*/
|
||||
public $processed = false;
|
||||
|
||||
/**
|
||||
* CacheResource Handler
|
||||
* @var Smarty_CacheResource
|
||||
*/
|
||||
public $handler = null;
|
||||
|
||||
/**
|
||||
* Template Compile Id (Smarty_Internal_Template::$compile_id)
|
||||
* @var string
|
||||
*/
|
||||
public $compile_id = null;
|
||||
|
||||
/**
|
||||
* Template Cache Id (Smarty_Internal_Template::$cache_id)
|
||||
* @var string
|
||||
*/
|
||||
public $cache_id = null;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$_template->cached = $this;
|
||||
$smarty = $_template->smarty;
|
||||
|
||||
//
|
||||
// load resource handler
|
||||
//
|
||||
$this->handler = $handler = Smarty_CacheResource::load($smarty); // Note: prone to circular references
|
||||
|
||||
//
|
||||
// check if cache is valid
|
||||
//
|
||||
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
while (true) {
|
||||
$handler->populate($this, $_template);
|
||||
if ($this->timestamp === false || $smarty->force_compile || $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->cache_locking) {
|
||||
break;
|
||||
}
|
||||
if (!$this->handler->locked($_template->smarty, $this)) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
if ($this->valid) {
|
||||
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
||||
// load cache file for the following checks
|
||||
if ($smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($_template);
|
||||
}
|
||||
if($handler->process($_template, $this) === false) {
|
||||
$this->valid = false;
|
||||
} else {
|
||||
$this->processed = true;
|
||||
}
|
||||
if ($smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_cache($_template);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
|
||||
$this->valid = false;
|
||||
}
|
||||
if (!$this->valid && $_template->smarty->cache_locking) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this cache object to handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
* @return boolean success
|
||||
*/
|
||||
public function write(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if (!$_template->source->recompiled) {
|
||||
if ($this->handler->writeCachedContent($_template, $content)) {
|
||||
$this->timestamp = time();
|
||||
$this->exists = true;
|
||||
$this->valid = true;
|
||||
if ($_template->smarty->cache_locking) {
|
||||
$this->handler->releaseLock($_template->smarty, $this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Handler API
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource {
|
||||
|
||||
/**
|
||||
* fetch cached content and its modification time from data source
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $content cached content
|
||||
* @param integer $mtime cache modification timestamp (epoch)
|
||||
* @return void
|
||||
*/
|
||||
protected abstract function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime);
|
||||
|
||||
/**
|
||||
* Fetch cached content'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 cached content.}}
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
||||
*/
|
||||
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to cache
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer|null $exp_time seconds till expiration or null
|
||||
* @param string $content content to cache
|
||||
* @return boolean success
|
||||
*/
|
||||
protected abstract function save($id, $name, $cache_id, $compile_id, $exp_time, $content);
|
||||
|
||||
/**
|
||||
* Delete content from cache
|
||||
*
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer|null $exp_time seconds till expiration time in seconds or null
|
||||
* @return integer number of deleted caches
|
||||
*/
|
||||
protected abstract function delete($name, $cache_id, $compile_id, $exp_time);
|
||||
|
||||
/**
|
||||
* populate Cached Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
|
||||
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;
|
||||
|
||||
$cached->filepath = sha1($cached->source->filepath . $_cache_id . $_compile_id);
|
||||
$this->populateTimestamp($cached);
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Cached Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $source cached object
|
||||
* @return void
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||
{
|
||||
$mtime = $this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
|
||||
if ($mtime !== null) {
|
||||
$cached->timestamp = $mtime;
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
return;
|
||||
}
|
||||
$timestamp = null;
|
||||
$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $timestamp);
|
||||
$cached->timestamp = isset($timestamp) ? $timestamp : false;
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the cached template and process the header
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return booelan true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
|
||||
{
|
||||
if (!$cached) {
|
||||
$cached = $_template->cached;
|
||||
}
|
||||
$content = $cached->content ? $cached->content : null;
|
||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||
if ($content === null || !$timestamp) {
|
||||
$this->fetch(
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$content,
|
||||
$timestamp
|
||||
);
|
||||
}
|
||||
if (isset($content)) {
|
||||
$_smarty_tpl = $_template;
|
||||
eval("?>" . $content);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the rendered template output to cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
* @return boolean success
|
||||
*/
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
return $this->save(
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$_template->properties['cache_lifetime'],
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param integer $exp_time expiration time (number of seconds, not timestamp)
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
public function clearAll(Smarty $smarty, $exp_time=null)
|
||||
{
|
||||
$this->cache = array();
|
||||
return $this->delete(null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @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)
|
||||
{
|
||||
$this->cache = array();
|
||||
return $this->delete($resource_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is cache is locked for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return booelan true or false if cache is locked
|
||||
*/
|
||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$id = $cached->filepath;
|
||||
$name = $cached->source->name . '.lock';
|
||||
|
||||
$mtime = $this->fetchTimestamp($id, $name, null, null);
|
||||
if ($mtime === null) {
|
||||
$this->fetch($id, $name, null, null, $content, $mtime);
|
||||
}
|
||||
|
||||
return $mtime && time() - $mtime < $smarty->locking_timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock cache for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
*/
|
||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = true;
|
||||
|
||||
$id = $cached->filepath;
|
||||
$name = $cached->source->name . '.lock';
|
||||
$this->save($id, $name, null, null, $smarty->locking_timeout, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock cache for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
*/
|
||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = false;
|
||||
|
||||
$id = $cached->filepath;
|
||||
$name = $cached->source->name . '.lock';
|
||||
$this->delete($name, null, null, null);
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,463 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Cache Handler Base for Key/Value Storage Implementations
|
||||
*
|
||||
* This class implements the functionality required to use simple key/value stores
|
||||
* for hierarchical cache groups. key/value stores like memcache or APC do not support
|
||||
* wildcards in keys, therefore a cache group cannot be cleared like "a|*" - which
|
||||
* is no problem to filesystem and RDBMS implementations.
|
||||
*
|
||||
* This implementation is based on the concept of invalidation. While one specific cache
|
||||
* can be identified and cleared, any range of caches cannot be identified. For this reason
|
||||
* each level of the cache group hierarchy can have its own value in the store. These values
|
||||
* are nothing but microtimes, telling us when a particular cache group was cleared for the
|
||||
* last time. These keys are evaluated for every cache read to determine if the cache has
|
||||
* been invalidated since it was created and should hence be treated as inexistent.
|
||||
*
|
||||
* Although deep hierarchies are possible, they are not recommended. Try to keep your
|
||||
* cache groups as shallow as possible. Anything up 3-5 parents should be ok. So
|
||||
* »a|b|c« is a good depth where »a|b|c|d|e|f|g|h|i|j|k« isn't. Try to join correlating
|
||||
* cache groups: if your cache groups look somewhat like »a|b|$page|$items|$whatever«
|
||||
* consider using »a|b|c|$page-$items-$whatever« instead.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
||||
|
||||
/**
|
||||
* cache for contents
|
||||
* @var array
|
||||
*/
|
||||
protected $contents = array();
|
||||
/**
|
||||
* cache for timestamps
|
||||
* @var array
|
||||
*/
|
||||
protected $timestamps = array();
|
||||
|
||||
/**
|
||||
* populate Cached Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$cached->filepath = $_template->source->uid
|
||||
. '#' . $this->sanitize($cached->source->name)
|
||||
. '#' . $this->sanitize($cached->cache_id)
|
||||
. '#' . $this->sanitize($cached->compile_id);
|
||||
|
||||
$this->populateTimestamp($cached);
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Cached Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return void
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||
{
|
||||
if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) {
|
||||
return;
|
||||
}
|
||||
$cached->content = $content;
|
||||
$cached->timestamp = (int) $timestamp;
|
||||
$cached->exists = $cached->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the cached template and process the header
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return booelan true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
|
||||
{
|
||||
if (!$cached) {
|
||||
$cached = $_template->cached;
|
||||
}
|
||||
$content = $cached->content ? $cached->content : null;
|
||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||
if ($content === null || !$timestamp) {
|
||||
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isset($content)) {
|
||||
$_smarty_tpl = $_template;
|
||||
eval("?>" . $content);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the rendered template output to cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
* @return boolean success
|
||||
*/
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
$this->addMetaTimestamp($content);
|
||||
return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache
|
||||
*
|
||||
* {@internal the $exp_time argument is ignored altogether }}
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param integer $exp_time expiration time [being ignored]
|
||||
* @return integer number of cache files deleted [always -1]
|
||||
* @uses purge() to clear the whole store
|
||||
* @uses invalidate() to mark everything outdated if purge() is inapplicable
|
||||
*/
|
||||
public function clearAll(Smarty $smarty, $exp_time=null)
|
||||
{
|
||||
if (!$this->purge()) {
|
||||
$this->invalidate(null);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* {@internal the $exp_time argument is ignored altogether}}
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer $exp_time expiration time [being ignored]
|
||||
* @return integer number of cache files deleted [always -1]
|
||||
* @uses buildCachedFilepath() to generate the CacheID
|
||||
* @uses invalidate() to mark CacheIDs parent chain as outdated
|
||||
* @uses delete() to remove CacheID from cache
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
|
||||
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
|
||||
$this->delete(array($cid));
|
||||
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* Get template's unique ID
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @return string filepath of cache file
|
||||
*/
|
||||
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
|
||||
{
|
||||
$uid = '';
|
||||
if (isset($resource_name)) {
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
if ($tpl->source->exists) {
|
||||
$uid = $tpl->source->uid;
|
||||
}
|
||||
|
||||
// remove from template cache
|
||||
if ($smarty->allow_ambiguous_resources) {
|
||||
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
|
||||
} else {
|
||||
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
unset($smarty->template_objects[$_templateId]);
|
||||
}
|
||||
return $uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize CacheID components
|
||||
*
|
||||
* @param string $string CacheID component to sanitize
|
||||
* @return string sanitized CacheID component
|
||||
*/
|
||||
protected function sanitize($string)
|
||||
{
|
||||
// some poeple smoke bad weed
|
||||
$string = trim($string, '|');
|
||||
if (!$string) {
|
||||
return null;
|
||||
}
|
||||
return preg_replace('#[^\w\|]+#S', '_', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and prepare a cache object.
|
||||
*
|
||||
* @param string $cid CacheID to fetch
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $content cached content
|
||||
* @param integer &$timestamp cached timestamp (epoch)
|
||||
* @param string $resource_uid resource's uid
|
||||
* @return boolean success
|
||||
*/
|
||||
protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
|
||||
{
|
||||
$t = $this->read(array($cid));
|
||||
$content = !empty($t[$cid]) ? $t[$cid] : null;
|
||||
$timestamp = null;
|
||||
|
||||
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
|
||||
$invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
|
||||
if ($invalidated > $timestamp) {
|
||||
$timestamp = null;
|
||||
$content = null;
|
||||
}
|
||||
}
|
||||
|
||||
return !!$content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add current microtime to the beginning of $cache_content
|
||||
*
|
||||
* {@internal the header uses 8 Bytes, the first 4 Bytes are the seconds, the second 4 Bytes are the microseconds}}
|
||||
*
|
||||
* @param string &$content the content to be cached
|
||||
*/
|
||||
protected function addMetaTimestamp(&$content)
|
||||
{
|
||||
$mt = explode(" ", microtime());
|
||||
$ts = pack("NN", $mt[1], (int) ($mt[0] * 100000000));
|
||||
$content = $ts . $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the timestamp the $content was cached
|
||||
*
|
||||
* @param string &$content the cached content
|
||||
* @return float the microtime the content was cached
|
||||
*/
|
||||
protected function getMetaTimestamp(&$content)
|
||||
{
|
||||
$s = unpack("N", substr($content, 0, 4));
|
||||
$m = unpack("N", substr($content, 4, 4));
|
||||
$content = substr($content, 8);
|
||||
return $s[1] + ($m[1] / 100000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate CacheID
|
||||
*
|
||||
* @param string $cid CacheID
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $resource_uid source's uid
|
||||
* @return void
|
||||
*/
|
||||
protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||
{
|
||||
$now = microtime(true);
|
||||
$key = null;
|
||||
// invalidate everything
|
||||
if (!$resource_name && !$cache_id && !$compile_id) {
|
||||
$key = 'IVK#ALL';
|
||||
}
|
||||
// invalidate all caches by template
|
||||
else if ($resource_name && !$cache_id && !$compile_id) {
|
||||
$key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
|
||||
}
|
||||
// invalidate all caches by cache group
|
||||
else if (!$resource_name && $cache_id && !$compile_id) {
|
||||
$key = 'IVK#CACHE#' . $this->sanitize($cache_id);
|
||||
}
|
||||
// invalidate all caches by compile id
|
||||
else if (!$resource_name && !$cache_id && $compile_id) {
|
||||
$key = 'IVK#COMPILE#' . $this->sanitize($compile_id);
|
||||
}
|
||||
// invalidate by combination
|
||||
else {
|
||||
$key = 'IVK#CID#' . $cid;
|
||||
}
|
||||
$this->write(array($key => $now));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the latest timestamp known to the invalidation chain
|
||||
*
|
||||
* @param string $cid CacheID to determine latest invalidation timestamp of
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $resource_uid source's filepath
|
||||
* @return float the microtime the CacheID was invalidated
|
||||
*/
|
||||
protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||
{
|
||||
// abort if there is no CacheID
|
||||
if (false && !$cid) {
|
||||
return 0;
|
||||
}
|
||||
// abort if there are no InvalidationKeys to check
|
||||
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// there are no InValidationKeys
|
||||
if (!($values = $this->read($_cid))) {
|
||||
return 0;
|
||||
}
|
||||
// make sure we're dealing with floats
|
||||
$values = array_map('floatval', $values);
|
||||
return max($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a CacheID into the list of applicable InvalidationKeys.
|
||||
*
|
||||
* Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
|
||||
*
|
||||
* @param string $cid CacheID to translate
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $resource_uid source's filepath
|
||||
* @return array list of InvalidationKeys
|
||||
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
|
||||
*/
|
||||
protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
|
||||
{
|
||||
$t = array('IVK#ALL');
|
||||
$_name = $_compile = '#';
|
||||
if ($resource_name) {
|
||||
$_name .= $resource_uid . '#' . $this->sanitize($resource_name);
|
||||
$t[] = 'IVK#TEMPLATE' . $_name;
|
||||
}
|
||||
if ($compile_id) {
|
||||
$_compile .= $this->sanitize($compile_id);
|
||||
$t[] = 'IVK#COMPILE' . $_compile;
|
||||
}
|
||||
$_name .= '#';
|
||||
// some poeple smoke bad weed
|
||||
$cid = trim($cache_id, '|');
|
||||
if (!$cid) {
|
||||
return $t;
|
||||
}
|
||||
$i = 0;
|
||||
while (true) {
|
||||
// determine next delimiter position
|
||||
$i = strpos($cid, '|', $i);
|
||||
// add complete CacheID if there are no more delimiters
|
||||
if ($i === false) {
|
||||
$t[] = 'IVK#CACHE#' . $cid;
|
||||
$t[] = 'IVK#CID' . $_name . $cid . $_compile;
|
||||
$t[] = 'IVK#CID' . $_name . $_compile;
|
||||
break;
|
||||
}
|
||||
$part = substr($cid, 0, $i);
|
||||
// add slice to list
|
||||
$t[] = 'IVK#CACHE#' . $part;
|
||||
$t[] = 'IVK#CID' . $_name . $part . $_compile;
|
||||
// skip past delimiter position
|
||||
$i++;
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is cache is locked for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return booelan true or false if cache is locked
|
||||
*/
|
||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$key = 'LOCK#' . $cached->filepath;
|
||||
$data = $this->read(array($key));
|
||||
return $data && time() - $data[$key] < $smarty->locking_timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock cache for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
*/
|
||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = true;
|
||||
$key = 'LOCK#' . $cached->filepath;
|
||||
$this->write(array($key => time()), $smarty->locking_timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock cache for this template
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
*/
|
||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = false;
|
||||
$key = 'LOCK#' . $cached->filepath;
|
||||
$this->delete(array($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read values for a set of keys from cache
|
||||
*
|
||||
* @param array $keys list of keys to fetch
|
||||
* @return array list of values with the given keys used as indexes
|
||||
*/
|
||||
protected abstract function read(array $keys);
|
||||
|
||||
/**
|
||||
* Save values for a set of keys to cache
|
||||
*
|
||||
* @param array $keys list of values to save
|
||||
* @param int $expire expiration time
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected abstract function write(array $keys, $expire=null);
|
||||
|
||||
/**
|
||||
* Remove values from cache
|
||||
*
|
||||
* @param array $keys list of keys to delete
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected abstract function delete(array $keys);
|
||||
|
||||
/**
|
||||
* Remove *all* values from cache
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function purge()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
*
|
||||
* Meta Data Container for Config Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*
|
||||
* @property string $content
|
||||
* @property int $timestamp
|
||||
* @property bool $exists
|
||||
*/
|
||||
class Smarty_Config_Source extends Smarty_Template_Source {
|
||||
|
||||
/**
|
||||
* create Config 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 config_resource
|
||||
* @param string $type type of resource
|
||||
* @param string $name resource name
|
||||
* @param string $unique_resource unqiue resource name
|
||||
*/
|
||||
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
|
||||
{
|
||||
$this->handler = $handler; // Note: prone to circular references
|
||||
|
||||
// Note: these may be ->config_compiler_class etc in the future
|
||||
//$this->config_compiler_class = $handler->config_compiler_class;
|
||||
//$this->config_lexer_class = $handler->config_lexer_class;
|
||||
//$this->config_parser_class = $handler->config_parser_class;
|
||||
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
$this->unique_resource = $unique_resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic setter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
* @param mixed $value newly assigned value (not check for correct type)
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'content':
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->$property_name = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SmartyException("invalid config property '$property_name'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic getter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __get($property_name)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->handler->populateTimestamp($this);
|
||||
return $this->$property_name;
|
||||
|
||||
case 'content':
|
||||
return $this->content = $this->handler->getContent($this);
|
||||
|
||||
default:
|
||||
throw new SmartyException("config property '$property_name' does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,90 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile extend
|
||||
*
|
||||
* Compiles the {extends} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile extend
|
||||
*
|
||||
* Compiles the {extends} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile extend Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile extend Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Compiles code for the {extends} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {extends} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->_rdl = preg_quote($this->smarty->right_delimiter);
|
||||
$this->_ldl = preg_quote($this->smarty->left_delimiter);
|
||||
$filepath = $compiler->template->getTemplateFilepath();
|
||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||
$this->_rdl = preg_quote($compiler->smarty->right_delimiter);
|
||||
$this->_ldl = preg_quote($compiler->smarty->left_delimiter);
|
||||
$filepath = $compiler->template->source->filepath;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$include_file = null;
|
||||
if (strpos($_attr['file'],'$_tmp') !== false) {
|
||||
$this->compiler->trigger_template_error('illegal value for file attribute', $this->compiler->lex->taglineno);
|
||||
if (strpos($_attr['file'], '$_tmp') !== false) {
|
||||
$compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
|
||||
}
|
||||
eval('$include_file = ' . $_attr['file'] . ';');
|
||||
// create template object
|
||||
$_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template);
|
||||
$_template = new $compiler->smarty->template_class($include_file, $compiler->smarty, $compiler->template);
|
||||
// save file dependency
|
||||
if (in_array($_template->resource_type,array('eval','string'))) {
|
||||
$template_sha1 = sha1($include_file);
|
||||
} else {
|
||||
$template_sha1 = sha1($_template->getTemplateFilepath());
|
||||
}
|
||||
if (isset($_is_stringy[$_template->source->type])) {
|
||||
$template_sha1 = sha1($include_file);
|
||||
} else {
|
||||
$template_sha1 = sha1($_template->source->filepath);
|
||||
}
|
||||
if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
|
||||
$this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"",$compiler->lex->line-1);
|
||||
$compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1);
|
||||
}
|
||||
$compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp(),$_template->resource_type);
|
||||
$_content = substr($compiler->template->template_source,$compiler->lex->counter-1);
|
||||
$compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
|
||||
$_content = substr($compiler->template->source->content, $compiler->lex->counter - 1);
|
||||
if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
|
||||
preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
|
||||
$this->compiler->trigger_template_error('unmatched {block} {/block} pairs');
|
||||
preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
|
||||
$compiler->trigger_template_error('unmatched {block} {/block} pairs');
|
||||
}
|
||||
preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
|
||||
preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
|
||||
$_result_count = count($_result[0]);
|
||||
$_start = 0;
|
||||
while ($_start < $_result_count) {
|
||||
while ($_start+1 < $_result_count) {
|
||||
$_end = 0;
|
||||
$_level = 1;
|
||||
if (substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') {
|
||||
$_start++;
|
||||
continue;
|
||||
}
|
||||
while ($_level != 0) {
|
||||
$_end++;
|
||||
if (substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') {
|
||||
continue;
|
||||
}
|
||||
if (!strpos($_result[0][$_start + $_end][0], '/')) {
|
||||
$_level++;
|
||||
} else {
|
||||
$_level--;
|
||||
}
|
||||
}
|
||||
$_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
|
||||
$_block_content = str_replace($compiler->smarty->left_delimiter . '$smarty.block.parent' . $compiler->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
|
||||
Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
|
||||
$_start = $_start + $_end + 1;
|
||||
}
|
||||
$compiler->template->template_source = $_template->getTemplateSource();
|
||||
$compiler->template->template_filepath = $_template->getTemplateFilepath();
|
||||
if ($_template->source->type == 'extends') {
|
||||
$_template->block_data = $compiler->template->block_data;
|
||||
}
|
||||
$compiler->template->source->content = $_template->source->content;
|
||||
if ($_template->source->type == 'extends') {
|
||||
$compiler->template->block_data = $_template->block_data;
|
||||
foreach ($_template->source->components as $key => $component) {
|
||||
$compiler->template->properties['file_dependency'][$key] = array($component->filepath, $component->timestamp, $component->type);
|
||||
}
|
||||
}
|
||||
$compiler->template->source->filepath = $_template->source->filepath;
|
||||
$compiler->abort_and_recompile = true;
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,179 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile If
|
||||
*
|
||||
* Compiles the {if} {else} {elseif} {/if} tags
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile If
|
||||
*
|
||||
* Compiles the {if} {else} {elseif} {/if} tags
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile If Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile If Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$this->_open_tag('if',array(1,$this->compiler->nocache));
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->openTag($compiler, 'if', array(1, $compiler->nocache));
|
||||
// must whole block be nocache ?
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
if (!array_key_exists("if condition",$parameter)) {
|
||||
$compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
if (is_array($parameter['if condition'])) {
|
||||
if ($this->compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
|
||||
} else {
|
||||
$_output = "<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
}
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php if ({$parameter['if condition']}){?>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Else Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Else Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {else} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {else} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
|
||||
$this->_open_tag('else',array($nesting,$compiler->tag_nocache));
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
||||
|
||||
return "<?php }else{ ?>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile ElseIf Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile ElseIf Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {elseif} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {elseif} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
|
||||
|
||||
if (is_array($parameter['if condition'])) {
|
||||
$condition_by_assign = true;
|
||||
if ($this->compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
} else {
|
||||
$condition_by_assign = false;
|
||||
}
|
||||
|
||||
if (empty($this->compiler->prefix_code)) {
|
||||
if ($condition_by_assign) {
|
||||
$this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php }else{ if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
|
||||
} else {
|
||||
$_output = "<?php }else{ \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
$this->_open_tag('elseif', array($nesting, $compiler->tag_nocache));
|
||||
return "<?php }elseif({$parameter['if condition']}){?>";
|
||||
}
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
|
||||
if (!array_key_exists("if condition",$parameter)) {
|
||||
$compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
if (is_array($parameter['if condition'])) {
|
||||
$condition_by_assign = true;
|
||||
if ($compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
} else {
|
||||
$condition_by_assign = false;
|
||||
}
|
||||
|
||||
if (empty($compiler->prefix_code)) {
|
||||
if ($condition_by_assign) {
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php }else{ if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . "){?>";
|
||||
} else {
|
||||
$_output = "<?php }else{ if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . "){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
||||
return "<?php }elseif({$parameter['if condition']}){?>";
|
||||
}
|
||||
} else {
|
||||
$tmp = '';
|
||||
foreach ($this->compiler->prefix_code as $code) $tmp .= $code;
|
||||
$this->compiler->prefix_code = array();
|
||||
$this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php }else{?>{$tmp}<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
|
||||
} else {
|
||||
$_output = "<?php }else{?>{$tmp}<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php }else{?>{$tmp}<?php if ({$parameter['if condition']}){?>";
|
||||
}
|
||||
foreach ($compiler->prefix_code as $code)
|
||||
$tmp .= $code;
|
||||
$compiler->prefix_code = array();
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php }else{?>{$tmp}<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . "){?>";
|
||||
} else {
|
||||
$_output = "<?php }else{?>{$tmp}<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . "){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php }else{?>{$tmp}<?php if ({$parameter['if condition']}){?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Ifclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
list($nesting, $this->compiler->nocache) = $this->_close_tag(array('if', 'else', 'elseif'));
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
|
||||
$tmp = '';
|
||||
for ($i = 0; $i < $nesting ; $i++) $tmp .= '}';
|
||||
for ($i = 0; $i < $nesting; $i++) {
|
||||
$tmp .= '}';
|
||||
}
|
||||
return "<?php {$tmp}?>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,63 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Nocache
|
||||
*
|
||||
* Compiles the {nocache} {/nocache} tags
|
||||
* Compiles the {nocache} {/nocache} tags.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Nocache Class
|
||||
* Smarty Internal Plugin Compile Nocache Classv
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {nocache} tag
|
||||
*
|
||||
* This tag does not generate compiled output. It only sets a compiler flag
|
||||
* @param array $args array with attributes from parser
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
}
|
||||
// enter nocache mode
|
||||
$this->compiler->nocache = true;
|
||||
$compiler->nocache = true;
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = false;
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Nocacheclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/nocache} tag
|
||||
*
|
||||
* This tag does not generate compiled output. It only sets a compiler flag
|
||||
* @param array $args array with attributes from parser
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// leave nocache mode
|
||||
$this->compiler->nocache = false;
|
||||
$compiler->nocache = false;
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = false;
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Setfilter
|
||||
*
|
||||
* Compiles code for setfilter tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Setfilter Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for setfilter tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$compiler->variable_filter_stack[] = $compiler->template->variable_filters;
|
||||
$compiler->template->variable_filters = $parameter['modifier_list'];
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Setfilterclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/setfilter} tag
|
||||
*
|
||||
* This tag does not generate compiled output. It resets variable filter.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// reset variable filter to previous state
|
||||
if (count($compiler->variable_filter_stack)) {
|
||||
$compiler->template->variable_filters = array_pop($compiler->variable_filter_stack);
|
||||
} else {
|
||||
$compiler->template->variable_filters = array();
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,82 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile While
|
||||
*
|
||||
* Compiles the {while} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile While
|
||||
*
|
||||
* Compiles the {while} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile While Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile While Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$this->_open_tag('while', $this->compiler->nocache);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->openTag($compiler, 'while', $compiler->nocache);
|
||||
|
||||
if (!array_key_exists("if condition",$parameter)) {
|
||||
$compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
// maybe nocache because of nocache variables
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
if (is_array($parameter['if condition'])) {
|
||||
if ($this->compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
|
||||
$_output .= "while (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . "){?>";
|
||||
} else {
|
||||
$_output = "<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";
|
||||
$_output .= "while (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
}
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . "){?>";
|
||||
}
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php while ({$parameter['if condition']}){?>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Whileclose Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Whileclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the {/while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$this->compiler->nocache = $this->_close_tag(array('while'));
|
||||
$compiler->nocache = $this->closeTag($compiler, array('while'));
|
||||
return "<?php }?>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,170 +1,206 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Debug
|
||||
*
|
||||
* Class to collect data for the Smarty Debugging Consol
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Debug
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Debug
|
||||
*
|
||||
* Class to collect data for the Smarty Debugging Consol
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Debug
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Debug Class
|
||||
*/
|
||||
* Smarty Internal Plugin Debug Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Debug
|
||||
*/
|
||||
class Smarty_Internal_Debug extends Smarty_Internal_Data {
|
||||
// template data
|
||||
static $template_data = array();
|
||||
|
||||
/**
|
||||
* Start logging of compile time
|
||||
*/
|
||||
public static function start_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
/**
|
||||
* template data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $template_data = array();
|
||||
|
||||
/**
|
||||
* Start logging of compile time
|
||||
*
|
||||
* @param object $template
|
||||
*/
|
||||
public static function start_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*
|
||||
* @param object $template
|
||||
*/
|
||||
public static function end_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging of render time
|
||||
*
|
||||
* @param object $template
|
||||
*/
|
||||
public static function start_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*
|
||||
* @param object $template
|
||||
*/
|
||||
public static function end_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*/
|
||||
public static function end_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
/**
|
||||
* Start logging of cache time
|
||||
*
|
||||
* @param object $template cached template
|
||||
*/
|
||||
public static function start_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging of render time
|
||||
*/
|
||||
public static function start_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
/**
|
||||
* End logging of cache time
|
||||
*
|
||||
* @param object $template cached template
|
||||
*/
|
||||
public static function end_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*/
|
||||
public static function end_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
/**
|
||||
* Opens a window for the Smarty Debugging Consol and display the data
|
||||
*
|
||||
* @param Smarty_Internal_Template|Smarty $obj object to debug
|
||||
*/
|
||||
public static function display_debug($obj)
|
||||
{
|
||||
// prepare information of assigned variables
|
||||
$ptr = self::get_debug_vars($obj);
|
||||
if ($obj instanceof Smarty) {
|
||||
$smarty = clone $obj;
|
||||
} else {
|
||||
$smarty = clone $obj->smarty;
|
||||
}
|
||||
$_assigned_vars = $ptr->tpl_vars;
|
||||
ksort($_assigned_vars);
|
||||
$_config_vars = $ptr->config_vars;
|
||||
ksort($_config_vars);
|
||||
$smarty->registered_filters = array();
|
||||
$smarty->autoload_filters = array();
|
||||
$smarty->default_modifiers = array();
|
||||
$smarty->force_compile = false;
|
||||
$smarty->left_delimiter = '{';
|
||||
$smarty->right_delimiter = '}';
|
||||
$smarty->debugging = false;
|
||||
$smarty->force_compile = false;
|
||||
$_template = new Smarty_Internal_Template($smarty->debug_tpl, $smarty);
|
||||
$_template->caching = false;
|
||||
$_template->disableSecurity();
|
||||
$_template->cache_id = null;
|
||||
$_template->compile_id = null;
|
||||
if ($obj instanceof Smarty_Internal_Template) {
|
||||
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
|
||||
}
|
||||
if ($obj instanceof Smarty) {
|
||||
$_template->assign('template_data', self::$template_data);
|
||||
} else {
|
||||
$_template->assign('template_data', null);
|
||||
}
|
||||
$_template->assign('assigned_vars', $_assigned_vars);
|
||||
$_template->assign('config_vars', $_config_vars);
|
||||
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
|
||||
echo $_template->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging of cache time
|
||||
*/
|
||||
public static function start_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = microtime(true);
|
||||
}
|
||||
/**
|
||||
* Recursively gets variables from all template/data scopes
|
||||
*
|
||||
* @param Smarty_Internal_Template|Smarty_Data $obj object to debug
|
||||
* @return StdClass
|
||||
*/
|
||||
public static function get_debug_vars($obj)
|
||||
{
|
||||
$config_vars = $obj->config_vars;
|
||||
$tpl_vars = array();
|
||||
foreach ($obj->tpl_vars as $key => $var) {
|
||||
$tpl_vars[$key] = clone $var;
|
||||
if ($obj instanceof Smarty_Internal_Template) {
|
||||
$tpl_vars[$key]->scope = $obj->source->type . ':' . $obj->source->name;
|
||||
} elseif ($obj instanceof Smarty_Data) {
|
||||
$tpl_vars[$key]->scope = 'Data object';
|
||||
} else {
|
||||
$tpl_vars[$key]->scope = 'Smarty root';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of cache time
|
||||
*/
|
||||
public static function end_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
/**
|
||||
* Opens a window for the Smarty Debugging Consol and display the data
|
||||
*/
|
||||
public static function display_debug($obj)
|
||||
{
|
||||
// prepare information of assigned variables
|
||||
$ptr = self::get_debug_vars($obj);
|
||||
if ($obj instanceof Smarty) {
|
||||
$smarty = $obj;
|
||||
} else {
|
||||
$smarty = $obj->smarty;
|
||||
}
|
||||
$_assigned_vars = $ptr->tpl_vars;
|
||||
ksort($_assigned_vars);
|
||||
$_config_vars = $ptr->config_vars;
|
||||
ksort($_config_vars);
|
||||
$ldelim = $smarty->left_delimiter;
|
||||
$rdelim = $smarty->right_delimiter;
|
||||
$smarty->left_delimiter = '{';
|
||||
$smarty->right_delimiter = '}';
|
||||
$_template = new Smarty_Internal_Template ($smarty->debug_tpl, $smarty);
|
||||
$_template->caching = false;
|
||||
$_template->force_compile = false;
|
||||
$_template->disableSecurity();
|
||||
$_template->cache_id = null;
|
||||
$_template->compile_id = null;
|
||||
if ($obj instanceof Smarty_Internal_Template) {
|
||||
$_template->assign('template_name',$obj->resource_type.':'.$obj->resource_name);
|
||||
}
|
||||
if ($obj instanceof Smarty) {
|
||||
$_template->assign('template_data', self::$template_data);
|
||||
} else {
|
||||
$_template->assign('template_data', null);
|
||||
}
|
||||
$_template->assign('assigned_vars', $_assigned_vars);
|
||||
$_template->assign('config_vars', $_config_vars);
|
||||
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
|
||||
echo $_template->getRenderedTemplate();
|
||||
$smarty->left_delimiter = $ldelim;
|
||||
$smarty->right_delimiter = $rdelim;
|
||||
}
|
||||
/*
|
||||
* Recursively gets variables from all template/data scopes
|
||||
*/
|
||||
public static function get_debug_vars($obj)
|
||||
{
|
||||
$config_vars = $obj->config_vars;
|
||||
$tpl_vars = array();
|
||||
foreach ($obj->tpl_vars as $key => $var) {
|
||||
$tpl_vars[$key] = clone $var;
|
||||
if ($obj instanceof Smarty_Internal_Template) {
|
||||
$tpl_vars[$key]->scope = $obj->resource_type.':'.$obj->resource_name;
|
||||
} elseif ($obj instanceof Smarty_Data) {
|
||||
$tpl_vars[$key]->scope = 'Data object';
|
||||
} else {
|
||||
$tpl_vars[$key]->scope = 'Smarty root';
|
||||
}
|
||||
}
|
||||
if (isset($obj->parent)) {
|
||||
$parent = self::get_debug_vars($obj->parent);
|
||||
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
|
||||
$config_vars = array_merge($parent->config_vars, $config_vars);
|
||||
} else {
|
||||
foreach (Smarty::$global_tpl_vars as $name => $var) {
|
||||
if (!array_key_exists($name, $tpl_vars)) {
|
||||
$clone = clone $var;
|
||||
$clone->scope = 'Global';
|
||||
$tpl_vars[$name] = $clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
|
||||
}
|
||||
|
||||
if (isset($obj->parent)) {
|
||||
$parent = self::get_debug_vars($obj->parent);
|
||||
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
|
||||
$config_vars = array_merge($parent->config_vars, $config_vars);
|
||||
} else {
|
||||
foreach (Smarty::$global_tpl_vars as $name => $var) {
|
||||
if (!array_key_exists($name, $tpl_vars)) {
|
||||
$clone = clone $var;
|
||||
$clone->scope = 'Global';
|
||||
$tpl_vars[$name] = $clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
|
||||
}
|
||||
/**
|
||||
* Return key into $template_data for template
|
||||
*
|
||||
* @param object $template template object
|
||||
* @return string key into $template_data
|
||||
*/
|
||||
private static function get_key($template)
|
||||
{
|
||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||
// calculate Uid if not already done
|
||||
if ($template->source->uid == '') {
|
||||
$template->source->filepath;
|
||||
}
|
||||
$key = $template->source->uid;
|
||||
if (isset(self::$template_data[$key])) {
|
||||
return $key;
|
||||
} else {
|
||||
if (isset($_is_stringy[$template->source->type])) {
|
||||
self::$template_data[$key]['name'] = '\''.substr($template->source->name,0,25).'...\'';
|
||||
} else {
|
||||
self::$template_data[$key]['name'] = $template->source->filepath;
|
||||
}
|
||||
self::$template_data[$key]['compile_time'] = 0;
|
||||
self::$template_data[$key]['render_time'] = 0;
|
||||
self::$template_data[$key]['cache_time'] = 0;
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get_key
|
||||
*/
|
||||
static function get_key($template)
|
||||
{
|
||||
// calculate Uid if not already done
|
||||
if ($template->templateUid == '') {
|
||||
$template->getTemplateFilepath();
|
||||
}
|
||||
$key = $template->templateUid;
|
||||
if (isset(self::$template_data[$key])) {
|
||||
return $key;
|
||||
} else {
|
||||
self::$template_data[$key]['name'] = $template->getTemplateFilepath();
|
||||
self::$template_data[$key]['compile_time'] = 0;
|
||||
self::$template_data[$key]['render_time'] = 0;
|
||||
self::$template_data[$key]['cache_time'] = 0;
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Filter
|
||||
*
|
||||
* External Smarty filter methods
|
||||
*
|
||||
* @package Smarty
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for filter methods
|
||||
*/
|
||||
class Smarty_Internal_Filter {
|
||||
|
||||
function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
/**
|
||||
* Registers a filter function
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param callback $callback
|
||||
*/
|
||||
public function registerFilter($type, $callback)
|
||||
{
|
||||
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a filter function
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param callback $callback
|
||||
*/
|
||||
public function unregisterFilter($type, $callback)
|
||||
{
|
||||
$name = $this->_get_filter_name($callback);
|
||||
if(isset($this->smarty->registered_filters[$type][$name])) {
|
||||
unset($this->smarty->registered_filters[$type][$name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return internal filter name
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
public function _get_filter_name($function_name)
|
||||
{
|
||||
if (is_array($function_name)) {
|
||||
$_class_name = (is_object($function_name[0]) ?
|
||||
get_class($function_name[0]) : $function_name[0]);
|
||||
return $_class_name . '_' . $function_name[1];
|
||||
} else {
|
||||
return $function_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* load a filter of specified type and name
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param string $name filter name
|
||||
* @return bool
|
||||
*/
|
||||
function loadFilter($type, $name)
|
||||
{
|
||||
$_plugin = "smarty_{$type}filter_{$name}";
|
||||
$_filter_name = $_plugin;
|
||||
if ($this->smarty->loadPlugin($_plugin)) {
|
||||
if (class_exists($_plugin, false)) {
|
||||
$_plugin = array($_plugin, 'execute');
|
||||
}
|
||||
if (is_callable($_plugin)) {
|
||||
return $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("{$type}filter \"{$name}\" not callable");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue