mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- major update including some API changes
This commit is contained in:
58
README
58
README
@@ -3,11 +3,13 @@ Smarty 3.0 Beta
|
||||
Author: Monte Ohrt <monte at ohrt dot com >
|
||||
Author: Uwe Tews
|
||||
|
||||
AN INTRODUCTION TO SMARTY 3 BETA
|
||||
AN INTRODUCTION TO SMARTY 3
|
||||
|
||||
NOTICE for BETA 8:
|
||||
NOTICE for RC5:
|
||||
|
||||
The Smarty 3 API (as of beta 8) has been refactored to a syntax geared
|
||||
With RC5 the API was changed once again.
|
||||
|
||||
The Smarty 3 API has been refactored to a syntax geared
|
||||
for consistency and modularity. The Smarty 2 API syntax is still supported, but
|
||||
will throw a deprecation notice. You can disable the notices, but it is highly
|
||||
recommended to adjust your syntax to Smarty 3, as the Smarty 2 syntax must run
|
||||
@@ -41,10 +43,10 @@ $smarty->getGlobal($varname = null)
|
||||
$smarty->getRegisteredObject($name)
|
||||
$smarty->getDebugTemplate()
|
||||
$smarty->setDebugTemplate($tpl_name)
|
||||
$smarty->assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
$smarty->assign($tpl_var, $value = null, $nocache = false)
|
||||
$smarty->assignGlobal($varname, $value = null, $nocache = false)
|
||||
$smarty->assignByRef($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
$smarty->append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
$smarty->assignByRef($tpl_var, &$value, $nocache = false)
|
||||
$smarty->append($tpl_var, $value = null, $merge = false, $nocache = false)
|
||||
$smarty->appendByRef($tpl_var, &$value, $merge = false)
|
||||
$smarty->clearAssign($tpl_var)
|
||||
$smarty->clearAllAssign()
|
||||
@@ -55,40 +57,26 @@ $smarty->getStreamVariable($variable)
|
||||
$smarty->getConfigVars($varname = null)
|
||||
$smarty->clearConfig($varname = null)
|
||||
$smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
$smarty->clearAllCache($exp_time = null, $type = null)
|
||||
$smarty->clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||
|
||||
// some API calls are moved into their own objects:
|
||||
$smarty->registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = array())
|
||||
|
||||
$smarty->cache->loadResource($type = null)
|
||||
$smarty->cache->clearAll($exp_time = null, $type = null)
|
||||
$smarty->cache->clear($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||
$smarty->registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
|
||||
$smarty->register->block($block_tag, $block_impl, $cacheable = true, $cache_attr = array())
|
||||
$smarty->register->compilerFunction($compiler_tag, $compiler_impl, $cacheable = true)
|
||||
$smarty->register->templateFunction($function_tag, $function_impl, $cacheable = true, $cache_attr = array())
|
||||
$smarty->register->modifier($modifier_name, $modifier_impl)
|
||||
$smarty->register->templateObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
$smarty->register->outputFilter($function_name)
|
||||
$smarty->register->postFilter($function_name)
|
||||
$smarty->register->preFilter($function_name)
|
||||
$smarty->register->resource($resource_type, $function_names)
|
||||
$smarty->register->variableFilter($function_name)
|
||||
$smarty->register->defaultPluginHandler($function_name)
|
||||
$smarty->register->defaultTemplateHandler($function_name)
|
||||
$smarty->registerFilter($type, $function_name)
|
||||
$smarty->registerResource($resource_type, $function_names)
|
||||
$smarty->registerDefaultPluginHandler($function_name)
|
||||
$smarty->registerDefaultTemplateHandler($function_name)
|
||||
|
||||
$smarty->unregister->block($block_tag)
|
||||
$smarty->unregister->compilerFunction($compiler_tag)
|
||||
$smarty->unregister->templateFunction($function_tag)
|
||||
$smarty->unregister->modifier($modifier)
|
||||
$smarty->unregister->templateObject($object_name)
|
||||
$smarty->unregister->outputFilter($function_name)
|
||||
$smarty->unregister->postFilter($function_name)
|
||||
$smarty->unregister->preFilter($function_name)
|
||||
$smarty->unregister->resource($resource_type)
|
||||
$smarty->unregister->variableFilter($function_name)
|
||||
$smarty->unregisterPlugin($type, $tag)
|
||||
$smarty->unregisterObject($object_name)
|
||||
$smarty->unregisterFilter($type, $function_name)
|
||||
$smarty->unregisterResource($resource_type)
|
||||
|
||||
$smarty->utility->compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
|
||||
$smarty->utility->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
|
||||
$smarty->utility->testInstall()
|
||||
$smarty->compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
|
||||
$smarty->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
|
||||
$smarty->testInstall()
|
||||
|
||||
// then all the getters/setters, available for all properties. Here are a few:
|
||||
|
||||
|
@@ -2,8 +2,9 @@
|
||||
|
||||
== Syntax ==
|
||||
|
||||
Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported but
|
||||
deprecated. See the README that comes with Smarty 3 for more information.
|
||||
Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported
|
||||
by a wrapper but deprecated. See the README that comes with Smarty 3 for more
|
||||
information.
|
||||
|
||||
The {$array|@mod} syntax has always been a bit confusing, where an "@" is required
|
||||
to apply a modifier to an array instead of the individual elements. Normally you
|
||||
@@ -89,3 +90,20 @@ get any output.
|
||||
== newline at {if} tags ==
|
||||
A \n was added to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source.
|
||||
If one of the {if} tags is at the line end you will now get a newline in the HTML output.
|
||||
|
||||
== trigger_error() ==
|
||||
The API function trigger_error() has been removed because it did just map to PHP trigger_error.
|
||||
However it's still included in the Smarty2 API wrapper.
|
||||
|
||||
== Smarty constants ==
|
||||
The constants
|
||||
SMARTY_PHP_PASSTHRU
|
||||
SMARTY_PHP_QUOTE
|
||||
SMARTY_PHP_REMOVE
|
||||
SMARTY_PHP_ALLOW
|
||||
have been replaced with class constants
|
||||
Smarty::PHP_PASSTHRU
|
||||
Smarty::PHP_QUOTE
|
||||
Smarty::PHP_REMOVE
|
||||
Smarty::PHP_ALLOW
|
||||
|
||||
|
@@ -1,3 +1,6 @@
|
||||
11/11/2010
|
||||
- major update including some API changes
|
||||
|
||||
10/11/2010
|
||||
- observe compile_id also for config files
|
||||
|
||||
|
@@ -63,30 +63,6 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
|
||||
define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
define('SMARTY_LOCAL_SCOPE', 0);
|
||||
define('SMARTY_PARENT_SCOPE', 1);
|
||||
define('SMARTY_ROOT_SCOPE', 2);
|
||||
define('SMARTY_GLOBAL_SCOPE', 3);
|
||||
|
||||
/**
|
||||
* define caching modes
|
||||
*/
|
||||
define('SMARTY_CACHING_OFF', 0);
|
||||
define('SMARTY_CACHING_LIFETIME_CURRENT', 1);
|
||||
define('SMARTY_CACHING_LIFETIME_SAVED', 2);
|
||||
|
||||
/**
|
||||
* This determines how Smarty handles "<?php ... ?>" tags in templates.
|
||||
* possible values:
|
||||
*/
|
||||
define('SMARTY_PHP_PASSTHRU', 0); //-> print tags as plain text
|
||||
define('SMARTY_PHP_QUOTE', 1); //-> escape tags as entities
|
||||
define('SMARTY_PHP_REMOVE', 2); //-> escape tags as entities
|
||||
define('SMARTY_PHP_ALLOW', 3); //-> escape tags as entities
|
||||
|
||||
/**
|
||||
* register the class autoloader
|
||||
*/
|
||||
@@ -107,8 +83,45 @@ if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR
|
||||
* This is the main Smarty class
|
||||
*/
|
||||
class Smarty extends Smarty_Internal_Data {
|
||||
/**
|
||||
* constant definitions
|
||||
*/
|
||||
// smarty version
|
||||
const SMARTY_VERSION = 'Smarty3-SVN$Rev: 3286 $';
|
||||
//define variable scopes
|
||||
const SCOPE_LOCAL = 0;
|
||||
const SCOPE_PARENT = 1;
|
||||
const SCOPE_ROOT = 2;
|
||||
const SCOPE_GLOBAL = 3;
|
||||
// define caching modes
|
||||
const CACHING_OFF = 0;
|
||||
const CACHING_LIFETIME_CURRENT = 1;
|
||||
const CACHING_LIFETIME_SAVED = 2;
|
||||
/** modes for handling of "<?php ... ?>" tags in templates. **/
|
||||
const PHP_PASSTHRU = 0; //-> print tags as plain text
|
||||
const PHP_QUOTE = 1; //-> escape tags as entities
|
||||
const PHP_REMOVE = 2; //-> escape tags as entities
|
||||
const PHP_ALLOW = 3; //-> escape tags as entities
|
||||
// filter types
|
||||
const FILTER_POST = 'post';
|
||||
const FILTER_PRE = 'pre';
|
||||
const FILTER_OUTPUT = 'output';
|
||||
const FILTER_VARIABLE = 'variable';
|
||||
// plugin types
|
||||
const PLUGIN_FUNCTION = 'function';
|
||||
const PLUGIN_BLOCK = 'block';
|
||||
const PLUGIN_COMPILER = 'compiler';
|
||||
const PLUGIN_MODIFIER = 'modifier';
|
||||
|
||||
/**
|
||||
* static variables
|
||||
*/
|
||||
// assigned global tpl vars
|
||||
static $global_tpl_vars = array();
|
||||
|
||||
/**
|
||||
* variables
|
||||
*/
|
||||
// auto literal on delimiters with whitspace
|
||||
public $auto_literal = true;
|
||||
// display error on not assigned variables
|
||||
@@ -137,7 +150,7 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $compile_error = false;
|
||||
// caching enabled
|
||||
public $caching = false;
|
||||
// merge compiled includea
|
||||
// merge compiled includes
|
||||
public $merge_compiled_includes = false;
|
||||
// cache lifetime
|
||||
public $cache_lifetime = 3600;
|
||||
@@ -152,12 +165,10 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $right_delimiter = "}";
|
||||
// security
|
||||
public $security_class = 'Smarty_Security';
|
||||
public $php_handling = SMARTY_PHP_PASSTHRU;
|
||||
public $security_policy = null;
|
||||
public $php_handling = self::PHP_PASSTHRU;
|
||||
public $allow_php_tag = false;
|
||||
public $allow_php_templates = false;
|
||||
public $security = false;
|
||||
public $security_policy = null;
|
||||
public $security_handler = null;
|
||||
public $direct_access_security = true;
|
||||
public $trusted_dir = array();
|
||||
// debug mode
|
||||
@@ -175,8 +186,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $config_vars = array();
|
||||
// assigned tpl vars
|
||||
public $tpl_vars = array();
|
||||
// assigned global tpl vars
|
||||
public $global_tpl_vars = array();
|
||||
// dummy parent object
|
||||
public $parent = null;
|
||||
// global template functions
|
||||
@@ -207,6 +216,8 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $registered_classes = array();
|
||||
// registered filters
|
||||
public $registered_filters = array();
|
||||
// registered resources
|
||||
public $registered_resources = array();
|
||||
// autoload filter
|
||||
public $autoload_filters = array();
|
||||
// status of filter on variable output
|
||||
@@ -221,25 +232,22 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $_file_perms = 0644;
|
||||
// default dir permissions
|
||||
public $_dir_perms = 0771;
|
||||
// smarty object reference
|
||||
public $smarty = null;
|
||||
// block tag hierarchy
|
||||
public $_tag_stack = array();
|
||||
// flag if {block} tag is compiled for template inheritance
|
||||
public $inheritance = false;
|
||||
// plugins
|
||||
public $_plugins = array();
|
||||
// generate deprecated function call notices?
|
||||
public $deprecation_notices = true;
|
||||
// Smarty 2 BC
|
||||
public $_version = self::SMARTY_VERSION;
|
||||
|
||||
/**
|
||||
* Class constructor, initializes basic smarty properties
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// self reference needed by other classes methods
|
||||
$this->smarty = $this;
|
||||
|
||||
// selfpointer need by some other class methods
|
||||
$this->smarty = $this;
|
||||
if (is_callable('mb_internal_encoding')) {
|
||||
mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
|
||||
}
|
||||
@@ -310,9 +318,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
// create template object if necessary
|
||||
($template instanceof $this->template_class)? $_template = $template :
|
||||
$_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent);
|
||||
if (isset($this->error_reporting)) {
|
||||
$_smarty_old_error_level = error_reporting($this->error_reporting);
|
||||
}
|
||||
// obtain data for cache modified check
|
||||
if ($this->cache_modified_check && $this->caching && $display) {
|
||||
$_isCached = $_template->isCached() && !$_template->has_nocache_code;
|
||||
@@ -329,9 +334,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
$_output = $_template->getRenderedTemplate();
|
||||
}
|
||||
$_template->rendered_content = null;
|
||||
if (isset($this->error_reporting)) {
|
||||
error_reporting($_smarty_old_error_level);
|
||||
}
|
||||
// display or fetch
|
||||
if ($display) {
|
||||
if ($this->caching && $this->cache_modified_check) {
|
||||
@@ -425,13 +427,13 @@ class Smarty extends Smarty_Internal_Data {
|
||||
if (!is_object($template)) {
|
||||
// we got a template resource
|
||||
// already in template cache?
|
||||
$_templateId = crc32($template . $cache_id . $compile_id);
|
||||
$_templateId = sha1($template . $cache_id . $compile_id);
|
||||
if (isset($this->template_objects[$_templateId]) && $this->caching) {
|
||||
// return cached template object
|
||||
$tpl = $this->template_objects[$_templateId];
|
||||
} else {
|
||||
// create new template object
|
||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
|
||||
$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
|
||||
}
|
||||
} else {
|
||||
// just return a copy of template class
|
||||
@@ -446,18 +448,95 @@ class Smarty extends Smarty_Internal_Data {
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if a template resource exists
|
||||
*
|
||||
* @param string $resource_name template name
|
||||
* @return boolean status
|
||||
*/
|
||||
function templateExists($resource_name)
|
||||
{
|
||||
// create template object
|
||||
$save = $this->template_objects;
|
||||
$tpl = new $this->template_class($resource_name, $this);
|
||||
// check if it does exists
|
||||
$result = $tpl->isExisting();
|
||||
$this->template_objects = $save;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single or all global variables
|
||||
*
|
||||
* @param object $smarty
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
function getGlobal($varname = null)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
if (isset(self::$global_tpl_vars[$varname])) {
|
||||
return self::$global_tpl_vars[$varname]->value;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
foreach (self::$global_tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
return $_result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache folder
|
||||
*
|
||||
* @param integer $exp_time expiration time
|
||||
* @param string $type resource type
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
function clearAllCache($exp_time = null, $type = null)
|
||||
{
|
||||
// load cache resource and call clearAll
|
||||
return $this->loadCacheResource($type)->clearAll($exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param string $template_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer $exp_time expiration time
|
||||
* @param string $type resource type
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||
{
|
||||
// load cache resource and call clear
|
||||
return $this->loadCacheResource($type)->clear($template_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads security class and enables security
|
||||
*/
|
||||
public function enableSecurity()
|
||||
public function enableSecurity($security_class = null)
|
||||
{
|
||||
if (isset($this->security_class)) {
|
||||
$this->security_policy = new $this->security_class;
|
||||
$this->security_handler = new Smarty_Internal_Security_Handler($this);
|
||||
$this->security = true;
|
||||
if ($security_class instanceof Smarty_Security) {
|
||||
$this->security_policy = $security_class;
|
||||
return;
|
||||
}
|
||||
if ($security_class == null) {
|
||||
$security_class = $this->security_class;
|
||||
}
|
||||
if (class_exists($security_class)) {
|
||||
$this->security_policy = new $security_class($this);
|
||||
} else {
|
||||
throw new SmartyException('Property security_class is not defined');
|
||||
throw new SmartyException("Security class '$security_class' is not defined");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,9 +545,40 @@ class Smarty extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function disableSecurity()
|
||||
{
|
||||
$this->security = false;
|
||||
$this->security_policy = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads cache resource.
|
||||
*
|
||||
* @param string $type cache resource type
|
||||
* @return object of cache resource
|
||||
*/
|
||||
public function loadCacheResource($type = null) {
|
||||
if (!isset($type)) {
|
||||
$type = $this->caching_type;
|
||||
}
|
||||
// already loaded?
|
||||
if (isset($this->cache_resource_objects[$type])) {
|
||||
return $this->cache_resource_objects[$type];
|
||||
}
|
||||
if (in_array($type, $this->cache_resource_types)) {
|
||||
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
|
||||
return $this->cache_resource_objects[$type] = new $cache_resource_class($this);
|
||||
}
|
||||
else {
|
||||
// try plugins dir
|
||||
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($cache_resource_class, $this->plugins_dir)) {
|
||||
return $this->cache_resource_objects[$type] = new $cache_resource_class($this);
|
||||
}
|
||||
else {
|
||||
throw new SmartyException("Unable to load cache resource '{$type}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set template directory
|
||||
*
|
||||
@@ -487,139 +597,10 @@ class Smarty extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function addTemplateDir($template_dir)
|
||||
{
|
||||
$this->template_dir = array_merge((array)$this->template_dir, (array)$template_dir);
|
||||
$this->template_dir = array_unique($this->template_dir);
|
||||
$this->template_dir = array_unique(array_merge((array)$this->template_dir, (array)$template_dir));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a template resource exists
|
||||
*
|
||||
* @param string $resource_name template name
|
||||
* @return boolean status
|
||||
*/
|
||||
function templateExists($resource_name)
|
||||
{
|
||||
// create template object
|
||||
$save = $this->template_objects;
|
||||
$tpl = new $this->template_class($resource_name, $this);
|
||||
// check if it does exists
|
||||
$result = $tpl->isExisting();
|
||||
$this->template_objects = $save;
|
||||
unset ($tpl);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes unknown classes and loads plugin files for them
|
||||
* class name format: Smarty_PluginType_PluginName
|
||||
* plugin filename format: plugintype.pluginname.php
|
||||
*
|
||||
* @param string $plugin_name class plugin name to load
|
||||
* @return string |boolean filepath of loaded file or false
|
||||
*/
|
||||
public function loadPlugin($plugin_name, $check = true)
|
||||
{
|
||||
// if function or class exists, exit silently (already loaded)
|
||||
if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false)))
|
||||
return true;
|
||||
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
||||
$_plugin_name = strtolower($plugin_name);
|
||||
$_name_parts = explode('_', $_plugin_name, 3);
|
||||
// class name must have three parts to be valid plugin
|
||||
if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
|
||||
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
||||
return false;
|
||||
}
|
||||
// if type is "internal", get plugin from sysplugins
|
||||
if ($_name_parts[1] == 'internal') {
|
||||
$file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// plugin filename is expected to be: [type].[name].php
|
||||
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
||||
// loop through plugin dirs and find the plugin
|
||||
foreach((array)$this->plugins_dir as $_plugin_dir) {
|
||||
if (strpos('/\\', substr($_plugin_dir, -1)) === false) {
|
||||
$_plugin_dir .= DS;
|
||||
}
|
||||
$file = $_plugin_dir . $_plugin_filename;
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
// no plugin loaded
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->loadPlugin($_plugin)) {
|
||||
if (class_exists($_plugin, false)) {
|
||||
$_plugin = array($_plugin, 'execute');
|
||||
}
|
||||
if (is_callable($_plugin)) {
|
||||
return $this->registered_filters[$type][$_filter_name] = $_plugin;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("{$type}filter \"{$name}\" not callable");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exception handler for Smarty.
|
||||
*
|
||||
* @param mixed $handler function name or array with object/method names
|
||||
* @return string previous exception handler
|
||||
*/
|
||||
public function setExceptionHandler($handler)
|
||||
{
|
||||
$this->exception_handler = $handler;
|
||||
return set_exception_handler($handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type
|
||||
*/
|
||||
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
throw new SmartyException("Smarty error: $error_msg");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds directory of plugin files
|
||||
*
|
||||
@@ -629,34 +610,10 @@ class Smarty extends Smarty_Internal_Data {
|
||||
*/
|
||||
function addPluginsDir($plugins_dir)
|
||||
{
|
||||
$this->plugins_dir = array_merge((array)$this->plugins_dir, (array)$plugins_dir);
|
||||
$this->plugins_dir = array_unique($this->plugins_dir);
|
||||
$this->plugins_dir = array_unique(array_merge((array)$this->plugins_dir, (array)$plugins_dir));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single or all global variables
|
||||
*
|
||||
* @param object $smarty
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
function getGlobal($varname = null)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
if (isset($this->global_tpl_vars[$varname])) {
|
||||
return $this->global_tpl_vars[$varname]->value;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
foreach ($this->global_tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
return $_result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return a reference to a registered object
|
||||
@@ -675,6 +632,7 @@ class Smarty extends Smarty_Internal_Data {
|
||||
return $this->registered_objects[$name][0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return name of debugging template
|
||||
*
|
||||
@@ -697,29 +655,23 @@ class Smarty extends Smarty_Internal_Data {
|
||||
}
|
||||
|
||||
/**
|
||||
* lazy loads (valid) property objects
|
||||
*
|
||||
* @param string $name property name
|
||||
* clean up properties on cloned object
|
||||
*/
|
||||
public function __get($name)
|
||||
public function __clone()
|
||||
{
|
||||
if (in_array($name, array('register', 'unregister', 'utility', 'cache'))) {
|
||||
$class = "Smarty_Internal_" . ucfirst($name);
|
||||
$this->$name = new $class($this);
|
||||
return $this->$name;
|
||||
} else if ($name == '_version') {
|
||||
// Smarty 2 BC
|
||||
$this->_version = self::SMARTY_VERSION;
|
||||
return $this->_version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// clear config vars
|
||||
$this->config_vars = array();
|
||||
// clear assigned tpl vars
|
||||
$this->tpl_vars = array();
|
||||
// clear objects for external methods
|
||||
unset($this->register);
|
||||
unset($this->filter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes unknown class methods and lazy loads sysplugin files for them
|
||||
* class name format: Smarty_Method_MethodName
|
||||
* plugin filename format: method.methodname.php
|
||||
*
|
||||
* Handle unknown class methods
|
||||
*
|
||||
* @param string $name unknown methode name
|
||||
* @param array $args aurgument array
|
||||
*/
|
||||
@@ -728,11 +680,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
static $camel_func;
|
||||
if (!isset($camel_func))
|
||||
$camel_func = create_function('$c', 'return "_" . strtolower($c[1]);');
|
||||
// PHP4 call to constructor?
|
||||
if (strtolower($name) == 'smarty') {
|
||||
throw new SmartyException('Please use parent::__construct() to call parent constuctor');
|
||||
return false;
|
||||
}
|
||||
// see if this is a set/get for a property
|
||||
$first3 = strtolower(substr($name, 0, 3));
|
||||
if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
|
||||
@@ -749,13 +696,37 @@ class Smarty extends Smarty_Internal_Data {
|
||||
return $this->$property_name;
|
||||
else
|
||||
return $this->$property_name = $args[0];
|
||||
}
|
||||
// Smarty Backward Compatible wrapper
|
||||
if (strpos($name,'_') !== false) {
|
||||
if (!isset($this->wrapper)) {
|
||||
$this->wrapper = new Smarty_Internal_Wrapper($this);
|
||||
}
|
||||
return $this->wrapper->convert($name, $args);
|
||||
}
|
||||
// external Smarty methods ?
|
||||
foreach(array('filter','register') as $external) {
|
||||
if (method_exists("Smarty_Internal_{$external}",$name)) {
|
||||
if (!isset($this->$external)) {
|
||||
$class = "Smarty_Internal_{$external}";
|
||||
$this->$external = new $class($this);
|
||||
}
|
||||
return call_user_func_array(array($this->$external,$name), $args);
|
||||
}
|
||||
}
|
||||
if (in_array($name,array('clearCompiledTemplate','compileAllTemplates','compileAllConfig','testInstall','getTags'))) {
|
||||
if (!isset($this->utility)) {
|
||||
$this->utility = new Smarty_Internal_Utility($this);
|
||||
}
|
||||
return call_user_func_array(array($this->utility,$name), $args);
|
||||
}
|
||||
// PHP4 call to constructor?
|
||||
if (strtolower($name) == 'smarty') {
|
||||
throw new SmartyException('Please use parent::__construct() to call parent constuctor');
|
||||
return false;
|
||||
}
|
||||
// Smarty Backward Compatible wrapper
|
||||
if (!isset($this->wrapper)) {
|
||||
$this->wrapper = new Smarty_Internal_Wrapper($this);
|
||||
}
|
||||
return $this->wrapper->convert($name, $args);
|
||||
}
|
||||
throw new SmartyException("Call of unknown function '$name'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -67,7 +67,7 @@ function smarty_block_textformat($params, $content, $smarty, &$repeat, $template
|
||||
break;
|
||||
|
||||
default:
|
||||
$smarty->trigger_error("textformat: unknown attribute '$_key'");
|
||||
trigger_error("textformat: unknown attribute '$_key'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -55,7 +55,7 @@ function smarty_function_cycle($params, $smarty, $template)
|
||||
|
||||
if (!in_array('values', array_keys($params))) {
|
||||
if(!isset($cycle_vars[$name]['values'])) {
|
||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||
trigger_error("cycle: missing 'values' parameter");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: smarty_internal_cache.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
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @version 3-SVN$Rev: 3286 $
|
||||
*/
|
||||
|
||||
class Smarty_Internal_Cache {
|
||||
|
||||
protected $smarty;
|
||||
|
||||
function __construct($smarty) {
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads cache resource.
|
||||
*
|
||||
* @return object of cache resource
|
||||
*/
|
||||
public function loadResource($type = null) {
|
||||
if (!isset($type)) {
|
||||
$type = $this->smarty->caching_type;
|
||||
}
|
||||
// already loaded?
|
||||
if (isset($this->smarty->cache_resource_objects[$type])) {
|
||||
return $this->smarty->cache_resource_objects[$type];
|
||||
}
|
||||
if (in_array($type, $this->smarty->cache_resource_types)) {
|
||||
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
|
||||
return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty);
|
||||
}
|
||||
else {
|
||||
// try plugins dir
|
||||
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
|
||||
if ($this->smarty->loadPlugin($cache_resource_class)) {
|
||||
return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty);
|
||||
}
|
||||
else {
|
||||
throw new SmartyException("Unable to load cache resource '{$type}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache folder
|
||||
*
|
||||
* @param integer $exp_time expiration time
|
||||
* @param string $type resource type
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
function clearAll($exp_time = null, $type = null)
|
||||
{
|
||||
return $this->loadResource($type)->clearAll($exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty cache for a specific template
|
||||
*
|
||||
* @param string $template_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer $exp_time expiration time
|
||||
* @param string $type resource type
|
||||
* @return integer number of cache files deleted
|
||||
*/
|
||||
function clear($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||
{
|
||||
// load cache resource
|
||||
$cacheResource = $this->loadResource($type);
|
||||
|
||||
return $cacheResource->clear($template_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
}
|
@@ -1,68 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Append
|
||||
*
|
||||
* Compiles the {append} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
* Smarty Internal Plugin Compile Append
|
||||
*
|
||||
* Compiles the {append} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Append Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Append extends Smarty_Internal_CompileBase {
|
||||
* Smarty Internal Plugin Compile Append Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('var', 'value');
|
||||
public $shorttag_order = array('var', 'value');
|
||||
public $optional_attributes = array('scope', 'index');
|
||||
|
||||
/**
|
||||
* Compiles code for the {append} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
* Compiles code for the {append} 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;
|
||||
$this->required_attributes = array('var', 'value');
|
||||
$this->optional_attributes = array('scope', 'nocache', 'index');
|
||||
|
||||
$_nocache = 'null';
|
||||
$_scope = 'null';
|
||||
// check for nocache attribute before _get_attributes because
|
||||
// it shall not controll caching of the compiled code, but is a parameter
|
||||
if (isset($args['nocache'])) {
|
||||
if ($args['nocache'] == 'true') {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($args['nocache']);
|
||||
}
|
||||
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($this->compiler->tag_nocache) {
|
||||
$_nocache = 'true';
|
||||
// create nocache var to make it know for further compiling
|
||||
$compiler->template->tpl_vars[trim($_attr['var'],"'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = SMARTY_PARENT_SCOPE;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = SMARTY_ROOT_SCOPE;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = SMARTY_GLOBAL_SCOPE;
|
||||
}
|
||||
}
|
||||
// compiled output
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// map to compile assign attributes
|
||||
if (isset($_attr['index'])) {
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],array($_attr[index] => $_attr[value]),true,$_nocache,$_scope);?>";
|
||||
$_params['smarty_internal_index'] = '[' . $_attr['index'] . ']';
|
||||
unset($_attr['index']);
|
||||
} else {
|
||||
return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>";
|
||||
$_params['smarty_internal_index'] = '[]';
|
||||
}
|
||||
$_new_attr = array();
|
||||
foreach ($_attr as $key => $value) {
|
||||
$_new_attr[] = array($key => $value);
|
||||
}
|
||||
// call compile assign
|
||||
return parent::compile($_new_attr, $compiler, $_params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,47 +19,41 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('var', 'value');
|
||||
$this->optional_attributes = array('scope', 'nocache', 'smarty_internal_index');
|
||||
|
||||
$this->shorttag_order = array('var', 'value');
|
||||
$this->optional_attributes = array('scope');
|
||||
$_nocache = 'null';
|
||||
$_scope = 'null';
|
||||
// check for nocache attribute before _get_attributes because
|
||||
// it shall not controll caching of the compiled code, but is a parameter
|
||||
if (isset($args['nocache'])) {
|
||||
if ($args['nocache'] == 'true') {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($args['nocache']);
|
||||
}
|
||||
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($this->compiler->tag_nocache) {
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// nocache ?
|
||||
if ($this->compiler->tag_nocache || $this->compiler->nocache) {
|
||||
$_nocache = 'true';
|
||||
// create nocache var to make it know for further compiling
|
||||
$compiler->template->tpl_vars[trim($_attr['var'],"'")] = new Smarty_variable(null, true);
|
||||
$compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
|
||||
}
|
||||
|
||||
// scope setup
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = SMARTY_PARENT_SCOPE;
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = SMARTY_ROOT_SCOPE;
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = SMARTY_GLOBAL_SCOPE;
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} else {
|
||||
$this->compiler->trigger_template_error('illegal value for "scope" attribute', $this->compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// compiled output
|
||||
if (isset($_attr['smarty_internal_index'])) {
|
||||
return "<?php if (!isset(\$_smarty_tpl->tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[smarty_internal_index] = $_attr[value];?>";
|
||||
if (isset($parameter['smarty_internal_index'])) {
|
||||
return "<?php if (!isset(\$_smarty_tpl->tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];?>";
|
||||
} else {
|
||||
return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";
|
||||
}
|
||||
|
@@ -13,6 +13,9 @@
|
||||
* Smarty Internal Plugin Compile Block Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('name');
|
||||
public $shorttag_order = array('name');
|
||||
/**
|
||||
* Compiles code for the {block} tag
|
||||
*
|
||||
@@ -23,16 +26,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('name');
|
||||
$this->optional_attributes = array('assign', 'nocache');
|
||||
// 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);
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $this->compiler->nocache, $this->compiler->smarty->merge_compiled_includes, $compiler->smarty->inheritance);
|
||||
$this->_open_tag('block', $save);
|
||||
if (isset($_attr['nocache'])) {
|
||||
if ($_attr['nocache'] == 'true') {
|
||||
$compiler->nocache = true;
|
||||
}
|
||||
if ($_attr['nocache'] == true) {
|
||||
$compiler->nocache = true;
|
||||
}
|
||||
// set flag for {block} tag
|
||||
$compiler->smarty->inheritance = true;
|
||||
@@ -43,7 +42,105 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
$compiler->has_code = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
||||
{
|
||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||
$_ldl = preg_quote($template->smarty->left_delimiter);
|
||||
|
||||
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'\w+'|\"\w+\")(\s*?)?((append|prepend|nocache)(=true)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||
$template->compiler_object->trigger_template_error('Illegal {block} tag syntax');
|
||||
} 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,
|
||||
$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,
|
||||
'', $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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
while (--$stack_count >= 0) {
|
||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_name == null) {
|
||||
$compiler->trigger_template_error('{$smarty.block.child} used out of context');
|
||||
}
|
||||
$_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);
|
||||
$compiler->template->block_data[$_name]['compiled'] = true;
|
||||
return $_output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile BlockClose Class
|
||||
@@ -62,61 +159,23 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->compiler->has_code = true;
|
||||
// check and get attributes
|
||||
$this->optional_attributes = array('name');
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$saved_data = $this->_close_tag(array('block'));
|
||||
// if name does match to opening tag
|
||||
if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) {
|
||||
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
|
||||
}
|
||||
$saved_data = $this->_close_tag(array('block'));
|
||||
$_name = trim($saved_data[0]['name'], "\"'");
|
||||
if (isset($compiler->template->block_data[$_name])) {
|
||||
// $_tpl = $this->smarty->createTemplate('eval:' . $compiler->template->block_data[$_name]['source'], null, null, $compiler->template);
|
||||
$_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $this->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);
|
||||
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||
} 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];
|
||||
// $_output content has already nocache code processed
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
// reset flag
|
||||
$compiler->smarty->inheritance = false;
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -13,21 +13,30 @@
|
||||
* Smarty Internal Plugin Compile Break Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('levels');
|
||||
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
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->optional_attributes = array('levels');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->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);
|
||||
|
@@ -14,28 +14,32 @@
|
||||
* Smarty Internal Plugin Compile Function_Call Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('name');
|
||||
public $shorttag_order = array('name');
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles the calls of user defined tags defined by {function}
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->required_attributes = array('name');
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// save posible attributes
|
||||
// save possible attributes
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of beind displayed
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
unset($_attr['name'], $_attr['assign']);
|
||||
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
|
||||
// set flag (compiled code of {function} must be included in cache file
|
||||
if ($compiler->nocache || $compiler->tag_nocache) {
|
||||
$_nocache = 'true';
|
||||
@@ -49,7 +53,8 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
|
||||
} else {
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (false) {
|
||||
if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
|
||||
foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
|
||||
if (!isset($_attr[$_key])) {
|
||||
@@ -70,15 +75,16 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$_hash = str_replace('-','_',$compiler->template->properties['nocache_hash']);
|
||||
// was there an assign attribute
|
||||
if (isset($_assign)) {
|
||||
if ($compiler->template->caching) {
|
||||
$_output = "\$_smarty_tpl->assign({$_assign},Smarty_Internal_Function_Call_Handler::call ('{$_name}',\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}));?>\n";
|
||||
$_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ('{$_name}',\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||
} else {
|
||||
$_output = "\$_smarty_tpl->assign({$_assign},smarty_template_function_{$_name}(\$_smarty_tpl,{$_params}));?>\n";
|
||||
$_output = "<?php ob_start(); smarty_template_function_{$_name}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||
}
|
||||
} else {
|
||||
if ($compiler->template->caching) {
|
||||
|
@@ -13,6 +13,10 @@
|
||||
* Smarty Internal Plugin Compile Capture Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $shorttag_order = array('name');
|
||||
public $optional_attributes = array('name', 'assign', 'append');
|
||||
|
||||
/**
|
||||
* Compiles code for the {capture} tag
|
||||
*
|
||||
@@ -23,7 +27,6 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->optional_attributes = array('name', 'assign', 'append');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
@@ -31,8 +34,9 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : null;
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : null;
|
||||
|
||||
$this->compiler->_capture_stack[] = array($buffer, $assign, $append);
|
||||
|
||||
$this->compiler->_capture_stack[] = array($buffer, $assign, $append, $this->compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$_output = "<?php ob_start(); ?>";
|
||||
|
||||
return $_output;
|
||||
@@ -55,8 +59,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($buffer, $assign, $append) = array_pop($this->compiler->_capture_stack);
|
||||
list($buffer, $assign, $append, $this->compiler->nocache) = array_pop($this->compiler->_capture_stack);
|
||||
|
||||
$_output = "<?php ";
|
||||
if (isset($assign)) {
|
||||
|
@@ -14,6 +14,11 @@
|
||||
* Smarty Internal Plugin Compile Config Load Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('file');
|
||||
public $shorttag_order = array('file','section');
|
||||
public $optional_attributes = array('section', 'scope');
|
||||
|
||||
/**
|
||||
* Compiles code for the {config_load} tag
|
||||
*
|
||||
@@ -24,10 +29,14 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('file');
|
||||
$this->optional_attributes = array('section', 'scope');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
|
||||
// save posible attributes
|
||||
$conf_file = $_attr['file'];
|
||||
if (isset($_attr['section'])) {
|
||||
@@ -35,13 +44,18 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
|
||||
} else {
|
||||
$section = 'null';
|
||||
}
|
||||
$scope = '$_smarty_tpl->smarty';
|
||||
$scope = '$_smarty_tpl';
|
||||
// scope setup
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'local') {
|
||||
$scope = '$_smarty_tpl';
|
||||
} elseif ($_attr['scope'] == 'parent') {
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$scope = '$_smarty_tpl->parent';
|
||||
} elseif ($_attr['scope'] == 'local') {
|
||||
$scope = '$_smarty_tpl';
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$scope = '$_smarty_tpl->smarty';
|
||||
} else {
|
||||
$this->compiler->trigger_template_error('illegal value for "scope" attribute', $this->compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// create config object
|
||||
|
@@ -13,21 +13,29 @@
|
||||
* Smarty Internal Plugin Compile Continue Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('levels');
|
||||
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
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{ {
|
||||
$this->compiler = $compiler;
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->optional_attributes = array('levels');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->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);
|
||||
|
@@ -26,8 +26,11 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase {
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
// compile always as nocache
|
||||
$this->compiler->tag_nocache = true;
|
||||
|
||||
// display debug template
|
||||
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl->smarty); ?>";
|
||||
$_output = "<?php Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Debug', \$_smarty_tpl->smarty->plugins_dir); Smarty_Internal_Debug::display_debug(\$_smarty_tpl->smarty); ?>";
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,10 @@
|
||||
* Smarty Internal Plugin Compile Eval Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase {
|
||||
public $required_attributes = array('var');
|
||||
public $optional_attributes = array('assign');
|
||||
public $shorttag_order = array('var','assign');
|
||||
|
||||
/**
|
||||
* Compiles code for the {eval} tag
|
||||
*
|
||||
|
@@ -14,6 +14,10 @@
|
||||
* Smarty Internal Plugin Compile extend Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('file');
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Compiles code for the {extends} tag
|
||||
*
|
||||
@@ -27,9 +31,13 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
$this->smarty = $compiler->smarty;
|
||||
$this->_rdl = preg_quote($this->smarty->right_delimiter);
|
||||
$this->_ldl = preg_quote($this->smarty->left_delimiter);
|
||||
$this->required_attributes = array('file');
|
||||
$filepath = $compiler->template->getTemplateFilepath();
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$include_file = null;
|
||||
eval('$include_file = ' . $_attr['file'] . ';');
|
||||
@@ -44,7 +52,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
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());
|
||||
$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);
|
||||
if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
|
||||
preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
|
||||
@@ -66,7 +74,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
$_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])));
|
||||
$this->saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template);
|
||||
Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
|
||||
$_start = $_start + $_end + 1;
|
||||
}
|
||||
$compiler->template->template_source = $_template->getTemplateSource();
|
||||
@@ -75,45 +83,5 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function saveBlockData($block_content, $block_tag, $template)
|
||||
{
|
||||
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
|
||||
$this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute");
|
||||
} else {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
// replace {$smarty.block.child}
|
||||
if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) {
|
||||
if (isset($template->block_data[$_name])) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
$template->block_data[$_name]['source'], $block_content);
|
||||
unset($template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->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 (preg_match('/(.?)(append)(.*)/', $block_tag, $_match) != 0) {
|
||||
$template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif (preg_match('/(.?)(prepend)(.*)/', $block_tag, $_match) != 0) {
|
||||
$template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
$template->block_data[$_name]['file'] = $template->getTemplateFilepath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -29,32 +29,33 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// {for $x=0; $x<$y; $x++} syntax
|
||||
if (isset($args['ifexp'])) {
|
||||
$this->required_attributes = array('ifexp', 'start', 'loop', 'varloop');
|
||||
if ($parameter == 0) {
|
||||
$this->required_attributes = array('start','to');
|
||||
$this->optional_attributes = array('max','step');
|
||||
} else {
|
||||
$this->required_attributes = array('start', 'to');
|
||||
$this->optional_attributes = array('step', 'max');
|
||||
}
|
||||
$this->required_attributes = array('start','ifexp','var','step');
|
||||
$this->optional_attributes = array();
|
||||
}
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
$local_vars = array();
|
||||
|
||||
$output = "<?php ";
|
||||
if (isset($_attr['ifexp'])) {
|
||||
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[varloop]]->value$_attr[loop]){\n";
|
||||
$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;";
|
||||
@@ -63,7 +64,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase {
|
||||
if (isset($_attr['step'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = ($_attr[to] - ($_statement[value]) < 0) ? -1 : 1;";
|
||||
$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";
|
||||
@@ -94,13 +95,14 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
list($_open_tag, $nocache, $local_vars) = $this->_close_tag(array('for'));
|
||||
$this->_open_tag('forelse', array('forelse', $nocache, $local_vars));
|
||||
@@ -117,13 +119,14 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
|
@@ -13,18 +13,22 @@
|
||||
* Smarty Internal Plugin Compile Foreach Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('from', 'item');
|
||||
public $optional_attributes = array('name', 'key');
|
||||
public $shorttag_order = array('from','item','key','name');
|
||||
|
||||
/**
|
||||
* Compiles code for the {foreach} 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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('from', 'item');
|
||||
$this->optional_attributes = array('name', 'key');
|
||||
$tpl = $compiler->template;
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
@@ -62,11 +66,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
$usesSmartyIndex = strpos($tpl->template_source, $SmartyVarName . 'index') !== false;
|
||||
$usesSmartyIteration = strpos($tpl->template_source, $SmartyVarName . 'iteration') !== false;
|
||||
$usesSmartyShow = strpos($tpl->template_source, $SmartyVarName . 'show') !== false;
|
||||
$usesSmartyTotal = $usesSmartyLast || strpos($tpl->template_source, $SmartyVarName . 'total') !== false;
|
||||
$usesSmartyTotal = strpos($tpl->template_source, $SmartyVarName . 'total') !== false;
|
||||
} else {
|
||||
$usesSmartyFirst = false;
|
||||
$usesSmartyLast = false;
|
||||
$usesSmartyTotal = false;
|
||||
$usesSmartyShow = false;
|
||||
}
|
||||
|
||||
$usesPropFirst = $usesSmartyFirst || strpos($tpl->template_source, $ItemVarName . 'first') !== false;
|
||||
@@ -74,7 +79,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
$usesPropIndex = $usesPropFirst || strpos($tpl->template_source, $ItemVarName . 'index') !== false;
|
||||
$usesPropIteration = $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'iteration') !== false;
|
||||
$usesPropShow = strpos($tpl->template_source, $ItemVarName . 'show') !== false;
|
||||
$usesPropTotal = $usesSmartyTotal || $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'total') !== false;
|
||||
$usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($tpl->template_source, $ItemVarName . 'total') !== false;
|
||||
// generate output code
|
||||
$output = "<?php ";
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n";
|
||||
@@ -85,7 +90,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
$output .= " \$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array');}\n";
|
||||
if ($usesPropTotal) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->total=(\$_from instanceof Traversable)?iterator_count(\$_from):count(\$_from);\n";
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_count(\$_from);\n";
|
||||
}
|
||||
if ($usesPropIteration) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->iteration=0;\n";
|
||||
@@ -93,6 +98,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
if ($usesPropIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->index=-1;\n";
|
||||
}
|
||||
if ($usesPropShow) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
|
||||
}
|
||||
if ($has_name) {
|
||||
if ($usesSmartyTotal) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['total'] = \$_smarty_tpl->tpl_vars[$item]->total;\n";
|
||||
@@ -103,9 +111,16 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
|
||||
if ($usesSmartyIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']=-1;\n";
|
||||
}
|
||||
if ($usesSmartyShow) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['show']=(\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
|
||||
}
|
||||
}
|
||||
$output .= "if (count(\$_from) > 0){\n";
|
||||
$output .= " foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value){\n";
|
||||
if ($usesPropTotal) {
|
||||
$output .= "if (\$_smarty_tpl->tpl_vars[$item]->total > 0){\n";
|
||||
} else {
|
||||
$output .= "if (\$_smarty_tpl->_count(\$_from) > 0){\n";
|
||||
}
|
||||
$output .= " foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value){\n";
|
||||
if ($key != null) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n";
|
||||
}
|
||||
@@ -150,9 +165,10 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
@@ -174,9 +190,10 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// check and get attributes
|
||||
|
@@ -13,20 +13,29 @@
|
||||
* Smarty Internal Plugin Compile Function Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('name');
|
||||
public $shorttag_order = array('name');
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the {function} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('name');
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
|
||||
$save = array($_attr, $compiler->parser->current_buffer,
|
||||
$compiler->template->has_nocache_code, $compiler->template->required_plugins);
|
||||
$this->_open_tag('function', $save);
|
||||
@@ -66,9 +75,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
@@ -18,21 +18,30 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('if condition');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$this->_open_tag('if',array(1,$compiler->tag_nocache));
|
||||
if (is_array($args['if condition'])) {
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value']."){?>";
|
||||
$this->_open_tag('if',array(1,$this->compiler->nocache));
|
||||
// must whole block be nocache ?
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
if (is_array($parameter['if condition'])) {
|
||||
if ($this->compiler->nocache) {
|
||||
$_nocache = '(null,true)';
|
||||
// create nocache var to make it know for further compiling
|
||||
$this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
$_output = "<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable{$_nocache};";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php if ({$args['if condition']}){?>";
|
||||
return "<?php if ({$parameter['if condition']}){?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,9 +55,10 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
|
||||
@@ -67,26 +77,52 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('if condition');
|
||||
// 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 = '(null,true)';
|
||||
// create nocache var to make it know for further compiling
|
||||
$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)) {
|
||||
$this->_open_tag('elseif', array($nesting, $compiler->tag_nocache));
|
||||
return "<?php }elseif({$args['if condition']}){?>";
|
||||
if ($condition_by_assign) {
|
||||
$this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
$_output = "<?php }else{ \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable{$_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']}){?>";
|
||||
}
|
||||
} 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));
|
||||
return "<?php }else{?>{$tmp}<?php if ({$args['if condition']}){?>";
|
||||
if ($condition_by_assign) {
|
||||
$_output = "<?php }else{?>{$tmp}<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable{$_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']}){?>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,12 +136,17 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'else', 'elseif'));
|
||||
// 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'));
|
||||
$tmp = '';
|
||||
for ($i = 0; $i < $nesting ; $i++) $tmp .= '}';
|
||||
return "<?php {$tmp}?>";
|
||||
|
@@ -14,6 +14,14 @@
|
||||
* Smarty Internal Plugin Compile Include Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
// caching mode to create nocache code but no cache file
|
||||
const CACHING_NOCACHE_CODE = 9999;
|
||||
// attribute definitions
|
||||
public $required_attributes = array('file');
|
||||
public $shorttag_order = array('file');
|
||||
public $option_flags = array('nocache','inline','caching');
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the {include} tag
|
||||
*
|
||||
@@ -24,28 +32,28 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('file');
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// save posible attributes
|
||||
$include_file = $_attr['file'];
|
||||
$has_compiled_template = false;
|
||||
if ($compiler->smarty->merge_compiled_includes || isset($_attr['inline'])) {
|
||||
if ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) {
|
||||
// check if compiled code can be merged (contains no variable part)
|
||||
if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2) and substr_count($include_file, '(') == 0) {
|
||||
$tmp = null;
|
||||
eval("\$tmp = $include_file;");
|
||||
if ($this->compiler->template->template_resource != $tmp) {
|
||||
$tpl = new $compiler->smarty->template_class ($tmp, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id);
|
||||
// suppress writing of compiled file
|
||||
$tpl->write_compiled_code = false;
|
||||
if ($this->compiler->template->caching) {
|
||||
// needs code for cached page but no cache file
|
||||
$tpl->caching = 9999;
|
||||
$tpl->caching = self::CACHING_NOCACHE_CODE;
|
||||
}
|
||||
if ($this->compiler->template->mustCompile) {
|
||||
// if ($this->compiler->template->mustCompile) {
|
||||
// make sure whole chain gest compiled
|
||||
$tpl->mustCompile = true;
|
||||
}
|
||||
// }
|
||||
if ($tpl->resource_object->usesCompiler && $tpl->isExisting()) {
|
||||
// get compiled code
|
||||
$compiled_tpl = $tpl->getCompiledTemplate();
|
||||
@@ -77,24 +85,24 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
|
||||
$_parent_scope = SMARTY_LOCAL_SCOPE;
|
||||
$_parent_scope = Smarty::SCOPE_LOCAL;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_parent_scope = SMARTY_PARENT_SCOPE;
|
||||
$_parent_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_parent_scope = SMARTY_ROOT_SCOPE;
|
||||
$_parent_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_parent_scope = SMARTY_GLOBAL_SCOPE;
|
||||
$_parent_scope = Smarty::SCOPE_GLOBAL;
|
||||
}
|
||||
}
|
||||
$_caching = 'null';
|
||||
if ($this->compiler->nocache || $this->compiler->tag_nocache) {
|
||||
$_caching = SMARTY_CACHING_OFF;
|
||||
$_caching = Smarty::CACHING_OFF;
|
||||
}
|
||||
// default for included templates
|
||||
if ($this->compiler->template->caching && !$this->compiler->nocache && !$this->compiler->tag_nocache) {
|
||||
$_caching = 9999;
|
||||
$_caching = self::CACHING_NOCACHE_CODE;
|
||||
}
|
||||
/*
|
||||
* if the {include} tag provides individual parameter for caching
|
||||
@@ -104,38 +112,36 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
||||
if (isset($_attr['cache_lifetime'])) {
|
||||
$_cache_lifetime = $_attr['cache_lifetime'];
|
||||
$this->compiler->tag_nocache = true;
|
||||
$_caching = SMARTY_CACHING_LIFETIME_CURRENT;
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
} else {
|
||||
$_cache_lifetime = 'null';
|
||||
}
|
||||
if (isset($_attr['cache_id'])) {
|
||||
$_cache_id = $_attr['cache_id'];
|
||||
$this->compiler->tag_nocache = true;
|
||||
$_caching = SMARTY_CACHING_LIFETIME_CURRENT;
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
} else {
|
||||
$_cache_id = '$_smarty_tpl->cache_id';
|
||||
}
|
||||
if (isset($_attr['nocache'])) {
|
||||
if (trim($_attr['nocache'], "'\"") == 'true') {
|
||||
$this->compiler->tag_nocache = true;
|
||||
$_caching = SMARTY_CACHING_OFF;
|
||||
}
|
||||
if (isset($_attr['compile_id'])) {
|
||||
$_compile_id = $_attr['compile_id'];
|
||||
} else {
|
||||
$_compile_id = '$_smarty_tpl->compile_id';
|
||||
}
|
||||
if (isset($_attr['caching'])) {
|
||||
if (trim($_attr['caching'], "'\"") == 'true') {
|
||||
$_caching = SMARTY_CACHING_LIFETIME_CURRENT;
|
||||
} else {
|
||||
$this->compiler->tag_nocache = true;
|
||||
$_caching = SMARTY_CACHING_OFF;
|
||||
}
|
||||
if ($_attr['caching'] === true) {
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
}
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
$_caching = Smarty::CACHING_OFF;
|
||||
}
|
||||
// create template object
|
||||
$_output = "<?php \$_template = new {$compiler->smarty->template_class}($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, $_cache_id, \$_smarty_tpl->compile_id, $_caching, $_cache_lifetime);\n";
|
||||
$_output = "<?php \$_template = new {$compiler->smarty->template_class}($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, $_cache_id, $_compile_id, $_caching, $_cache_lifetime);\n";
|
||||
// delete {include} standard attributes
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
|
||||
// remaining attributes must be assigned as smarty variable
|
||||
if (!empty($_attr)) {
|
||||
if ($_parent_scope == SMARTY_LOCAL_SCOPE) {
|
||||
if ($_parent_scope == Smarty::SCOPE_LOCAL) {
|
||||
// create variables
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
$_output .= "\$_template->assign('$_key',$_value);";
|
||||
|
@@ -14,6 +14,11 @@
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('file');
|
||||
public $shorttag_order = array('file');
|
||||
public $optional_attributes = array('once', 'assign');
|
||||
|
||||
/**
|
||||
* Compiles code for the {include_php} tag
|
||||
*
|
||||
@@ -23,30 +28,46 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
|
||||
*/
|
||||
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;
|
||||
$this->required_attributes = array('file');
|
||||
$this->optional_attributes = array('once', 'assign');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
$_output = '<?php ';
|
||||
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_file = ' . $_attr['file'] . ';');
|
||||
|
||||
$_file = realpath($_file);
|
||||
|
||||
if ($this->compiler->smarty->security) {
|
||||
$this->compiler->smarty->security_handler->isTrustedPHPDir($_file);
|
||||
if (!isset($this->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;
|
||||
} else {
|
||||
$_dir = $this->compiler->smarty->trusted_dir;
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach((array)$_dir as $_script_dir) {
|
||||
if (strpos('/\\', substr($_script_dir, -1)) === false) {
|
||||
$_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);
|
||||
}
|
||||
|
||||
if ($_file === false) {
|
||||
$this->compiler->trigger_template_error('include_php: file "' . $_attr['file'] . '" is not readable');
|
||||
if (isset($this->compiler->smarty->security_policy)) {
|
||||
$this->compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
|
||||
}
|
||||
|
||||
if ($this->compiler->smarty->security) {
|
||||
$this->compiler->smarty->security_handler->isTrustedPHPDir($_file);
|
||||
}
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
@@ -59,9 +80,9 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
|
||||
if (isset($_assign)) {
|
||||
return "<?php ob_start(); include{$_once} ('{$_file}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
|
||||
return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
|
||||
} else {
|
||||
return "<?php include{$_once} ('{$_file}');?>\n";
|
||||
return "<?php include{$_once} ('{$_filepath}');?>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,11 @@
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('name');
|
||||
public $shorttag_order = array('name');
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the {insert} tag
|
||||
*
|
||||
@@ -24,8 +29,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('name');
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// never compile as nocache code
|
||||
@@ -39,7 +42,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
|
||||
// save posible attributes
|
||||
eval('$_name = ' . $_attr['name'] . ';');
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of beind displayed
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
// create variable to make shure that the compiler knows about its nocache status
|
||||
$this->compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true);
|
||||
@@ -50,10 +53,10 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_script = ' . $_attr['script'] . ';');
|
||||
if (!$this->compiler->smarty->security && file_exists($_script)) {
|
||||
if (!isset($this->compiler->smarty->security_policy) && file_exists($_script)) {
|
||||
$_filepath = $_script;
|
||||
} else {
|
||||
if ($this->compiler->smarty->security) {
|
||||
if (isset($this->compiler->smarty->security_policy)) {
|
||||
$_dir = $this->compiler->smarty->security_policy->trusted_dir;
|
||||
} else {
|
||||
$_dir = $this->compiler->smarty->trusted_dir;
|
||||
@@ -91,7 +94,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
}
|
||||
// delete {insert} standard attributes
|
||||
unset($_attr['name'], $_attr['assign'], $_attr['script']);
|
||||
unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
|
@@ -25,6 +25,9 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = true;
|
||||
return $this->compiler->smarty->left_delimiter;
|
||||
|
@@ -25,6 +25,9 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
// enter nocache mode
|
||||
$this->compiler->nocache = true;
|
||||
// this tag does not return compiled code
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Plugin
|
||||
*
|
||||
@@ -13,23 +13,30 @@
|
||||
* Smarty Internal Plugin Compile Block Plugin Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of block function
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block plugin
|
||||
* @param string $function PHP function name
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $function)
|
||||
public function compile($args, $compiler, $parameter, $tag, $function)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
|
@@ -13,24 +13,32 @@
|
||||
* Smarty Internal Plugin Compile Function Plugin Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array();
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of function
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function plugin
|
||||
* @param string $function PHP function name
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $function)
|
||||
public function compile($args, $compiler, $parameter, $tag, $function)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
|
@@ -18,44 +18,44 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->smarty = $this->compiler->smarty;
|
||||
$this->required_attributes = array('value', 'modifierlist');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$output = $_attr['value'];
|
||||
$output = $parameter['value'];
|
||||
// loop over list of modifiers
|
||||
foreach ($_attr['modifierlist'] as $single_modifier) {
|
||||
foreach ($parameter['modifierlist'] as $single_modifier) {
|
||||
$modifier = $single_modifier[0];
|
||||
$single_modifier[0] = $output;
|
||||
$params = implode(',', $single_modifier);
|
||||
// check for registered modifier
|
||||
if (isset($compiler->smarty->registered_plugins['modifier'][$modifier])) {
|
||||
$function = $compiler->smarty->registered_plugins['modifier'][$modifier][0];
|
||||
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
|
||||
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$params})";
|
||||
} else {
|
||||
if (is_object($function[0])) {
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
} else {
|
||||
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
|
||||
}
|
||||
}
|
||||
// check for plugin modifiercompiler
|
||||
} else if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
|
||||
} else if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_modifiercompiler_' . $modifier, $compiler->smarty->plugins_dir)) {
|
||||
$plugin = 'smarty_modifiercompiler_' . $modifier;
|
||||
$output = $plugin($single_modifier, $compiler);
|
||||
// check for plugin modifier
|
||||
} else if ($function = $this->compiler->getPlugin($modifier, 'modifier')) {
|
||||
} else if ($function = $this->compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
|
||||
$output = "{$function}({$params})";
|
||||
// check if trusted PHP function
|
||||
} else if (is_callable($modifier)) {
|
||||
// check if modifier allowed
|
||||
if (!$this->compiler->template->security || $this->smarty->security_handler->isTrustedModifier($modifier, $this->compiler)) {
|
||||
if (!is_object($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedModifier($modifier, $this->compiler)) {
|
||||
$output = "{$modifier}({$params})";
|
||||
}
|
||||
} else {
|
||||
|
@@ -13,24 +13,31 @@
|
||||
* Smarty Internal Plugin Compile Object Block Function Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array();
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of block function
|
||||
* @param string $methode name of methode to call
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block object
|
||||
* @param string $methode name of methode to call
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $methode)
|
||||
public function compile($args, $compiler, $parameter, $tag, $methode)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
if (strlen($tag) < 5 || substr($tag, -5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
@@ -42,13 +49,19 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
|
||||
$this->_open_tag($tag . '->' . $methode, $_params);
|
||||
$this->_open_tag($tag . '->' . $methode, array($_params, $this->compiler->nocache));
|
||||
// maybe nocache because of nocache variables or nocache plugin
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
// compile code
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$methode}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
$base_tag = substr($tag, 0, -5);
|
||||
// closing tag of block plugin
|
||||
$_params = $this->_close_tag($base_tag . '->' . $methode);
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
// closing tag of block plugin, restore nocache
|
||||
list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag . '->' . $methode);
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
// compile code
|
||||
|
@@ -13,22 +13,29 @@
|
||||
* Smarty Internal Plugin Compile Object Function Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array();
|
||||
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 object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $methode)
|
||||
public function compile($args, $compiler, $parameter, $tag, $methode)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
$_assign = null;
|
||||
if (isset($_attr['assign'])) {
|
||||
$_assign = $_attr['assign'];
|
||||
|
@@ -13,47 +13,46 @@
|
||||
* Smarty Internal Plugin Compile Print Expression Class
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->optional_attributes = array('assign');
|
||||
$this->required_attributes = array('value');
|
||||
$this->optional_attributes = array('assign', 'nocache', 'nofilter', 'modifierlist');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// nocache option
|
||||
if (isset($_attr['nocache'])) {
|
||||
if ($_attr['nocache'] == 'true') {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
// filter handling
|
||||
if (isset($_attr['nofilter'])) {
|
||||
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']},{$_attr['value']});?>";
|
||||
$output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
|
||||
} else {
|
||||
// display value
|
||||
if (isset($this->compiler->smarty->registered_filters['variable'])) {
|
||||
$output = "Smarty_Internal_Filter_Handler::runFilter('variable', {$_attr['value']},\$_smarty_tpl->smarty, \$_smarty_tpl, {$_filter})";
|
||||
if (!$_attr['nofilter'] && isset($this->compiler->smarty->registered_filters['variable'])) {
|
||||
$output = "Smarty_Internal_Filter_Handler::runFilter('variable', {$parameter['value']},\$_smarty_tpl->smarty, \$_smarty_tpl, {$_filter})";
|
||||
} else {
|
||||
$output = $_attr['value'];
|
||||
$output = $parameter['value'];
|
||||
}
|
||||
if (!isset($_attr['nofilter']) && !empty($this->compiler->smarty->default_modifiers)) {
|
||||
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);
|
||||
@@ -63,10 +62,10 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
}
|
||||
}
|
||||
$output = $this->compiler->compileTag('private_modifier', array('modifierlist' => $modifierlist, 'value' => $output));
|
||||
$output = $this->compiler->compileTag('private_modifier', array(), array('modifierlist' => $modifierlist, 'value' => $output));
|
||||
}
|
||||
if (!empty($_attr['modifierlist'])) {
|
||||
$output = $this->compiler->compileTag('private_modifier', array('modifierlist' => $_attr['modifierlist'], 'value' => $output));
|
||||
if (!empty($parameter['modifierlist'])) {
|
||||
$output = $this->compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
|
||||
}
|
||||
$this->compiler->has_output = true;
|
||||
$output = "<?php echo {$output};?>";
|
||||
|
@@ -13,23 +13,29 @@
|
||||
* Smarty Internal Plugin Compile Registered Block Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of a block function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of block function
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block function
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag)
|
||||
public function compile($args, $compiler, $parameter, $tag)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
if (strlen($tag) < 6 || substr($tag,-5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache']) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
@@ -43,8 +49,8 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
|
||||
$this->_open_tag($tag, array($_params, $this->compiler->nocache));
|
||||
// maybe nocache because of nocache variables or nocache plugin
|
||||
$this->compiler->nocache = !$compiler->smarty->registered_plugins['block'][$tag][1] | $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$function = $compiler->smarty->registered_plugins['block'][$tag][0];
|
||||
$this->compiler->nocache = !$compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag][1] | $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag][0];
|
||||
// compile code
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
@@ -63,7 +69,7 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag);
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
$function = $compiler->smarty->registered_plugins['block'][$base_tag][0];
|
||||
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
|
||||
// compile code
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
|
@@ -13,26 +13,31 @@
|
||||
* Smarty Internal Plugin Compile Registered Function Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Compiles code for the execution of a registered function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of function
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag)
|
||||
public function compile($args, $compiler, $parameter, $tag)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array('_any');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache']) {
|
||||
$this->compiler->tag_nocache = true;
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
// not cachable?
|
||||
$this->compiler->tag_nocache = !$compiler->smarty->registered_plugins['function'][$tag][1];
|
||||
$this->compiler->tag_nocache = $this->compiler->tag_nocache || !$compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][1];
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
@@ -43,12 +48,12 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
}
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$function = $compiler->smarty->registered_plugins['function'][$tag][0];
|
||||
$function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][0];
|
||||
// compile code
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php echo {$function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = "<?php echo \$_smarty_tpl->smarty->registered_plugins['function']['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
$output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
} else {
|
||||
$output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
}
|
||||
|
@@ -20,22 +20,22 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$_index = preg_split("/\]\[/",substr($args, 1, strlen($args)-2));
|
||||
$_index = preg_split("/\]\[/",substr($parameter, 1, strlen($parameter)-2));
|
||||
$compiled_ref = ' ';
|
||||
$variable = trim($_index[0], "'");
|
||||
switch ($variable) {
|
||||
case 'foreach':
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$args";
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
|
||||
case 'section':
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$args";
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
|
||||
case 'capture':
|
||||
return "\$_smarty_tpl->smarty->_smarty_vars$args";
|
||||
return "\$_smarty_tpl->smarty->_smarty_vars$parameter";
|
||||
case 'now':
|
||||
return 'time()';
|
||||
case 'cookies':
|
||||
if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
case 'server':
|
||||
case 'session':
|
||||
case 'request':
|
||||
if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
return "'$_version'";
|
||||
|
||||
case 'const':
|
||||
if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
|
||||
$compiler->trigger_template_error("(secure mode) constants not permitted");
|
||||
break;
|
||||
}
|
||||
|
@@ -25,6 +25,9 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$_attr = $this->_get_attributes($args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$this->compiler->has_code = true;
|
||||
return $this->compiler->smarty->right_delimiter;
|
||||
|
@@ -13,6 +13,11 @@
|
||||
* Smarty Internal Plugin Compile Section Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase {
|
||||
// attribute definitions
|
||||
public $required_attributes = array('name', 'loop');
|
||||
public $shorttag_order = array('name', 'loop');
|
||||
public $optional_attributes = array('start', 'step', 'max', 'show');
|
||||
|
||||
/**
|
||||
* Compiles code for the {section} tag
|
||||
*
|
||||
@@ -23,8 +28,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase {
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('name', 'loop');
|
||||
$this->optional_attributes = array('start', 'step', 'max', 'show');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
|
||||
|
@@ -18,12 +18,12 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
|
||||
*
|
||||
* @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)
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$this->required_attributes = array('if condition');
|
||||
// check and get attributes
|
||||
$_attr = $this->_get_attributes($args);
|
||||
$this->_open_tag('while', $this->compiler->nocache);
|
||||
@@ -32,12 +32,12 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
|
||||
|
||||
if (is_array($args['if condition'])) {
|
||||
$_output = " <?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;\n";
|
||||
$_output .= " while (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value'].") {\n ?>";
|
||||
if (is_array($parameter['if condition'])) {
|
||||
$_output = " <?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable;\n";
|
||||
$_output .= " while (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value'].") {\n ?>";
|
||||
return $_output;
|
||||
} else {
|
||||
return '<?php while (' . $args['if condition'] . ') { ?>';
|
||||
return '<?php while (' . $parameter['if condition'] . ') { ?>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,80 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin CompileBase
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin CompileBase
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class does extend all internal compile plugins
|
||||
*/
|
||||
//abstract class Smarty_Internal_CompileBase implements TagCompilerInterface
|
||||
abstract class Smarty_Internal_CompileBase
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
// initialize valid attributes
|
||||
$this->required_attributes = array();
|
||||
$this->optional_attributes = array();
|
||||
}
|
||||
* This class does extend all internal compile plugins
|
||||
*/
|
||||
// abstract class Smarty_Internal_CompileBase implements TagCompilerInterface
|
||||
class Smarty_Internal_CompileBase {
|
||||
public $required_attributes = array();
|
||||
public $optional_attributes = array();
|
||||
public $shorttag_order = array();
|
||||
public $option_flags = array('nocache');
|
||||
|
||||
|
||||
/**
|
||||
* This function checks if the attributes passed are valid
|
||||
*
|
||||
* The attributes passed for the tag to compile are checked against the list of required and
|
||||
* optional attributes. Required attributes must be present. Optional attributes are check against
|
||||
* against the corresponding list. The keyword '_any' specifies that any attribute will be accepted
|
||||
* as valid
|
||||
*
|
||||
* @todo More generallized handling of the nocache attributes in compile plugins
|
||||
* @param array $args attributes applied to the tag
|
||||
* @return array attributes for further processing
|
||||
*/
|
||||
function _get_attributes ($args)
|
||||
{
|
||||
* This function checks if the attributes passed are valid
|
||||
*
|
||||
* The attributes passed for the tag to compile are checked against the list of required and
|
||||
* optional attributes. Required attributes must be present. Optional attributes are check against
|
||||
* against the corresponding list. The keyword '_any' specifies that any attribute will be accepted
|
||||
* as valid
|
||||
*
|
||||
* @param array $attributes attributes applied to the tag
|
||||
* @return array of mapped attributes for further processing
|
||||
*/
|
||||
function _get_attributes ($attributes)
|
||||
{
|
||||
$_indexed_attr = array();
|
||||
// loop over attributes
|
||||
foreach ($attributes as $key => $mixed) {
|
||||
// shorthand ?
|
||||
if (!is_array($mixed)) {
|
||||
// option flag ?
|
||||
if (in_array(trim($mixed, '\'"'), $this->option_flags)) {
|
||||
$_indexed_attr[trim($mixed, '\'"')] = true;
|
||||
// shorthand attribute ?
|
||||
} else if (isset($this->shorttag_order[$key])) {
|
||||
$_indexed_attr[$this->shorttag_order[$key]] = $mixed;
|
||||
} else {
|
||||
// too many shorthands
|
||||
$this->compiler->trigger_template_error('too many shorthand attributes', $this->compiler->lex->taglineno);
|
||||
}
|
||||
// named attribute
|
||||
} else {
|
||||
$kv = each($mixed);
|
||||
// option flag?
|
||||
if (in_array($kv['key'], $this->option_flags)) {
|
||||
if (is_bool($kv['value'])) {
|
||||
$_indexed_attr[$kv['key']] = $kv['value'];
|
||||
} else if (is_string($kv['value']) && in_array(trim($kv['value'], '\'"'), array('true', 'false'))) {
|
||||
if (trim($kv['value']) == 'true') {
|
||||
$_indexed_attr[$kv['key']] = true;
|
||||
} else {
|
||||
$_indexed_attr[$kv['key']] = false;
|
||||
}
|
||||
} else if (is_numeric($kv['value']) && in_array($kv['value'], array(0, 1))) {
|
||||
if ($kv['value'] == 1) {
|
||||
$_indexed_attr[$kv['key']] = true;
|
||||
} else {
|
||||
$_indexed_attr[$kv['key']] = false;
|
||||
}
|
||||
} else {
|
||||
$this->compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $this->compiler->lex->taglineno);
|
||||
}
|
||||
// must be named attribute
|
||||
} else {
|
||||
$_indexed_attr = array_merge($_indexed_attr, $mixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
// check if all required attributes present
|
||||
foreach ($this->required_attributes as $attr) {
|
||||
if (!array_key_exists($attr, $args)) {
|
||||
$this->compiler->trigger_template_error("missing \"" . $attr . "\" attribute");
|
||||
if (!array_key_exists($attr, $_indexed_attr)) {
|
||||
$this->compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $this->compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// check for unallowed attributes
|
||||
if ($this->optional_attributes != array('_any')) {
|
||||
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes);
|
||||
foreach ($args as $key => $dummy) {
|
||||
if (!in_array($key, $tmp_array) && $key !== 0) {
|
||||
$this->compiler->trigger_template_error("unexpected \"" . $key . "\" attribute");
|
||||
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
|
||||
foreach ($_indexed_attr as $key => $dummy) {
|
||||
if (!in_array($key, $tmp_array) && $key !== 0) {
|
||||
$this->compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $this->compiler->lex->taglineno);
|
||||
}
|
||||
}
|
||||
}
|
||||
// default 'false' for all option flags not set
|
||||
foreach ($this->option_flags as $flag) {
|
||||
if (!isset($_indexed_attr[$flag])) {
|
||||
$_indexed_attr[$flag] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
return $_indexed_attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push opening tag name on stack
|
||||
*
|
||||
* Optionally additional data can be saved on stack
|
||||
*
|
||||
* @param string $open_tag the opening tag's name
|
||||
* @param anytype $data optional data which shall be saved on stack
|
||||
*/
|
||||
* Push opening tag name on stack
|
||||
*
|
||||
* Optionally additional data can be saved on stack
|
||||
*
|
||||
* @param string $open_tag the opening tag's name
|
||||
* @param anytype $data optional data which shall be saved on stack
|
||||
*/
|
||||
function _open_tag($open_tag, $data = null)
|
||||
{
|
||||
array_push($this->compiler->_tag_stack, array($open_tag, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop closing tag
|
||||
*
|
||||
* Raise an error if this stack-top doesn't match with expected opening tags
|
||||
*
|
||||
* @param array $ |string $expected_tag the expected opening tag names
|
||||
* @return anytype the opening tag's name or saved data
|
||||
*/
|
||||
* Pop closing tag
|
||||
*
|
||||
* Raise an error if this stack-top doesn't match with expected opening tags
|
||||
*
|
||||
* @param array $ |string $expected_tag the expected opening tag names
|
||||
* @return anytype the opening tag's name or saved data
|
||||
*/
|
||||
function _close_tag($expected_tag)
|
||||
{
|
||||
if (count($this->compiler->_tag_stack) > 0) {
|
||||
@@ -95,7 +141,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
return;
|
||||
}
|
||||
// wrong nesting of tags
|
||||
$this->compiler->trigger_template_error("unexpected closing tag",$this->compiler->lex->taglineno);
|
||||
$this->compiler->trigger_template_error("unexpected closing tag", $this->compiler->lex->taglineno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -241,9 +241,9 @@ class Smarty_Internal_Config {
|
||||
public function loadConfigVars ($sections = null, $scope)
|
||||
{
|
||||
if (isset($this->template)) {
|
||||
$this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
|
||||
$this->template->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp(),'file');
|
||||
} else {
|
||||
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp());
|
||||
$this->smarty->properties['file_dependency'][sha1($this->getConfigFilepath())] = array($this->getConfigFilepath(), $this->getTimestamp(),'file');
|
||||
}
|
||||
if ($this->mustCompile()) {
|
||||
$this->compileConfigSource();
|
||||
|
@@ -22,8 +22,8 @@ class Smarty_Internal_Config_File_Compiler {
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
// get required plugins
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Configfilelexer');
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Configfileparser');
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfilelexer', $this->smarty->plugins_dir);
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfileparser', $this->smarty->plugins_dir);
|
||||
$this->config_data['sections'] = array();
|
||||
$this->config_data['vars'] = array();
|
||||
}
|
||||
|
@@ -25,17 +25,17 @@ class Smarty_Internal_Data {
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function assign($tpl_var, $value = null, $nocache = false)
|
||||
{
|
||||
if (is_array($tpl_var)) {
|
||||
foreach ($tpl_var as $_key => $_val) {
|
||||
if ($_key != '') {
|
||||
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache, $scope);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($tpl_var != '') {
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache, $scope);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class Smarty_Internal_Data {
|
||||
public function assignGlobal($varname, $value = null, $nocache = false)
|
||||
{
|
||||
if ($varname != '') {
|
||||
$this->smarty->global_tpl_vars[$varname] = new Smarty_variable($value, $nocache);
|
||||
Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -58,27 +58,26 @@ class Smarty_Internal_Data {
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $ &$value the referenced value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function assignByRef($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function assignByRef($tpl_var, &$value, $nocache = false)
|
||||
{
|
||||
if ($tpl_var != '') {
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $scope);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
|
||||
$this->tpl_vars[$tpl_var]->value = &$value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper function for Smarty 2 BC
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $ &$value the referenced value to assign
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function assign_by_ref($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function assign_by_ref($tpl_var, &$value)
|
||||
{
|
||||
trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE);
|
||||
$this->assignByRef($tpl_var, $value, $nocache, $scope);
|
||||
if($this->smarty->deprecation_notices)
|
||||
trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE);
|
||||
$this->assignByRef($tpl_var, $value);
|
||||
}
|
||||
/**
|
||||
* appends values to template variables
|
||||
@@ -87,9 +86,8 @@ class Smarty_Internal_Data {
|
||||
* @param mixed $value the value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function append($tpl_var, $value = null, $merge = false, $nocache = false)
|
||||
{
|
||||
if (is_array($tpl_var)) {
|
||||
// $tpl_var is an array, ignore $value
|
||||
@@ -98,12 +96,9 @@ class Smarty_Internal_Data {
|
||||
if (!isset($this->tpl_vars[$_key])) {
|
||||
$tpl_var_inst = $this->getVariable($_key, null, true, false);
|
||||
if ($tpl_var_inst instanceof Undefined_Smarty_Variable) {
|
||||
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache, $scope);
|
||||
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache);
|
||||
} else {
|
||||
$this->tpl_vars[$_key] = clone $tpl_var_inst;
|
||||
if ($scope != SMARTY_LOCAL_SCOPE) {
|
||||
$this->tpl_vars[$_key]->scope = $scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
|
||||
@@ -123,12 +118,9 @@ class Smarty_Internal_Data {
|
||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
||||
$tpl_var_inst = $this->getVariable($tpl_var, null, true, false);
|
||||
if ($tpl_var_inst instanceof Undefined_Smarty_Variable) {
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $scope);
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
|
||||
} else {
|
||||
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
|
||||
if ($scope != SMARTY_LOCAL_SCOPE) {
|
||||
$this->tpl_vars[$tpl_var]->scope = $scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
|
||||
@@ -170,8 +162,8 @@ class Smarty_Internal_Data {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* wrapper function for Smarty 2 BC
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $ &$value the referenced value to append
|
||||
@@ -179,7 +171,8 @@ class Smarty_Internal_Data {
|
||||
*/
|
||||
public function append_by_ref($tpl_var, &$value, $merge = false)
|
||||
{
|
||||
trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE);
|
||||
if($this->smarty->deprecation_notices)
|
||||
trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE);
|
||||
$this->appendByRef($tpl_var, $value, $merge);
|
||||
}
|
||||
/**
|
||||
@@ -212,8 +205,8 @@ class Smarty_Internal_Data {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if ($search_parents && isset($this->global_tpl_vars)) {
|
||||
foreach ($this->global_tpl_vars AS $key => $var) {
|
||||
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
|
||||
foreach (Smarty::$global_tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
}
|
||||
@@ -282,9 +275,9 @@ class Smarty_Internal_Data {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if (isset($this->smarty->global_tpl_vars[$variable])) {
|
||||
if (isset(Smarty::$global_tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return $this->smarty->global_tpl_vars[$variable];
|
||||
return Smarty::$global_tpl_vars[$variable];
|
||||
}
|
||||
if ($this->smarty->error_unassigned && $error_enable) {
|
||||
throw new SmartyException('Undefined Smarty variable "' . $variable . '"');
|
||||
@@ -428,7 +421,7 @@ class Smarty_Variable {
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
* @param boolean $scope the scope the variable will have (local,parent or root)
|
||||
*/
|
||||
public function __construct ($value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function __construct ($value = null, $nocache = false, $scope = Smarty::SCOPE_LOCAL)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->nocache = $nocache;
|
||||
|
@@ -87,7 +87,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data {
|
||||
$_template = new Smarty_Template ($smarty->debug_tpl, $smarty);
|
||||
$_template->caching = false;
|
||||
$_template->force_compile = false;
|
||||
$_template->security = false;
|
||||
$_template->disableSecurity();
|
||||
$_template->cache_id = null;
|
||||
$_template->compile_id = null;
|
||||
$_template->assign('template_data', self::$template_data);
|
||||
|
89
libs/sysplugins/smarty_internal_filter.php
Normal file
89
libs/sysplugins/smarty_internal_filter.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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 (Smarty_Internal_Plugin_Loader::loadPlugin($_plugin, $this->smarty->plugins_dir)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
@@ -34,7 +34,7 @@ class Smarty_Internal_Filter_Handler {
|
||||
if (!empty($smarty->autoload_filters[$type])) {
|
||||
foreach ((array)$smarty->autoload_filters[$type] as $name) {
|
||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||
if ($smarty->loadPlugin($plugin_name)) {
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($plugin_name, $smarty->plugins_dir)) {
|
||||
if (function_exists($plugin_name)) {
|
||||
// use loaded Smarty2 style plugin
|
||||
$output = $plugin_name($output, $smarty);
|
||||
|
64
libs/sysplugins/smarty_internal_plugin_loader.php
Normal file
64
libs/sysplugins/smarty_internal_plugin_loader.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Loader
|
||||
*
|
||||
* Compiles the {ldelim} tag
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Loader Class
|
||||
*/
|
||||
class Smarty_Internal_Plugin_Loader {
|
||||
/**
|
||||
* Takes unknown classes and loads plugin files for them
|
||||
* class name format: Smarty_PluginType_PluginName
|
||||
* plugin filename format: plugintype.pluginname.php
|
||||
*
|
||||
* @param string $plugin_name class plugin name to load
|
||||
* @return string |boolean filepath of loaded file or false
|
||||
*/
|
||||
static function loadPlugin($plugin_name, $plugins_dir)
|
||||
{
|
||||
// if function or class exists, exit silently (already loaded)
|
||||
if (is_callable($plugin_name) || class_exists($plugin_name, false))
|
||||
return true;
|
||||
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
||||
$_plugin_name = strtolower($plugin_name);
|
||||
$_name_parts = explode('_', $_plugin_name, 3);
|
||||
// class name must have three parts to be valid plugin
|
||||
if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
|
||||
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
||||
return false;
|
||||
}
|
||||
// if type is "internal", get plugin from sysplugins
|
||||
if ($_name_parts[1] == 'internal') {
|
||||
$file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// plugin filename is expected to be: [type].[name].php
|
||||
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
||||
// loop through plugin dirs and find the plugin
|
||||
foreach((array)$plugins_dir as $_plugin_dir) {
|
||||
if (strpos('/\\', substr($_plugin_dir, -1)) === false) {
|
||||
$_plugin_dir .= DS;
|
||||
}
|
||||
$file = $_plugin_dir . $_plugin_filename;
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
// no plugin loaded
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -1,121 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: smarty_internal_register.php
|
||||
* SVN: $Id: $
|
||||
* Smarty Internal Plugin Register
|
||||
*
|
||||
* 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.
|
||||
* External Smarty methods register/unregister
|
||||
*
|
||||
* 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
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @version 3-SVN$Rev: 3286 $
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for register/unregister methods
|
||||
*/
|
||||
class Smarty_Internal_Register {
|
||||
protected $smarty;
|
||||
|
||||
function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers block function to be used in templates
|
||||
* Registers plugin to be used in templates
|
||||
*
|
||||
* @param string $block_tag name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param string $type plugin type
|
||||
* @param string $tag name of template tag
|
||||
* @param callback $callback PHP callback to register
|
||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||
* @param array $cache_attr caching attributes if any
|
||||
*/
|
||||
function block($block_tag, $block_impl, $cacheable = true, $cache_attr = array())
|
||||
|
||||
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||
throw new Exception("Plugin tag \"{$tag}\" already registered");
|
||||
} elseif (!is_callable($callback)) {
|
||||
throw new Exception("Plugin \"{$tag}\" not callable");
|
||||
} else {
|
||||
$this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable);
|
||||
if (isset($cache_attr)&&in_array($type, array(Smarty::PLUGIN_BLOCK, Smarty::PLUGIN_FUNCTION))) {
|
||||
$this->smarty->registered_plugins[$type][$tag][] = (array) $cache_attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister Plugin
|
||||
*
|
||||
* @param string $type of plugin
|
||||
* @param string $tag name of plugin
|
||||
*/
|
||||
function unregisterPlugin($type, $tag)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['block'][$block_tag])) {
|
||||
throw new SmartyException("Plugin tag \"{$block_tag}\" already registered");
|
||||
} elseif (!is_callable($block_impl)) {
|
||||
throw new SmartyException("Plugin \"{$block_tag}\" not callable");
|
||||
} else {
|
||||
$this->smarty->registered_plugins['block'][$block_tag] =
|
||||
array($block_impl, $cacheable, $cache_attr);
|
||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||
unset($this->smarty->registered_plugins[$type][$tag]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @param string $type name of resource type
|
||||
* @param array $callback array of callbacks to handle resource
|
||||
*/
|
||||
public function registerResource($type, $callback)
|
||||
{
|
||||
$this->smarty->registered_resources[$type] = array($callback, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a resource
|
||||
*
|
||||
* @param string $type name of resource type
|
||||
*/
|
||||
function unregisterResource($type)
|
||||
{
|
||||
if (isset($this->smarty->registered_resources[$type])) {
|
||||
unset($this->smarty->registered_resources[$type]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers compiler function
|
||||
*
|
||||
* @param string $compiler_tag of template function
|
||||
* @param string $compiler_impl name of PHP function to register
|
||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||
*/
|
||||
function compilerFunction($compiler_tag, $compiler_impl, $cacheable = true)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['compiler'][$compiler_tag])) {
|
||||
throw new SmartyException("Plugin tag \"{$compiler_tag}\" already registered");
|
||||
} elseif (!is_callable($compiler_impl)) {
|
||||
throw new SmartyException("Plugin \"{$compiler_tag}\" not callable");
|
||||
} else {
|
||||
$this->smarty->registered_plugins['compiler'][$compiler_tag] =
|
||||
array($compiler_impl, $cacheable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers custom function to be used in templates
|
||||
*
|
||||
* @param string $function_tag the name of the template function
|
||||
* @param string $function_impl the name of the PHP function to register
|
||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||
* @param array $cache_attr caching attributes if any
|
||||
*/
|
||||
function templateFunction($function_tag, $function_impl, $cacheable = true, $cache_attr = array())
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['function'][$function_tag])) {
|
||||
throw new SmartyException("Plugin tag \"{$function_tag}\" already registered");
|
||||
} elseif (!is_callable($function_impl)) {
|
||||
throw new SmartyException("Plugin \"{$function_tag}\" not callable");
|
||||
} else {
|
||||
$this->smarty->registered_plugins['function'][$function_tag] =
|
||||
array($function_impl, $cacheable, $cache_attr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers modifier to be used in templates
|
||||
*
|
||||
* @param string $modifier_name name of template modifier
|
||||
* @param string $modifier_impl name of PHP function to register
|
||||
*/
|
||||
function modifier($modifier_name, $modifier_impl)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['modifier'][$modifier_name])) {
|
||||
throw new SmartyException("Plugin \"{$modifier_name}\" already registered");
|
||||
} elseif (!is_callable($modifier_impl)) {
|
||||
throw new SmartyException("Plugin \"{$modifier_name}\" not callable");
|
||||
} else {
|
||||
$this->smarty->registered_plugins['modifier'][$modifier_name] =
|
||||
array($modifier_impl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
@@ -126,7 +88,7 @@ class Smarty_Internal_Register {
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param mixed $ null | array $block_functs list of methods that are block format
|
||||
*/
|
||||
function templateObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
{
|
||||
// test if allowed methodes callable
|
||||
if (!empty($allowed)) {
|
||||
@@ -155,7 +117,7 @@ class Smarty_Internal_Register {
|
||||
* @param string $class name of template class
|
||||
* @param string $class_impl the referenced PHP class to register
|
||||
*/
|
||||
function templateClass($class_name, $class_impl)
|
||||
function registerClass($class_name, $class_impl)
|
||||
{
|
||||
// test if exists
|
||||
if (!class_exists($class_impl)) {
|
||||
@@ -165,100 +127,33 @@ class Smarty_Internal_Register {
|
||||
$this->smarty->registered_classes[$class_name] = $class_impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an output filter function to apply
|
||||
* to a template output
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function outputFilter($function_name)
|
||||
{
|
||||
$this->smarty->registered_filters['output'][$this->smarty->_get_filter_name($function_name)] = $function_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a postfilter function to apply
|
||||
* to a compiled template after compilation
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function postFilter($function_name)
|
||||
{
|
||||
$this->smarty->registered_filters['post'][$this->smarty->_get_filter_name($function_name)] = $function_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a prefilter function to apply
|
||||
* to a template before compiling
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function preFilter($function_name)
|
||||
{
|
||||
$this->smarty->registered_filters['pre'][$this->smarty->_get_filter_name($function_name)] = $function_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @param string $resource_type name of resource type
|
||||
* @param array $function_names array of functions to handle resource
|
||||
*/
|
||||
function resource($resource_type, $function_names)
|
||||
{
|
||||
if (count($function_names) == 4) {
|
||||
$this->smarty->_plugins['resource'][$resource_type] =
|
||||
array($function_names, false);
|
||||
} elseif (count($function_names) == 5) {
|
||||
$this->smarty->_plugins['resource'][$resource_type] =
|
||||
array(array(array(&$function_names[0], $function_names[1]),
|
||||
array(&$function_names[0], $function_names[2]),
|
||||
array(&$function_names[0], $function_names[3]),
|
||||
array(&$function_names[0], $function_names[4])),
|
||||
false);
|
||||
} else {
|
||||
throw new SmartyException("malformed function-list for '$resource_type' in register_resource");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an output filter function which
|
||||
* runs over any variable output
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function variableFilter($function_name)
|
||||
{
|
||||
$this->smarty->registered_filters['variable'][$this->smarty->_get_filter_name($function_name)] = $function_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a default plugin handler
|
||||
*
|
||||
* @param $function_name mixed string | array $plugin class/methode name
|
||||
* @param $callback mixed string | array $plugin class/methode name
|
||||
*/
|
||||
function defaultPluginHandler($function_name)
|
||||
function registerDefaultPluginHandler($callback)
|
||||
{
|
||||
if (is_callable($function_name)) {
|
||||
$this->smarty->default_plugin_handler_func = $function_name;
|
||||
if (is_callable($callback)) {
|
||||
$this->smarty->default_plugin_handler_func = $callback;
|
||||
} else {
|
||||
throw new SmartyException("Default plugin handler '$function_name' not callable");
|
||||
throw new SmartyException("Default plugin handler '$callback' not callable");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a default template handler
|
||||
*
|
||||
* @param $function_name mixed string | array class/method name
|
||||
* @param $callback mixed string | array class/method name
|
||||
*/
|
||||
function defaultTemplateHandler($function_name)
|
||||
function registerDefaultTemplateHandler($callback)
|
||||
{
|
||||
if (is_callable($function_name)) {
|
||||
$this->smarty->default_template_handler_func = $function_name;
|
||||
if (is_callable($callback)) {
|
||||
$this->smarty->default_template_handler_func = $callback;
|
||||
} else {
|
||||
throw new SmartyException("Default template handler '$function_name' not callable");
|
||||
throw new SmartyException("Default template handler '$callback' not callable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@@ -86,5 +86,4 @@ class Smarty_Internal_Resource_Eval {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -58,9 +58,9 @@ class Smarty_Internal_Resource_Extends {
|
||||
foreach ($_files as $_file) {
|
||||
$_filepath = $_template->buildTemplateFilepath ($_file);
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
if (is_object($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
$sha1String .= $_filepath;
|
||||
$this->allFilepaths[$_file] = $_filepath;
|
||||
@@ -98,14 +98,14 @@ class Smarty_Internal_Resource_Extends {
|
||||
}
|
||||
// read template file
|
||||
if ($_filepath != $_first) {
|
||||
$_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath));
|
||||
$_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath),'file');
|
||||
}
|
||||
$_template->template_filepath = $_filepath;
|
||||
$_content = file_get_contents($_filepath);
|
||||
if ($_filepath != $_last) {
|
||||
if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $_open) !=
|
||||
preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $_close)) {
|
||||
$this->smarty->trigger_error("unmatched {block} {/block} pairs in file '$_filepath'");
|
||||
$this->smarty->triggerError("unmatched {block} {/block} pairs in file '$_filepath'");
|
||||
}
|
||||
preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
|
||||
$_result_count = count($_result[0]);
|
||||
@@ -123,7 +123,7 @@ class Smarty_Internal_Resource_Extends {
|
||||
}
|
||||
$_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])));
|
||||
$this->saveBlockData($_block_content, $_result[0][$_start][0], $_filepath, $_template);
|
||||
Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $_template, $_filepath);
|
||||
$_start = $_start + $_end + 1;
|
||||
}
|
||||
} else {
|
||||
@@ -133,48 +133,6 @@ class Smarty_Internal_Resource_Extends {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* saveBlockData
|
||||
*/
|
||||
protected function saveBlockData($block_content, $block_tag, $_filepath, $_template)
|
||||
{
|
||||
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
|
||||
$this->smarty->trigger_error("'{$block_tag}' missing name attribute in file '$_filepath'");
|
||||
} else {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
// replace {$smarty.block.child}
|
||||
if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) {
|
||||
if (isset($_template->block_data[$_name])) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
$_template->block_data[$_name]['source'], $block_content);
|
||||
unset($_template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->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 (preg_match('/(.?)(append)(.*)/', $block_tag, $_match) != 0) {
|
||||
$_template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif (preg_match('/(.?)(prepend)(.*)/', $block_tag, $_match) != 0) {
|
||||
$_template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$_template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
$_template->block_data[$_name]['file'] = $_filepath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filepath to compiled template
|
||||
|
@@ -51,8 +51,8 @@ class Smarty_Internal_Resource_File {
|
||||
$_filepath = $_template->buildTemplateFilepath ();
|
||||
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
if (is_object($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
$_template->templateUid = sha1($_filepath);
|
||||
@@ -79,8 +79,8 @@ class Smarty_Internal_Resource_File {
|
||||
public function getTemplateSource($_template)
|
||||
{
|
||||
// read template file
|
||||
if (file_exists($_template->getTemplateFilepath())) {
|
||||
$_template->template_source = file_get_contents($_template->getTemplateFilepath());
|
||||
if (file_exists($_tfp = $_template->getTemplateFilepath())) {
|
||||
$_template->template_source = file_get_contents($_tfp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@@ -50,8 +50,8 @@ class Smarty_Internal_Resource_PHP {
|
||||
{
|
||||
$_filepath = $_template->buildTemplateFilepath ();
|
||||
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
if (is_object($_template->smarty->security_policy)) {
|
||||
$_template->smarty->security_policy->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
$_template->templateUid = sha1($_filepath);
|
||||
return $_filepath;
|
||||
@@ -76,8 +76,8 @@ class Smarty_Internal_Resource_PHP {
|
||||
*/
|
||||
public function getTemplateSource($_template)
|
||||
{
|
||||
if (file_exists($_template->getTemplateFilepath())) {
|
||||
$_template->template_source = file_get_contents($_template->getTemplateFilepath());
|
||||
if (file_exists($_tfp = $_template->getTemplateFilepath())) {
|
||||
$_template->template_source = file_get_contents($_tfp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@@ -14,9 +14,16 @@
|
||||
* Smarty Internal Plugin Resource Registered
|
||||
*/
|
||||
class Smarty_Internal_Resource_Registered {
|
||||
public function __construct($smarty)
|
||||
public function __construct($template, $resource_type = null)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
$this->smarty = $template->smarty;
|
||||
if (isset($resource_type)) {
|
||||
$template->smarty->registerResource($resource_type,
|
||||
array("smarty_resource_{$resource_type}_source",
|
||||
"smarty_resource_{$resource_type}_timestamp",
|
||||
"smarty_resource_{$resource_type}_secure",
|
||||
"smarty_resource_{$resource_type}_trusted"));
|
||||
}
|
||||
}
|
||||
// classes used for compiling Smarty templates from file resource
|
||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
@@ -62,7 +69,7 @@ class Smarty_Internal_Resource_Registered {
|
||||
{
|
||||
// return timestamp
|
||||
$time_stamp = false;
|
||||
call_user_func_array($this->smarty->_plugins['resource'][$_template->resource_type][0][1],
|
||||
call_user_func_array($this->smarty->registered_resources[$_template->resource_type][0][1],
|
||||
array($_template->resource_name, &$time_stamp, $this->smarty));
|
||||
return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
|
||||
}
|
||||
@@ -77,7 +84,7 @@ class Smarty_Internal_Resource_Registered {
|
||||
{
|
||||
// return timestamp
|
||||
$time_stamp = false;
|
||||
call_user_func_array($this->smarty->_plugins['resource'][$_resource_type][0][1],
|
||||
call_user_func_array($this->smarty->registered_resources[$_resource_type][0][1],
|
||||
array($_resource_name, &$time_stamp, $this->smarty));
|
||||
return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
|
||||
}
|
||||
@@ -91,7 +98,7 @@ class Smarty_Internal_Resource_Registered {
|
||||
public function getTemplateSource($_template)
|
||||
{
|
||||
// return template string
|
||||
return call_user_func_array($this->smarty->_plugins['resource'][$_template->resource_type][0][0],
|
||||
return call_user_func_array($this->smarty->registered_resources[$_template->resource_type][0][0],
|
||||
array($_template->resource_name, &$_template->template_source, $this->smarty));
|
||||
}
|
||||
|
||||
|
@@ -1,148 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Security Handler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Security
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains all methods for security checking
|
||||
*/
|
||||
class Smarty_Internal_Security_Handler {
|
||||
function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
/**
|
||||
* Check if PHP function is trusted.
|
||||
*
|
||||
* @param string $function_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if function is trusted
|
||||
*/
|
||||
function isTrustedPhpFunction($function_name, $compiler)
|
||||
{
|
||||
if (empty($this->smarty->security_policy->php_functions) || in_array($function_name, $this->smarty->security_policy->php_functions)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("PHP function '{$function_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if static class is trusted.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if class is trusted
|
||||
*/
|
||||
function isTrustedStaticClass($class_name, $compiler)
|
||||
{
|
||||
if (empty($this->smarty->security_policy->static_classes) || in_array($class_name, $this->smarty->security_policy->static_classes)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("access to static class '{$class_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if modifier is trusted.
|
||||
*
|
||||
* @param string $modifier_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if modifier is trusted
|
||||
*/
|
||||
function isTrustedModifier($modifier_name, $compiler)
|
||||
{
|
||||
if (empty($this->smarty->security_policy->modifiers) || in_array($modifier_name, $this->smarty->security_policy->modifiers)) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("modifier '{$modifier_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if stream is trusted.
|
||||
*
|
||||
* @param string $stream_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if stream is trusted
|
||||
*/
|
||||
function isTrustedStream($stream_name)
|
||||
{
|
||||
if (empty($this->smarty->security_policy->streams) || in_array($stream_name, $this->smarty->security_policy->streams)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new SmartyException ("stream '{$stream_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if directory is trusted
|
||||
*/
|
||||
function isTrustedResourceDir($filepath)
|
||||
{
|
||||
$_rp = realpath($filepath);
|
||||
if (isset($this->smarty->template_dir)) {
|
||||
foreach ((array)$this->smarty->template_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false &&
|
||||
strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
(strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($this->smarty->security_policy->secure_dir)) {
|
||||
foreach ((array)$this->smarty->security_policy->secure_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false) {
|
||||
if ($_cd == $_rp) {
|
||||
return true;
|
||||
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
(strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SmartyException ("directory '{$_rp}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if directory is trusted
|
||||
*/
|
||||
function isTrustedPHPDir($filepath)
|
||||
{
|
||||
$_rp = realpath($filepath);
|
||||
if (!empty($this->smarty->security_policy->trusted_dir)) {
|
||||
foreach ((array)$this->smarty->security_policy->trusted_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false) {
|
||||
if ($_cd == $_rp) {
|
||||
return true;
|
||||
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
substr($_rp, strlen($_cd), 1) == DS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SmartyException ("directory '{$_rp}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -24,13 +24,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
public $cache_lifetime = null;
|
||||
public $cacher_class = null;
|
||||
public $caching_type = null;
|
||||
public $force_compile = null;
|
||||
public $forceNocache = false;
|
||||
// Template resource
|
||||
public $template_resource = null;
|
||||
public $resource_type = null;
|
||||
public $resource_name = null;
|
||||
public $resource_object = null;
|
||||
// public $resource_object = null;
|
||||
private $isExisting = null;
|
||||
public $templateUid = '';
|
||||
// Template source
|
||||
@@ -45,13 +44,14 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
public $suppressHeader = false;
|
||||
public $suppressFileDependency = false;
|
||||
public $has_nocache_code = false;
|
||||
public $write_compiled_code = true;
|
||||
// Rendered content
|
||||
public $rendered_content = null;
|
||||
// Cache file
|
||||
private $cached_filepath = null;
|
||||
public $cached_timestamp = null;
|
||||
private $isCached = null;
|
||||
private $cache_resource_object = null;
|
||||
// private $cache_resource_object = null;
|
||||
private $cacheFileChecked = false;
|
||||
// template variables
|
||||
public $tpl_vars = array();
|
||||
@@ -65,7 +65,6 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
'function' => array());
|
||||
// required plugins
|
||||
public $required_plugins = array('compiled' => array(), 'nocache' => array());
|
||||
public $security = false;
|
||||
public $saved_modifier = null;
|
||||
public $smarty = null;
|
||||
// blocks for template inheritance
|
||||
@@ -87,25 +86,14 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// Smarty parameter
|
||||
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
|
||||
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
|
||||
$this->force_compile = $this->smarty->force_compile;
|
||||
$this->caching = $_caching === null ? $this->smarty->caching : $_caching;
|
||||
if ($this->caching === true) $this->caching = SMARTY_CACHING_LIFETIME_CURRENT;
|
||||
if ($this->caching === true) $this->caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
$this->cache_lifetime = $_cache_lifetime === null ?$this->smarty->cache_lifetime : $_cache_lifetime;
|
||||
$this->force_cache = $this->smarty->force_cache;
|
||||
$this->security = $this->smarty->security;
|
||||
$this->parent = $_parent;
|
||||
// dummy local smarty variable
|
||||
$this->tpl_vars['smarty'] = new Smarty_Variable;
|
||||
// Template resource
|
||||
$this->template_resource = $template_resource;
|
||||
// parse resource name
|
||||
if (!$this->parseResourceName ($template_resource, $this->resource_type, $this->resource_name, $this->resource_object)) {
|
||||
throw new SmartyException ("Unable to parse resource name \"{$template_resource}\"");
|
||||
}
|
||||
// load cache resource
|
||||
if (!$this->resource_object->isEvaluated && ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) {
|
||||
$this->cache_resource_object = $this->smarty->cache->loadResource();
|
||||
}
|
||||
// copy block data of template inheritance
|
||||
if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
|
||||
$this->block_data = $this->parent->block_data;
|
||||
@@ -187,7 +175,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
{
|
||||
$this->isExisting(true);
|
||||
if ($this->mustCompile === null) {
|
||||
$this->mustCompile = ($this->resource_object->usesCompiler && ($this->force_compile || $this->resource_object->isEvaluated || $this->getCompiledTimestamp () === false ||
|
||||
$this->mustCompile = ($this->resource_object->usesCompiler && ($this->smarty->force_compile || $this->resource_object->isEvaluated || $this->getCompiledTimestamp () === false ||
|
||||
// ($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
|
||||
($this->smarty->compile_check && $this->getCompiledTimestamp () < $this->getTemplateTimestamp ())));
|
||||
}
|
||||
@@ -249,7 +237,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
{
|
||||
if (!$this->resource_object->isEvaluated) {
|
||||
$this->properties['file_dependency'] = array();
|
||||
$this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
|
||||
$this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp(),$this->resource_type);
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_compile($this);
|
||||
@@ -257,7 +245,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
$this->smarty->loadPlugin($this->resource_object->compiler_class);
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin($this->resource_object->compiler_class,$this->smarty->plugins_dir);
|
||||
$this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty);
|
||||
}
|
||||
// compile locking
|
||||
@@ -278,7 +266,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
throw $e;
|
||||
}
|
||||
// compiling succeded
|
||||
if (!$this->resource_object->isEvaluated) {
|
||||
if (!$this->resource_object->isEvaluated && $this->write_compiled_code) {
|
||||
// write compiled template
|
||||
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty);
|
||||
}
|
||||
@@ -296,11 +284,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function getCachedFilepath ()
|
||||
{
|
||||
if (!isset($this->cache_resource_object)) {
|
||||
$this->cache_resource_object = $this->smarty->cache->loadResource();
|
||||
}
|
||||
return $this->cached_filepath === null ?
|
||||
$this->cached_filepath = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedFilepath($this) :
|
||||
$this->cached_filepath = ($this->resource_object->isEvaluated || !($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedFilepath($this) :
|
||||
$this->cached_filepath;
|
||||
}
|
||||
|
||||
@@ -313,11 +298,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function getCachedTimestamp ()
|
||||
{
|
||||
if (!isset($this->cache_resource_object)) {
|
||||
$this->cache_resource_object = $this->smarty->cache->loadResource();
|
||||
}
|
||||
return $this->cached_timestamp === null ?
|
||||
$this->cached_timestamp = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedTimestamp($this) :
|
||||
$this->cached_timestamp = ($this->resource_object->isEvaluated || !($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedTimestamp($this) :
|
||||
$this->cached_timestamp;
|
||||
}
|
||||
|
||||
@@ -328,11 +310,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function getCachedContent ()
|
||||
{
|
||||
if (!isset($this->cache_resource_object)) {
|
||||
$this->cache_resource_object = $this->smarty->cache->loadResource();
|
||||
}
|
||||
return $this->rendered_content === null ?
|
||||
$this->rendered_content = ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedContents($this) :
|
||||
$this->rendered_content = ($this->resource_object->isEvaluated || !($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED)) ? false : $this->cache_resource_object->getCachedContents($this) :
|
||||
$this->rendered_content;
|
||||
}
|
||||
|
||||
@@ -341,7 +320,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
*/
|
||||
public function writeCachedContent ($content)
|
||||
{
|
||||
if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) {
|
||||
if ($this->resource_object->isEvaluated || !($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED)) {
|
||||
// don't write cache file
|
||||
return false;
|
||||
}
|
||||
@@ -360,15 +339,12 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
{
|
||||
if ($this->isCached === null) {
|
||||
$this->isCached = false;
|
||||
if (($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED) && !$this->resource_object->isEvaluated) {
|
||||
if (!isset($this->cache_resource_object)) {
|
||||
$this->cache_resource_object = $this->smarty->cache->loadResource();
|
||||
}
|
||||
if (($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED) && !$this->resource_object->isEvaluated) {
|
||||
$cachedTimestamp = $this->getCachedTimestamp();
|
||||
if ($cachedTimestamp === false || $this->force_compile || $this->force_cache) {
|
||||
if ($cachedTimestamp === false || $this->smarty->force_compile || $this->smarty->force_cache) {
|
||||
return $this->isCached;
|
||||
}
|
||||
if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED || ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT && (time() <= ($cachedTimestamp + $this->cache_lifetime) || $this->cache_lifetime < 0))) {
|
||||
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED || ($this->caching == Smarty::CACHING_LIFETIME_CURRENT && (time() <= ($cachedTimestamp + $this->cache_lifetime) || $this->cache_lifetime < 0))) {
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($this);
|
||||
}
|
||||
@@ -381,7 +357,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
return $this->isCached;
|
||||
}
|
||||
$this->cacheFileChecked = true;
|
||||
if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED && $this->properties['cache_lifetime'] >= 0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) {
|
||||
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && $this->properties['cache_lifetime'] >= 0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) {
|
||||
$this->tpl_vars = array();
|
||||
$this->rendered_content = null;
|
||||
return $this->isCached;
|
||||
@@ -390,10 +366,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
$resource_type = null;
|
||||
$resource_name = null;
|
||||
foreach ($this->properties['file_dependency'] as $_file_to_check) {
|
||||
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
|
||||
If ($resource_type == 'file') {
|
||||
If ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
|
||||
$mtime = filemtime($_file_to_check[0]);
|
||||
} else {
|
||||
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
|
||||
$resource_handler = $this->loadTemplateResourceHandler($resource_type);
|
||||
$mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
|
||||
}
|
||||
@@ -441,10 +417,10 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
$resource_type = null;
|
||||
$resource_name = null;
|
||||
foreach ($this->properties['file_dependency'] as $_file_to_check) {
|
||||
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
|
||||
If ($resource_type == 'file') {
|
||||
If ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
|
||||
$mtime = filemtime($_file_to_check[0]);
|
||||
} else {
|
||||
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
|
||||
$resource_handler = $this->loadTemplateResourceHandler($resource_type);
|
||||
$mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
|
||||
}
|
||||
@@ -477,7 +453,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
}
|
||||
$this->rendered_content = ob_get_clean();
|
||||
if (!$this->resource_object->isEvaluated && empty($this->properties['file_dependency'][$this->templateUid])) {
|
||||
$this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
|
||||
$this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp(),$this->resource_type);
|
||||
}
|
||||
if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
|
||||
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
|
||||
@@ -493,7 +469,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
Smarty_Internal_Debug::end_render($this);
|
||||
}
|
||||
// write to cache when nessecary
|
||||
if (!$this->resource_object->isEvaluated && ($this->caching == SMARTY_CACHING_LIFETIME_SAVED || $this->caching == SMARTY_CACHING_LIFETIME_CURRENT)) {
|
||||
if (!$this->resource_object->isEvaluated && ($this->caching == Smarty::CACHING_LIFETIME_SAVED || $this->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($this);
|
||||
}
|
||||
@@ -591,7 +567,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// cache template object under a unique ID
|
||||
// do not cache eval resources
|
||||
if ($resource_type != 'eval') {
|
||||
$this->smarty->template_objects[crc32($this->template_resource . $this->cache_id . $this->compile_id)] = $this;
|
||||
$this->smarty->template_objects[sha1($this->template_resource . $this->cache_id . $this->compile_id)] = $this;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -634,25 +610,25 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
/**
|
||||
* Update Smarty variables in other scopes
|
||||
*/
|
||||
public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE)
|
||||
public function updateParentVariables ($scope = Smarty::SCOPE_LOCAL)
|
||||
{
|
||||
$has_root = false;
|
||||
foreach ($this->tpl_vars as $_key => $_variable) {
|
||||
$_variable_scope = $this->tpl_vars[$_key]->scope;
|
||||
if ($scope == SMARTY_LOCAL_SCOPE && $_variable_scope == SMARTY_LOCAL_SCOPE) {
|
||||
if ($scope == Smarty::SCOPE_LOCAL && $_variable_scope == Smarty::SCOPE_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
if (isset($this->parent) && ($scope == SMARTY_PARENT_SCOPE || $_variable_scope == SMARTY_PARENT_SCOPE)) {
|
||||
if (isset($this->parent) && ($scope == Smarty::SCOPE_PARENT || $_variable_scope == Smarty::SCOPE_PARENT)) {
|
||||
if (isset($this->parent->tpl_vars[$_key])) {
|
||||
// variable is already defined in parent, copy value
|
||||
$this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
} else {
|
||||
// create variable in parent
|
||||
$this->parent->tpl_vars[$_key] = clone $_variable;
|
||||
$this->parent->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
$this->parent->tpl_vars[$_key]->scope = Smarty::SCOPE_LOCAL;
|
||||
}
|
||||
}
|
||||
if ($scope == SMARTY_ROOT_SCOPE || $_variable_scope == SMARTY_ROOT_SCOPE) {
|
||||
if ($scope == Smarty::SCOPE_ROOT || $_variable_scope == Smarty::SCOPE_ROOT) {
|
||||
if ($this->parent == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -670,18 +646,18 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
} else {
|
||||
// create variable in root
|
||||
$root_ptr->tpl_vars[$_key] = clone $_variable;
|
||||
$root_ptr->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
$root_ptr->tpl_vars[$_key]->scope = Smarty::SCOPE_LOCAL;
|
||||
}
|
||||
}
|
||||
if ($scope == SMARTY_GLOBAL_SCOPE || $_variable_scope == SMARTY_GLOBAL_SCOPE) {
|
||||
if (isset($this->smarty->global_tpl_vars[$_key])) {
|
||||
if ($scope == Smarty::SCOPE_GLOBAL || $_variable_scope == Smarty::SCOPE_GLOBAL) {
|
||||
if (isset(Smarty::$global_tpl_vars[$_key])) {
|
||||
// variable is already defined in root, copy value
|
||||
$this->smarty->global_tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
Smarty::$global_tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
} else {
|
||||
// create variable in root
|
||||
$this->smarty->global_tpl_vars[$_key] = clone $_variable;
|
||||
// create global variable
|
||||
Smarty::$global_tpl_vars[$_key] = clone $_variable;
|
||||
}
|
||||
$this->smarty->global_tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
Smarty::$global_tpl_vars[$_key]->scope = Smarty::SCOPE_LOCAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -706,9 +682,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// 1 char is not resource type, but part of filepath
|
||||
$resource_type = 'file';
|
||||
$resource_name = $template_resource;
|
||||
} else {
|
||||
$resource_type = $resource_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,34 +695,29 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
protected function loadTemplateResourceHandler ($resource_type)
|
||||
{
|
||||
// try registered resource
|
||||
if (isset($this->smarty->_plugins['resource'][$resource_type])) {
|
||||
return new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
if (isset($this->smarty->registered_resources[$resource_type])) {
|
||||
return new Smarty_Internal_Resource_Registered($this);
|
||||
} else {
|
||||
// try sysplugins dir
|
||||
if (in_array($resource_type, array('file', 'string', 'extends', 'php', 'registered', 'stream', 'eval'))) {
|
||||
if (in_array($resource_type, array('file', 'string', 'extends', 'php', 'stream', 'eval'))) {
|
||||
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($resource_type);
|
||||
return new $_resource_class($this->smarty);
|
||||
} else {
|
||||
// try plugins dir
|
||||
$_resource_class = 'Smarty_Resource_' . ucfirst($resource_type);
|
||||
if ($this->smarty->loadPlugin($_resource_class)) {
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($_resource_class,$this->smarty->plugins_dir)) {
|
||||
if (class_exists($_resource_class, false)) {
|
||||
return new $_resource_class($this->smarty);
|
||||
} else {
|
||||
$this->smarty->register->resource($resource_type,
|
||||
array("smarty_resource_{$resource_type}_source",
|
||||
"smarty_resource_{$resource_type}_timestamp",
|
||||
"smarty_resource_{$resource_type}_secure",
|
||||
"smarty_resource_{$resource_type}_trusted"));
|
||||
return new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
return new Smarty_Internal_Resource_Registered($this, $resource_type);
|
||||
}
|
||||
} else {
|
||||
// try streams
|
||||
$_known_stream = stream_get_wrappers();
|
||||
if (in_array($resource_type, $_known_stream)) {
|
||||
// is known stream
|
||||
if ($this->smarty->security) {
|
||||
$this->smarty->security_handler->isTrustedStream($resource_type);
|
||||
if (is_object($this->smarty->security_policy)) {
|
||||
$this->smarty->security_policy->isTrustedStream($resource_type);
|
||||
}
|
||||
return new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
} else {
|
||||
@@ -830,9 +799,9 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a loacal Smarty variable for array assihgments
|
||||
* creates a loacal Smarty variable for array assignments
|
||||
*/
|
||||
public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = SMARTY_LOCAL_SCOPE)
|
||||
public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = Smarty::SCOPE_LOCAL)
|
||||
{
|
||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
||||
$tpl_var_inst = $this->getVariable($tpl_var, null, true, false);
|
||||
@@ -840,7 +809,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(array(), $nocache, $scope);
|
||||
} else {
|
||||
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
|
||||
if ($scope != SMARTY_LOCAL_SCOPE) {
|
||||
if ($scope != Smarty::SCOPE_LOCAL) {
|
||||
$this->tpl_vars[$tpl_var]->scope = $scope;
|
||||
}
|
||||
}
|
||||
@@ -857,6 +826,38 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
return $this->smarty->display($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* [util function] counts an array, arrayaccess/traversable or PDOStatement object
|
||||
* @param mixed $value
|
||||
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 for empty elements
|
||||
*/
|
||||
public function _count($value)
|
||||
{
|
||||
if (is_array($value) === true || $value instanceof Countable) {
|
||||
return count($value);
|
||||
} elseif ($value instanceof ArrayAccess) {
|
||||
if ($value->offsetExists(0)) {
|
||||
return 1;
|
||||
}
|
||||
} elseif ($value instanceof Iterator) {
|
||||
$value->rewind();
|
||||
if ($value->valid()) {
|
||||
return 1;
|
||||
}
|
||||
} elseif ($value instanceof PDOStatement) {
|
||||
return $value->rowCount();
|
||||
} elseif ($value instanceof Traversable) {
|
||||
return iterator_count($value);
|
||||
} elseif ($value instanceof ArrayAccess) {
|
||||
if ($value->offsetExists(0)) {
|
||||
return 1;
|
||||
}
|
||||
} elseif (is_object($value)) {
|
||||
return count($value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for fetch
|
||||
*/
|
||||
@@ -864,25 +865,48 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
{
|
||||
return $this->smarty->fetch($this);
|
||||
}
|
||||
/**
|
||||
* set Smarty property in template context
|
||||
* @param string $property_name property name
|
||||
* @param mixed $value value
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
if ($property_name == 'resource_object' || $property_name == 'cache_resource_object') {
|
||||
$this->$property_name = $value;
|
||||
} elseif (property_exists($this->smarty, $property_name)) {
|
||||
$this->smarty->$property_name = $value;
|
||||
} else {
|
||||
throw new SmartyException("invalid template property '$property_name'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* lazy loads (valid) property objects
|
||||
*
|
||||
* @param string $name property name
|
||||
* get Smarty property in template context
|
||||
* @param string $property_name property name
|
||||
*/
|
||||
public function __get($name)
|
||||
public function __get($property_name)
|
||||
{
|
||||
if (in_array($name, array('register', 'unregister', 'utility', 'cache'))) {
|
||||
$class = "Smarty_Internal_" . ucfirst($name);
|
||||
$this->$name = new $class($this);
|
||||
return $this->$name;
|
||||
} else if ($name == '_version') {
|
||||
// Smarty 2 BC
|
||||
$this->_version = self::SMARTY_VERSION;
|
||||
return $this->_version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if ($property_name == 'resource_object') {
|
||||
// load template resource
|
||||
$this->resource_object = null;
|
||||
if (!$this->parseResourceName ($this->template_resource, $this->resource_type, $this->resource_name, $this->resource_object)) {
|
||||
throw new SmartyException ("Unable to parse resource name \"{$template_resource}\"");
|
||||
}
|
||||
return $this->resource_object;
|
||||
}
|
||||
if ($property_name == 'cache_resource_object') {
|
||||
// load cache resource
|
||||
$this->cache_resource_object = $this->loadCacheResource();
|
||||
return $this->cache_resource_object;
|
||||
}
|
||||
if (property_exists($this->smarty, $property_name)) {
|
||||
return $this->smarty->$property_name;
|
||||
} else {
|
||||
throw new SmartyException("template property '$property_name' does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes unknown class methods and lazy loads sysplugin files for them
|
||||
@@ -905,18 +929,18 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
|
||||
// convert camel case to underscored name
|
||||
$property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name);
|
||||
if (!property_exists($this, $property_name)) {
|
||||
throw new SmartyException("property '$property_name' does not exist.");
|
||||
return false;
|
||||
}
|
||||
if ($first3 == 'get')
|
||||
return $this->$property_name;
|
||||
else
|
||||
return $this->$property_name = $args[0];
|
||||
}
|
||||
if (property_exists($this, $property_name)) {
|
||||
if ($first3 == 'get')
|
||||
return $this->$property_name;
|
||||
else
|
||||
return $this->$property_name = $args[0];
|
||||
}
|
||||
}
|
||||
// pass call to Smarty object
|
||||
return call_user_func_array(array($this->smarty,$name),$args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* wrapper for template class
|
||||
*/
|
||||
|
@@ -23,6 +23,8 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
public $_tag_stack = array();
|
||||
// current template
|
||||
public $template = null;
|
||||
// optional log of tag/attributes
|
||||
public $used_tags = array();
|
||||
|
||||
/**
|
||||
* Initialize compiler
|
||||
@@ -45,9 +47,6 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
} else {
|
||||
$this->nocache_hash = $template->properties['nocache_hash'];
|
||||
}
|
||||
/* here is where the compiling takes place. Smarty
|
||||
tags in the templates are replaces with PHP code,
|
||||
then written to compiled files. */
|
||||
// flag for nochache sections
|
||||
$this->nocache = false;
|
||||
$this->tag_nocache = false;
|
||||
@@ -102,20 +101,30 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
*
|
||||
* @param string $tag tag name
|
||||
* @param array $args array with tag attributes
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compileTag($tag, $args)
|
||||
public function compileTag($tag, $args, $parameter = array())
|
||||
{
|
||||
// $args contains the attributes parsed and compiled by the lexer/parser
|
||||
// assume that tag does compile into code, but creates no HTML output
|
||||
$this->has_code = true;
|
||||
$this->has_output = false;
|
||||
$this->has_output = false;
|
||||
// log tag/attributes
|
||||
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
|
||||
$this->used_tags[] = array($tag,$args);
|
||||
}
|
||||
// check nocache option flag
|
||||
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args)
|
||||
|| in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) {
|
||||
$this->tag_nocache = true;
|
||||
}
|
||||
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
||||
if (($_output = $this->callTagCompiler($tag, $args)) === false) {
|
||||
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
||||
if (isset($this->smarty->template_functions[$tag])) {
|
||||
// template defined by {template} tag
|
||||
$args['name'] = "'" . $tag . "'";
|
||||
$_output = $this->callTagCompiler('call', $args);
|
||||
$args['_attr']['name'] = "'" . $tag . "'";
|
||||
$_output = $this->callTagCompiler('call', $args, $parameter);
|
||||
}
|
||||
}
|
||||
if ($_output !== false) {
|
||||
@@ -133,47 +142,58 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
// tag did not produce compiled code
|
||||
return '';
|
||||
} else {
|
||||
// map_named attributes
|
||||
if (isset($args['_attr'])) {
|
||||
foreach ($args['_attr'] as $key => $attribute) {
|
||||
if (is_array($attribute)) {
|
||||
$args = array_merge($args, $attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
// not an internal compiler tag
|
||||
if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
|
||||
// check if tag is a registered object
|
||||
if (isset($this->smarty->registered_objects[$tag]) && isset($args['object_methode'])) {
|
||||
$methode = $args['object_methode'];
|
||||
unset ($args['object_methode']);
|
||||
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
|
||||
$methode = $parameter['object_methode'];
|
||||
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
|
||||
(empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
|
||||
return $this->callTagCompiler('private_object_function', $args, $tag, $methode);
|
||||
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
|
||||
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
|
||||
return $this->callTagCompiler('private_object_block_function', $args, $tag, $methode);
|
||||
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
|
||||
} else {
|
||||
return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// check if tag is registered
|
||||
foreach (array('compiler', 'function', 'block') as $type) {
|
||||
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $type) {
|
||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||
// if compiler function plugin call it now
|
||||
if ($type == 'compiler') {
|
||||
if ($type == Smarty::PLUGIN_COMPILER) {
|
||||
$new_args = array();
|
||||
foreach ($args as $mixed) {
|
||||
$new_args = array_merge($new_args, $mixed);
|
||||
}
|
||||
if (!$this->smarty->registered_plugins[$type][$tag][1]) {
|
||||
$this->tag_nocache = true;
|
||||
}
|
||||
$function = $this->smarty->registered_plugins[$type][$tag][0];
|
||||
if (!is_array($function)) {
|
||||
return $function($args, $this);
|
||||
return $function($new_args, $this);
|
||||
} else if (is_object($function[0])) {
|
||||
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($args, $this);
|
||||
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($new_args, $this);
|
||||
} else {
|
||||
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this));
|
||||
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($new_args, $this));
|
||||
}
|
||||
}
|
||||
// compile registered function or block function
|
||||
if ($type == 'function' || $type == 'block') {
|
||||
return $this->callTagCompiler('private_registered_' . $type, $args, $tag);
|
||||
if ($type == Smarty::PLUGIN_FUNCTION || $type == Smarty::PLUGIN_BLOCK) {
|
||||
return $this->callTagCompiler('private_registered_' . $type, $args, $parameter, $tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
// check plugins from plugins folder
|
||||
foreach ($this->smarty->plugin_search_order as $plugin_type) {
|
||||
if ($plugin_type == 'compiler' && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
|
||||
if ($plugin_type == Smarty::PLUGIN_BLOCK && Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
|
||||
$plugin = 'smarty_compiler_' . $tag;
|
||||
if (is_callable($plugin)) {
|
||||
return $plugin($args, $this->smarty);
|
||||
@@ -187,7 +207,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
throw new SmartyException("Plugin \"{$tag}\" not callable");
|
||||
} else {
|
||||
if ($function = $this->getPlugin($tag, $plugin_type)) {
|
||||
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $tag, $function);
|
||||
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,24 +215,23 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
// compile closing tag of block function
|
||||
$base_tag = substr($tag, 0, -5);
|
||||
// check if closing tag is a registered object
|
||||
if (isset($this->smarty->registered_objects[$base_tag]) && isset($args['object_methode'])) {
|
||||
$methode = $args['object_methode'];
|
||||
unset ($args['object_methode']);
|
||||
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) {
|
||||
$methode = $parameter['object_methode'];
|
||||
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
|
||||
return $this->callTagCompiler('private_object_block_function', $args, $tag, $methode);
|
||||
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
|
||||
} else {
|
||||
return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
|
||||
}
|
||||
}
|
||||
// registered block tag ?
|
||||
if (isset($this->smarty->registered_plugins['block'][$base_tag])) {
|
||||
return $this->callTagCompiler('private_registered_block', $args, $tag);
|
||||
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
|
||||
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
|
||||
}
|
||||
// block plugin?
|
||||
if ($function = $this->getPlugin($base_tag, 'block')) {
|
||||
return $this->callTagCompiler('private_block_plugin', $args, $tag, $function);
|
||||
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
|
||||
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
|
||||
}
|
||||
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
|
||||
$plugin = 'smarty_compiler_' . $tag;
|
||||
if (is_callable($plugin)) {
|
||||
return $plugin($args, $this->smarty);
|
||||
@@ -253,7 +272,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
// lazy load internal compiler plugin
|
||||
$class_name = 'Smarty_Internal_Compile_' . $tag;
|
||||
if ($this->smarty->loadPlugin($class_name)) {
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($class_name, $this->smarty->plugins_dir)) {
|
||||
// use plugin if found
|
||||
self::$_tag_objects[$tag] = new $class_name;
|
||||
// compile this tag
|
||||
@@ -403,5 +422,6 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
throw new SmartyCompilerException($error_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -133,16 +133,16 @@ class Smarty_Internal_Templatelexer
|
||||
{
|
||||
$tokenMap = array (
|
||||
1 => 0,
|
||||
2 => 1,
|
||||
4 => 0,
|
||||
2 => 0,
|
||||
3 => 1,
|
||||
5 => 0,
|
||||
6 => 0,
|
||||
7 => 0,
|
||||
8 => 0,
|
||||
9 => 0,
|
||||
10 => 0,
|
||||
11 => 1,
|
||||
13 => 0,
|
||||
11 => 0,
|
||||
12 => 1,
|
||||
14 => 0,
|
||||
15 => 0,
|
||||
16 => 0,
|
||||
@@ -151,13 +151,14 @@ class Smarty_Internal_Templatelexer
|
||||
19 => 0,
|
||||
20 => 0,
|
||||
21 => 0,
|
||||
22 => 2,
|
||||
25 => 0,
|
||||
22 => 0,
|
||||
23 => 2,
|
||||
26 => 0,
|
||||
);
|
||||
if ($this->counter >= strlen($this->data)) {
|
||||
return false; // end of input
|
||||
}
|
||||
$yy_global_pattern = "/^(\\{\\})|^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\\s{1,}strip\\s{1,}".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."\\s{1,}\/strip\\s{1,}".$this->rdel.")|^(".$this->ldel."\\s*literal\\s*".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|^(\\?>)|^(<%)|^(%>)|^(([\S\s]*?)(?=([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?|\\?>|<%|%>)))|^([\S\s]+)/";
|
||||
$yy_global_pattern = "/^(".$this->ldel."[$]smarty\\.block\\.child".$this->rdel.")|^(\\{\\})|^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\\s{1,}strip\\s{1,}".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."\\s{1,}\/strip\\s{1,}".$this->rdel.")|^(".$this->ldel."\\s*literal\\s*".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|^(\\?>)|^(<%)|^(%>)|^(([\S\s]*?)(?=([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?|\\?>|<%|%>)))|^([\S\s]+)/";
|
||||
|
||||
do {
|
||||
if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
|
||||
@@ -210,14 +211,19 @@ class Smarty_Internal_Templatelexer
|
||||
function yy_r1_1($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILD;
|
||||
}
|
||||
function yy_r1_2($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
}
|
||||
function yy_r1_3($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_COMMENT;
|
||||
}
|
||||
function yy_r1_4($yy_subpatterns)
|
||||
function yy_r1_5($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->strip) {
|
||||
@@ -226,13 +232,13 @@ class Smarty_Internal_Templatelexer
|
||||
$this->token = Smarty_Internal_Templateparser::TP_LINEBREAK;
|
||||
}
|
||||
}
|
||||
function yy_r1_5($yy_subpatterns)
|
||||
function yy_r1_6($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->strip = true;
|
||||
return false;
|
||||
}
|
||||
function yy_r1_6($yy_subpatterns)
|
||||
function yy_r1_7($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal) {
|
||||
@@ -242,13 +248,13 @@ class Smarty_Internal_Templatelexer
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function yy_r1_7($yy_subpatterns)
|
||||
function yy_r1_8($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->strip = false;
|
||||
return false;
|
||||
}
|
||||
function yy_r1_8($yy_subpatterns)
|
||||
function yy_r1_9($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal) {
|
||||
@@ -258,13 +264,13 @@ class Smarty_Internal_Templatelexer
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function yy_r1_9($yy_subpatterns)
|
||||
function yy_r1_10($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
|
||||
$this->yypushstate(self::LITERAL);
|
||||
}
|
||||
function yy_r1_10($yy_subpatterns)
|
||||
function yy_r1_11($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal) {
|
||||
@@ -275,7 +281,7 @@ class Smarty_Internal_Templatelexer
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
}
|
||||
function yy_r1_11($yy_subpatterns)
|
||||
function yy_r1_12($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
|
||||
@@ -286,7 +292,7 @@ class Smarty_Internal_Templatelexer
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
}
|
||||
function yy_r1_13($yy_subpatterns)
|
||||
function yy_r1_14($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
|
||||
@@ -297,7 +303,7 @@ class Smarty_Internal_Templatelexer
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
}
|
||||
function yy_r1_14($yy_subpatterns)
|
||||
function yy_r1_15($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal && trim(substr($this->value,$this->ldel_length,1)) == '') {
|
||||
@@ -308,7 +314,7 @@ class Smarty_Internal_Templatelexer
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
}
|
||||
function yy_r1_15($yy_subpatterns)
|
||||
function yy_r1_16($yy_subpatterns)
|
||||
{
|
||||
|
||||
if ($this->smarty->auto_literal) {
|
||||
@@ -319,21 +325,21 @@ class Smarty_Internal_Templatelexer
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
}
|
||||
function yy_r1_16($yy_subpatterns)
|
||||
function yy_r1_17($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
|
||||
$this->yypushstate(self::SMARTY);
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
function yy_r1_17($yy_subpatterns)
|
||||
function yy_r1_18($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_LDEL;
|
||||
$this->yypushstate(self::SMARTY);
|
||||
$this->taglineno = $this->line;
|
||||
}
|
||||
function yy_r1_18($yy_subpatterns)
|
||||
function yy_r1_19($yy_subpatterns)
|
||||
{
|
||||
|
||||
if (in_array($this->value, Array('<?', '<?=', '<?php'))) {
|
||||
@@ -345,27 +351,27 @@ class Smarty_Internal_Templatelexer
|
||||
$this->value = substr($this->value, 0, 2);
|
||||
}
|
||||
}
|
||||
function yy_r1_19($yy_subpatterns)
|
||||
function yy_r1_20($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
|
||||
}
|
||||
function yy_r1_20($yy_subpatterns)
|
||||
function yy_r1_21($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
|
||||
}
|
||||
function yy_r1_21($yy_subpatterns)
|
||||
function yy_r1_22($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
|
||||
}
|
||||
function yy_r1_22($yy_subpatterns)
|
||||
function yy_r1_23($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
}
|
||||
function yy_r1_25($yy_subpatterns)
|
||||
function yy_r1_26($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
@@ -421,9 +427,10 @@ class Smarty_Internal_Templatelexer
|
||||
62 => 0,
|
||||
63 => 0,
|
||||
64 => 0,
|
||||
65 => 1,
|
||||
67 => 1,
|
||||
69 => 1,
|
||||
65 => 0,
|
||||
66 => 1,
|
||||
68 => 1,
|
||||
70 => 0,
|
||||
71 => 0,
|
||||
72 => 0,
|
||||
73 => 0,
|
||||
@@ -441,12 +448,11 @@ class Smarty_Internal_Templatelexer
|
||||
85 => 0,
|
||||
86 => 0,
|
||||
87 => 0,
|
||||
88 => 0,
|
||||
);
|
||||
if ($this->counter >= strlen($this->data)) {
|
||||
return false; // end of input
|
||||
}
|
||||
$yy_global_pattern = "/^('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(\\s{1,}".$this->rdel.")|^(".$this->ldel."\/)|^(".$this->ldel.")|^(".$this->rdel.")|^(\\s+is\\s+in\\s+)|^(\\s+(AS|as)\\s+)|^(\\s+(to)\\s+)|^(\\s+(step)\\s+)|^(\\s+instanceof\\s+)|^(\\s*===\\s*)|^(\\s*!==\\s*)|^(\\s*==\\s*|\\s+(EQ|eq)\\s+)|^(\\s*!=\\s*|\\s*<>\\s*|\\s+(NE|NEQ|ne|neq)\\s+)|^(\\s*>=\\s*|\\s+(GE|GTE|ge|gte)\\s+)|^(\\s*<=\\s*|\\s+(LE|LTE|le|lte)\\s+)|^(\\s*>\\s*|\\s+(GT|gt)\\s+)|^(\\s*<\\s*|\\s+(LT|lt)\\s+)|^(\\s+(MOD|mod)\\s+)|^(!\\s*|(NOT|not)\\s+)|^(\\s*&&\\s*|\\s*(AND|and)\\s+)|^(\\s*\\|\\|\\s*|\\s*(OR|or)\\s+)|^(\\s*(XOR|xor)\\s+)|^(\\s+is\\s+odd\\s+by\\s+)|^(\\s+is\\s+not\\s+odd\\s+by\\s+)|^(\\s+is\\s+odd)|^(\\s+is\\s+not\\s+odd)|^(\\s+is\\s+even\\s+by\\s+)|^(\\s+is\\s+not\\s+even\\s+by\\s+)|^(\\s+is\\s+even)|^(\\s+is\\s+not\\s+even)|^(\\s+is\\s+div\\s+by\\s+)|^(\\s+is\\s+not\\s+div\\s+by\\s+)|^(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|^(\\(\\s*)|^(\\s*\\))|^(\\[\\s*)|^(\\s*\\])|^(\\s*->\\s*)|^(\\s*=>\\s*)|^(\\s*=\\s*)|^((\\+\\+|--)\\s*)|^(\\s*(\\+|-)\\s*)|^(\\s*(\\*|\/|%)\\s*)|^(\\$)|^(\\s*;)|^(::)|^(\\s*:\\s*)|^(@)|^(#)|^(\")|^(`)|^(\\|)|^(\\.)|^(\\s*,\\s*)|^(\\s*&\\s*)|^(\\s*\\?\\s*)|^(0[xX][0-9a-fA-F]+)|^([0-9]*[a-zA-Z_]\\w*)|^(\\d+)|^(\\s+)|^(.)/";
|
||||
$yy_global_pattern = "/^('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s*(if|elseif|else if|while)(?![^\s]))|^(".$this->ldel."\\s*for(?![^\s]))|^(".$this->ldel."\\s*foreach(?![^\s]))|^(".$this->ldel."\\s{1,})|^(\\s{1,}".$this->rdel.")|^(".$this->ldel."\/)|^(".$this->ldel.")|^(".$this->rdel.")|^(\\s+is\\s+in\\s+)|^(\\s+(AS|as)\\s+)|^(\\s+(to)\\s+)|^(\\s+(step)\\s+)|^(\\s+instanceof\\s+)|^(\\s*===\\s*)|^(\\s*!==\\s*)|^(\\s*==\\s*|\\s+(EQ|eq)\\s+)|^(\\s*!=\\s*|\\s*<>\\s*|\\s+(NE|NEQ|ne|neq)\\s+)|^(\\s*>=\\s*|\\s+(GE|GTE|ge|gte)\\s+)|^(\\s*<=\\s*|\\s+(LE|LTE|le|lte)\\s+)|^(\\s*>\\s*|\\s+(GT|gt)\\s+)|^(\\s*<\\s*|\\s+(LT|lt)\\s+)|^(\\s+(MOD|mod)\\s+)|^(!\\s*|(NOT|not)\\s+)|^(\\s*&&\\s*|\\s*(AND|and)\\s+)|^(\\s*\\|\\|\\s*|\\s*(OR|or)\\s+)|^(\\s*(XOR|xor)\\s+)|^(\\s+is\\s+odd\\s+by\\s+)|^(\\s+is\\s+not\\s+odd\\s+by\\s+)|^(\\s+is\\s+odd)|^(\\s+is\\s+not\\s+odd)|^(\\s+is\\s+even\\s+by\\s+)|^(\\s+is\\s+not\\s+even\\s+by\\s+)|^(\\s+is\\s+even)|^(\\s+is\\s+not\\s+even)|^(\\s+is\\s+div\\s+by\\s+)|^(\\s+is\\s+not\\s+div\\s+by\\s+)|^(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|^(\\(\\s*)|^(\\s*\\))|^(\\[\\s*)|^(\\s*\\])|^(\\s*->\\s*)|^(\\s*=>\\s*)|^(\\s*=\\s*)|^(\\+\\+|--)|^(\\s*(\\+|-)\\s*)|^(\\s*(\\*|\/|%)\\s*)|^(\\$)|^(\\s*;)|^(::)|^(\\s*:\\s*)|^(@)|^(#)|^(\")|^(`)|^(\\|)|^(\\.)|^(\\s*,\\s*)|^(\\s*&\\s*)|^(\\s*\\?\\s*)|^(0[xX][0-9a-fA-F]+)|^([0-9]*[a-zA-Z_]\\w*)|^(\\d+)|^(\\s+)|^(.)/";
|
||||
|
||||
do {
|
||||
if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
|
||||
@@ -771,104 +777,104 @@ class Smarty_Internal_Templatelexer
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_INCDEC;
|
||||
}
|
||||
function yy_r2_67($yy_subpatterns)
|
||||
function yy_r2_66($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
|
||||
}
|
||||
function yy_r2_69($yy_subpatterns)
|
||||
function yy_r2_68($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_MATH;
|
||||
}
|
||||
function yy_r2_71($yy_subpatterns)
|
||||
function yy_r2_70($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_DOLLAR;
|
||||
}
|
||||
function yy_r2_72($yy_subpatterns)
|
||||
function yy_r2_71($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
|
||||
}
|
||||
function yy_r2_73($yy_subpatterns)
|
||||
function yy_r2_72($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
|
||||
}
|
||||
function yy_r2_74($yy_subpatterns)
|
||||
function yy_r2_73($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_COLON;
|
||||
}
|
||||
function yy_r2_75($yy_subpatterns)
|
||||
function yy_r2_74($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_AT;
|
||||
}
|
||||
function yy_r2_76($yy_subpatterns)
|
||||
function yy_r2_75($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_HATCH;
|
||||
}
|
||||
function yy_r2_77($yy_subpatterns)
|
||||
function yy_r2_76($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_QUOTE;
|
||||
$this->yypushstate(self::DOUBLEQUOTEDSTRING);
|
||||
}
|
||||
function yy_r2_78($yy_subpatterns)
|
||||
function yy_r2_77($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
|
||||
$this->yypopstate();
|
||||
}
|
||||
function yy_r2_79($yy_subpatterns)
|
||||
function yy_r2_78($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_VERT;
|
||||
}
|
||||
function yy_r2_80($yy_subpatterns)
|
||||
function yy_r2_79($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_DOT;
|
||||
}
|
||||
function yy_r2_81($yy_subpatterns)
|
||||
function yy_r2_80($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_COMMA;
|
||||
}
|
||||
function yy_r2_82($yy_subpatterns)
|
||||
function yy_r2_81($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_ANDSYM;
|
||||
}
|
||||
function yy_r2_83($yy_subpatterns)
|
||||
function yy_r2_82($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_QMARK;
|
||||
}
|
||||
function yy_r2_84($yy_subpatterns)
|
||||
function yy_r2_83($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_HEX;
|
||||
}
|
||||
function yy_r2_85($yy_subpatterns)
|
||||
function yy_r2_84($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_ID;
|
||||
}
|
||||
function yy_r2_86($yy_subpatterns)
|
||||
function yy_r2_85($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_INTEGER;
|
||||
}
|
||||
function yy_r2_87($yy_subpatterns)
|
||||
function yy_r2_86($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
|
||||
}
|
||||
function yy_r2_88($yy_subpatterns)
|
||||
function yy_r2_87($yy_subpatterns)
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
@@ -1169,6 +1175,5 @@ class Smarty_Internal_Templatelexer
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@@ -1,162 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: smarty_internal_unregister.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
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @version 3-SVN$Rev: 3286 $
|
||||
*/
|
||||
|
||||
class Smarty_Internal_Unregister {
|
||||
|
||||
protected $smarty;
|
||||
|
||||
function __construct($smarty) {
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters block function
|
||||
*
|
||||
* @param string $block_tag name of template function
|
||||
*/
|
||||
function block($block_tag)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['block'][$block_tag])) {
|
||||
unset($this->smarty->registered_plugins['block'][$block_tag]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters compiler function
|
||||
*
|
||||
* @param string $compiler_tag name of template function
|
||||
*/
|
||||
function compilerFunction($compiler_tag)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['compiler'][$compiler_tag])) {
|
||||
unset($this->smarty->registered_plugins['compiler'][$compiler_tag]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters custom function
|
||||
*
|
||||
* @param string $function_tag name of template function
|
||||
*/
|
||||
function templateFunction($function_tag)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['function'][$function_tag])) {
|
||||
unset($this->smarty->registered_plugins['function'][$function_tag]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters modifier
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
*/
|
||||
function modifier($modifier)
|
||||
{
|
||||
if (isset($this->smarty->registered_plugins['modifier'][$modifier])) {
|
||||
unset($this->smarty->registered_plugins['modifier'][$modifier]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters template object
|
||||
*
|
||||
* @param string $object_name name of template object
|
||||
*/
|
||||
function templateObject($object_name)
|
||||
{
|
||||
unset($this->smarty->registered_objects[$object_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters template class
|
||||
*
|
||||
* @param string $object_name name of template object
|
||||
*/
|
||||
function templateClass($class_name)
|
||||
{
|
||||
unset($this->smarty->registered_classes[$class_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an output filter
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function outputFilter($function_name)
|
||||
{
|
||||
unset($this->smarty->registered_filters['output'][$this->smarty->_get_filter_name($function_name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a postfilter function
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function postFilter($function_name)
|
||||
{
|
||||
unset($this->smarty->registered_filters['post'][$this->smarty->_get_filter_name($function_name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a prefilter function
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function preFilter($function_name)
|
||||
{
|
||||
unset($this->smarty->registered_filters['pre'][$this->smarty->_get_filter_name($function_name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a resource
|
||||
*
|
||||
* @param string $resource_name name of resource
|
||||
*/
|
||||
function resource($resource_name)
|
||||
{
|
||||
unset($this->smarty->plugins['resource'][$resource_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a variablefilter function
|
||||
*
|
||||
* @param callback $function_name
|
||||
*/
|
||||
function variableFilter($function_name)
|
||||
{
|
||||
unset($this->smarty->registered_filters['variable'][$this->smarty->_get_filter_name($function_name)]);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@@ -60,6 +60,9 @@ class Smarty_Internal_Utility {
|
||||
$_error_count = 0;
|
||||
// loop over array of template directories
|
||||
foreach((array)$this->smarty->template_dir as $_dir) {
|
||||
if (strpos('/\\', substr($_dir, -1)) === false) {
|
||||
$_dir .= DS;
|
||||
}
|
||||
$_compileDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs);
|
||||
foreach ($_compile as $_fileinfo) {
|
||||
@@ -69,7 +72,7 @@ class Smarty_Internal_Utility {
|
||||
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
|
||||
$_template_file = $_file;
|
||||
} else {
|
||||
$_template_file = substr(substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file,1);
|
||||
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
|
||||
}
|
||||
echo '<br>', $_dir, '---', $_template_file;
|
||||
flush();
|
||||
@@ -118,6 +121,9 @@ class Smarty_Internal_Utility {
|
||||
$_error_count = 0;
|
||||
// loop over array of template directories
|
||||
foreach((array)$this->smarty->config_dir as $_dir) {
|
||||
if (strpos('/\\', substr($_dir, -1)) === false) {
|
||||
$_dir .= DS;
|
||||
}
|
||||
$_compileDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs);
|
||||
foreach ($_compile as $_fileinfo) {
|
||||
@@ -127,7 +133,7 @@ class Smarty_Internal_Utility {
|
||||
if ($_fileinfo->getPath() == substr($_dir, 0, -1)) {
|
||||
$_config_file = $_file;
|
||||
} else {
|
||||
$_config_file = substr(substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file,1);
|
||||
$_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
|
||||
}
|
||||
echo '<br>', $_dir, '---', $_config_file;
|
||||
flush();
|
||||
@@ -208,6 +214,19 @@ class Smarty_Internal_Utility {
|
||||
return $_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of tag/attributes of all tags used by an template
|
||||
*
|
||||
* @param object $templae template object
|
||||
* @return array of tag/attributes
|
||||
*/
|
||||
function getTags(Smarty_Internal_Template $template)
|
||||
{
|
||||
$template->smarty->get_used_tags = true;
|
||||
$template->compileTemplateSource();
|
||||
return $template->compiler_object->used_tags;
|
||||
}
|
||||
|
||||
function testInstall()
|
||||
{
|
||||
echo "<PRE>\n";
|
||||
|
@@ -60,68 +60,67 @@ class Smarty_Internal_Wrapper {
|
||||
switch($name_parts[0]) {
|
||||
case 'register':
|
||||
case 'unregister':
|
||||
$myobj = $name_parts[0] == 'register' ? $this->smarty->register : $this->smarty->unregister;
|
||||
switch($name_parts[1]) {
|
||||
case 'function':
|
||||
return call_user_func_array(array($myobj,'templateFunction'),$args);
|
||||
break;
|
||||
case 'object':
|
||||
return call_user_func_array(array($myobj,'templateObject'),$args);
|
||||
break;
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Object"),$args);
|
||||
case 'compiler_function':
|
||||
return call_user_func_array(array($myobj,'compilerFunction'),$args);
|
||||
break;
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Plugin"),array_merge(array('compiler'),$args));
|
||||
case 'prefilter':
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('pre'),$args));
|
||||
case 'postfilter':
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('post'),$args));
|
||||
case 'outputfilter':
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Filter"),array_merge(array('output'),$args));
|
||||
case 'resource':
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Resource"),$args);
|
||||
default:
|
||||
return call_user_func_array(array($myobj,$name_parts[1]),$args);
|
||||
break;
|
||||
return call_user_func_array(array($this->smarty,"{$name_parts[0]}Plugin"),array_merge(array($name_parts[1]),$args));
|
||||
}
|
||||
break;
|
||||
case 'get':
|
||||
switch($name_parts[1]) {
|
||||
case 'template_vars':
|
||||
return call_user_func_array(array($this->smarty,'getTemplateVars'),$args);
|
||||
break;
|
||||
case 'config_vars':
|
||||
return call_user_func_array(array($this->smarty,'getConfigVars'),$args);
|
||||
break;
|
||||
default:
|
||||
return call_user_func_array(array($myobj,$name_parts[1]),$args);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'clear':
|
||||
switch($name_parts[1]) {
|
||||
case 'all_assign':
|
||||
return call_user_func_array(array($this->smarty,'clearAllAssign'),$args);
|
||||
break;
|
||||
case 'assign':
|
||||
return call_user_func_array(array($this->smarty,'clearAssign'),$args);
|
||||
case 'all_cache':
|
||||
return call_user_func_array(array($this->smarty,'clearAllCache'),$args);
|
||||
case 'cache':
|
||||
return call_user_func_array(array($this->smarty,'clearCache'),$args);
|
||||
case 'compiled_template':
|
||||
return call_user_func_array(array($this->smarty,'clearCompiledTemplate'),$args);
|
||||
}
|
||||
break;
|
||||
case 'config':
|
||||
switch($name_parts[1]) {
|
||||
case 'load':
|
||||
return call_user_func_array(array($this->smarty,'configLoad'),$args);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// convert foo_bar_baz to fooBarBaz style names
|
||||
$name_parts = explode('_',$name);
|
||||
foreach($name_parts as $idx=>$part) {
|
||||
if($idx==0)
|
||||
$name_parts[$idx] = strtolower($part);
|
||||
else
|
||||
$name_parts[$idx] = ucfirst($part);
|
||||
}
|
||||
$func_name = implode('',$name_parts);
|
||||
if(!method_exists($this->smarty,$func_name)) {
|
||||
throw new SmartyException("unknown method '$name'");
|
||||
return false;
|
||||
}
|
||||
return call_user_func_array(array($this->smarty,$func_name),$args);
|
||||
break;
|
||||
case 'trigger':
|
||||
switch($name_parts[1]) {
|
||||
case 'error':
|
||||
return call_user_func_array(array($this,'trigger_error'),$args);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
throw new SmartyException("unknown method '$name'");
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type
|
||||
*/
|
||||
function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Smarty error: $error_msg", $error_type);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -15,19 +15,18 @@ class Smarty_Security {
|
||||
* This determines how Smarty handles "<?php ... ?>" tags in templates.
|
||||
* possible values:
|
||||
* <ul>
|
||||
* <li>SMARTY_PHP_PASSTHRU -> echo PHP tags as they are</li>
|
||||
* <li>SMARTY_PHP_QUOTE -> escape tags as entities</li>
|
||||
* <li>SMARTY_PHP_REMOVE -> remove php tags</li>
|
||||
* <li>SMARTY_PHP_ALLOW -> execute php tags</li>
|
||||
* <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li>
|
||||
* <li>Smarty::PHP_QUOTE -> escape tags as entities</li>
|
||||
* <li>Smarty::PHP_REMOVE -> remove php tags</li>
|
||||
* <li>Smarty::PHP_ALLOW -> execute php tags</li>
|
||||
* </ul>
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $php_handling = SMARTY_PHP_PASSTHRU;
|
||||
public $php_handling = Smarty::PHP_PASSTHRU;
|
||||
|
||||
/**
|
||||
* This is the list of template directories that are considered secure.
|
||||
* One directory per array element.
|
||||
* $template_dir is in this list implicitly.
|
||||
*
|
||||
* @var array
|
||||
@@ -57,26 +56,26 @@ class Smarty_Security {
|
||||
* This is an array of trusted PHP functions.
|
||||
*
|
||||
* If empty all functions are allowed.
|
||||
* If set to 'none' none is allowed.
|
||||
* To disable all PHP functions set $php_functions = null.
|
||||
* @var array
|
||||
*/
|
||||
public $php_functions = array('isset', 'empty',
|
||||
'count', 'sizeof','in_array', 'is_array','time','nl2br');
|
||||
|
||||
/**
|
||||
* This is an array of trusted modifers.
|
||||
* This is an array of trusted PHP modifers.
|
||||
*
|
||||
* If empty all modifiers are allowed.
|
||||
* If set to 'none' none is allowed.
|
||||
* To disable all modifier set $modifiers = null.
|
||||
* @var array
|
||||
*/
|
||||
public $modifiers = array('escape','count');
|
||||
public $php_modifiers = array('escape','count');
|
||||
|
||||
/**
|
||||
* This is an array of trusted streams.
|
||||
*
|
||||
* If empty all streams are allowed.
|
||||
* If set to 'none' none is allowed.
|
||||
* To disable all streams set $streams = null.
|
||||
* @var array
|
||||
*/
|
||||
public $streams = array('file');
|
||||
@@ -89,9 +88,142 @@ class Smarty_Security {
|
||||
*/
|
||||
public $allow_super_globals = true;
|
||||
/**
|
||||
* + flag if {php} tag can be executed
|
||||
* + flag if the {php} and {include_php} tag can be executed
|
||||
*/
|
||||
public $allow_php_tag = false;
|
||||
|
||||
public function __construct($smarty)
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
/**
|
||||
* Check if PHP function is trusted.
|
||||
*
|
||||
* @param string $function_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if function is trusted
|
||||
*/
|
||||
function isTrustedPhpFunction($function_name, $compiler)
|
||||
{
|
||||
if (isset($this->php_functions) && (empty($this->php_functions) || in_array($function_name, $this->php_functions))) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("PHP function '{$function_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if static class is trusted.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if class is trusted
|
||||
*/
|
||||
function isTrustedStaticClass($class_name, $compiler)
|
||||
{
|
||||
if (isset($this->static_classes) && (empty($this->static_classes) || in_array($class_name, $this->static_classes))) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("access to static class '{$class_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if modifier is trusted.
|
||||
*
|
||||
* @param string $modifier_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if modifier is trusted
|
||||
*/
|
||||
function isTrustedModifier($modifier_name, $compiler)
|
||||
{
|
||||
if (isset($this->php_modifiers) && (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))) {
|
||||
return true;
|
||||
} else {
|
||||
$compiler->trigger_template_error ("modifier '{$modifier_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if stream is trusted.
|
||||
*
|
||||
* @param string $stream_name
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if stream is trusted
|
||||
*/
|
||||
function isTrustedStream($stream_name)
|
||||
{
|
||||
if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) {
|
||||
return true;
|
||||
} else {
|
||||
throw new SmartyException ("stream '{$stream_name}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if directory is trusted
|
||||
*/
|
||||
function isTrustedResourceDir($filepath)
|
||||
{
|
||||
$_rp = realpath($filepath);
|
||||
if (isset($this->smarty->template_dir)) {
|
||||
foreach ((array)$this->smarty->template_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false &&
|
||||
strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
(strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($this->smarty->security_policy->secure_dir)) {
|
||||
foreach ((array)$this->smarty->security_policy->secure_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false) {
|
||||
if ($_cd == $_rp) {
|
||||
return true;
|
||||
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
(strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SmartyException ("directory '{$_rp}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if directory of file resource is trusted.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param object $compiler compiler object
|
||||
* @return boolean true if directory is trusted
|
||||
*/
|
||||
function isTrustedPHPDir($filepath)
|
||||
{
|
||||
$_rp = realpath($filepath);
|
||||
if (!empty($this->trusted_dir)) {
|
||||
foreach ((array)$this->trusted_dir as $curr_dir) {
|
||||
if (($_cd = realpath($curr_dir)) !== false) {
|
||||
if ($_cd == $_rp) {
|
||||
return true;
|
||||
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
|
||||
substr($_rp, strlen($_cd), 1) == DS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new SmartyException ("directory '{$_rp}' not allowed by security setting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user