From 770ef89611acf47a9d9febd59cfcd4aaae990072 Mon Sep 17 00:00:00 2001 From: "monte.ohrt" Date: Sat, 29 Aug 2009 22:57:29 +0000 Subject: [PATCH] remove built-in exception handling, add DS as shorthand to DIRECTORY_SEPARATOR --- libs/Smarty.class.php | 76 +++++++------------ libs/plugins/modifier.date_format.php | 2 +- .../internal.cacheresource_file.php | 16 ++-- libs/sysplugins/internal.config.php | 12 +-- libs/sysplugins/internal.resource_extend.php | 12 +-- libs/sysplugins/internal.resource_file.php | 10 +-- .../internal.resource_registered.php | 10 +-- libs/sysplugins/internal.security_handler.php | 6 +- libs/sysplugins/internal.template.php | 2 +- libs/sysplugins/method.clear_compiled_tpl.php | 2 +- 10 files changed, 62 insertions(+), 86 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6fe1b76a..7f58a010 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -30,13 +30,20 @@ * @version 3.0-alpha1 */ +/** +* define shorthand directory separator constant +*/ +if (!defined('DS')) { + define('DS',DIRECTORY_SEPARATOR); +} + /** * set SMARTY_DIR to absolute path to Smarty library files. * if not defined, include_path will be used. Sets SMARTY_DIR only if user * application has not already defined it. */ if (!defined('SMARTY_DIR')) { - define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); + define('SMARTY_DIR', dirname(__FILE__) . DS); } /** @@ -54,17 +61,10 @@ define('SMARTY_CACHING_OFF', 0); define('SMARTY_CACHING_LIFETIME_CURRENT', 1); define('SMARTY_CACHING_LIVETIME_SAVED', 2); -/** -* define exception handling -*/ -if (!defined('SMARTY_EXCEPTION_HANDLER')) { - define('SMARTY_EXCEPTION_HANDLER', 1); -} - /** * load required base class for creation of the smarty object */ -require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR . 'internal.templatebase.php'); +require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.templatebase.php'); /** * This is the main Smarty class @@ -153,8 +153,8 @@ class Smarty extends Smarty_Internal_TemplateBase { public $default_config_type = 'file'; // class used for cacher public $cacher_class = 'Smarty_Internal_Cacher_InlineCode'; - // exception handler: define SMARTY_EXCEPTION_HANDLER to 0 to disable - public $exception_handler = array('SmartyException', 'getStaticException'); + // exception handler: array('ExceptionClass','ExceptionMethod'); + public $exception_handler = null; // cached template objects public $template_objects = null; // check If-Modified-Since headers @@ -203,23 +203,23 @@ class Smarty extends Smarty_Internal_TemplateBase { } $this->start_time = $this->_get_time(); // set exception handler - if (SMARTY_EXCEPTION_HANDLER && !empty($this->exception_handler)) + if (!empty($this->exception_handler)) set_exception_handler($this->exception_handler); // set default dirs - $this->template_dir = array('.' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR); - $this->compile_dir = '.' . DIRECTORY_SEPARATOR . 'templates_c' . DIRECTORY_SEPARATOR; - $this->plugins_dir = array(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR); - $this->cache_dir = '.' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; - $this->config_dir = '.' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; - $this->sysplugins_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR; + $this->template_dir = array('.' . DS . 'templates' . DS); + $this->compile_dir = '.' . DS . 'templates_c' . DS; + $this->plugins_dir = array(dirname(__FILE__) . DS . 'plugins' . DS); + $this->cache_dir = '.' . DS . 'cache' . DS; + $this->config_dir = '.' . DS . 'configs' . DS; + $this->sysplugins_dir = dirname(__FILE__) . DS . 'sysplugins' . DS; $this->debug_tpl = SMARTY_DIR . 'debug.tpl'; // load basic plugins -require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR . 'internal.template.php'); -require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR . 'internal.plugin_handler.php'); -require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_SEPARATOR . 'internal.run_filter.php'); -// $this->loadPlugin($this->template_class); -// $this->loadPlugin('Smarty_Internal_Plugin_Handler'); -// $this->loadPlugin('Smarty_Internal_Run_Filter'); + require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.template.php'); + require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . 'internal.plugin_handler.php'); + require_once(dirname(__FILE__) . DS . 'sysplugins' . DS . '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') { @@ -256,7 +256,7 @@ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_ public function __destruct() { // restore to previous exception handler, if any - if (SMARTY_EXCEPTION_HANDLER && !empty($this->exception_handler)) + if (!empty($this->exception_handler)) restore_exception_handler(); } @@ -460,7 +460,7 @@ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_ // 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 .= DIRECTORY_SEPARATOR; + $_plugin_dir .= DS; } if (file_exists($_plugin_dir . $_plugin_filename)) { @@ -508,28 +508,4 @@ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sysplugins' . DIRECTORY_ } } -/** -* Smarty Exception Handler -* -* All errors thrown in Smarty will be handled here. -* -* @param string $message the error message -* @param string $code the error code -*/ -class SmartyException { - public static function printException($e) - { - echo "Code: " . $e->getCode() . "
Error: " . htmlentities($e->getMessage()) . "
" - . "File: " . $e->getFile() . "
" - . "Line: " . $e->getLine() . "
" - // . "Trace" . $e->getTraceAsString() . "
" - . "\n"; - } - - public static function getStaticException($e) - { - self::printException($e); - } -} - ?> diff --git a/libs/plugins/modifier.date_format.php b/libs/plugins/modifier.date_format.php index dc6587e7..02eb703a 100644 --- a/libs/plugins/modifier.date_format.php +++ b/libs/plugins/modifier.date_format.php @@ -38,7 +38,7 @@ function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_da } else { return; } - if (DIRECTORY_SEPARATOR == '\\') { + if (DS == '\\') { $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); if (strpos($format, '%e') !== false) { diff --git a/libs/sysplugins/internal.cacheresource_file.php b/libs/sysplugins/internal.cacheresource_file.php index 48398f21..2aa7f75b 100644 --- a/libs/sysplugins/internal.cacheresource_file.php +++ b/libs/sysplugins/internal.cacheresource_file.php @@ -92,15 +92,15 @@ class Smarty_Internal_CacheResource_File { */ public function clear($resource_name, $cache_id, $compile_id, $exp_time) { - $_dir_sep = $this->smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_dir_sep = $this->smarty->use_sub_dirs ? DS : '^'; if (isset($resource_name)) { $_resource_part = (string)abs(crc32($resource_name)) . '.' . $resource_name . $this->smarty->php_ext; } else { $_resource_part = null; } $_dir = $this->smarty->cache_dir; - if (substr($_dir, -1) != DIRECTORY_SEPARATOR) { - $_dir .= DIRECTORY_SEPARATOR; + if (substr($_dir, -1) != DS) { + $_dir .= DS; } if ($this->smarty->use_sub_dirs && isset($cache_id)) { $_dir .= str_replace('|', $_dir_sep, $cache_id) . $_dir_sep; @@ -152,12 +152,12 @@ class Smarty_Internal_CacheResource_File { $_filepath = (string)abs(crc32($resource_name)); // if use_sub_dirs, break file into directories if ($this->smarty->use_sub_dirs) { - $_filepath = substr($_filepath, 0, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 2, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 4, 2) . DIRECTORY_SEPARATOR + $_filepath = substr($_filepath, 0, 2) . DS + . substr($_filepath, 2, 2) . DS + . substr($_filepath, 4, 2) . DS . $_filepath; } - $_compile_dir_sep = $this->smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^'; if (isset($cache_id)) { $_cache_id = str_replace('|', $_compile_dir_sep, $cache_id) . $_compile_dir_sep; } else { @@ -170,7 +170,7 @@ class Smarty_Internal_CacheResource_File { } $_cache_dir = $this->smarty->cache_dir; if (strpos('/\\',substr($_cache_dir, -1)) === false) { - $_cache_dir .= DIRECTORY_SEPARATOR; + $_cache_dir .= DS; } return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_files[0]) . $this->smarty->php_ext; diff --git a/libs/sysplugins/internal.config.php b/libs/sysplugins/internal.config.php index a23de77a..0e14673b 100644 --- a/libs/sysplugins/internal.config.php +++ b/libs/sysplugins/internal.config.php @@ -75,7 +75,7 @@ class Smarty_Internal_Config { { foreach((array)$this->smarty->config_dir as $_config_dir) { if (strpos('/\\', substr($_config_dir, -1)) === false) { - $_config_dir .= DIRECTORY_SEPARATOR; + $_config_dir .= DS; } $_filepath = $_config_dir . $this->config_resource_name; @@ -134,14 +134,14 @@ class Smarty_Internal_Config { $_filepath = (string)abs(crc32($this->config_resource_name)); // if use_sub_dirs, break file into directories if ($this->smarty->use_sub_dirs) { - $_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 1) . DIRECTORY_SEPARATOR + $_filepath = substr($_filepath, 0, 3) . DS + . substr($_filepath, 0, 2) . DS + . substr($_filepath, 0, 1) . DS . $_filepath; } $_compile_dir = $this->smarty->compile_dir; - if (substr($_compile_dir, -1) != DIRECTORY_SEPARATOR) { - $_compile_dir .= DIRECTORY_SEPARATOR; + if (substr($_compile_dir, -1) != DS) { + $_compile_dir .= DS; } return $_compile_dir . $_filepath . '.' . basename($this->config_resource_name) . '.config' . $this->smarty->php_ext; } diff --git a/libs/sysplugins/internal.resource_extend.php b/libs/sysplugins/internal.resource_extend.php index 2b37b24e..b6af047f 100644 --- a/libs/sysplugins/internal.resource_extend.php +++ b/libs/sysplugins/internal.resource_extend.php @@ -138,12 +138,12 @@ class Smarty_Internal_Resource_Extend extends Smarty_Internal_Base { $_filepath = (string)abs(crc32($_template->resource_name)); // if use_sub_dirs, break file into directories if ($_template->smarty->use_sub_dirs) { - $_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 1) . DIRECTORY_SEPARATOR + $_filepath = substr($_filepath, 0, 3) . DS + . substr($_filepath, 0, 2) . DS + . substr($_filepath, 0, 1) . DS . $_filepath; } - $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; if (isset($_template->compile_id)) { $_filepath = $_template->compile_id . $_compile_dir_sep . $_filepath; } @@ -153,8 +153,8 @@ class Smarty_Internal_Resource_Extend extends Smarty_Internal_Base { $_cache = ''; } $_compile_dir = $_template->smarty->compile_dir; - if (substr($_compile_dir, -1) != DIRECTORY_SEPARATOR) { - $_compile_dir .= DIRECTORY_SEPARATOR; + if (substr($_compile_dir, -1) != DS) { + $_compile_dir .= DS; } return $_compile_dir . $_filepath . '.' . basename($_files[0]) . $_cache . $_template->smarty->php_ext; } diff --git a/libs/sysplugins/internal.resource_file.php b/libs/sysplugins/internal.resource_file.php index c7745992..966fa8e8 100644 --- a/libs/sysplugins/internal.resource_file.php +++ b/libs/sysplugins/internal.resource_file.php @@ -100,12 +100,12 @@ class Smarty_Internal_Resource_File { $_filepath = (string)abs(crc32($_template->resource_name)); // if use_sub_dirs, break file into directories if ($_template->smarty->use_sub_dirs) { - $_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 1) . DIRECTORY_SEPARATOR + $_filepath = substr($_filepath, 0, 3) . DS + . substr($_filepath, 0, 2) . DS + . substr($_filepath, 0, 1) . DS . $_filepath; } - $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; if (isset($_template->compile_id)) { $_filepath = $_template->compile_id . $_compile_dir_sep . $_filepath; } @@ -116,7 +116,7 @@ class Smarty_Internal_Resource_File { } $_compile_dir = $_template->smarty->compile_dir; if (strpos('/\\', substr($_compile_dir, -1)) === false) { - $_compile_dir .= DIRECTORY_SEPARATOR; + $_compile_dir .= DS; } return $_compile_dir . $_filepath . '.' . basename($_template->resource_name) . $_cache . $_template->smarty->php_ext; } diff --git a/libs/sysplugins/internal.resource_registered.php b/libs/sysplugins/internal.resource_registered.php index bdb9ae95..cb0d1a3e 100644 --- a/libs/sysplugins/internal.resource_registered.php +++ b/libs/sysplugins/internal.resource_registered.php @@ -114,12 +114,12 @@ class Smarty_Internal_Resource_Registered { $_filepath = (string)abs(crc32($_template->resource_name)); // if use_sub_dirs, break file into directories if ($_template->smarty->use_sub_dirs) { - $_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 2) . DIRECTORY_SEPARATOR - . substr($_filepath, 0, 1) . DIRECTORY_SEPARATOR + $_filepath = substr($_filepath, 0, 3) . DS + . substr($_filepath, 0, 2) . DS + . substr($_filepath, 0, 1) . DS . $_filepath; } - $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; if (isset($_template->compile_id)) { $_filepath = $_template->compile_id . $_compile_dir_sep . $_filepath; } @@ -130,7 +130,7 @@ class Smarty_Internal_Resource_Registered { } $_compile_dir = $_template->smarty->compile_dir; if (strpos('/\\', substr($_compile_dir, -1)) === false) { - $_compile_dir .= DIRECTORY_SEPARATOR; + $_compile_dir .= DS; } return $_compile_dir . $_filepath . '.' . basename($_template->resource_name) . '.' . $_template->resource_type . $_cache . $_template->smarty->php_ext; } diff --git a/libs/sysplugins/internal.security_handler.php b/libs/sysplugins/internal.security_handler.php index bf2ee390..f433e9e9 100644 --- a/libs/sysplugins/internal.security_handler.php +++ b/libs/sysplugins/internal.security_handler.php @@ -78,7 +78,7 @@ class Smarty_Internal_Security_Handler { 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) == DIRECTORY_SEPARATOR)) { + (strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) { return true; } } @@ -89,7 +89,7 @@ class Smarty_Internal_Security_Handler { if ($_cd == $_rp) { return true; } elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && - (strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR)) { + (strlen($_rp) == strlen($_cd) || substr($_rp, strlen($_cd), 1) == DS)) { return true; } } @@ -115,7 +115,7 @@ class Smarty_Internal_Security_Handler { if ($_cd == $_rp) { return true; } elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && - substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) { + substr($_rp, strlen($_cd), 1) == DS) { return true; } } diff --git a/libs/sysplugins/internal.template.php b/libs/sysplugins/internal.template.php index 0ad91428..158078a1 100644 --- a/libs/sysplugins/internal.template.php +++ b/libs/sysplugins/internal.template.php @@ -613,7 +613,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { } foreach((array)$this->smarty->template_dir as $_template_dir) { if (strpos('/\\', substr($_template_dir, -1)) === false) { - $_template_dir .= DIRECTORY_SEPARATOR; + $_template_dir .= DS; } $_filepath = $_template_dir . $file; diff --git a/libs/sysplugins/method.clear_compiled_tpl.php b/libs/sysplugins/method.clear_compiled_tpl.php index f9675a72..39f4e2ce 100644 --- a/libs/sysplugins/method.clear_compiled_tpl.php +++ b/libs/sysplugins/method.clear_compiled_tpl.php @@ -20,7 +20,7 @@ */ function clear_compiled_tpl($smarty, $resource_name = null, $compile_id = null, $exp_time = null) { - $_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; + $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; if (isset($resource_name)) { $_resource_part_1 = $resource_name . $smarty->php_ext; $_resource_part_2 = $resource_name . '.cache' . $smarty->php_ext;