allow plugins_dir to be an array of directories

This commit is contained in:
mohrt
2002-06-26 14:51:12 +00:00
parent 347b62ce4f
commit 3dbab9bedc
11 changed files with 90 additions and 86 deletions

2
NEWS
View File

@@ -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) - move debug.tpl to SMARTY_DIR, add to constructor (Monte)
- fixed warning message in function.assign_debug_info (Monte) - fixed warning message in function.assign_debug_info (Monte)
- fixed $template_dir, $compile_dir, $cache_dir, $config_dir - fixed $template_dir, $compile_dir, $cache_dir, $config_dir

View File

@@ -67,8 +67,7 @@ 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 $plugins_dir = 'plugins'; // directory where plugins are kept var $plugins_dir = array('plugins'); // plugin directories
// (relative to Smarty directory)
var $debugging = false; // enable debugging console true/false var $debugging = false; // enable debugging console true/false
var $debug_tpl = ''; // path to debug console template var $debug_tpl = ''; // path to debug console template
@@ -1661,6 +1660,35 @@ function _run_insert_handler($args)
return true; 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 Function: _load_plugins
@@ -1668,6 +1696,7 @@ function _run_insert_handler($args)
\*======================================================================*/ \*======================================================================*/
function _load_plugins($plugins) function _load_plugins($plugins)
{ {
foreach ($plugins as $plugin_info) { foreach ($plugins as $plugin_info) {
list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info; list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info;
$plugin = &$this->_plugins[$type][$name]; $plugin = &$this->_plugins[$type][$name];
@@ -1705,18 +1734,10 @@ function _run_insert_handler($args)
} }
} }
$plugin_file = SMARTY_DIR . $plugin_file = $this->_get_plugin_filepath($type, $name);
$this->plugins_dir .
DIR_SEP .
$type .
'.' .
$name .
'.php';
$found = true; if ($found = ($plugin_file != false)) {
if (!file_exists($plugin_file) || !is_readable($plugin_file)) { $message = "could not load plugin file '$type.$name.php'\n";
$message = "could not load plugin file $plugin_file\n";
$found = false;
} }
/* /*
@@ -1811,18 +1832,10 @@ function _run_insert_handler($args)
return; return;
} }
$plugin_file = SMARTY_DIR . $plugin_file = $this->_get_plugin_filepath('resource', $type);
$this->plugins_dir . DIR_SEP . $found = ($plugin_file != false);
'resource.' .
$type .
'.php';
$found = true; if ($found) { /*
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
$this->_trigger_plugin_error("could not load plugin file $plugin_file");
$found = false;
} else {
/*
* If the plugin file is found, it -must- provide the properly named * If the plugin file is found, it -must- provide the properly named
* plugin functions. * plugin functions.
*/ */

View File

