From b557a5c100cb477fe38c9195cafee1b43d38c307 Mon Sep 17 00:00:00 2001 From: andrey Date: Mon, 26 Feb 2001 16:33:30 +0000 Subject: [PATCH] Reverting the plugins patch - needs more thought. --- NEWS | 2 - Smarty.addons.php | 278 ++++++++++++++++++++++++++++++++++++++++++ Smarty.class.php | 146 ++++------------------ libs/Smarty.class.php | 146 ++++------------------ 4 files changed, 332 insertions(+), 240 deletions(-) create mode 100644 Smarty.addons.php diff --git a/NEWS b/NEWS index 28923b3a..62ca2790 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,3 @@ - - added plugin functionality and made existing modifiers - and custom functions into plugins. (Andrei) - fixed issue with php executing in literal blocks (Monte) Version 1.3.0 diff --git a/Smarty.addons.php b/Smarty.addons.php new file mode 100644 index 00000000..e5ef6ecd --- /dev/null +++ b/Smarty.addons.php @@ -0,0 +1,278 @@ + + * Andrei Zmievski + * Version: 1.3.0 + * Copyright: 2001 ispi of Lincoln, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * You may contact the authors of Smarty by e-mail at: + * monte@ispi.net + * andrei@ispi.net + * + * Or, write to: + * Monte Ohrt + * CTO, ispi + * 237 S. 70th suite 220 + * Lincoln, NE 68510 + * + * The latest version of Smarty can be obtained from: + * http://www.phpinsider.com + * + */ + + +/*============================================*\ + Inserts handler +\*============================================*/ + +function _smarty_insert_handler($args, $caching, $delimiter) +{ + if ($caching) { + $arg_string = serialize($args); + return "$delimiter{insert_cache $arg_string}$delimiter"; + } else { + $function_name = 'insert_'.$args['name']; + return $function_name($args); + } +} + + +/*============================================*\ + Modifiers +\*============================================*/ + +function _smarty_mod_handler() +{ + $args = func_get_args(); + list($func_name, $map_array) = array_splice($args, 0, 2); + $var = $args[0]; + + if ($map_array && is_array($var)) { + foreach ($var as $key => $val) { + $args[0] = $val; + $var[$key] = call_user_func_array($func_name, $args); + } + return $var; + } else { + return call_user_func_array($func_name, $args); + } +} + + +/*======================================================================*\ + Function: smarty_mod_escape + Purpose: Escape the string according to escapement type +\*======================================================================*/ +function smarty_mod_escape($string, $esc_type = 'html') +{ + switch ($esc_type) { + case 'html': + return htmlspecialchars($string); + + case 'url': + return urlencode($string); + + default: + return $string; + } +} + + +/*======================================================================*\ + Function: smarty_mod_truncate + Purpose: Truncate a string to a certain length if necessary, + optionally splitting in the middle of a word, and + appending the $etc string. +\*======================================================================*/ +function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false) +{ + if ($length == 0) + return ''; + + if (strlen($string) > $length) { + $length -= strlen($etc); + $fragment = substr($string, 0, $length+1); + if ($break_words) + $fragment = substr($fragment, 0, -1); + else + $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment); + return $fragment.$etc; + } else + return $string; +} + + +function smarty_mod_spacify($string, $spacify_char = ' ') +{ + return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY)); +} + + +function smarty_mod_date_format($string, $format="%b %e, %Y") +{ + return strftime($format, $string); +} + + +function smarty_mod_string_format($string, $format) +{ + return sprintf($format, $string); +} + +function smarty_mod_replace($string, $search, $replace) +{ + return str_replace($search, $replace, $string); +} + +function smarty_mod_strip_tags($string, $replace_with_space = true) +{ + if ($replace_with_space) + return preg_replace('!<[^>]*?>!', ' ', $string); + else + return strip_tags($string); +} + +function smarty_mod_default($string, $default="") +{ + if(empty($string)) + return $default; + else + return $string; +} + +/*============================================*\ + Custom tag functions +\*============================================*/ + +/*======================================================================*\ + Function: smarty_func_html_options + Purpose: Prints the list of