mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- added {$foo++}{$foo--} syntax
- buxfix changed PHP "if (..):" to "if (..){" because of possible bad code when concenating PHP tags - autoload Smarty internal classes
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
10/21/2009
|
||||
- added {$foo++}{$foo--} syntax
|
||||
- buxfix changed PHP "if (..):" to "if (..){" because of possible bad code when concenating PHP tags
|
||||
- autoload Smarty internal classes
|
||||
|
||||
10/20/2009
|
||||
- check at compile time for variable filter to improve rendering speed if no filter is used
|
||||
- fixed bug at combination of {elseif} tag and {...} in double quoted strings of static class parameter
|
||||
|
@@ -84,9 +84,9 @@ define('SMARTY_PHP_REMOVE', 2); //-> escape tags as entities
|
||||
define('SMARTY_PHP_ALLOW', 3); //-> escape tags as entities
|
||||
|
||||
/**
|
||||
* load required base class for creation of the smarty object
|
||||
*/
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatebase.php');
|
||||
* register the class autoloader
|
||||
**/
|
||||
spl_autoload_register('smartyAutoload');
|
||||
|
||||
/**
|
||||
* This is the main Smarty class
|
||||
@@ -153,7 +153,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
// config var settings
|
||||
public $config_overwrite = true; //Controls whether variables with the same name overwrite each other.
|
||||
public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean
|
||||
public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
|
||||
public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
|
||||
// config vars
|
||||
public $config_vars = array();
|
||||
// assigned tpl vars
|
||||
@@ -202,8 +202,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
public $variable_filter = true;
|
||||
// cache resorce objects
|
||||
public $cache_resource_objects = array();
|
||||
// write file object
|
||||
public $write_file_object = null;
|
||||
// global internal smarty vars
|
||||
public $_smarty_vars = array();
|
||||
// start time for execution time calculation
|
||||
@@ -212,7 +210,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
* Class constructor, initializes basic smarty properties
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
{
|
||||
// self reference needed by other classes methodes
|
||||
$this->smarty = $this;
|
||||
|
||||
@@ -230,13 +228,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
$this->cache_dir = '.' . DS . 'cache' . DS;
|
||||
$this->config_dir = '.' . DS . 'configs' . DS;
|
||||
$this->debug_tpl = SMARTY_DIR . 'debug.tpl';
|
||||
// load basic plugins
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.template.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.plugin_handler.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.run_filter.php');
|
||||
// $this->loadPlugin($this->template_class);
|
||||
// $this->loadPlugin('Smarty_Internal_Plugin_Handler');
|
||||
// $this->loadPlugin('Smarty_Internal_Run_Filter');
|
||||
$this->plugin_handler = new Smarty_Internal_Plugin_Handler($this);
|
||||
$this->filter_handler = new Smarty_Internal_Run_Filter($this);
|
||||
if (!$this->debugging && $this->debugging_ctrl == 'URL') {
|
||||
@@ -288,7 +279,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function fetch($template, $cache_id = null, $compile_id = null, $parent = null)
|
||||
{
|
||||
$this->checkDebugging();
|
||||
if (is_object($cache_id)) {
|
||||
$parent = $cache_id;
|
||||
$cache_id = null;
|
||||
@@ -340,7 +330,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function is_cached($template, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
$this->checkDebugging();
|
||||
if (!($template instanceof $this->template_class)) {
|
||||
$template = $this->createTemplate ($template, $cache_id, $compile_id, $this);
|
||||
}
|
||||
@@ -364,7 +353,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
throw new Exception("Security policy must define class 'Smarty_Security_Policy'");
|
||||
}
|
||||
$this->security_policy = new Smarty_Security_Policy;
|
||||
$this->loadPlugin('Smarty_Internal_Security_Handler');
|
||||
$this->security_handler = new Smarty_Internal_Security_Handler($this);
|
||||
$this->security = true;
|
||||
} else {
|
||||
@@ -493,16 +481,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
return set_exception_handler($handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if debugging handler must be loaded
|
||||
*/
|
||||
public function checkDebugging()
|
||||
{
|
||||
if ($this->debugging && !class_exists('Smarty_Internal_Debug', false)) {
|
||||
$this->loadPlugin('Smarty_Internal_Debug');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display debug info
|
||||
*/
|
||||
@@ -548,4 +526,13 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
}
|
||||
|
||||
function smartyAutoload($class)
|
||||
{
|
||||
if (substr($class, 0, 16) === 'Smarty_Internal_') {
|
||||
$class = strtolower($class);
|
||||
$_name_parts = explode('_', $class, 3);
|
||||
include SMARTY_SYSPLUGINS_DIR . 'internal.' . $_name_parts[2] . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -64,12 +64,7 @@ class Smarty_Internal_CacheResource_File {
|
||||
public function writeCachedContent($template, $content)
|
||||
{
|
||||
if (!$template->isEvaluated()) {
|
||||
if (!is_object($this->smarty->write_file_object)) {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.write_file.php');
|
||||
// $this->smarty->loadPlugin("Smarty_Internal_Write_File");
|
||||
$this->smarty->write_file_object = new Smarty_Internal_Write_File;
|
||||
}
|
||||
return $this->smarty->write_file_object->writeFile($template->getCachedFilepath(), $content);
|
||||
return Smarty_Internal_Write_File::writeFile($template->getCachedFilepath(), $content);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase {
|
||||
$nesting = $this->_close_tag(array('if', 'elseif'));
|
||||
$this->_open_tag('else',$nesting);
|
||||
|
||||
return '<?php else: ?>';
|
||||
return '<?php }else{ ?>';
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,13 +30,13 @@ class Smarty_Internal_Compile_ElseIf extends Smarty_Internal_CompileBase {
|
||||
|
||||
if (empty($this->compiler->prefix_code)) {
|
||||
$this->_open_tag('elseif', $nesting);
|
||||
return '<?php elseif (' . $args['if condition'] . '): ?>';
|
||||
return '<?php }elseif(' . $args['if condition'] . '){?>';
|
||||
} else {
|
||||
$tmp = '';
|
||||
foreach ($this->compiler->prefix_code as $code) $tmp .= $code;
|
||||
$this->compiler->prefix_code = array();
|
||||
$this->_open_tag('elseif', $nesting + 1);
|
||||
return '<?php else: ?>' . $tmp . '<?php if (' . $args['if condition'] . '): ?>';
|
||||
return '<?php }else{?>' . $tmp . '<?php if (' . $args['if condition'] . '){?>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,11 +28,11 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase {
|
||||
|
||||
$this->_open_tag('if',1);
|
||||
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 .= "if (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value']."): ?>";
|
||||
$_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']."){?>";
|
||||
return $_output;
|
||||
} else {
|
||||
return '<?php if (' . $args['if condition'] . '): ?>';
|
||||
return '<?php if (' . $args['if condition'] . '){?>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,8 +25,8 @@ class Smarty_Internal_Compile_IfClose extends Smarty_Internal_CompileBase {
|
||||
$this->compiler = $compiler;
|
||||
$nesting = $this->_close_tag(array('if', 'else', 'elseif'));
|
||||
$tmp = '';
|
||||
for ($i = 0; $i < $nesting ; $i++) $tmp .= ' endif;';
|
||||
return "<?php $tmp ?>";
|
||||
for ($i = 0; $i < $nesting ; $i++) $tmp .= '}';
|
||||
return "<?php $tmp?>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -199,18 +199,13 @@ class Smarty_Internal_Config {
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Config_File_Compiler');
|
||||
$this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
|
||||
}
|
||||
if (!is_object($this->smarty->write_file_object)) {
|
||||
$this->smarty->loadPlugin("Smarty_Internal_Write_File");
|
||||
$this->smarty->write_file_object = new Smarty_Internal_Write_File;
|
||||
}
|
||||
// call compiler
|
||||
if ($this->compiler_object->compileSource($this)) {
|
||||
// compiling succeded
|
||||
// write compiled template
|
||||
$this->smarty->write_file_object->writeFile($this->getCompiledFilepath(), $this->getCompiledConfig());
|
||||
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig());
|
||||
// make template and compiled file timestamp match
|
||||
touch($this->getCompiledFilepath(), $this->getTimestamp());
|
||||
} else {
|
||||
|
@@ -21,8 +21,8 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
||||
$this->smarty = $smarty;
|
||||
parent::__construct();
|
||||
// get required plugins
|
||||
$this->smarty->loadPlugin($lexer_class);
|
||||
$this->smarty->loadPlugin($parser_class);
|
||||
// $this->smarty->loadPlugin($lexer_class);
|
||||
// $this->smarty->loadPlugin($parser_class);
|
||||
$this->lexer_class = $lexer_class;
|
||||
$this->parser_class = $parser_class;
|
||||
}
|
||||
|
@@ -275,10 +275,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.compilebase.php');
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatecompilerbase.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_CompileBase');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase');
|
||||
$this->smarty->loadPlugin($this->smarty->resource_objects[$this->resource_type]->compiler_class);
|
||||
$this->compiler_object = new $this->smarty->resource_objects[$this->resource_type]->compiler_class($this->smarty->resource_objects[$this->resource_type]->template_lexer_class, $this->smarty->resource_objects[$this->resource_type]->template_parser_class, $this->smarty);
|
||||
// load cacher
|
||||
@@ -287,17 +283,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->cacher_object = new $this->cacher_class($this->smarty);
|
||||
}
|
||||
}
|
||||
if (!is_object($this->smarty->write_file_object)) {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.write_file.php');
|
||||
// $this->smarty->loadPlugin("Smarty_Internal_Write_File");
|
||||
$this->smarty->write_file_object = new Smarty_Internal_Write_File;
|
||||
}
|
||||
// call compiler
|
||||
if ($this->compiler_object->compileTemplate($this)) {
|
||||
// compiling succeded
|
||||
if (!$this->isEvaluated()) {
|
||||
// write compiled template
|
||||
$this->smarty->write_file_object->writeFile($this->getCompiledFilepath(), $this->compiled_template);
|
||||
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template);
|
||||
// make template and compiled file timestamp match
|
||||
touch($this->getCompiledFilepath(), $this->getTemplateTimestamp());
|
||||
}
|
||||
@@ -669,8 +660,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if (!isset($this->smarty->resource_objects[$resource_type])) {
|
||||
// try registered resource
|
||||
if (isset($this->smarty->_plugins['resource'][$resource_type])) {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_registered.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_Resource_Registered');
|
||||
return $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
} else {
|
||||
// try sysplugins dir
|
||||
@@ -689,8 +678,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
"smarty_resource_{$resource_type}_timestamp",
|
||||
"smarty_resource_{$resource_type}_secure",
|
||||
"smarty_resource_{$resource_type}_trusted"));
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_registered.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_Resource_Registered');
|
||||
return $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
}
|
||||
} else {
|
||||
@@ -701,10 +688,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if ($this->smarty->security) {
|
||||
$this->smarty->security_handler->isTrustedStream($resource_type);
|
||||
}
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_stream.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_Resource_Stream');
|
||||
return $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
// $resource_name = str_replace(':', '://', $template_resource);
|
||||
} else {
|
||||
throw new Exception('Unkown resource type \'' . $resource_type . '\'');
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ class Smarty_Internal_Write_File {
|
||||
* @param string $_contents file content
|
||||
* @return boolean true
|
||||
*/
|
||||
public function writeFile($_filepath, $_contents)
|
||||
public static function writeFile($_filepath, $_contents)
|
||||
{
|
||||
$_dirpath = dirname($_filepath);
|
||||
// if subdirs, create dir structure
|
||||
|
Reference in New Issue
Block a user