mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- reverted location of loadPlugin() to Smarty class
- fixed comments in plugins
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
13/11/2010
|
||||
- bugfix on {debug}
|
||||
- reverted location of loadPlugin() to Smarty class
|
||||
- fixed comments in plugins
|
||||
|
||||
===== Smarty 3.0.2 =====
|
||||
|
||||
|
@@ -660,6 +660,54 @@ class Smarty extends Smarty_Internal_Data {
|
||||
return $this->debug_tpl = $tpl_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes unknown classes and loads plugin files for them
|
||||
* class name format: Smarty_PluginType_PluginName
|
||||
* plugin filename format: plugintype.pluginname.php
|
||||
*
|
||||
* @param string $plugin_name class plugin name to load
|
||||
* @return string |boolean filepath of loaded file or false
|
||||
*/
|
||||
public function loadPlugin($plugin_name, $check = true)
|
||||
{
|
||||
// if function or class exists, exit silently (already loaded)
|
||||
if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false)))
|
||||
return true;
|
||||
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
||||
$_plugin_name = strtolower($plugin_name);
|
||||
$_name_parts = explode('_', $_plugin_name, 3);
|
||||
// class name must have three parts to be valid plugin
|
||||
if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
|
||||
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
||||
return false;
|
||||
}
|
||||
// if type is "internal", get plugin from sysplugins
|
||||
if ($_name_parts[1] == 'internal') {
|
||||
$file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// plugin filename is expected to be: [type].[name].php
|
||||
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
||||
// 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 .= DS;
|
||||
}
|
||||
$file = $_plugin_dir . $_plugin_filename;
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
// no plugin loaded
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* clean up properties on cloned object
|
||||
*/
|
||||
|
@@ -11,9 +11,8 @@
|
||||
* Smarty {php}{/php} block plugin
|
||||
*
|
||||
* @param string $content contents of the block
|
||||
* @param object $smarty Smarty object
|
||||
* @param boolean $ &$repeat repeat flag
|
||||
* @param object $template template object
|
||||
* @param boolean $ &$repeat repeat flag
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_block_php($params, $content, $template, &$repeat)
|
||||
|
@@ -27,9 +27,8 @@
|
||||
* </pre>
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param string $content contents of the block
|
||||
* @param object $smarty Smarty object
|
||||
* @param boolean &$repeat repeat flag
|
||||
* @param object $template template object
|
||||
* @param boolean &$repeat repeat flag
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_block_textformat($params, $content, $template, &$repeat)
|
||||
|
@@ -39,7 +39,6 @@
|
||||
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
|
||||
* @version 1.3
|
||||
* @param array
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string|null
|
||||
*/
|
||||
|
@@ -16,7 +16,6 @@
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string|null if the assign parameter is passed, Smarty assigns the
|
||||
* result to a template variable
|
||||
|
@@ -34,7 +34,6 @@
|
||||
* - separator (optional) - ie <br> or
|
||||
* - output (optional) - the output next to each checkbox
|
||||
* - assign (optional) - assign the output as an array to this variable
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
@@ -42,7 +41,6 @@
|
||||
function smarty_function_html_checkboxes($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
|
||||
$name = 'checkbox';
|
||||
$values = null;
|
||||
|
@@ -29,7 +29,6 @@
|
||||
* - basedir = base directory for absolute paths, default
|
||||
* is environment variable DOCUMENT_ROOT
|
||||
* - path_prefix = prefix for path output (optional, default empty)
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
@@ -37,8 +36,7 @@
|
||||
function smarty_function_html_image($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
|
||||
|
||||
$alt = '';
|
||||
$file = '';
|
||||
$height = '';
|
||||
|
@@ -24,7 +24,6 @@
|
||||
* - options (required if no values supplied) - associative array
|
||||
* - selected (optional) - string default not set
|
||||
* - output (required if not options supplied) - array
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
@@ -32,7 +31,6 @@
|
||||
function smarty_function_html_options($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
|
||||
$name = null;
|
||||
$values = null;
|
||||
|
@@ -35,7 +35,6 @@
|
||||
* - separator (optional) - ie <br> or
|
||||
* - output (optional) - the output next to each radio button
|
||||
* - assign (optional) - assign the output as an array to this variable
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
@@ -43,7 +42,6 @@
|
||||
function smarty_function_html_radios($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
|
||||
$name = 'radio';
|
||||
$values = null;
|
||||
|
@@ -34,7 +34,6 @@
|
||||
* @author Andrei Zmievski
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
*/
|
||||
@@ -43,9 +42,6 @@ function smarty_function_html_select_date($params, $template)
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
//$smarty->loadPlugin('Smarty_shared_make_timestamp');
|
||||
//$smarty->loadPlugin('Smarty_function_html_options');
|
||||
|
||||
/* Default values. */
|
||||
$prefix = "Date_";
|
||||
@@ -219,7 +215,7 @@ function smarty_function_html_select_date($params, $template)
|
||||
'values' => $month_values,
|
||||
'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$month_result .= '</select>';
|
||||
}
|
||||
|
||||
@@ -255,7 +251,7 @@ function smarty_function_html_select_date($params, $template)
|
||||
'values' => $day_values,
|
||||
'selected' => $time[2],
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$day_result .= '</select>';
|
||||
}
|
||||
|
||||
@@ -302,7 +298,7 @@ function smarty_function_html_select_date($params, $template)
|
||||
'values' => $yearvals,
|
||||
'selected' => $time[0],
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$year_result .= '</select>';
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@
|
||||
* @author Roberto Berto <roberto@berto.net>
|
||||
* @credits Monte Ohrt <monte AT ohrt DOT com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_make_timestamp()
|
||||
@@ -27,8 +26,6 @@ function smarty_function_html_select_time($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_make_timestamp');
|
||||
//$smarty->loadPlugin('Smarty_function_html_options');
|
||||
|
||||
/* Default values. */
|
||||
$prefix = "Time_";
|
||||
@@ -108,7 +105,7 @@ function smarty_function_html_select_time($params, $template)
|
||||
'values' => $hours,
|
||||
'selected' => strftime($hour_fmt, $time),
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$html_result .= "</select>\n";
|
||||
}
|
||||
|
||||
@@ -135,7 +132,7 @@ function smarty_function_html_select_time($params, $template)
|
||||
'values' => $minutes,
|
||||
'selected' => $selected,
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$html_result .= "</select>\n";
|
||||
}
|
||||
|
||||
@@ -163,7 +160,7 @@ function smarty_function_html_select_time($params, $template)
|
||||
'values' => $seconds,
|
||||
'selected' => $selected,
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$html_result .= "</select>\n";
|
||||
}
|
||||
|
||||
@@ -187,7 +184,7 @@ function smarty_function_html_select_time($params, $template)
|
||||
'values' => array('am', 'pm'),
|
||||
'selected' => strtolower(strftime('%p', $time)),
|
||||
'print_result' => false),
|
||||
$smarty, $template);
|
||||
$template);
|
||||
$html_result .= "</select>\n";
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,6 @@
|
||||
* - hdir = horizontal direction (default: "right", means left-to-right)
|
||||
* - inner = inner loop (default "cols": print $loop line by line,
|
||||
* $loop will be printed column by column otherwise)
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -45,7 +45,6 @@
|
||||
* - newsgroups = (optional) newsgroup(s) to post to
|
||||
* - followupto = (optional) address(es) to follow up to
|
||||
* - extra = (optional) extra tags for the href link
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -17,7 +17,6 @@
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string|null
|
||||
*/
|
||||
|
@@ -16,7 +16,6 @@
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -16,7 +16,6 @@
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase {
|
||||
$this->compiler->tag_nocache = true;
|
||||
|
||||
// display debug template
|
||||
$_output = "<?php Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Debug', \$_smarty_tpl->smarty->plugins_dir); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>";
|
||||
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>";
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
}
|
||||
}
|
||||
// check for plugin modifiercompiler
|
||||
} else if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_modifiercompiler_' . $modifier, $compiler->smarty->plugins_dir)) {
|
||||
} else if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
|
||||
$plugin = 'smarty_modifiercompiler_' . $modifier;
|
||||
$output = $plugin($single_modifier, $compiler);
|
||||
// check for plugin modifier
|
||||
|
@@ -22,8 +22,8 @@ class Smarty_Internal_Config_File_Compiler {
|
||||
{
|
||||
$this->smarty = $smarty;
|
||||
// get required plugins
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfilelexer', $this->smarty->plugins_dir);
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfileparser', $this->smarty->plugins_dir);
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Configfilelexer');
|
||||
$this->smarty->loadPlugin('Smarty_Internal_Configfileparser');
|
||||
$this->config_data['sections'] = array();
|
||||
$this->config_data['vars'] = array();
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ class Smarty_Internal_Filter {
|
||||
{
|
||||
$_plugin = "smarty_{$type}filter_{$name}";
|
||||
$_filter_name = $_plugin;
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($_plugin, $this->smarty->plugins_dir)) {
|
||||
if ($this->smarty->loadPlugin($_plugin)) {
|
||||
if (class_exists($_plugin, false)) {
|
||||
$_plugin = array($_plugin, 'execute');
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ class Smarty_Internal_Filter_Handler {
|
||||
if (!empty($smarty->autoload_filters[$type])) {
|
||||
foreach ((array)$smarty->autoload_filters[$type] as $name) {
|
||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($plugin_name, $smarty->plugins_dir)) {
|
||||
if ($smarty->loadPlugin($plugin_name)) {
|
||||
if (function_exists($plugin_name)) {
|
||||
// use loaded Smarty2 style plugin
|
||||
$output = $plugin_name($output, $smarty);
|
||||
|
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Loader
|
||||
*
|
||||
* Compiles the {ldelim} tag
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Loader Class
|
||||
*/
|
||||
class Smarty_Internal_Plugin_Loader {
|
||||
/**
|
||||
* Takes unknown classes and loads plugin files for them
|
||||
* class name format: Smarty_PluginType_PluginName
|
||||
* plugin filename format: plugintype.pluginname.php
|
||||
*
|
||||
* @param string $plugin_name class plugin name to load
|
||||
* @return string |boolean filepath of loaded file or false
|
||||
*/
|
||||
static function loadPlugin($plugin_name, $plugins_dir)
|
||||
{
|
||||
// if function or class exists, exit silently (already loaded)
|
||||
if (is_callable($plugin_name) || class_exists($plugin_name, false))
|
||||
return true;
|
||||
// Plugin name is expected to be: Smarty_[Type]_[Name]
|
||||
$_plugin_name = strtolower($plugin_name);
|
||||
$_name_parts = explode('_', $_plugin_name, 3);
|
||||
// class name must have three parts to be valid plugin
|
||||
if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
|
||||
throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
||||
return false;
|
||||
}
|
||||
// if type is "internal", get plugin from sysplugins
|
||||
if ($_name_parts[1] == 'internal') {
|
||||
$file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// plugin filename is expected to be: [type].[name].php
|
||||
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
|
||||
// loop through plugin dirs and find the plugin
|
||||
foreach((array)$plugins_dir as $_plugin_dir) {
|
||||
if (strpos('/\\', substr($_plugin_dir, -1)) === false) {
|
||||
$_plugin_dir .= DS;
|
||||
}
|
||||
$file = $_plugin_dir . $_plugin_filename;
|
||||
if (file_exists($file)) {
|
||||
require_once($file);
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
// no plugin loaded
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -245,7 +245,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
Smarty_Internal_Plugin_Loader::loadPlugin($this->resource_object->compiler_class,$this->smarty->plugins_dir);
|
||||
$this->smarty->loadPlugin($this->resource_object->compiler_class);
|
||||
$this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty);
|
||||
}
|
||||
// compile locking
|
||||
@@ -705,7 +705,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
} else {
|
||||
// try plugins dir
|
||||
$_resource_class = 'Smarty_Resource_' . ucfirst($resource_type);
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($_resource_class,$this->smarty->plugins_dir)) {
|
||||
if ($this->smarty->loadPlugin($_resource_class)) {
|
||||
if (class_exists($_resource_class, false)) {
|
||||
return new $_resource_class($this->smarty);
|
||||
} else {
|
||||
|
@@ -193,7 +193,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
// check plugins from plugins folder
|
||||
foreach ($this->smarty->plugin_search_order as $plugin_type) {
|
||||
if ($plugin_type == Smarty::PLUGIN_BLOCK && Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
|
||||
if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
|
||||
$plugin = 'smarty_compiler_' . $tag;
|
||||
if (is_callable($plugin)) {
|
||||
return $plugin($args, $this->smarty);
|
||||
@@ -231,7 +231,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
|
||||
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
|
||||
}
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) {
|
||||
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
|
||||
$plugin = 'smarty_compiler_' . $tag;
|
||||
if (is_callable($plugin)) {
|
||||
return $plugin($args, $this->smarty);
|
||||
@@ -272,7 +272,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
// lazy load internal compiler plugin
|
||||
$class_name = 'Smarty_Internal_Compile_' . $tag;
|
||||
if (Smarty_Internal_Plugin_Loader::loadPlugin($class_name, $this->smarty->plugins_dir)) {
|
||||
if ($this->smarty->loadPlugin($class_name)) {
|
||||
// use plugin if found
|
||||
self::$_tag_objects[$tag] = new $class_name;
|
||||
// compile this tag
|
||||
|
Reference in New Issue
Block a user