mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
Reverting the plugins patch - needs more thought.
This commit is contained in:
2
NEWS
2
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)
|
- fixed issue with php executing in literal blocks (Monte)
|
||||||
|
|
||||||
Version 1.3.0
|
Version 1.3.0
|
||||||
|
278
Smarty.addons.php
Normal file
278
Smarty.addons.php
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Project: Smarty: the PHP compiled template engine
|
||||||
|
* File: Smarty.addons.php
|
||||||
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
|
* Andrei Zmievski <andrei@ispi.net>
|
||||||
|
* 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 <option> tags generated from
|
||||||
|
the passed parameters
|
||||||
|
\*======================================================================*/
|
||||||
|
function smarty_func_html_options()
|
||||||
|
{
|
||||||
|
$print_result = true;
|
||||||
|
|
||||||
|
extract(func_get_arg(0));
|
||||||
|
|
||||||
|
$html_result = "";
|
||||||
|
|
||||||
|
settype($selected, 'array');
|
||||||
|
if (isset($options)) {
|
||||||
|
settype($options, 'array');
|
||||||
|
foreach ($options as $key => $value) {
|
||||||
|
$html_result .= "<option value=\"$key\"";
|
||||||
|
if (in_array($key, $selected))
|
||||||
|
$html_result .= " selected";
|
||||||
|
$html_result .= ">$value</option>\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settype($output, 'array');
|
||||||
|
settype($values, 'array');
|
||||||
|
for ($i = 0; $i < count($output); $i++) {
|
||||||
|
/* By default, check value against $selected */
|
||||||
|
$sel_check = $values[$i];
|
||||||
|
$html_result .= "<option";
|
||||||
|
if ($i < count($values))
|
||||||
|
$html_result .= " value=\"".$values[$i]."\"";
|
||||||
|
else
|
||||||
|
$sel_check = $output[$i]; /* if more outputs than values, then
|
||||||
|
check output against $selected */
|
||||||
|
if (in_array($sel_check, $selected))
|
||||||
|
$html_result .= " selected";
|
||||||
|
$html_result .= ">".$output[$i]."</option>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($print_result)
|
||||||
|
print $html_result;
|
||||||
|
else
|
||||||
|
return $html_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: smarty_func_html_select_date
|
||||||
|
Purpose: Prints the dropdowns for date selection.
|
||||||
|
\*======================================================================*/
|
||||||
|
function smarty_func_html_select_date()
|
||||||
|
{
|
||||||
|
/* Default values. */
|
||||||
|
$prefix = "Date_";
|
||||||
|
$time = time();
|
||||||
|
$start_year = strftime("%Y");
|
||||||
|
$end_year = $start_year;
|
||||||
|
$display_days = true;
|
||||||
|
$display_months = true;
|
||||||
|
$display_years = true;
|
||||||
|
$month_format = "%B";
|
||||||
|
$day_format = "%02d";
|
||||||
|
$year_as_text = false;
|
||||||
|
|
||||||
|
extract(func_get_arg(0));
|
||||||
|
|
||||||
|
$html_result = "";
|
||||||
|
|
||||||
|
if ($display_months) {
|
||||||
|
$month_names = array();
|
||||||
|
|
||||||
|
for ($i = 1; $i <= 12; $i++)
|
||||||
|
$month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
|
||||||
|
|
||||||
|
$html_result .= '<select name="'.$prefix.'Month">'."\n";
|
||||||
|
$html_result .= smarty_func_html_options(array('output' => $month_names,
|
||||||
|
'values' => range(1, 12),
|
||||||
|
'selected' => strftime("%m", $time),
|
||||||
|
'print_result' => false));
|
||||||
|
$html_result .= "</select>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($display_days) {
|
||||||
|
$days = range(1, 31);
|
||||||
|
array_walk($days, create_function('&$x', '$x = sprintf("'.$day_format.'", $x);'));
|
||||||
|
|
||||||
|
$html_result .= '<select name="'.$prefix.'Day">'."\n";
|
||||||
|
$html_result .= smarty_func_html_options(array('output' => $days,
|
||||||
|
'values' => range(1, 31),
|
||||||
|
'selected' => strftime("%d", $time),
|
||||||
|
'print_result' => false));
|
||||||
|
$html_result .= "</select>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($display_years) {
|
||||||
|
if ($year_as_text) {
|
||||||
|
$html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">';
|
||||||
|
} else {
|
||||||
|
$years = range($start_year, $end_year);
|
||||||
|
|
||||||
|
$html_result .= '<select name="'.$prefix.'Year">'."\n";
|
||||||
|
$html_result .= smarty_func_html_options(array('output' => $years,
|
||||||
|
'values' => $years,
|
||||||
|
'selected' => strftime("%Y", $time),
|
||||||
|
'print_result' => false));
|
||||||
|
$html_result .= "</select>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print $html_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
|
?>
|
134
Smarty.class.php
134
Smarty.class.php
@@ -37,14 +37,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('SMARTY_PHP_PASSTHRU', 0);
|
require('Smarty.addons.php');
|
||||||
define('SMARTY_PHP_QUOTE', 1);
|
|
||||||
define('SMARTY_PHP_REMOVE', 2);
|
|
||||||
define('SMARTY_PHP_ALLOW', 3);
|
|
||||||
|
|
||||||
define('SMARTY_PLUGIN_MODIFIER', 0);
|
|
||||||
define('SMARTY_PLUGIN_FUNCTION', 1);
|
|
||||||
|
|
||||||
|
define("SMARTY_PHP_PASSTHRU",0);
|
||||||
|
define("SMARTY_PHP_QUOTE",1);
|
||||||
|
define("SMARTY_PHP_REMOVE",2);
|
||||||
|
define("SMARTY_PHP_ALLOW",3);
|
||||||
|
|
||||||
class Smarty
|
class Smarty
|
||||||
{
|
{
|
||||||
@@ -53,7 +51,6 @@ class Smarty
|
|||||||
var $template_dir = './templates'; // name of directory for templates
|
var $template_dir = './templates'; // name of directory for templates
|
||||||
var $compile_dir = './templates_c'; // name of directory for compiled templates
|
var $compile_dir = './templates_c'; // name of directory for compiled templates
|
||||||
var $config_dir = './configs'; // directory where config files are located
|
var $config_dir = './configs'; // directory where config files are located
|
||||||
var $plugin_dir = './plugins'; // directory where plugins are located
|
|
||||||
|
|
||||||
var $global_assign = array('SCRIPT_NAME'); // variables from the GLOBALS array
|
var $global_assign = array('SCRIPT_NAME'); // variables from the GLOBALS array
|
||||||
// that are implicitly assigned
|
// that are implicitly assigned
|
||||||
@@ -87,8 +84,22 @@ class Smarty
|
|||||||
var $right_delimiter = '}';
|
var $right_delimiter = '}';
|
||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array(); // a table of custom functions
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
var $custom_mods = array(); // a table of custom modifiers
|
'html_select_date' => 'smarty_func_html_select_date'
|
||||||
|
);
|
||||||
|
|
||||||
|
var $custom_mods = array( 'lower' => 'strtolower',
|
||||||
|
'upper' => 'strtoupper',
|
||||||
|
'capitalize' => 'ucwords',
|
||||||
|
'escape' => 'smarty_mod_escape',
|
||||||
|
'truncate' => 'smarty_mod_truncate',
|
||||||
|
'spacify' => 'smarty_mod_spacify',
|
||||||
|
'date_format' => 'smarty_mod_date_format',
|
||||||
|
'string_format' => 'smarty_mod_string_format',
|
||||||
|
'replace' => 'smarty_mod_replace',
|
||||||
|
'strip_tags' => 'smarty_mod_strip_tags',
|
||||||
|
'default' => 'smarty_mod_default'
|
||||||
|
);
|
||||||
|
|
||||||
// internal vars
|
// internal vars
|
||||||
var $_error_msg = false; // error messages. true/false
|
var $_error_msg = false; // error messages. true/false
|
||||||
@@ -98,7 +109,6 @@ class Smarty
|
|||||||
var $_current_file = null; // the current template being compiled
|
var $_current_file = null; // the current template being compiled
|
||||||
var $_current_line_no = 1; // line number for error messages
|
var $_current_line_no = 1; // line number for error messages
|
||||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||||
var $_plugins_loaded = false; // keeps track of whether plugins are loaded
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
@@ -323,9 +333,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load Smarty plugins. */
|
|
||||||
$this->_load_plugins();
|
|
||||||
|
|
||||||
// compile files
|
// compile files
|
||||||
$this->_compile($this->template_dir);
|
$this->_compile($this->template_dir);
|
||||||
//assemble compile directory path to file
|
//assemble compile directory path to file
|
||||||
@@ -1244,66 +1251,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _load_plugins
|
|
||||||
Purpose: Load Smarty plugins
|
|
||||||
\*======================================================================*/
|
|
||||||
function _load_plugins()
|
|
||||||
{
|
|
||||||
if ($this->_plugins_loaded)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!is_dir($this->plugin_dir))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$included_files = implode(',', get_included_files());
|
|
||||||
$dir_handle = opendir($this->plugin_dir);
|
|
||||||
while ($entry = readdir($dir_handle)) {
|
|
||||||
$plugin_file = $this->plugin_dir.'/'.$entry;
|
|
||||||
|
|
||||||
if ($entry == '.' || $entry == '..' ||
|
|
||||||
!is_file($plugin_file) ||
|
|
||||||
substr($plugin_file, -11) != '.plugin.php' ||
|
|
||||||
strpos($included_files, $entry) !== false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
unset($smarty_plugin_info);
|
|
||||||
include_once $plugin_file;
|
|
||||||
|
|
||||||
if (!isset($smarty_plugin_info) || !is_array($smarty_plugin_info)) {
|
|
||||||
trigger_error("Could not load plugin '$plugin_file': missing or incorrect plugin info descriptor", E_USER_WARNING);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$plugin_table = (array)$smarty_plugin_info['table'];
|
|
||||||
foreach ($plugin_table as $plugin) {
|
|
||||||
extract($plugin);
|
|
||||||
if (empty($name) || empty($impl))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case SMARTY_PLUGIN_MODIFIER:
|
|
||||||
$this->register_modifier($name, $impl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SMARTY_PLUGIN_FUNCTION:
|
|
||||||
$this->register_function($name, $impl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
trigger_error("Unknown plugin type $type in $plugin_file", E_USER_WARNING);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($dir_handle);
|
|
||||||
|
|
||||||
$this->_plugins_loaded = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _dequote
|
Function: _dequote
|
||||||
Purpose: Remove starting and ending quotes from the string
|
Purpose: Remove starting and ending quotes from the string
|
||||||
@@ -1421,45 +1368,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _smarty_insert_handler
|
|
||||||
Purpose: Handles insert tag calls
|
|
||||||
\*======================================================================*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _smarty_mod_handler
|
|
||||||
Purpose: Handles modifier calls
|
|
||||||
\*======================================================================*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -37,14 +37,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('SMARTY_PHP_PASSTHRU', 0);
|
require('Smarty.addons.php');
|
||||||
define('SMARTY_PHP_QUOTE', 1);
|
|
||||||
define('SMARTY_PHP_REMOVE', 2);
|
|
||||||
define('SMARTY_PHP_ALLOW', 3);
|
|
||||||
|
|
||||||
define('SMARTY_PLUGIN_MODIFIER', 0);
|
|
||||||
define('SMARTY_PLUGIN_FUNCTION', 1);
|
|
||||||
|
|
||||||
|
define("SMARTY_PHP_PASSTHRU",0);
|
||||||
|
define("SMARTY_PHP_QUOTE",1);
|
||||||
|
define("SMARTY_PHP_REMOVE",2);
|
||||||
|
define("SMARTY_PHP_ALLOW",3);
|
||||||
|
|
||||||
class Smarty
|
class Smarty
|
||||||
{
|
{
|
||||||
@@ -53,7 +51,6 @@ class Smarty
|
|||||||
var $template_dir = './templates'; // name of directory for templates
|
var $template_dir = './templates'; // name of directory for templates
|
||||||
var $compile_dir = './templates_c'; // name of directory for compiled templates
|
var $compile_dir = './templates_c'; // name of directory for compiled templates
|
||||||
var $config_dir = './configs'; // directory where config files are located
|
var $config_dir = './configs'; // directory where config files are located
|
||||||
var $plugin_dir = './plugins'; // directory where plugins are located
|
|
||||||
|
|
||||||
var $global_assign = array('SCRIPT_NAME'); // variables from the GLOBALS array
|
var $global_assign = array('SCRIPT_NAME'); // variables from the GLOBALS array
|
||||||
// that are implicitly assigned
|
// that are implicitly assigned
|
||||||
@@ -87,8 +84,22 @@ class Smarty
|
|||||||
var $right_delimiter = '}';
|
var $right_delimiter = '}';
|
||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array(); // a table of custom functions
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
var $custom_mods = array(); // a table of custom modifiers
|
'html_select_date' => 'smarty_func_html_select_date'
|
||||||
|
);
|
||||||
|
|
||||||
|
var $custom_mods = array( 'lower' => 'strtolower',
|
||||||
|
'upper' => 'strtoupper',
|
||||||
|
'capitalize' => 'ucwords',
|
||||||
|
'escape' => 'smarty_mod_escape',
|
||||||
|
'truncate' => 'smarty_mod_truncate',
|
||||||
|
'spacify' => 'smarty_mod_spacify',
|
||||||
|
'date_format' => 'smarty_mod_date_format',
|
||||||
|
'string_format' => 'smarty_mod_string_format',
|
||||||
|
'replace' => 'smarty_mod_replace',
|
||||||
|
'strip_tags' => 'smarty_mod_strip_tags',
|
||||||
|
'default' => 'smarty_mod_default'
|
||||||
|
);
|
||||||
|
|
||||||
// internal vars
|
// internal vars
|
||||||
var $_error_msg = false; // error messages. true/false
|
var $_error_msg = false; // error messages. true/false
|
||||||
@@ -98,7 +109,6 @@ class Smarty
|
|||||||
var $_current_file = null; // the current template being compiled
|
var $_current_file = null; // the current template being compiled
|
||||||
var $_current_line_no = 1; // line number for error messages
|
var $_current_line_no = 1; // line number for error messages
|
||||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||||
var $_plugins_loaded = false; // keeps track of whether plugins are loaded
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
@@ -323,9 +333,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load Smarty plugins. */
|
|
||||||
$this->_load_plugins();
|
|
||||||
|
|
||||||
// compile files
|
// compile files
|
||||||
$this->_compile($this->template_dir);
|
$this->_compile($this->template_dir);
|
||||||
//assemble compile directory path to file
|
//assemble compile directory path to file
|
||||||
@@ -1244,66 +1251,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _load_plugins
|
|
||||||
Purpose: Load Smarty plugins
|
|
||||||
\*======================================================================*/
|
|
||||||
function _load_plugins()
|
|
||||||
{
|
|
||||||
if ($this->_plugins_loaded)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!is_dir($this->plugin_dir))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$included_files = implode(',', get_included_files());
|
|
||||||
$dir_handle = opendir($this->plugin_dir);
|
|
||||||
while ($entry = readdir($dir_handle)) {
|
|
||||||
$plugin_file = $this->plugin_dir.'/'.$entry;
|
|
||||||
|
|
||||||
if ($entry == '.' || $entry == '..' ||
|
|
||||||
!is_file($plugin_file) ||
|
|
||||||
substr($plugin_file, -11) != '.plugin.php' ||
|
|
||||||
strpos($included_files, $entry) !== false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
unset($smarty_plugin_info);
|
|
||||||
include_once $plugin_file;
|
|
||||||
|
|
||||||
if (!isset($smarty_plugin_info) || !is_array($smarty_plugin_info)) {
|
|
||||||
trigger_error("Could not load plugin '$plugin_file': missing or incorrect plugin info descriptor", E_USER_WARNING);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$plugin_table = (array)$smarty_plugin_info['table'];
|
|
||||||
foreach ($plugin_table as $plugin) {
|
|
||||||
extract($plugin);
|
|
||||||
if (empty($name) || empty($impl))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case SMARTY_PLUGIN_MODIFIER:
|
|
||||||
$this->register_modifier($name, $impl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SMARTY_PLUGIN_FUNCTION:
|
|
||||||
$this->register_function($name, $impl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
trigger_error("Unknown plugin type $type in $plugin_file", E_USER_WARNING);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($dir_handle);
|
|
||||||
|
|
||||||
$this->_plugins_loaded = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _dequote
|
Function: _dequote
|
||||||
Purpose: Remove starting and ending quotes from the string
|
Purpose: Remove starting and ending quotes from the string
|
||||||
@@ -1421,45 +1368,6 @@ class Smarty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _smarty_insert_handler
|
|
||||||
Purpose: Handles insert tag calls
|
|
||||||
\*======================================================================*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
|
||||||
Function: _smarty_mod_handler
|
|
||||||
Purpose: Handles modifier calls
|
|
||||||
\*======================================================================*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user