- change of utility->compileAllTemplates() log messages

- bugfix on nocache code in {function} tags
This commit is contained in:
Uwe.Tews
2010-03-25 20:43:56 +00:00
parent 8372ef8874
commit c24dce9ed4
3 changed files with 83 additions and 74 deletions

View File

@@ -1,3 +1,7 @@
25/03/2010
- change of utility->compileAllTemplates() log messages
- bugfix on nocache code in {function} tags
24/03/2010 24/03/2010
- bugfix on register->modifier() error messages - bugfix on register->modifier() error messages

View File

@@ -37,7 +37,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase {
// make function known for recursive calls // make function known for recursive calls
$this->compiler->smarty->template_functions[$_name]['compiled'] = ''; $this->compiler->smarty->template_functions[$_name]['compiled'] = '';
// Init temporay context // Init temporay context
$compiler->template->required_plugins = array('compiled' => array(), 'cache' => array()); $compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
$compiler->template->extract_code = true; $compiler->template->extract_code = true;
$compiler->template->extracted_compiled_code = ''; $compiler->template->extracted_compiled_code = '';
$compiler->template->has_nocache_code = false; $compiler->template->has_nocache_code = false;
@@ -75,11 +75,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
} }
$plugins_string .= '?>'; $plugins_string .= '?>';
} }
if (!empty($compiler->template->required_plugins['cache'])) { if (!empty($compiler->template->required_plugins['nocache'])) {
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; $plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
foreach($compiler->template->required_plugins['nocache'] as $tmp) { foreach($compiler->template->required_plugins['nocache'] as $tmp) {
foreach($tmp as $data) { foreach($tmp as $data) {
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; $plugins_string .= "if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n";
} }
} }
$plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n"; $plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n";
@@ -97,4 +97,4 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
} }
} }
?> ?>

View File

