mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- remove unused properties
- optimization use real function instead anonymous function for preg_replace_callback - bugfix a relative {include} in child template blocks failed - bugfix direct setting of $template_dir, $config_dir, $plugins_dir in __construct() of an extended Smarty class created problems
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
|
23.09.2011
|
||||||
|
- remove unused properties
|
||||||
|
- optimization use real function instead anonymous function for preg_replace_callback
|
||||||
|
- bugfix a relative {include} in child template blocks failed
|
||||||
|
- bugfix direct setting of $template_dir, $config_dir, $plugins_dir in __construct() of an
|
||||||
|
extended Smarty class created problems
|
||||||
|
|
||||||
===== Smarty 3.1.1 =====
|
===== Smarty 3.1.1 =====
|
||||||
22.09.2011
|
22.09.2011
|
||||||
- bugfix {foreachelse} does fail if {section} was nested inside {foreach}
|
- bugfix {foreachelse} does fail if {section} was nested inside {foreach}
|
||||||
|
@@ -821,7 +821,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
|
return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->template_dir;
|
return (array)$this->template_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -885,7 +885,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
|
return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->config_dir;
|
return (array)$this->config_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -942,7 +942,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
*/
|
*/
|
||||||
public function getPluginsDir()
|
public function getPluginsDir()
|
||||||
{
|
{
|
||||||
return $this->plugins_dir;
|
return (array)$this->plugins_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1293,7 +1293,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
{
|
{
|
||||||
return Smarty_Internal_Utility::testInstall($this, $errors);
|
return Smarty_Internal_Utility::testInstall($this, $errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error Handler to mute expected messages
|
* Error Handler to mute expected messages
|
||||||
*
|
*
|
||||||
@@ -1306,7 +1306,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
// return false if $errno is not 0 and included in current error level
|
// return false if $errno is not 0 and included in current error level
|
||||||
return (bool)($errno && $errno & error_reporting());
|
return (bool)($errno && $errno & error_reporting());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable error handler to mute expected messages
|
* Enable error handler to mute expected messages
|
||||||
*
|
*
|
||||||
@@ -1315,26 +1315,26 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
public static function muteExpectedErrors()
|
public static function muteExpectedErrors()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
error muting is done because some people implemented custom error_handlers using
|
error muting is done because some people implemented custom error_handlers using
|
||||||
http://php.net/set_error_handler and for some reason did not understand the following paragraph:
|
http://php.net/set_error_handler and for some reason did not understand the following paragraph:
|
||||||
|
|
||||||
It is important to remember that the standard PHP error handler is completely bypassed for the
|
It is important to remember that the standard PHP error handler is completely bypassed for the
|
||||||
error types specified by error_types unless the callback function returns FALSE.
|
error types specified by error_types unless the callback function returns FALSE.
|
||||||
error_reporting() settings will have no effect and your error handler will be called regardless -
|
error_reporting() settings will have no effect and your error handler will be called regardless -
|
||||||
however you are still able to read the current value of error_reporting and act appropriately.
|
however you are still able to read the current value of error_reporting and act appropriately.
|
||||||
Of particular note is that this value will be 0 if the statement that caused the error was
|
Of particular note is that this value will be 0 if the statement that caused the error was
|
||||||
prepended by the @ error-control operator.
|
prepended by the @ error-control operator.
|
||||||
|
|
||||||
Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
|
Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
|
||||||
- @filemtime() is almost twice as fast as using an additional file_exists()
|
- @filemtime() is almost twice as fast as using an additional file_exists()
|
||||||
- between file_exists() and filemtime() a possible race condition is opened,
|
- between file_exists() and filemtime() a possible race condition is opened,
|
||||||
which does not exist using the simple @filemtime() approach.
|
which does not exist using the simple @filemtime() approach.
|
||||||
*/
|
*/
|
||||||
if (self::$error_muting) {
|
if (self::$error_muting) {
|
||||||
set_error_handler(array('Smarty', 'mutingErrorHandler'));
|
set_error_handler(array('Smarty', 'mutingErrorHandler'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable error handler muting expected messages
|
* Disable error handler muting expected messages
|
||||||
*
|
*
|
||||||
@@ -1380,7 +1380,7 @@ function smartyAutoload($class)
|
|||||||
'smarty_resource_uncompiled' => true,
|
'smarty_resource_uncompiled' => true,
|
||||||
'smarty_resource_recompiled' => true,
|
'smarty_resource_recompiled' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) {
|
if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) {
|
||||||
include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
||||||
}
|
}
|
||||||
|
@@ -152,6 +152,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
|||||||
$_tpl->variable_filters = $compiler->template->variable_filters;
|
$_tpl->variable_filters = $compiler->template->variable_filters;
|
||||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||||
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
|
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
|
||||||
|
$_tpl->allow_relative_path = true;
|
||||||
if ($compiler->nocache) {
|
if ($compiler->nocache) {
|
||||||
$_tpl->compiler->forceNocache = 2;
|
$_tpl->compiler->forceNocache = 2;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -41,19 +41,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
public $cache_lifetime = null;
|
public $cache_lifetime = null;
|
||||||
/**
|
|
||||||
* Class name
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $cacher_class = null;
|
|
||||||
/**
|
|
||||||
* caching type
|
|
||||||
*
|
|
||||||
* Must be an element of $cache_resource_types.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $caching_type = null;
|
|
||||||
/**
|
/**
|
||||||
* Template resource
|
* Template resource
|
||||||
* @var string
|
* @var string
|
||||||
@@ -101,6 +88,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $used_tags = array();
|
public $used_tags = array();
|
||||||
|
/**
|
||||||
|
* internal flag to allow relative path in child template blocks
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $allow_relative_path = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create template data object
|
* Create template data object
|
||||||
|
@@ -653,6 +653,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* preg_replace callback to convert camelcase getter/setter to underscore property names
|
||||||
|
*
|
||||||
|
* @param string $match match string
|
||||||
|
* @return string replacemant
|
||||||
|
*/
|
||||||
|
private function replaceCamelcase($match) {
|
||||||
|
return "_" . strtolower($match[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle unknown class methods
|
* Handle unknown class methods
|
||||||
*
|
*
|
||||||
@@ -661,13 +671,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
*/
|
*/
|
||||||
public function __call($name, $args)
|
public function __call($name, $args)
|
||||||
{
|
{
|
||||||
static $camel_func;
|
|
||||||
// methode of Smarty object?
|
// methode of Smarty object?
|
||||||
if (method_exists($this->smarty, $name)) {
|
if (method_exists($this->smarty, $name)) {
|
||||||
return call_user_func_array(array($this->smarty, $name), $args);
|
return call_user_func_array(array($this->smarty, $name), $args);
|
||||||
}
|
}
|
||||||
if (!isset($camel_func))
|
|
||||||
$camel_func = create_function('$c', 'return "_" . strtolower($c[1]);');
|
|
||||||
// see if this is a set/get for a property
|
// see if this is a set/get for a property
|
||||||
$first3 = strtolower(substr($name, 0, 3));
|
$first3 = strtolower(substr($name, 0, 3));
|
||||||
if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
|
if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
|
||||||
@@ -675,7 +682,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
// lcfirst() not available < PHP 5.3.0, so improvise
|
// lcfirst() not available < PHP 5.3.0, so improvise
|
||||||
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
|
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
|
||||||
// convert camel case to underscored name
|
// convert camel case to underscored name
|
||||||
$property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name);
|
$property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name);
|
||||||
if (property_exists($this, $property_name)) {
|
if (property_exists($this, $property_name)) {
|
||||||
if ($first3 == 'get')
|
if ($first3 == 'get')
|
||||||
return $this->$property_name;
|
return $this->$property_name;
|
||||||
@@ -692,7 +699,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// must be unknown
|
// must be unknown
|
||||||
throw new SmartyException("Call of unknown function '$name'.");
|
throw new SmartyException("Call of unknown method '$name'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -154,7 +154,7 @@ abstract class Smarty_Resource {
|
|||||||
// go relative to a given template?
|
// go relative to a given template?
|
||||||
$_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\");
|
$_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\");
|
||||||
if ($_template && $_template->parent instanceof Smarty_Internal_Template && $_file_is_dotted) {
|
if ($_template && $_template->parent instanceof Smarty_Internal_Template && $_file_is_dotted) {
|
||||||
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends') {
|
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) {
|
||||||
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
|
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
|
||||||
}
|
}
|
||||||
$file = dirname($_template->parent->source->filepath) . DS . $file;
|
$file = dirname($_template->parent->source->filepath) . DS . $file;
|
||||||
@@ -164,7 +164,7 @@ abstract class Smarty_Resource {
|
|||||||
// as expansions (like include_path) have already been done
|
// as expansions (like include_path) have already been done
|
||||||
$file = getcwd() . DS . $file;
|
$file = getcwd() . DS . $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve relative path
|
// resolve relative path
|
||||||
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
|
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
|
||||||
@@ -422,7 +422,7 @@ abstract class Smarty_Resource {
|
|||||||
$resource_name = $template_resource;
|
$resource_name = $template_resource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = Smarty_Resource::load($smarty, $resource_type);
|
$resource = Smarty_Resource::load($smarty, $resource_type);
|
||||||
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name);
|
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name);
|
||||||
$resource->populate($source, $_template);
|
$resource->populate($source, $_template);
|
||||||
|
Reference in New Issue
Block a user