[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-cvs
Subject:    [SMARTY-CVS] cvs: smarty / NEWS Smarty.class.php Smarty_Compiler.class.php  /plugins function.html_s
From:       "Monte Ohrt" <monte () ispi ! net>
Date:       2002-06-26 14:51:12
[Download RAW message or body]

mohrt		Wed Jun 26 10:51:12 2002 EDT

  Modified files:              
    /smarty	NEWS Smarty.class.php Smarty_Compiler.class.php 
    /smarty/plugins	function.html_select_date.php 
                   	function.html_select_time.php 
                   	modifier.date_format.php 
  Log:
  allow plugins_dir to be an array of directories
  
  
["mohrt-20020626105112.txt" (text/plain)]

Index: smarty/NEWS
diff -u smarty/NEWS:1.212 smarty/NEWS:1.213
--- smarty/NEWS:1.212	Tue Jun 25 09:26:47 2002
+++ smarty/NEWS	Wed Jun 26 10:51:10 2002
@@ -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
Index: smarty/Smarty.class.php
diff -u smarty/Smarty.class.php:1.286 smarty/Smarty.class.php:1.287
--- smarty/Smarty.class.php:1.286	Tue Jun 25 09:26:47 2002
+++ smarty/Smarty.class.php	Wed Jun 26 10:51:10 2002
@@ -67,8 +67,7 @@
     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
@@ -1660,7 +1659,36 @@
 
         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 _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 @@
                 }
             }
 
-            $plugin_file = SMARTY_DIR .
-                           $this->plugins_dir .
-                           DIR_SEP .
-                           $type .
-                           '.' .
-                           $name .
-                           '.php';
-
-            $found = true;
-            if (!file_exists($plugin_file) || !is_readable($plugin_file)) {
-                $message = "could not load plugin file $plugin_file\n";
-                $found = false;
+            $plugin_file = $this->_get_plugin_filepath($type, $name);
+
+            if ($found = ($plugin_file != false)) {
+                $message = "could not load plugin file '$type.$name.php'\n";
             }
 
             /*
@@ -1811,18 +1832,10 @@
             return;
         }
 
-        $plugin_file = SMARTY_DIR .
-                       $this->plugins_dir . DIR_SEP .
-                       'resource.' .
-                       $type .
-                       '.php';
-
-        $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 {
-            /*
+        $plugin_file = $this->_get_plugin_filepath('resource', $type);
+        $found = ($plugin_file != false);
+
+        if ($found) {            /*
              * If the plugin file is found, it -must- provide the properly named
              * plugin functions.
              */
Index: smarty/Smarty_Compiler.class.php
diff -u smarty/Smarty_Compiler.class.php:1.117 smarty/Smarty_Compiler.class.php:1.118
--- smarty/Smarty_Compiler.class.php:1.117	Thu Jun 13 16:14:46 2002
+++ smarty/Smarty_Compiler.class.php	Wed Jun 26 10:51:11 2002
@@ -348,12 +348,6 @@
         $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 @@
          * 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 @@
         $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 @@
          * 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;
Index: smarty/plugins/function.html_select_date.php
diff -u smarty/plugins/function.html_select_date.php:1.11 \
                smarty/plugins/function.html_select_date.php:1.12
--- smarty/plugins/function.html_select_date.php:1.11	Tue Jun 18 10:15:58 2002
+++ smarty/plugins/function.html_select_date.php	Wed Jun 26 10:51:12 2002
@@ -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. */
Index: smarty/plugins/function.html_select_time.php
diff -u smarty/plugins/function.html_select_time.php:1.5 \
                smarty/plugins/function.html_select_time.php:1.6
--- smarty/plugins/function.html_select_time.php:1.5	Mon Jun  3 12:05:33 2002
+++ smarty/plugins/function.html_select_time.php	Wed Jun 26 10:51:12 2002
@@ -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. */
Index: smarty/plugins/modifier.date_format.php
diff -u smarty/plugins/modifier.date_format.php:1.6 \
                smarty/plugins/modifier.date_format.php:1.7
--- smarty/plugins/modifier.date_format.php:1.6	Wed Jun 19 10:43:58 2002
+++ smarty/plugins/modifier.date_format.php	Wed Jun 26 10:51:12 2002
@@ -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 != '') {



-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic