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 '';
|
||||
}
|
||||
|
||||
?>
|
@ -1,31 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_words modifier plugin
|
||||
*
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: count_words<br>
|
||||
* Purpose: count the number of words in a text
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_count_words($params, $compiler)
|
||||
{
|
||||
// mb_ functions available?
|
||||
if (function_exists('mb_strlen')) {
|
||||
return '((mb_detect_encoding(' . $params[0] . ', \'UTF-8, ISO-8859-1\') === \'UTF-8\') ? preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp) : preg_match_all(\'#\w+#\',' . $params[0] . ', $tmp))';
|
||||
} else {
|
||||
return 'str_word_count(' . $params[0] . ')';
|
||||
}
|
||||
}
|
||||
{
|
||||
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||
// return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)';
|
||||
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
|
||||
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)';
|
||||
}
|
||||
// no MBString fallback
|
||||
return 'str_word_count(' . $params[0] . ')';
|
||||
}
|
||||
|
||||
?>
|
@ -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] . ')';
|
||||
}
|
||||
|
||||
?>
|
@ -1,26 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty string_format modifier plugin
|
||||
*
|
||||
*
|
||||
* Type: modifier<br>
|
||||
* Name: string_format<br>
|
||||
* Purpose: format strings via sprintf
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
* @param array $params parameters
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_string_format($params, $compiler)
|
||||
{
|
||||
return 'sprintf(' . $params[1] . ',' . $params[0] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -1,22 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFilter
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty htmlspecialchars variablefilter plugin
|
||||
*
|
||||
* @param string $source input string
|
||||
* @param object $ &$smarty Smarty object
|
||||
*
|
||||
* @param string $source input string
|
||||
* @param Smarty_Internal_Template $smarty Smarty object
|
||||
* @return string filtered output
|
||||
*/
|
||||
|
||||
function smarty_variablefilter_htmlspecialchars($source, $smarty)
|
||||
{
|
||||
return htmlspecialchars($source, ENT_QUOTES);
|
||||
}
|
||||
return htmlspecialchars($source, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET);
|
||||
}
|
||||
|
||||
?>
|
@ -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,205 +1,264 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin CacheResource File
|
||||
*
|
||||
* Implements the file system as resource for the HTML cache
|
||||
* Version ussing nocache inserts
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class does contain all necessary methods for the HTML cache on file system
|
||||
*
|
||||
* Implements the file system as resource for the HTML cache Version ussing nocache inserts.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Cacher
|
||||
*/
|
||||
class Smarty_Internal_CacheResource_File {
|
||||
function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
||||
|
||||
/**
|
||||
* Returns the filepath of the cached template output
|
||||
*
|
||||
* @param object $_template current template
|
||||
* @return string the cache filepath
|
||||
* 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 getCachedFilepath($_template)
|
||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_source_file_path = str_replace(':', '.', $_template->getTemplateFilepath());
|
||||
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
|
||||
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
|
||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
|
||||
$_filepath = $_template->templateUid;
|
||||
$_filepath = $_template->source->uid;
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($this->smarty->use_sub_dirs) {
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 2) . DS
|
||||
. substr($_filepath, 2, 2) . DS
|
||||
. substr($_filepath, 4, 2) . DS
|
||||
. $_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
|
||||
. substr($_filepath, 2, 2) . DS
|
||||
. substr($_filepath, 4, 2) . DS
|
||||
. $_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_cache_id)) {
|
||||
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
|
||||
} else {
|
||||
$_cache_id = '';
|
||||
}
|
||||
}
|
||||
if (isset($_compile_id)) {
|
||||
$_compile_id = $_compile_id . $_compile_dir_sep;
|
||||
} else {
|
||||
$_compile_id = '';
|
||||
}
|
||||
$_cache_dir = $this->smarty->cache_dir;
|
||||
if (strpos('/\\', substr($_cache_dir, -1)) === false) {
|
||||
$_cache_dir .= DS;
|
||||
}
|
||||
return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||
}
|
||||
}
|
||||
$_cache_dir = $_template->smarty->getCacheDir();
|
||||
if ($_template->smarty->cache_locking) {
|
||||
// create locking file name
|
||||
// relative file name?
|
||||
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
|
||||
$_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
|
||||
} else {
|
||||
$_lock_dir = $_cache_dir;
|
||||
}
|
||||
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
|
||||
}
|
||||
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||
$cached->timestamp = @filemtime($cached->filepath);
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timpestamp of the cached template output
|
||||
*
|
||||
* @param object $_template current template
|
||||
* @return integer |booelan the template timestamp or false if the file does not exist
|
||||
* populate Cached Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @return void
|
||||
*/
|
||||
public function getCachedTimestamp($_template)
|
||||
{
|
||||
// return @filemtime ($_template->getCachedFilepath());
|
||||
return ($_template->getCachedFilepath() && file_exists($_template->getCachedFilepath())) ? filemtime($_template->getCachedFilepath()) : false ;
|
||||
}
|
||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->timestamp = @filemtime($cached->filepath);
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached template output
|
||||
*
|
||||
* @param object $_template current template
|
||||
* @return string |booelan the template content or false if the file does not exist
|
||||
* Read the cached template and process its 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 getCachedContents($_template, $no_render = false)
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
|
||||
{
|
||||
if (!$no_render) {
|
||||
ob_start();
|
||||
}
|
||||
$_smarty_tpl = $_template;
|
||||
include $_template->getCachedFilepath();
|
||||
if ($no_render) {
|
||||
return null;
|
||||
} else {
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
return @include $_template->cached->filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the rendered template output to cache file
|
||||
*
|
||||
* @param object $_template current template
|
||||
* @return boolean status
|
||||
* 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($_template, $content)
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if (!$_template->resource_object->isEvaluated) {
|
||||
if (Smarty_Internal_Write_File::writeFile($_template->getCachedFilepath(), $content, $this->smarty) === true) {
|
||||
$_template->cached_timestamp = filemtime($_template->getCachedFilepath());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
|
||||
$_template->cached->timestamp = filemtime($_template->cached->filepath);
|
||||
$_template->cached->exists = !!$_template->cached->timestamp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache folder
|
||||
*
|
||||
* @param integer $exp_time expiration time
|
||||
* Empty cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param integer $exp_time expiration time (number of seconds, not timestamp)
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
public function clearAll($exp_time = null)
|
||||
public function clearAll(Smarty $smarty, $exp_time = null)
|
||||
{
|
||||
return $this->clear(null, null, null, $exp_time);
|
||||
}
|
||||
return $this->clear($smarty, null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer $exp_time expiration time
|
||||
*
|
||||
* @param Smarty $_template template 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($resource_name, $cache_id, $compile_id, $exp_time)
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
|
||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
|
||||
$_dir_sep = $this->smarty->use_sub_dirs ? '/' : '^';
|
||||
$_compile_id_offset = $this->smarty->use_sub_dirs ? 3 : 0;
|
||||
$_dir = rtrim($this->smarty->cache_dir, '/\\') . DS;
|
||||
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
|
||||
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
|
||||
$_dir = $smarty->getCacheDir();
|
||||
$_dir_length = strlen($_dir);
|
||||
if (isset($_cache_id)) {
|
||||
$_cache_id_parts = explode('|', $_cache_id);
|
||||
$_cache_id_parts_count = count($_cache_id_parts);
|
||||
if ($this->smarty->use_sub_dirs) {
|
||||
if ($smarty->use_sub_dirs) {
|
||||
foreach ($_cache_id_parts as $id_part) {
|
||||
$_dir .= $id_part . DS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $this->smarty->caching;
|
||||
$this->smarty->caching = true;
|
||||
$tpl = new $this->smarty->template_class($resource_name, $this->smarty);
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = true;
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
$smarty->caching = $_save_stat;
|
||||
|
||||
// remove from template cache
|
||||
unset($this->smarty->template_objects[crc32($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||
$this->smarty->caching = $_save_stat;
|
||||
if ($tpl->isExisting()) {
|
||||
$_resourcename_parts = basename(str_replace('^', '/', $tpl->getCachedFilepath()));
|
||||
$tpl->source; // have the template registered before unset()
|
||||
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]);
|
||||
|
||||
if ($tpl->source->exists) {
|
||||
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count = 0;
|
||||
$_time = time();
|
||||
if (file_exists($_dir)) {
|
||||
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_cache as $_file) {
|
||||
if (strpos($_file, '.svn') !== false) continue;
|
||||
if (substr($_file->getBasename(),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
|
||||
// directory ?
|
||||
if ($_file->isDir()) {
|
||||
if (!$_cache->isDot()) {
|
||||
// delete folder if empty
|
||||
@rmdir($_file->getPathname());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length)));
|
||||
$_parts_count = count($_parts);
|
||||
$_parts_count = count($_parts);
|
||||
// check name
|
||||
if (isset($resource_name)) {
|
||||
if ($_parts[$_parts_count-1] != $_resourcename_parts) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// check compile id
|
||||
if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// check cache id
|
||||
if (isset($_cache_id)) {
|
||||
// count of cache id parts
|
||||
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
|
||||
if ($_parts_count < $_cache_id_parts_count) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for ($i = 0; $i < $_cache_id_parts_count; $i++) {
|
||||
if ($_parts[$i] != $_cache_id_parts[$i]) continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// expired ?
|
||||
if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) {
|
||||
if (isset($exp_time) && $_time - @filemtime($_file) < $exp_time) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$_count += @unlink((string) $_file) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
|
||||
clearstatcache(true, $cached->lock_id);
|
||||
} else {
|
||||
clearstatcache();
|
||||
}
|
||||
$t = @filemtime($cached->lock_id);
|
||||
return $t && (time() - $t < $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;
|
||||
touch($cached->lock_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@unlink($cached->lock_id);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,187 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block
|
||||
*
|
||||
*
|
||||
* Compiles the {block}{/block} tags
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
public $shorttag_order = array('name');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name', 'hide');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('hide');
|
||||
|
||||
/**
|
||||
* Compiles code for the {block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $this->compiler->nocache, $this->compiler->smarty->merge_compiled_includes, $compiler->smarty->inheritance);
|
||||
$this->_open_tag('block', $save);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes);
|
||||
$this->openTag($compiler, 'block', $save);
|
||||
if ($_attr['nocache'] == true) {
|
||||
$compiler->nocache = true;
|
||||
}
|
||||
// set flag for {block} tag
|
||||
$compiler->smarty->inheritance = true;
|
||||
$compiler->inheritance = true;
|
||||
// must merge includes
|
||||
$this->compiler->smarty->merge_compiled_includes = true;
|
||||
$compiler->smarty->merge_compiled_includes = true;
|
||||
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
||||
/**
|
||||
* Save or replace child block source by block name during parsing
|
||||
*
|
||||
* @param string $block_content block source content
|
||||
* @param string $block_tag opening block tag
|
||||
* @param object $template template object
|
||||
* @param string $filepath filepath of template source
|
||||
*/
|
||||
public static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
||||
{
|
||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||
$_ldl = preg_quote($template->smarty->left_delimiter);
|
||||
|
||||
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)(=true)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||
$error_text = 'Syntax Error in template "' . $template->getTemplateFilepath() . '" "' . htmlspecialchars($block_tag) . '" illegal options';
|
||||
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . htmlspecialchars($block_tag) . '" illegal options';
|
||||
throw new SmartyCompilerException($error_text);
|
||||
} else {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
// replace {$smarty.block.child}
|
||||
if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) {
|
||||
if (isset($template->block_data[$_name])) {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
$_name = trim($_match[3], '\'"');
|
||||
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
|
||||
if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) {
|
||||
if (isset($template->block_data[$_name])) {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
$template->block_data[$_name]['source'], $block_content);
|
||||
unset($template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
unset($template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
'', $block_content);
|
||||
}
|
||||
}
|
||||
if (isset($template->block_data[$_name])) {
|
||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$template->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$template->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'append') {
|
||||
$template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source'];
|
||||
}
|
||||
} else {
|
||||
$template->block_data[$_name]['source'] = $block_content;
|
||||
}
|
||||
if ($_match[6] == 'append') {
|
||||
$template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif ($_match[6] == 'prepend') {
|
||||
$template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
$template->block_data[$_name]['file'] = $filepath;
|
||||
}
|
||||
}
|
||||
if (isset($template->block_data[$_name])) {
|
||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$template->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$template->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'append') {
|
||||
$template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source'];
|
||||
}
|
||||
} else {
|
||||
$template->block_data[$_name]['source'] = $block_content;
|
||||
$template->block_data[$_name]['file'] = $filepath;
|
||||
}
|
||||
if ($_match[6] == 'append') {
|
||||
$template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif ($_match[6] == 'prepend') {
|
||||
$template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function compileChildBlock ($compiler, $_name = null)
|
||||
{
|
||||
$_output = '';
|
||||
/**
|
||||
* Compile saved child block source
|
||||
*
|
||||
* @param object $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
* @return string compiled code of schild block
|
||||
*/
|
||||
public static function compileChildBlock($compiler, $_name = null)
|
||||
{
|
||||
$_output = '';
|
||||
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
||||
if ($_name == null) {
|
||||
$stack_count = count($compiler->_tag_stack);
|
||||
if ($_name == null) {
|
||||
$stack_count = count($compiler->_tag_stack);
|
||||
while (--$stack_count >= 0) {
|
||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'\"");
|
||||
break;
|
||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'\"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// flag that child is already compile by {$smarty.block.child} inclusion
|
||||
$compiler->template->block_data[$_name]['compiled'] = true;
|
||||
}
|
||||
if ($_name == null) {
|
||||
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $compiler->lex->taglineno);
|
||||
}
|
||||
// undefined child?
|
||||
if (!isset($compiler->template->block_data[$_name]['source'])) {
|
||||
return '';
|
||||
}
|
||||
$_tpl = new Smarty_Internal_template ('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
|
||||
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
|
||||
$_tpl->variable_filters = $compiler->template->variable_filters;
|
||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
|
||||
$_tpl->allow_relative_path = true;
|
||||
if ($compiler->nocache) {
|
||||
$_tpl->compiler->forceNocache = 2;
|
||||
} else {
|
||||
$_tpl->compiler->forceNocache = 1;
|
||||
}
|
||||
$_tpl->compiler->suppressHeader = true;
|
||||
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||
$_tpl->compiler->suppressMergedTemplates = true;
|
||||
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl));
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_output = $_tpl->compiler->compileTemplate($_tpl) . $compiler->parser->current_buffer->to_smarty_php();
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl);
|
||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||
$_output = $_tpl->compiler->compileTemplate($_tpl);
|
||||
}
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
||||
$compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates);
|
||||
$compiler->template->variable_filters = $_tpl->variable_filters;
|
||||
if ($_tpl->has_nocache_code) {
|
||||
$compiler->template->has_nocache_code = true;
|
||||
}
|
||||
foreach($_tpl->required_plugins as $code => $tmp1) {
|
||||
foreach($tmp1 as $name => $tmp) {
|
||||
foreach($tmp as $type => $data) {
|
||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
||||
}
|
||||
}
|
||||
// flag that child is already compile by {$smarty.block.child} inclusion
|
||||
$compiler->template->block_data[$_name]['compiled'] = true;
|
||||
}
|
||||
if ($_name == null) {
|
||||
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $this->compiler->lex->taglineno);
|
||||
}
|
||||
// undefined child?
|
||||
if (!isset($compiler->template->block_data[$_name])) {
|
||||
return '';
|
||||
}
|
||||
$_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
|
||||
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
|
||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$_tpl->template_filepath = $compiler->template->block_data[$_name]['file'];
|
||||
if ($compiler->nocache) {
|
||||
$_tpl->forceNocache = 2;
|
||||
} else {
|
||||
$_tpl->forceNocache = 1;
|
||||
}
|
||||
$_tpl->suppressHeader = true;
|
||||
$_tpl->suppressFileDependency = true;
|
||||
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->getCompiledTemplate());
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_output = $_tpl->getCompiledTemplate() . $compiler->parser->current_buffer->to_smarty_php();
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->getCompiledTemplate();
|
||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||
$_output = $_tpl->getCompiledTemplate();
|
||||
}
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
||||
if ($_tpl->has_nocache_code) {
|
||||
$compiler->template->has_nocache_code = true;
|
||||
}
|
||||
foreach($_tpl->required_plugins as $code => $tmp1) {
|
||||
foreach($tmp1 as $name => $tmp) {
|
||||
foreach($tmp as $type => $data) {
|
||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($_tpl);
|
||||
return $_output;
|
||||
}
|
||||
unset($_tpl);
|
||||
return $_output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile BlockClose Class
|
||||
*/
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @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->compiler->has_code = true;
|
||||
$compiler->has_code = true;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$saved_data = $this->_close_tag(array('block'));
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$saved_data = $this->closeTag($compiler, array('block'));
|
||||
$_name = trim($saved_data[0]['name'], "\"'");
|
||||
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||
} else {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
||||
if (isset($saved_data[0]['hide']) && !isset($compiler->template->block_data[$_name]['source'])) {
|
||||
$_output = '';
|
||||
} else {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
||||
}
|
||||
unset ($compiler->template->block_data[$_name]['compiled']);
|
||||
}
|
||||
// reset flags
|
||||
$compiler->parser->current_buffer = $saved_data[1];
|
||||
$compiler->nocache = $saved_data[2];
|
||||
$compiler->smarty->merge_compiled_includes = $saved_data[3];
|
||||
$compiler->smarty->inheritance = $saved_data[4];
|
||||
// reset flag for {block} tag
|
||||
$compiler->inheritance = false;
|
||||
// $_output content has already nocache code processed
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,65 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Break
|
||||
*
|
||||
*
|
||||
* Compiles the {break} tag
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Break Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('levels');
|
||||
public $shorttag_order = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('levels');
|
||||
|
||||
/**
|
||||
* Compiles code for the {break} 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;
|
||||
$this->smarty = $compiler->smarty;
|
||||
{
|
||||
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (isset($_attr['levels'])) {
|
||||
if (!is_numeric($_attr['levels'])) {
|
||||
$this->compiler->trigger_template_error('level attribute must be a numeric constant', $this->compiler->lex->taglineno);
|
||||
}
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
|
||||
}
|
||||
$_levels = $_attr['levels'];
|
||||
} else {
|
||||
$_levels = 1;
|
||||
}
|
||||
}
|
||||
$level_count = $_levels;
|
||||
$stack_count = count($compiler->_tag_stack) - 1;
|
||||
while ($level_count > 0 && $stack_count >= 0) {
|
||||
if (in_array($compiler->_tag_stack[$stack_count][0], array('for', 'foreach', 'while', 'section'))) {
|
||||
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
|
||||
$level_count--;
|
||||
}
|
||||
}
|
||||
$stack_count--;
|
||||
}
|
||||
}
|
||||
if ($level_count != 0) {
|
||||
$this->compiler->trigger_template_error("cannot break {$_levels} level(s)", $this->compiler->lex->taglineno);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = true;
|
||||
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
return "<?php break {$_levels}?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,81 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Capture
|
||||
*
|
||||
*
|
||||
* Compiles the {capture} tag
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Capture Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
public $optional_attributes = array('name', 'assign', 'append');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('name', 'assign', 'append');
|
||||
|
||||
/**
|
||||
* Compiles code for the {capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @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;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : null;
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : null;
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
||||
|
||||
$this->compiler->_capture_stack[] = array($buffer, $assign, $append, $this->compiler->nocache);
|
||||
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$_output = "<?php ob_start(); ?>";
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
$_output = "<?php \$_smarty_tpl->_capture_stack[] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Captureclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @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;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($buffer, $assign, $append, $this->compiler->nocache) = array_pop($this->compiler->_capture_stack);
|
||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
||||
|
||||
$_output = "<?php ";
|
||||
if (isset($assign)) {
|
||||
$_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
|
||||
}
|
||||
if (isset($append)) {
|
||||
$_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
|
||||
}
|
||||
$_output .= " Smarty::\$_smarty_vars['capture'][$buffer]=ob_get_clean();?>";
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack);\n";
|
||||
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
||||
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
|
||||
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
|
||||
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "} else \$_smarty_tpl->capture_error();?>";
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,64 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Config Load
|
||||
*
|
||||
*
|
||||
* Compiles the {config load} tag
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Config Load Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Config_Load 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','section');
|
||||
public $optional_attributes = array('section', 'scope');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('section', 'scope');
|
||||
|
||||
/**
|
||||
* Compiles code for the {config_load} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @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;
|
||||
static $_is_legal_scope = array('local' => true,'parent' => true,'root' => true,'global' => true);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// save posible attributes
|
||||
$conf_file = $_attr['file'];
|
||||
if (isset($_attr['section'])) {
|
||||
$section = $_attr['section'];
|
||||
} else {
|
||||
$section = 'null';
|
||||
}
|
||||
}
|
||||
$scope = 'local';
|
||||
// scope setup
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if (in_array($_attr['scope'],array('local','parent','root','global'))) {
|
||||
if (isset($_is_legal_scope[$_attr['scope']])) {
|
||||
$scope = $_attr['scope'];
|
||||
} else {
|
||||
$this->compiler->trigger_template_error('illegal value for "scope" attribute', $this->compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// create config object
|
||||
$_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
||||
$_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,64 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Continue
|
||||
*
|
||||
*
|
||||
* Compiles the {continue} tag
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Continue Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('levels');
|
||||
|
||||
/**
|
||||
* Compiles code for the {continue} 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;
|
||||
$this->smarty = $compiler->smarty;
|
||||
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (isset($_attr['levels'])) {
|
||||
if (!is_numeric($_attr['levels'])) {
|
||||
$this->compiler->trigger_template_error('level attribute must be a numeric constant', $this->compiler->lex->taglineno);
|
||||
}
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
|
||||
}
|
||||
$_levels = $_attr['levels'];
|
||||
} else {
|
||||
$_levels = 1;
|
||||
}
|
||||
}
|
||||
$level_count = $_levels;
|
||||
$stack_count = count($compiler->_tag_stack) - 1;
|
||||
while ($level_count > 0 && $stack_count >= 0) {
|
||||
if (in_array($compiler->_tag_stack[$stack_count][0], array('for', 'foreach', 'while', 'section'))) {
|
||||
if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
|
||||
$level_count--;
|
||||
}
|
||||
}
|
||||
$stack_count--;
|
||||
}
|
||||
}
|
||||
if ($level_count != 0) {
|
||||
$this->compiler->trigger_template_error("cannot continue {$_levels} level(s)", $this->compiler->lex->taglineno);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = true;
|
||||
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
return "<?php continue {$_levels}?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
$_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'] . ';');
|
||||
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->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->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 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\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
|
||||
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}|{$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,147 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile For
|
||||
*
|
||||
*
|
||||
* Compiles the {for} {forelse} {/for} tags
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile For Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {for} tag
|
||||
*
|
||||
*
|
||||
* Smarty 3 does implement two different sytaxes:
|
||||
*
|
||||
*
|
||||
* - {for $var in $array}
|
||||
* For looping over arrays or iterators
|
||||
*
|
||||
*
|
||||
* - {for $x=0; $x<$y; $x++}
|
||||
* For general loops
|
||||
*
|
||||
* The parser is gereration different sets of attribute by which this compiler can
|
||||
*
|
||||
* The parser is gereration different sets of attribute by which this compiler can
|
||||
* determin which syntax is used.
|
||||
*
|
||||
* @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;
|
||||
if ($parameter == 0) {
|
||||
$this->required_attributes = array('start','to');
|
||||
$this->optional_attributes = array('max','step');
|
||||
$this->required_attributes = array('start', 'to');
|
||||
$this->optional_attributes = array('max', 'step');
|
||||
} else {
|
||||
$this->required_attributes = array('start','ifexp','var','step');
|
||||
$this->optional_attributes = array();
|
||||
$this->required_attributes = array('start', 'ifexp', 'var', 'step');
|
||||
$this->optional_attributes = array();
|
||||
}
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
$local_vars = array();
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$output = "<?php ";
|
||||
if ($parameter == 1) {
|
||||
foreach ($_attr['start'] as $_statement) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n";
|
||||
$compiler->local_var[$_statement['var']] = true;
|
||||
$local_vars[] = $_statement['var'];
|
||||
}
|
||||
}
|
||||
$output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[step]){\n";
|
||||
} else {
|
||||
$_statement = $_attr['start'];
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
|
||||
$compiler->local_var[$_statement['var']] = true;
|
||||
$local_vars[] = $_statement['var'];
|
||||
if (isset($_attr['step'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
|
||||
}
|
||||
}
|
||||
if (isset($_attr['max'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)min(ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step)),$_attr[max]);\n";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step));\n";
|
||||
}
|
||||
}
|
||||
$output .= "if (\$_smarty_tpl->tpl_vars[$_statement[var]]->total > 0){\n";
|
||||
$output .= "for (\$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value], \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration = 1;\$_smarty_tpl->tpl_vars[$_statement[var]]->iteration <= \$_smarty_tpl->tpl_vars[$_statement[var]]->total;\$_smarty_tpl->tpl_vars[$_statement[var]]->value += \$_smarty_tpl->tpl_vars[$_statement[var]]->step, \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration++){\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->first = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == 1;";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->last = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == \$_smarty_tpl->tpl_vars[$_statement[var]]->total;";
|
||||
}
|
||||
}
|
||||
$output .= "?>";
|
||||
|
||||
$this->_open_tag('for', array('for', $this->compiler->nocache, $local_vars));
|
||||
$this->openTag($compiler, 'for', array('for', $compiler->nocache));
|
||||
// maybe nocache because of nocache variables
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
// return compiled code
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Forelse Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {forelse} 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;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($_open_tag, $nocache, $local_vars) = $this->_close_tag(array('for'));
|
||||
$this->_open_tag('forelse', array('forelse', $nocache, $local_vars));
|
||||
list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
|
||||
$this->openTag($compiler, 'forelse', array('forelse', $nocache));
|
||||
return "<?php }} else { ?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Forclose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase {
|
||||
|
||||
/**
|
||||
* Compiles code for the {/for} 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;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($_open_tag, $this->compiler->nocache, $local_vars) = $this->_close_tag(array('for', 'forelse'));
|
||||
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
|
||||
|
||||
foreach ($local_vars as $var) {
|
||||
unset($compiler->local_var[$var]);
|
||||
}
|
||||
if ($_open_tag == 'forelse')
|
||||
if ($openTag == 'forelse') {
|
||||
return "<?php } ?>";
|
||||
else
|
||||
} else {
|
||||
return "<?php }} ?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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,90 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Include PHP
|
||||
*
|
||||
*
|
||||
* Compiles the {include_php} tag
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
public $shorttag_order = array('file');
|
||||
public $optional_attributes = array('once', 'assign');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('once', 'assign');
|
||||
|
||||
/**
|
||||
* Compiles code for the {include_php} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
if (!$compiler->smarty->allow_php_tag) {
|
||||
throw new SmartyException("{include_php} is deprecated, set allow_php_tag = true to enable");
|
||||
}
|
||||
$this->compiler = $compiler;
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
|
||||
}
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$_output = '<?php ';
|
||||
$_output = '<?php ';
|
||||
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_file = ' . $_attr['file'] . ';');
|
||||
if (!isset($this->compiler->smarty->security_policy) && file_exists($_file)) {
|
||||
$_filepath = $_file;
|
||||
eval('$_file = ' . $_attr['file'] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
|
||||
$_filepath = $_file;
|
||||
} else {
|
||||
if (isset($this->compiler->smarty->security_policy)) {
|
||||
$_dir = $this->compiler->smarty->security_policy->trusted_dir;
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$_dir = $compiler->smarty->security_policy->trusted_dir;
|
||||
} else {
|
||||
$_dir = $this->compiler->smarty->trusted_dir;
|
||||
}
|
||||
$_dir = $compiler->smarty->trusted_dir;
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach((array)$_dir as $_script_dir) {
|
||||
if (strpos('/\\', substr($_script_dir, -1)) === false) {
|
||||
$_script_dir .= DS;
|
||||
}
|
||||
$_script_dir = rtrim($_script_dir, '/\\') . DS;
|
||||
if (file_exists($_script_dir . $_file)) {
|
||||
$_filepath = $_script_dir . $_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_filepath == false) {
|
||||
$this->compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $this->compiler->lex->taglineno);
|
||||
}
|
||||
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
if (isset($this->compiler->smarty->security_policy)) {
|
||||
$this->compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
|
||||
}
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
|
||||
}
|
||||
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
}
|
||||
$_once = '_once';
|
||||
if (isset($_attr['once'])) {
|
||||
if ($_attr['once'] == 'false') {
|
||||
$_once = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_assign)) {
|
||||
return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
|
||||
} else {
|
||||
return "<?php include{$_once} ('{$_filepath}');?>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,71 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Object Funtion
|
||||
*
|
||||
*
|
||||
* Compiles code for registered objects as function
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Object Function Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array();
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $methode name of methode to call
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $method name of method to call
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag, $methode)
|
||||
public function compile($args, $compiler, $parameter, $tag, $method)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
$_assign = null;
|
||||
if (isset($_attr['assign'])) {
|
||||
$_assign = $_attr['assign'];
|
||||
unset($_attr['assign']);
|
||||
}
|
||||
}
|
||||
// convert attributes into parameter array string
|
||||
if ($this->compiler->smarty->registered_objects[$tag][2]) {
|
||||
if ($compiler->smarty->registered_objects[$tag][2]) {
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
if (is_int($_key)) {
|
||||
$_paramsArray[] = "$_key=>$_value";
|
||||
} else {
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params},\$_smarty_tpl)";
|
||||
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
|
||||
} else {
|
||||
$_params = implode(",", $_attr);
|
||||
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params})";
|
||||
}
|
||||
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
|
||||
}
|
||||
if (empty($_assign)) {
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
$compiler->has_output = true;
|
||||
$output = "<?php echo {$return};?>\n";
|
||||
} else {
|
||||
$output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,77 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Print Expression
|
||||
*
|
||||
* Compiles any tag which will output an expression or variable
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Print Expression
|
||||
*
|
||||
* Compiles any tag which will output an expression or variable
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Print Expression Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Print Expression Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('assign');
|
||||
public $option_flags = array('nocache', 'nofilter');
|
||||
|
||||
/**
|
||||
* Compiles code for gererting output from any expression
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('assign');
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('nocache', 'nofilter');
|
||||
|
||||
/**
|
||||
* Compiles code for gererting output from any expression
|
||||
*
|
||||
* @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);
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// nocache option
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
// filter handling
|
||||
if ($_attr['nofilter'] === true) {
|
||||
$_filter = 'false';
|
||||
} else {
|
||||
$_filter = 'true';
|
||||
}
|
||||
// compiled output
|
||||
// compiled output
|
||||
}
|
||||
if (isset($_attr['assign'])) {
|
||||
// assign output to variable
|
||||
$output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
|
||||
} else {
|
||||
// display value
|
||||
if (!$_attr['nofilter'] && isset($this->compiler->smarty->registered_filters['variable'])) {
|
||||
$output = "Smarty_Internal_Filter_Handler::runFilter('variable', {$parameter['value']}, \$_smarty_tpl, {$_filter})";
|
||||
} else {
|
||||
$output = $parameter['value'];
|
||||
}
|
||||
if (!$_attr['nofilter'] && !empty($this->compiler->smarty->default_modifiers)) {
|
||||
$modifierlist = array();
|
||||
foreach ($this->compiler->smarty->default_modifiers as $key => $single_default_modifier) {
|
||||
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, $mod_array);
|
||||
for ($i = 0, $count = count($mod_array[0]);$i < $count;$i++) {
|
||||
if ($mod_array[0][$i] != ':') {
|
||||
$modifierlist[$key][] = $mod_array[0][$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
$output = $this->compiler->compileTag('private_modifier', array(), array('modifierlist' => $modifierlist, 'value' => $output));
|
||||
}
|
||||
$output = $parameter['value'];
|
||||
// tag modifier
|
||||
if (!empty($parameter['modifierlist'])) {
|
||||
$output = $this->compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
|
||||
}
|
||||
$this->compiler->has_output = true;
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
|
||||
}
|
||||
if (!$_attr['nofilter']) {
|
||||
// default modifier
|
||||
if (!empty($compiler->smarty->default_modifiers)) {
|
||||
if (empty($compiler->default_modifier_list)) {
|
||||
$modifierlist = array();
|
||||
foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
|
||||
preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, $mod_array);
|
||||
for ($i = 0, $count = count($mod_array[0]);$i < $count;$i++) {
|
||||
if ($mod_array[0][$i] != ':') {
|
||||
$modifierlist[$key][] = $mod_array[0][$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
$compiler->default_modifier_list = $modifierlist;
|
||||
}
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output));
|
||||
}
|
||||
// autoescape html
|
||||
if ($compiler->template->smarty->escape_html) {
|
||||
$output = "htmlspecialchars({$output}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET)";
|
||||
}
|
||||
// loop over registerd filters
|
||||
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
|
||||
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) {
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$output},\$_smarty_tpl)";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE][{$key}][0]->{$function[1]}({$output},\$_smarty_tpl)";
|
||||
} else {
|
||||
$output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
|
||||
}
|
||||
}
|
||||
}
|
||||
// auto loaded filters
|
||||
if (isset($compiler->smarty->autoload_filters[Smarty::FILTER_VARIABLE])) {
|
||||
foreach ((array)$compiler->template->smarty->autoload_filters[Smarty::FILTER_VARIABLE] as $name) {
|
||||
$result = $this->compile_output_filter($compiler, $name, $output);
|
||||
if ($result !== false) {
|
||||
$output = $result;
|
||||
} else {
|
||||
// not found, throw exception
|
||||
throw new SmartyException("Unable to load filter '{$name}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($compiler->template->variable_filters)) {
|
||||
foreach ($compiler->template->variable_filters as $filter) {
|
||||
if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) {
|
||||
$output = $result;
|
||||
} else {
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->has_output = true;
|
||||
$output = "<?php echo {$output};?>";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $compiler compiler object
|
||||
* @param string $name name of variable filter
|
||||
* @param type $output embedded output
|
||||
* @return string
|
||||
*/
|
||||
private function compile_output_filter($compiler, $name, $output)
|
||||
{
|
||||
$plugin_name = "smarty_variablefilter_{$name}";
|
||||
$path = $compiler->smarty->loadPlugin($plugin_name, false);
|
||||
if ($path) {
|
||||
if ($compiler->template->caching) {
|
||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
}
|
||||
} else {
|
||||
// not found
|
||||
return false;
|
||||
}
|
||||
return "{$plugin_name}({$output},\$_smarty_tpl)";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
@ -1,67 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Filter Handler
|
||||
*
|
||||
*
|
||||
* Smarty filter handler class
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for filter processing
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Filter_Handler {
|
||||
|
||||
/**
|
||||
* Run filters over content
|
||||
*
|
||||
*
|
||||
* The filters will be lazy loaded if required
|
||||
* class name format: Smarty_FilterType_FilterName
|
||||
* plugin filename format: filtertype.filtername.php
|
||||
* Smarty2 filter plugins could be used
|
||||
*
|
||||
* @param string $type the type of filter ('pre','post','output' or 'variable') which shall run
|
||||
* @param string $content the content which shall be processed by the filters
|
||||
*
|
||||
* @param string $type the type of filter ('pre','post','output') which shall run
|
||||
* @param string $content the content which shall be processed by the filters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
* @return string the filtered content
|
||||
*/
|
||||
static function runFilter($type, $content, $template, $flag = null)
|
||||
public static function runFilter($type, $content, Smarty_Internal_Template $template)
|
||||
{
|
||||
$output = $content;
|
||||
if ($type != 'variable' || ($template->smarty->variable_filter && $flag !== false) || $flag === true) {
|
||||
// loop over autoload filters of specified type
|
||||
if (!empty($template->smarty->autoload_filters[$type])) {
|
||||
foreach ((array)$template->smarty->autoload_filters[$type] as $name) {
|
||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||
if ($template->smarty->loadPlugin($plugin_name)) {
|
||||
if (function_exists($plugin_name)) {
|
||||
// use loaded Smarty2 style plugin
|
||||
$output = $plugin_name($output, $template);
|
||||
} elseif (class_exists($plugin_name, false)) {
|
||||
// loaded class of filter plugin
|
||||
$output = call_user_func(array($plugin_name, 'execute'), $output, $template);
|
||||
}
|
||||
} else {
|
||||
// nothing found, throw exception
|
||||
throw new SmartyException("Unable to load filter {$plugin_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// loop over registerd filters of specified type
|
||||
if (!empty($template->smarty->registered_filters[$type])) {
|
||||
foreach ($template->smarty->registered_filters[$type] as $key => $name) {
|
||||
if (is_array($template->smarty->registered_filters[$type][$key])) {
|
||||
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
|
||||
} else {
|
||||
$output = $template->smarty->registered_filters[$type][$key]($output, $template);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// loop over autoload filters of specified type
|
||||
if (!empty($template->smarty->autoload_filters[$type])) {
|
||||
foreach ((array)$template->smarty->autoload_filters[$type] as $name) {
|
||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||
if ($template->smarty->loadPlugin($plugin_name)) {
|
||||
if (function_exists($plugin_name)) {
|
||||
// use loaded Smarty2 style plugin
|
||||
$output = $plugin_name($output, $template);
|
||||
} elseif (class_exists($plugin_name, false)) {
|
||||
// loaded class of filter plugin
|
||||
$output = call_user_func(array($plugin_name, 'execute'), $output, $template);
|
||||
}
|
||||
} else {
|
||||
// nothing found, throw exception
|
||||
throw new SmartyException("Unable to load filter {$plugin_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// loop over registerd filters of specified type
|
||||
if (!empty($template->smarty->registered_filters[$type])) {
|
||||
foreach ($template->smarty->registered_filters[$type] as $key => $name) {
|
||||
if (is_array($template->smarty->registered_filters[$type][$key])) {
|
||||
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
|
||||
} else {
|
||||
$output = $template->smarty->registered_filters[$type][$key]($output, $template);
|
||||
}
|
||||
}
|
||||
}
|
||||
// return filtered output
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,40 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Function Call Handler
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class does call function defined with the {function} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Function_Call_Handler extends Smarty_Internal_Template {
|
||||
static function call ($_name, $_template, $_params, $_hash, $_nocache)
|
||||
class Smarty_Internal_Function_Call_Handler {
|
||||
|
||||
/**
|
||||
* This function handles calls to template functions defined by {function}
|
||||
* It does create a PHP function at the first call
|
||||
*
|
||||
* @param string $_name template function name
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param array $_params Smarty variables passed as call parameter
|
||||
* @param string $_hash nocache hash value
|
||||
* @param bool $_nocache nocache flag
|
||||
*/
|
||||
public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache)
|
||||
{
|
||||
if ($_nocache) {
|
||||
$_function = "smarty_template_function_{$_name}_nocache";
|
||||
$_template->smarty->template_functions[$_name]['called_nocache'] = true;
|
||||
} else {
|
||||
$_function = "smarty_template_function_{$_hash}_{$_name}";
|
||||
}
|
||||
}
|
||||
if (!is_callable($_function)) {
|
||||
$_code = "function {$_function}(\$_smarty_tpl,\$params) {
|
||||
\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
|
||||
foreach (\$_smarty_tpl->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(trim(\$value,'\''));};
|
||||
foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
|
||||
foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
|
||||
if ($_nocache) {
|
||||
$_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
|
||||
"!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
|
||||
$_template->smarty->template_functions[$_name]['called_nocache'] = true;
|
||||
} else {
|
||||
$_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
|
||||
}
|
||||
}
|
||||
$_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";
|
||||
eval($_code);
|
||||
}
|
||||
}
|
||||
$_function($_template, $_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -1,44 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty read include path plugin
|
||||
*
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Monte Ohrt
|
||||
* @author Monte Ohrt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Read Include Path Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
*/
|
||||
class Smarty_Internal_Get_Include_Path {
|
||||
|
||||
/**
|
||||
* Return full file path from PHP include_path
|
||||
*
|
||||
*
|
||||
* @param string $filepath filepath
|
||||
* @return mixed full filepath or false
|
||||
* @return string|boolean full filepath or false
|
||||
*/
|
||||
public static function getIncludePath($filepath)
|
||||
{
|
||||
static $_path_array = null;
|
||||
static $_include_path = null;
|
||||
|
||||
if(!isset($_path_array)) {
|
||||
$_ini_include_path = ini_get('include_path');
|
||||
|
||||
if(strstr($_ini_include_path,';')) {
|
||||
// windows pathnames
|
||||
$_path_array = explode(';',$_ini_include_path);
|
||||
} else {
|
||||
$_path_array = explode(':',$_ini_include_path);
|
||||
if ($_path_array === null) {
|
||||
$_include_path = explode(PATH_SEPARATOR, get_include_path());
|
||||
}
|
||||
}
|
||||
foreach ($_path_array as $_include_path) {
|
||||
if (file_exists($_include_path . DS . $filepath)) {
|
||||
return $_include_path . DS . $filepath;
|
||||
|
||||
foreach ($_include_path as $_path) {
|
||||
if (file_exists($_path . DS . $filepath)) {
|
||||
return $_path . DS . $filepath;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue