From 7e45bcf52738979add2a3675de2349e80a4632a3 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Tue, 1 Dec 2009 20:34:32 +0000 Subject: [PATCH] - replaced most hard errors (exceptions) by softerrors(trigger_error) in plugins --- change_log.txt | 1 + libs/plugins/function.cycle.php | 2 +- libs/plugins/function.fetch.php | 18 +++++++++--------- libs/plugins/function.html_checkboxes.php | 4 ++-- libs/plugins/function.html_image.php | 8 ++++---- libs/plugins/function.html_options.php | 2 +- libs/plugins/function.html_radios.php | 6 +++--- libs/plugins/function.html_select_date.php | 2 +- libs/plugins/function.html_select_time.php | 2 +- libs/plugins/function.html_table.php | 2 +- libs/plugins/function.mailto.php | 6 +++--- libs/plugins/function.math.php | 10 +++++----- libs/plugins/function.popup.php | 4 ++-- libs/plugins/function.popup_init.php | 2 +- 14 files changed, 35 insertions(+), 34 deletions(-) diff --git a/change_log.txt b/change_log.txt index 8ded47fc..357e1cd7 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,6 +2,7 @@ - fixed parsing of names of special formated tags like if,elseif,while,for,foreach - removed direct access to constants in templates because of some syntax problems - removed cache resource plugin for mysql from the distribution +- replaced most hard errors (exceptions) by softerrors(trigger_error) in plugins 11/30/2009 - map 'true' to SMARTY_CACHING_LIFETIME_CURRENT for the $smarty->caching parameter diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index e93a040d..f1cb46ba 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -50,7 +50,7 @@ function smarty_function_cycle($params, $smarty, $template) if (!in_array('values', array_keys($params))) { if(!isset($template->plugin_data['cycle'][$name]['values'])) { - throw new Exception ("cycle: missing 'values' parameter"); + trigger_error("cycle: missing 'values' parameter",E_USER_WARNING); return; } } else { diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php index 958d2ef7..391ff1bb 100644 --- a/libs/plugins/function.fetch.php +++ b/libs/plugins/function.fetch.php @@ -24,7 +24,7 @@ function smarty_function_fetch($params, $smarty, $template) { if (empty($params['file'])) { - throw new Exception ("[plugin] fetch parameter 'file' cannot be empty"); + trigger_error("[plugin] fetch parameter 'file' cannot be empty",E_USER_NOTICE); return; } @@ -41,7 +41,7 @@ function smarty_function_fetch($params, $smarty, $template) } fclose($fp); } else { - throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] . '\''); + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'',E_USER_NOTICE); return; } } else { @@ -94,7 +94,7 @@ function smarty_function_fetch($params, $smarty, $template) case "header": if(!empty($param_value)) { if(!preg_match('![\w\d-]+: .+!',$param_value)) { - throw new Exception ("[plugin] invalid header format '".$param_value."'"); + trigger_error("[plugin] invalid header format '".$param_value."'",E_USER_NOTICE); return; } else { $extra_headers[] = $param_value; @@ -110,7 +110,7 @@ function smarty_function_fetch($params, $smarty, $template) if(!preg_match('!\D!', $param_value)) { $proxy_port = (int) $param_value; } else { - throw new Exception ("[plugin] invalid value for attribute '".$param_key."'"); + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); return; } break; @@ -128,12 +128,12 @@ function smarty_function_fetch($params, $smarty, $template) if(!preg_match('!\D!', $param_value)) { $timeout = (int) $param_value; } else { - throw new Exception ("[plugin] invalid value for attribute '".$param_key."'"); + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); return; } break; default: - throw new Exception ("[plugin] unrecognized attribute '".$param_key."'"); + trigger_error("[plugin] unrecognized attribute '".$param_key."'",E_USER_NOTICE); return; } } @@ -145,7 +145,7 @@ function smarty_function_fetch($params, $smarty, $template) } if(!$fp) { - throw new Exception ("[plugin] unable to fetch: $errstr ($errno)"); + trigger_error("[plugin] unable to fetch: $errstr ($errno)",E_USER_NOTICE); return; } else { if($_is_proxy) { @@ -188,7 +188,7 @@ function smarty_function_fetch($params, $smarty, $template) } } } else { - throw new Exception ("[plugin] unable to parse URL, check syntax"); + trigger_error("[plugin fetch] unable to parse URL, check syntax",E_USER_NOTICE); return; } } else { @@ -199,7 +199,7 @@ function smarty_function_fetch($params, $smarty, $template) } fclose($fp); } else { - throw new Exception ('[plugin] fetch cannot read file \'' . $params['file'] .'\''); + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'',E_USER_NOTICE); return; } } diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 0e04f6e1..ac72f3fd 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -80,7 +80,7 @@ function smarty_function_html_checkboxes($params, $smarty, $template) break; case 'checkboxes': - throw new Exception ('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); + trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); $options = (array)$_val; break; @@ -91,7 +91,7 @@ function smarty_function_html_checkboxes($params, $smarty, $template) if(!is_array($_val)) { $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; } else { - throw new Exception ("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); } break; } diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index 6d612dfa..3f031dc0 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -85,7 +85,7 @@ function smarty_function_html_image($params, $smarty, $template) } if (empty($file)) { - throw new Exception ("html_image: missing 'file' parameter", E_USER_NOTICE); + trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); return; } @@ -98,13 +98,13 @@ function smarty_function_html_image($params, $smarty, $template) if (!isset($params['width']) || !isset($params['height'])) { if (!$_image_data = @getimagesize($_image_path)) { if (!file_exists($_image_path)) { - throw new Exception ("html_image: unable to find '$_image_path'", E_USER_NOTICE); + trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); return; } else if (!is_readable($_image_path)) { - throw new Exception ("html_image: unable to read '$_image_path'", E_USER_NOTICE); + trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); return; } else { - throw new Exception ("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); + trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); return; } } diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 66d8b76f..69f56e80 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -66,7 +66,7 @@ function smarty_function_html_options($params, $smarty, $template) if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { - throw new Exception ("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); } break; } diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index edfd8ad6..c7f72bf6 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -65,7 +65,7 @@ function smarty_function_html_radios($params, $smarty, $template) case 'checked': case 'selected': if (is_array($_val)) { - throw new Exception ('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); + trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); } else { $selected = (string)$_val; } @@ -86,7 +86,7 @@ function smarty_function_html_radios($params, $smarty, $template) break; case 'radios': - throw new Exception ('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING); + trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING); $options = (array)$_val; break; @@ -97,7 +97,7 @@ function smarty_function_html_radios($params, $smarty, $template) if (!is_array($_val)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { - throw new Exception ("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE); } break; } diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 1416c3bc..7001f887 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -134,7 +134,7 @@ function smarty_function_html_select_date($params, $smarty, $template) if (!is_array($_value)) { $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; } else { - throw new Exception ("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); } break; } diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index 097df93d..51d307ae 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -78,7 +78,7 @@ function smarty_function_html_select_time($params, $smarty, $template) break; default: - throw new Exception ("[html_select_time] unknown parameter $_key", E_USER_WARNING); + trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING); } } diff --git a/libs/plugins/function.html_table.php b/libs/plugins/function.html_table.php index 8f7afd2e..198b03ca 100644 --- a/libs/plugins/function.html_table.php +++ b/libs/plugins/function.html_table.php @@ -63,7 +63,7 @@ function smarty_function_html_table($params, $smarty, $template) $caption = ''; if (!isset($params['loop'])) { - throw new Exception ("html_table: missing 'loop' parameter"); + trigger_error("html_table: missing 'loop' parameter",E_USER_WARNING); return; } diff --git a/libs/plugins/function.mailto.php b/libs/plugins/function.mailto.php index a5552e68..29a87c69 100644 --- a/libs/plugins/function.mailto.php +++ b/libs/plugins/function.mailto.php @@ -54,7 +54,7 @@ function smarty_function_mailto($params, $smarty, $template) $extra = ''; if (empty($params['address'])) { - throw new Exception ("mailto: missing 'address' parameter"); + trigger_error("mailto: missing 'address' parameter",E_USER_WARNING); return; } else { $address = $params['address']; @@ -97,7 +97,7 @@ function smarty_function_mailto($params, $smarty, $template) $encode = (empty($params['encode'])) ? 'none' : $params['encode']; if (!in_array($encode, array('javascript', 'javascript_charcode', 'hex', 'none'))) { - throw new Exception ("mailto: 'encode' parameter must be none, javascript or hex"); + trigger_error("mailto: 'encode' parameter must be none, javascript or hex",E_USER_WARNING); return; } @@ -130,7 +130,7 @@ function smarty_function_mailto($params, $smarty, $template) } elseif ($encode == 'hex') { preg_match('!^(.*)(\?.*)$!', $address, $match); if (!empty($match[2])) { - throw new Exception ("mailto: hex encoding does not work with extra attributes. Try javascript."); + trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.",E_USER_WARNING); return; } $address_encode = ''; diff --git a/libs/plugins/function.math.php b/libs/plugins/function.math.php index b309af11..d7ac9f8f 100644 --- a/libs/plugins/function.math.php +++ b/libs/plugins/function.math.php @@ -26,7 +26,7 @@ function smarty_function_math($params, $smarty, $template) { // be sure equation parameter is present if (empty($params['equation'])) { - throw new Exception ("math: missing equation parameter"); + trigger_error("math: missing equation parameter",E_USER_WARNING); return; } @@ -34,7 +34,7 @@ function smarty_function_math($params, $smarty, $template) // make sure parenthesis are balanced if (substr_count($equation,"(") != substr_count($equation,")")) { - throw new Exception ("math: unbalanced parenthesis"); + trigger_error("math: unbalanced parenthesis",E_USER_WARNING); return; } @@ -45,7 +45,7 @@ function smarty_function_math($params, $smarty, $template) foreach($match[1] as $curr_var) { if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) { - throw new Exception ("math: function call $curr_var not allowed"); + trigger_error("math: function call $curr_var not allowed",E_USER_WARNING); return; } } @@ -54,11 +54,11 @@ function smarty_function_math($params, $smarty, $template) if ($key != "equation" && $key != "format" && $key != "assign") { // make sure value is not empty if (strlen($val)==0) { - throw new Exception ("math: parameter $key is empty"); + trigger_error("math: parameter $key is empty",E_USER_WARNING); return; } if (!is_numeric($val)) { - throw new Exception ("math: parameter $key: is not numeric"); + trigger_error("math: parameter $key: is not numeric",E_USER_WARNING); return; } $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); diff --git a/libs/plugins/function.popup.php b/libs/plugins/function.popup.php index 509c3c36..e683556a 100644 --- a/libs/plugins/function.popup.php +++ b/libs/plugins/function.popup.php @@ -96,12 +96,12 @@ function smarty_function_popup($params, $smarty, $template) break; default: - throw new Exception ("[popup] unknown parameter $_key", E_USER_WARNING); + trigger_error("[popup] unknown parameter $_key", E_USER_WARNING); } } if (empty($text) && !isset($inarray) && empty($function)) { - throw new Exception ("overlib: attribute 'text' or 'inarray' or 'function' required"); + trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required",E_USER_WARNING); return false; } diff --git a/libs/plugins/function.popup_init.php b/libs/plugins/function.popup_init.php index 053b155b..ae580376 100644 --- a/libs/plugins/function.popup_init.php +++ b/libs/plugins/function.popup_init.php @@ -32,7 +32,7 @@ function smarty_function_popup_init($params, $smarty, $template) return '' . "\n" . '' . "\n"; } else { - throw new Exception ("popup_init: missing src parameter"); + trigger_error("popup_init: missing src parameter",E_USER_WARNING); } }