@@ -1,54 +1,54 @@
<?php <?php
/** /**
* Project: Smarty: the PHP compiling template engine * Project: Smarty: the PHP compiling template engine
* File: smarty_internal_utility.php * File: smarty_internal_utility.php
* SVN: $Id: $ * SVN: $Id: $
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* For questions, help, comments, discussion, etc., please join the * For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to * Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com * smarty-discussion-subscribe@googlegroups.com
* *
* @link http://www.smarty.net/ * @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc. * @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* @package Smarty * @package Smarty
* @subpackage PluginsInternal * @subpackage PluginsInternal
* @version 3-SVN$Rev: 3286 $ * @version 3-SVN$Rev: 3286 $
*/ */
class Smarty_Internal_Utility { class Smarty_Internal_Utility {
protected $smarty; protected $smarty;
function __construct($smarty) { function __construct($smarty)
$this->smarty = $smarty; {
} $this->smarty = $smarty;
}
/** /**
* Compile all template files * Compile all template files
* *
* @param string $extension file extension * @param string $extension file extension
* @param bool $force_compile force all to recompile * @param bool $force_compile force all to recompile
* @param int $time_limit * @param int $time_limit
* @param int $max_errors * @param int $max_errors
* @return integer number of template files recompiled * @return integer number of template files recompiled
*/ */
function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{ {
function _get_time() function _get_time()
@@ -82,13 +82,19 @@ class Smarty_Internal_Utility {
$_start_time = _get_time(); $_start_time = _get_time();
try { try {
$_tpl = $this->smarty->createTemplate($_template_file); $_tpl = $this->smarty->createTemplate($_template_file);
$_tpl->getCompiledTemplate(); if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource();
echo ' compiled in ', _get_time() - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
} }
catch (Exception $e) { catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>"; echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count++; $_error_count++;
} }
echo ' done in ', _get_time() - $_start_time, ' seconds';
if ($max_errors !== null && $_error_count == $max_errors) { if ($max_errors !== null && $_error_count == $max_errors) {
echo '<br><br>too many errors'; echo '<br><br>too many errors';
exit(); exit();
@@ -99,16 +105,16 @@ class Smarty_Internal_Utility {
} }
/** /**
* Delete compiled template file * Delete compiled template file
* *
* @param string $resource_name template name * @param string $resource_name template name
* @param string $compile_id compile id * @param string $compile_id compile id
* @param integer $exp_time expiration time * @param integer $exp_time expiration time
* @return integer number of template files deleted * @return integer number of template files deleted
*/ */
function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
{ {
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!','_',$compile_id) : null; $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $this->smarty->use_sub_dirs ? DS : '^'; $_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
if (isset($resource_name)) { if (isset($resource_name)) {
$_resource_part_1 = $resource_name . '.php'; $_resource_part_1 = $resource_name . '.php';
@@ -148,16 +154,16 @@ class Smarty_Internal_Utility {
} }
} }
return $_count; return $_count;
} }
function testInstall() function testInstall()
{ {
echo "<PRE>\n"; echo "<PRE>\n";
echo "Smarty Installation test...\n"; echo "Smarty Installation test...\n";
echo "Testing template directory...\n"; echo "Testing template directory...\n";
foreach((array)$this->smarty->template_dir as $template_dir) { foreach((array)$this->smarty->template_dir as $template_dir) {
if (!is_dir($template_dir)) if (!is_dir($template_dir))
echo "FAILED: $template_dir is not a directory.\n"; echo "FAILED: $template_dir is not a directory.\n";
@@ -166,9 +172,9 @@ class Smarty_Internal_Utility {
else else
echo "$template_dir is OK.\n"; echo "$template_dir is OK.\n";
} }
echo "Testing compile directory...\n"; echo "Testing compile directory...\n";
if (!is_dir($this->smarty->compile_dir)) if (!is_dir($this->smarty->compile_dir))
echo "FAILED: {$this->smarty->compile_dir} is not a directory.\n"; echo "FAILED: {$this->smarty->compile_dir} is not a directory.\n";
elseif (!is_readable($this->smarty->compile_dir)) elseif (!is_readable($this->smarty->compile_dir))
@@ -177,9 +183,9 @@ class Smarty_Internal_Utility {
echo "FAILED: {$this->smarty->compile_dir} is not writable.\n"; echo "FAILED: {$this->smarty->compile_dir} is not writable.\n";
else else
echo "{$this->smarty->compile_dir} is OK.\n"; echo "{$this->smarty->compile_dir} is OK.\n";
echo "Testing plugins directory...\n"; echo "Testing plugins directory...\n";
foreach((array)$this->smarty->plugins_dir as $plugin_dir) { foreach((array)$this->smarty->plugins_dir as $plugin_dir) {
if (!is_dir($plugin_dir)) if (!is_dir($plugin_dir))
echo "FAILED: $plugin_dir is not a directory.\n"; echo "FAILED: $plugin_dir is not a directory.\n";
@@ -188,9 +194,9 @@ class Smarty_Internal_Utility {
else else
echo "$plugin_dir is OK.\n"; echo "$plugin_dir is OK.\n";
} }
echo "Testing cache directory...\n"; echo "Testing cache directory...\n";
if (!is_dir($this->smarty->cache_dir)) if (!is_dir($this->smarty->cache_dir))
echo "FAILED: {$this->smarty->cache_dir} is not a directory.\n"; echo "FAILED: {$this->smarty->cache_dir} is not a directory.\n";
elseif (!is_readable($this->smarty->cache_dir)) elseif (!is_readable($this->smarty->cache_dir))
@@ -199,21 +205,20 @@ class Smarty_Internal_Utility {
echo "FAILED: {$this->smarty->cache_dir} is not writable.\n"; echo "FAILED: {$this->smarty->cache_dir} is not writable.\n";
else else
echo "{$this->smarty->cache_dir} is OK.\n"; echo "{$this->smarty->cache_dir} is OK.\n";
echo "Testing configs directory...\n"; echo "Testing configs directory...\n";
if (!is_dir($this->smarty->config_dir)) if (!is_dir($this->smarty->config_dir))
echo "FAILED: {$this->smarty->config_dir} is not a directory.\n"; echo "FAILED: {$this->smarty->config_dir} is not a directory.\n";
elseif (!is_readable($this->smarty->config_dir)) elseif (!is_readable($this->smarty->config_dir))
echo "FAILED: {$this->smarty->config_dir} is not readable.\n"; echo "FAILED: {$this->smarty->config_dir} is not readable.\n";
else else
echo "{$this->smarty->config_dir} is OK.\n"; echo "{$this->smarty->config_dir} is OK.\n";
echo "Tests complete.\n"; echo "Tests complete.\n";
echo "</PRE>\n"; echo "</PRE>\n";
return true; return true;
} }
} }