mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
allow plugins_dir to be an array of directories
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,3 +1,5 @@
|
||||
- allow $plugins_dir to be an array of directories
|
||||
(Andreas Kossmeier, Monte)
|
||||
- move debug.tpl to SMARTY_DIR, add to constructor (Monte)
|
||||
- fixed warning message in function.assign_debug_info (Monte)
|
||||
- fixed $template_dir, $compile_dir, $cache_dir, $config_dir
|
||||
|
@@ -67,8 +67,7 @@ class Smarty
|
||||
var $template_dir = 'templates'; // name of directory for templates
|
||||
var $compile_dir = 'templates_c'; // name of directory for compiled templates
|
||||
var $config_dir = 'configs'; // directory where config files are located
|
||||
var $plugins_dir = 'plugins'; // directory where plugins are kept
|
||||
// (relative to Smarty directory)
|
||||
var $plugins_dir = array('plugins'); // plugin directories
|
||||
|
||||
var $debugging = false; // enable debugging console true/false
|
||||
var $debug_tpl = ''; // path to debug console template
|
||||
@@ -1661,6 +1660,35 @@ function _run_insert_handler($args)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _get_plugin_filepath
|
||||
Purpose: get filepath of requested plugin
|
||||
\*======================================================================*/
|
||||
function _get_plugin_filepath($type, $name)
|
||||
{
|
||||
$_plugin_filename = "$type.$name.php";
|
||||
|
||||
foreach ((array)$this->plugins_dir as $_plugin_dir) {
|
||||
|
||||
$_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename;
|
||||
|
||||
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
|
||||
// relative path
|
||||
$_plugin_filepath = SMARTY_DIR . $_plugin_filepath;
|
||||
}
|
||||
|
||||
if (@is_readable($_plugin_filepath)) {
|
||||
return $_plugin_filepath;
|
||||
}
|
||||
|
||||
// didn't find it try include path
|
||||
if ($this->_get_include_path($_plugin_dir . DIR_SEP . $_plugin_filename, $_include_filepath)) {
|
||||
return $_include_filepath;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _load_plugins
|
||||
@@ -1668,6 +1696,7 @@ function _run_insert_handler($args)
|
||||
\*======================================================================*/
|
||||
function _load_plugins($plugins)
|
||||
{
|
||||
|
||||
foreach ($plugins as $plugin_info) {
|
||||
list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info;
|
||||
$plugin = &$this->_plugins[$type][$name];
|
||||
@@ -1705,18 +1734,10 @@ function _run_insert_handler($args)
|
||||
}
|
||||
}
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir .
|
||||
DIR_SEP .
|
||||
$type .
|
||||
'.' .
|
||||
$name .
|
||||
'.php';
|
||||
$plugin_file = $this->_get_plugin_filepath($type, $name);
|
||||
|
||||
$found = true;
|
||||
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
|
||||
$message = "could not load plugin file $plugin_file\n";
|
||||
$found = false;
|
||||
if ($found = ($plugin_file != false)) {
|
||||
$message = "could not load plugin file '$type.$name.php'\n";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1811,18 +1832,10 @@ function _run_insert_handler($args)
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'resource.' .
|
||||
$type .
|
||||
'.php';
|
||||
$plugin_file = $this->_get_plugin_filepath('resource', $type);
|
||||
$found = ($plugin_file != false);
|
||||
|
||||
$found = true;
|
||||
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
|
||||
$this->_trigger_plugin_error("could not load plugin file $plugin_file");
|
||||
$found = false;
|
||||
} else {
|
||||
/*
|
||||
if ($found) { /*
|
||||
* If the plugin file is found, it -must- provide the properly named
|
||||
* plugin functions.
|
||||
*/
|
||||
|
@@ -348,12 +348,6 @@ class Smarty_Compiler extends Smarty {
|
||||
$found = false;
|
||||
$have_function = true;
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'compiler.' .
|
||||
$tag_command .
|
||||
'.php';
|
||||
|
||||
/*
|
||||
* First we check if the compiler function has already been registered
|
||||
* or loaded from a plugin file.
|
||||
@@ -370,7 +364,7 @@ class Smarty_Compiler extends Smarty {
|
||||
* Otherwise we need to load plugin file and look for the function
|
||||
* inside it.
|
||||
*/
|
||||
else if (file_exists($plugin_file) && is_readable($plugin_file)) {
|
||||
else if ($plugin_file = $this->_get_plugin_filepath('compiler', $tag_command)) {
|
||||
$found = true;
|
||||
|
||||
include_once $plugin_file;
|
||||
@@ -418,12 +412,6 @@ class Smarty_Compiler extends Smarty {
|
||||
$found = false;
|
||||
$have_function = true;
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'block.' .
|
||||
$tag_command .
|
||||
'.php';
|
||||
|
||||
/*
|
||||
* First we check if the block function has already been registered
|
||||
* or loaded from a plugin file.
|
||||
@@ -440,7 +428,7 @@ class Smarty_Compiler extends Smarty {
|
||||
* Otherwise we need to load plugin file and look for the function
|
||||
* inside it.
|
||||
*/
|
||||
else if (file_exists($plugin_file) && is_readable($plugin_file)) {
|
||||
else if ($plugin_file = $this->_get_plugin_filepath('block', $tag_command)) {
|
||||
$found = true;
|
||||
|
||||
include_once $plugin_file;
|
||||
|
@@ -67,8 +67,7 @@ class Smarty
|
||||
var $template_dir = 'templates'; // name of directory for templates
|
||||
var $compile_dir = 'templates_c'; // name of directory for compiled templates
|
||||
var $config_dir = 'configs'; // directory where config files are located
|
||||
var $plugins_dir = 'plugins'; // directory where plugins are kept
|
||||
// (relative to Smarty directory)
|
||||
var $plugins_dir = array('plugins'); // plugin directories
|
||||
|
||||
var $debugging = false; // enable debugging console true/false
|
||||
var $debug_tpl = ''; // path to debug console template
|
||||
@@ -1661,6 +1660,35 @@ function _run_insert_handler($args)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _get_plugin_filepath
|
||||
Purpose: get filepath of requested plugin
|
||||
\*======================================================================*/
|
||||
function _get_plugin_filepath($type, $name)
|
||||
{
|
||||
$_plugin_filename = "$type.$name.php";
|
||||
|
||||
foreach ((array)$this->plugins_dir as $_plugin_dir) {
|
||||
|
||||
$_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename;
|
||||
|
||||
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
|
||||
// relative path
|
||||
$_plugin_filepath = SMARTY_DIR . $_plugin_filepath;
|
||||
}
|
||||
|
||||
if (@is_readable($_plugin_filepath)) {
|
||||
return $_plugin_filepath;
|
||||
}
|
||||
|
||||
// didn't find it try include path
|
||||
if ($this->_get_include_path($_plugin_dir . DIR_SEP . $_plugin_filename, $_include_filepath)) {
|
||||
return $_include_filepath;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _load_plugins
|
||||
@@ -1668,6 +1696,7 @@ function _run_insert_handler($args)
|
||||
\*======================================================================*/
|
||||
function _load_plugins($plugins)
|
||||
{
|
||||
|
||||
foreach ($plugins as $plugin_info) {
|
||||
list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info;
|
||||
$plugin = &$this->_plugins[$type][$name];
|
||||
@@ -1705,18 +1734,10 @@ function _run_insert_handler($args)
|
||||
}
|
||||
}
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir .
|
||||
DIR_SEP .
|
||||
$type .
|
||||
'.' .
|
||||
$name .
|
||||
'.php';
|
||||
$plugin_file = $this->_get_plugin_filepath($type, $name);
|
||||
|
||||
$found = true;
|
||||
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
|
||||
$message = "could not load plugin file $plugin_file\n";
|
||||
$found = false;
|
||||
if ($found = ($plugin_file != false)) {
|
||||
$message = "could not load plugin file '$type.$name.php'\n";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1811,18 +1832,10 @@ function _run_insert_handler($args)
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'resource.' .
|
||||
$type .
|
||||
'.php';
|
||||
$plugin_file = $this->_get_plugin_filepath('resource', $type);
|
||||
$found = ($plugin_file != false);
|
||||
|
||||
$found = true;
|
||||
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
|
||||
$this->_trigger_plugin_error("could not load plugin file $plugin_file");
|
||||
$found = false;
|
||||
} else {
|
||||
/*
|
||||
if ($found) { /*
|
||||
* If the plugin file is found, it -must- provide the properly named
|
||||
* plugin functions.
|
||||
*/
|
||||
|
@@ -348,12 +348,6 @@ class Smarty_Compiler extends Smarty {
|
||||
$found = false;
|
||||
$have_function = true;
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'compiler.' .
|
||||
$tag_command .
|
||||
'.php';
|
||||
|
||||
/*
|
||||
* First we check if the compiler function has already been registered
|
||||
* or loaded from a plugin file.
|
||||
@@ -370,7 +364,7 @@ class Smarty_Compiler extends Smarty {
|
||||
* Otherwise we need to load plugin file and look for the function
|
||||
* inside it.
|
||||
*/
|
||||
else if (file_exists($plugin_file) && is_readable($plugin_file)) {
|
||||
else if ($plugin_file = $this->_get_plugin_filepath('compiler', $tag_command)) {
|
||||
$found = true;
|
||||
|
||||
include_once $plugin_file;
|
||||
@@ -418,12 +412,6 @@ class Smarty_Compiler extends Smarty {
|
||||
$found = false;
|
||||
$have_function = true;
|
||||
|
||||
$plugin_file = SMARTY_DIR .
|
||||
$this->plugins_dir . DIR_SEP .
|
||||
'block.' .
|
||||
$tag_command .
|
||||
'.php';
|
||||
|
||||
/*
|
||||
* First we check if the block function has already been registered
|
||||
* or loaded from a plugin file.
|
||||
@@ -440,7 +428,7 @@ class Smarty_Compiler extends Smarty {
|
||||
* Otherwise we need to load plugin file and look for the function
|
||||
* inside it.
|
||||
*/
|
||||
else if (file_exists($plugin_file) && is_readable($plugin_file)) {
|
||||
else if ($plugin_file = $this->_get_plugin_filepath('block', $tag_command)) {
|
||||
$found = true;
|
||||
|
||||
include_once $plugin_file;
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* month values (Gary Loescher)
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $this->_get_plugin_filepath('function','html_options');
|
||||
function smarty_function_html_select_date($params, &$smarty)
|
||||
{
|
||||
/* Default values. */
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* Purpose: Prints the dropdowns for time selection
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $this->_get_plugin_filepath('function','html_options');
|
||||
function smarty_function_html_select_time($params, &$smarty)
|
||||
{
|
||||
/* Default values. */
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* default_date: default date if $string is empty
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
|
||||
{
|
||||
if($string != '') {
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* month values (Gary Loescher)
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $this->_get_plugin_filepath('function','html_options');
|
||||
function smarty_function_html_select_date($params, &$smarty)
|
||||
{
|
||||
/* Default values. */
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* Purpose: Prints the dropdowns for time selection
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
require_once $this->_get_plugin_filepath('function','html_options');
|
||||
function smarty_function_html_select_time($params, &$smarty)
|
||||
{
|
||||
/* Default values. */
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* default_date: default date if $string is empty
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php';
|
||||
require_once $this->_get_plugin_filepath('shared','make_timestamp');
|
||||
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
|
||||
{
|
||||
if($string != '') {
|
||||
|
Reference in New Issue
Block a user