@@ -348,12 +348,6 @@ class Smarty_Compiler extends Smarty {
$found = false; $found = false;
$have_function = true; $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 * First we check if the compiler function has already been registered
* or loaded from a plugin file. * 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 * Otherwise we need to load plugin file and look for the function
* inside it. * 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; $found = true;
include_once $plugin_file; include_once $plugin_file;
@@ -418,12 +412,6 @@ class Smarty_Compiler extends Smarty {
$found = false; $found = false;
$have_function = true; $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 * First we check if the block function has already been registered
* or loaded from a plugin file. * 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 * Otherwise we need to load plugin file and look for the function
* inside it. * 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; $found = true;
include_once $plugin_file; include_once $plugin_file;

View File

@@ -67,8 +67,7 @@ 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 $plugins_dir = 'plugins'; // directory where plugins are kept var $plugins_dir = array('plugins'); // plugin directories
// (relative to Smarty directory)
var $debugging = false; // enable debugging console true/false var $debugging = false; // enable debugging console true/false
var $debug_tpl = ''; // path to debug console template var $debug_tpl = ''; // path to debug console template
@@ -1661,6 +1660,35 @@ function _run_insert_handler($args)
return true; 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 Function: _load_plugins
@@ -1668,6 +1696,7 @@ function _run_insert_handler($args)
\*======================================================================*/ \*======================================================================*/
function _load_plugins($plugins) function _load_plugins($plugins)
{ {
foreach ($plugins as $plugin_info) { foreach ($plugins as $plugin_info) {
list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info; list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info;
$plugin = &$this->_plugins[$type][$name]; $plugin = &$this->_plugins[$type][$name];
@@ -1705,18 +1734,10 @@ function _run_insert_handler($args)
} }
} }
$plugin_file = SMARTY_DIR . $plugin_file = $this->_get_plugin_filepath($type, $name);
$this->plugins_dir .
DIR_SEP .
$type .
'.' .
$name .
'.php';
$found = true; if ($found = ($plugin_file != false)) {
if (!file_exists($plugin_file) || !is_readable($plugin_file)) { $message = "could not load plugin file '$type.$name.php'\n";
$message = "could not load plugin file $plugin_file\n";
$found = false;
} }
/* /*
@@ -1811,18 +1832,10 @@ function _run_insert_handler($args)
return; return;
} }
$plugin_file = SMARTY_DIR . $plugin_file = $this->_get_plugin_filepath('resource', $type);
$this->plugins_dir . DIR_SEP . $found = ($plugin_file != false);
'resource.' .
$type .
'.php';
$found = true; if ($found) { /*
if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
$this->_trigger_plugin_error("could not load plugin file $plugin_file");
$found = false;
} else {
/*
* If the plugin file is found, it -must- provide the properly named * If the plugin file is found, it -must- provide the properly named
* plugin functions. * plugin functions.
*/ */

View File

@@ -348,12 +348,6 @@ class Smarty_Compiler extends Smarty {
$found = false; $found = false;
$have_function = true; $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 * First we check if the compiler function has already been registered
* or loaded from a plugin file. * 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 * Otherwise we need to load plugin file and look for the function
* inside it. * 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; $found = true;
include_once $plugin_file; include_once $plugin_file;
@@ -418,12 +412,6 @@ class Smarty_Compiler extends Smarty {
$found = false; $found = false;
$have_function = true; $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 * First we check if the block function has already been registered
* or loaded from a plugin file. * 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 * Otherwise we need to load plugin file and look for the function
* inside it. * 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; $found = true;
include_once $plugin_file; include_once $plugin_file;

View File

@@ -17,8 +17,8 @@
* month values (Gary Loescher) * month values (Gary Loescher)
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; require_once $this->_get_plugin_filepath('shared','make_timestamp');
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php'; require_once $this->_get_plugin_filepath('function','html_options');
function smarty_function_html_select_date($params, &$smarty) function smarty_function_html_select_date($params, &$smarty)
{ {
/* Default values. */ /* Default values. */

View File

@@ -8,8 +8,8 @@
* Purpose: Prints the dropdowns for time selection * Purpose: Prints the dropdowns for time selection
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; require_once $this->_get_plugin_filepath('shared','make_timestamp');
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php'; require_once $this->_get_plugin_filepath('function','html_options');
function smarty_function_html_select_time($params, &$smarty) function smarty_function_html_select_time($params, &$smarty)
{ {
/* Default values. */ /* Default values. */

View File

@@ -11,7 +11,7 @@
* default_date: default date if $string is empty * 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) function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
{ {
if($string != '') { if($string != '') {

View File

@@ -17,8 +17,8 @@
* month values (Gary Loescher) * month values (Gary Loescher)
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; require_once $this->_get_plugin_filepath('shared','make_timestamp');
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php'; require_once $this->_get_plugin_filepath('function','html_options');
function smarty_function_html_select_date($params, &$smarty) function smarty_function_html_select_date($params, &$smarty)
{ {
/* Default values. */ /* Default values. */

View File

@@ -8,8 +8,8 @@
* Purpose: Prints the dropdowns for time selection * Purpose: Prints the dropdowns for time selection
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; require_once $this->_get_plugin_filepath('shared','make_timestamp');
require_once SMARTY_DIR . $this->plugins_dir . '/function.html_options.php'; require_once $this->_get_plugin_filepath('function','html_options');
function smarty_function_html_select_time($params, &$smarty) function smarty_function_html_select_time($params, &$smarty)
{ {
/* Default values. */ /* Default values. */

View File

@@ -11,7 +11,7 @@
* default_date: default date if $string is empty * 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) function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
{ {
if($string != '') { if($string != '') {