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

List:       smarty-cvs
Subject:    [SMARTY-CVS] cvs: smarty /libs Smarty.class.php  /libs/core core.display_debug_console.php core.fetc
From:       "Messju Mohr" <messju () php ! net>
Date:       2003-07-23 16:14:47
[Download RAW message or body]

messju		Wed Jul 23 12:14:47 2003 EDT

  Removed files:               
    /smarty/libs/core	core.fetch_resource_info.php 
                     	core.parse_resource_name.php 

  Modified files:              
    /smarty/libs	Smarty.class.php 
    /smarty/libs/core	core.display_debug_console.php 
                     	core.get_php_resource.php 
                     	core.process_cached_inserts.php 
                     	core.read_cache_file.php 
                     	core.run_insert_handler.php 
                     	core.smarty_include.php 
                     	core.smarty_include_php.php 
    /smarty/libs/plugins	function.eval.php 
  Log:
  moved  _fetch_resource_info and _parse_resource_name back into Smarty.class.php
  renamed smarty_include and smarty_eval wrappers to _include and _eval
  
  
  
["messju-20030723121447.txt" (text/plain)]

Index: smarty/libs/Smarty.class.php
diff -u smarty/libs/Smarty.class.php:1.422 smarty/libs/Smarty.class.php:1.423
--- smarty/libs/Smarty.class.php:1.422	Sun Jun 29 20:07:27 2003
+++ smarty/libs/Smarty.class.php	Wed Jul 23 12:14:47 2003
@@ -42,7 +42,7 @@
  * @version 2.5.0-cvs
  */
 
-/* $Id: Smarty.class.php,v 1.422 2003/06/30 00:07:27 messju Exp $ */
+/* $Id: Smarty.class.php,v 1.423 2003/07/23 16:14:47 messju Exp $ */
 
 /**
  * DIR_SEP isn't used anymore, but third party apps might
@@ -1099,8 +1099,7 @@
     function template_exists($tpl_file)
     {
 		$_params = array('resource_name' => $tpl_file);
-		require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
                'core.fetch_resource_info.php');
-        return smarty_core_fetch_resource_info($_params, $this);
+        return $this->_fetch_resource_info($_params);
     }
 
     /**
@@ -1460,9 +1459,8 @@
                 return true;
             } else {
                 // get file source and timestamp
-				require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
'core.fetch_resource_info.php');  $_params = array('resource_name' => \
                $resource_name);
-                if (!smarty_core_fetch_resource_info($_params, $this)) {
+                if (!$this->_fetch_resource_info($_params, $this)) {
                     return false;
                 }
                 if ($_params['resource_timestamp'] <= filemtime($compile_path)) {
@@ -1490,8 +1488,7 @@
     {
 		
 		$_params = array('resource_name' => $resource_name);
-		require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
                'core.fetch_resource_info.php');
-        if (!smarty_core_fetch_resource_info($_params, $this)) {
+        if (!$this->_fetch_resource_info($_params)) {
             return false;
         }
 
@@ -1596,6 +1593,153 @@
     }
 
     /**
+     * fetch the template info. Gets timestamp, and source
+     * if get_source is true
+     *
+     * sets $source_content to the source of the template, and
+     * $resource_timestamp to its time stamp
+     * @param string $resource_name
+     * @param string $source_content
+     * @param integer $resource_timestamp
+     * @param boolean $get_source
+     * @param boolean $quiet
+     * @return boolean
+     */
+
+    function _fetch_resource_info(&$params)
+    {
+			
+        if(!isset($params['get_source'])) { $params['get_source'] = true; }
+        if(!isset($params['quiet'])) { $params['quiet'] = false; }
+	
+        $_return = false;
+        $_params = array('resource_name' => $params['resource_name']) ;
+        if ($this->_parse_resource_name($_params)) {
+            $_resource_type = $_params['resource_type'];
+            $_resource_name = $_params['resource_name'];
+            switch ($_resource_type) {
+                case 'file':
+                    if ($params['get_source']) {
+                        $params['source_content'] = \
$this->_read_file($_resource_name); +                    }
+                    $params['resource_timestamp'] = filemtime($_resource_name);
+                    $_return = true;
+                    break;
+
+                default:                    
+                    // call resource functions to fetch the template source and \
timestamp +                    if ($params['get_source']) {
+                        $_source_return = \
isset($this->_plugins['resource'][$_resource_type]) && +                            \
call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], +            \
array($_resource_name, &$params['source_content'], &$this)); +                    } \
else { +                        $_source_return = true;
+                    }
+
+                    $_timestamp_return = \
isset($this->_plugins['resource'][$_resource_type]) && +                        \
call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], +            \
array($_resource_name, &$params['resource_timestamp'], &$this)); +
+                    $_return = $_source_return && $_timestamp_return;
+                    break;
+            }
+        }
+	
+        if (!$_return) {
+            // see if we can get a template with the default template handler
+            if (!empty($this->default_template_handler_func)) {
+                if (!$this->_plugin_implementation_exists($this->default_template_handler_func)) \
{ +                    $this->trigger_error("default template handler function \
\"$this->default_template_handler_func\" doesn't exist."); +                } else {
+                    $_return = call_user_func_array(
+                        $this->default_template_handler_func,
+                        array($_resource_type, $_resource_name, \
&$params['source_content'], &$params['resource_timestamp'], &$this)); +               \
} +            }
+        }
+
+        if (!$_return) {
+            if (!$params['quiet']) {
+                $this->trigger_error('unable to read resource: "' . \
$params['resource_name'] . '"'); +            }
+        } else if ($_return && $this->security) {
+            require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
'core.is_secure.php'); +            if (!smarty_core_is_secure($_params, $this)) {
+                if (!$params['quiet'])
+                    $this->trigger_error('(secure mode) accessing "' . \
$params['resource_name'] . '" is not allowed'); +                \
$params['source_content'] = null; +                $params['resource_timestamp'] = \
null; +                return false;
+            }
+        }
+        return $_return;
+    }
+
+
+    /**
+     * parse out the type and name from the resource
+     *
+     * @param string $resource_base_path
+     * @param string $resource_name
+     * @param string $resource_type
+     * @param string $resource_name
+     * @return boolean
+     */
+ 
+    function _parse_resource_name(&$params)
+    {
+		
+        // split tpl_path by the first colon
+        $_resource_name_parts = explode(':', $params['resource_name'], 2);
+		
+        if (count($_resource_name_parts) == 1) {
+            // no resource type given
+            $params['resource_type'] = $this->default_resource_type;
+            $params['resource_name'] = $_resource_name_parts[0];
+        } else {
+            if(strlen($_resource_name_parts[0]) == 1) {
+                // 1 char is not resource type, but part of filepath
+                $params['resource_type'] = $this->default_resource_type;
+                $params['resource_name'] = $params['resource_name'];	
+            } else {
+                $params['resource_type'] = $_resource_name_parts[0];
+                $params['resource_name'] = $_resource_name_parts[1];
+            }
+        }	
+		
+        if ($params['resource_type'] == 'file') {
+            if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", \
$params['resource_name'])) { +                // relative pathname to \
$params['resource_base_path'] +                // use the first directory where the \
file is found +                $_resource_base_path = \
isset($params['resource_base_path']) ? $params['resource_base_path'] : \
array($this->template_dir, '.'); +                settype($_resource_base_path, \
'array'); +                foreach ($_resource_base_path as $_curr_path) {
+                    $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . \
$params['resource_name']; +                    if (file_exists($_fullpath) && \
is_file($_fullpath)) { +                        $params['resource_name'] = \
$_fullpath; +                        return true;
+                    }
+                    // didn't find the file, try include_path
+                    $_params = array('file_path' => $_fullpath);
+                    require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
'core.get_include_path.php'); +                    \
if(smarty_core_get_include_path($_params, $smarty)) { +                        \
$params['resource_name'] = $_params['new_file_path']; +                        return \
true; +                    }
+                }
+                return false;
+            }
+        } else {
+            $_params = array('type' => $params['resource_type']);
+            require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
'core.load_resource_plugin.php'); +            \
smarty_core_load_resource_plugin($_params, $this); +        }
+
+        return true;
+    }
+
+
+    /**
      * Handle modifiers
      *
      * @param string|null $modifier_name
@@ -1800,7 +1944,7 @@
      * wrapper for include() retaining $this
      * @return mixed
      */
-    function smarty_include($filename, $once=false)
+    function _include($filename, $once=false)
     {
         if ($once) {
             return include_once($filename);
@@ -1814,7 +1958,7 @@
      * wrapper for eval() retaining $this
      * @return mixed
      */
-    function smarty_eval($code)
+    function _eval($code)
     {
         return eval($code);
     }
Index: smarty/libs/core/core.display_debug_console.php
diff -u smarty/libs/core/core.display_debug_console.php:1.5 \
                smarty/libs/core/core.display_debug_console.php:1.6
--- smarty/libs/core/core.display_debug_console.php:1.5	Sun Jun 29 20:08:28 2003
+++ smarty/libs/core/core.display_debug_console.php	Wed Jul 23 12:14:47 2003
@@ -40,7 +40,7 @@
 	if ($smarty->_compile_resource($smarty->debug_tpl, $_compile_path))
 	{
 		ob_start();
-		$smarty->smarty_include($_compile_path);
+		$smarty->_include($_compile_path);
 		$_results = ob_get_contents();
 		ob_end_clean();
 	} else {
Index: smarty/libs/core/core.get_php_resource.php
diff -u smarty/libs/core/core.get_php_resource.php:1.4 \
                smarty/libs/core/core.get_php_resource.php:1.5
--- smarty/libs/core/core.get_php_resource.php:1.4	Sat Jun 21 23:13:25 2003
+++ smarty/libs/core/core.get_php_resource.php	Wed Jul 23 12:14:47 2003
@@ -19,8 +19,7 @@
 {
 	
 	$params['resource_base_path'] = $smarty->trusted_dir;	
-	require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
                'core.parse_resource_name.php');
-	smarty_core_parse_resource_name($params, $smarty);
+	$smarty->_parse_resource_name($params, $smarty);
 		
     /*
      * Find out if the resource exists.
Index: smarty/libs/core/core.process_cached_inserts.php
diff -u smarty/libs/core/core.process_cached_inserts.php:1.4 \
                smarty/libs/core/core.process_cached_inserts.php:1.5
--- smarty/libs/core/core.process_cached_inserts.php:1.4	Sun Jun 29 20:08:28 2003
+++ smarty/libs/core/core.process_cached_inserts.php	Wed Jul 23 12:14:47 2003
@@ -38,9 +38,9 @@
 
 
             if ($resource_type == 'file') {
-                $smarty->smarty_include($php_resource, true);
+                $smarty->_include($php_resource, true);
             } else {
-                $smarty->smarty_eval($php_resource);
+                $smarty->_eval($php_resource);
             }
         }
 
Index: smarty/libs/core/core.read_cache_file.php
diff -u smarty/libs/core/core.read_cache_file.php:1.8 \
                smarty/libs/core/core.read_cache_file.php:1.9
--- smarty/libs/core/core.read_cache_file.php:1.8	Thu Jul 17 15:25:22 2003
+++ smarty/libs/core/core.read_cache_file.php	Wed Jul 23 12:14:47 2003
@@ -68,10 +68,9 @@
     }
 
     if ($smarty->compile_check) {
-		require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
                'core.fetch_resource_info.php');
         foreach (array_keys($smarty->_cache_info['template']) as $_template_dep) {
 			$_params = array('resource_name' => $_template_dep);
-			smarty_core_fetch_resource_info($_params, $smarty);
+			$smarty->_fetch_resource_info($_params);
             if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) \
{  // template file has changed, regenerate cache
                 return false;
@@ -79,10 +78,9 @@
         }
 
         if (isset($smarty->_cache_info['config'])) {
-			require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . \
                'core.fetch_resource_info.php');
             foreach (array_keys($smarty->_cache_info['config']) as $_config_dep) {
 				$_params = array('resource_name' => $_config_dep);
-				smarty_core_fetch_resource_info($_params, $smarty);
+				$smarty->_fetch_resource_info($_params);
             	if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) \
{  // config file has changed, regenerate cache
                 	return false;
@@ -93,7 +91,7 @@
 
     foreach ($smarty->_cache_info['cache_serials'] as \
$_include_file_path=>$_cache_serial) {  if \
                (empty($smarty->_cache_serials[$_include_file_path])) {
-            $smarty->smarty_include($_include_file_path, true);
+            $smarty->_include($_include_file_path, true);
         }
         
         if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {
Index: smarty/libs/core/core.run_insert_handler.php
diff -u smarty/libs/core/core.run_insert_handler.php:1.4 \
                smarty/libs/core/core.run_insert_handler.php:1.5
--- smarty/libs/core/core.run_insert_handler.php:1.4	Sun Jun 29 20:08:28 2003
+++ smarty/libs/core/core.run_insert_handler.php	Wed Jul 23 12:14:47 2003
@@ -40,9 +40,9 @@
 			}
 
             if ($_params['resource_type'] == 'file') {
-                $smarty->smarty_include_once($_params['php_resource']);
+                $smarty->_include($_params['php_resource'], true);
             } else {
-                $smarty->smarty_eval($_params['php_resource']);
+                $smarty->_eval($_params['php_resource']);
             }
             unset($params['args']['script']);
         }
Index: smarty/libs/core/core.smarty_include.php
diff -u smarty/libs/core/core.smarty_include.php:1.6 \
                smarty/libs/core/core.smarty_include.php:1.7
--- smarty/libs/core/core.smarty_include.php:1.6	Sun Jun 29 18:57:33 2003
+++ smarty/libs/core/core.smarty_include.php	Wed Jul 23 12:14:47 2003
@@ -38,7 +38,7 @@
     if ($smarty->_is_compiled($params['smarty_include_tpl_file'], \
                $_smarty_compile_path)
         || $smarty->_compile_resource($params['smarty_include_tpl_file'], \
$_smarty_compile_path))  {
-        $smarty->smarty_include($_smarty_compile_path);
+        $smarty->_include($_smarty_compile_path);
     }
 
     // pop the local vars off the front of the stack
Index: smarty/libs/core/core.smarty_include_php.php
diff -u smarty/libs/core/core.smarty_include_php.php:1.5 \
                smarty/libs/core/core.smarty_include_php.php:1.6
--- smarty/libs/core/core.smarty_include_php.php:1.5	Sun Jun 29 18:57:33 2003
+++ smarty/libs/core/core.smarty_include_php.php	Wed Jul 23 12:14:47 2003
@@ -31,17 +31,17 @@
     if (!empty($params['smarty_assign'])) {
         ob_start();
         if ($_smarty_resource_type == 'file') {
-            $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
+            $smarty->_include($_smarty_php_resource, $params['smarty_once']);
         } else {
-            $smarty->smarty_eval($_smarty_php_resource);
+            $smarty->_eval($_smarty_php_resource);
         }
         $smarty->assign($params['smarty_assign'], ob_get_contents());
         ob_end_clean();
     } else {
         if ($_smarty_resource_type == 'file') {
-            $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
+            $smarty->_include($_smarty_php_resource, $params['smarty_once']);
         } else {
-            $smarty->smarty_eval($_smarty_php_resource);
+            $smarty->_eval($_smarty_php_resource);
         }
     }
 }
Index: smarty/libs/plugins/function.eval.php
diff -u smarty/libs/plugins/function.eval.php:1.11 \
                smarty/libs/plugins/function.eval.php:1.12
--- smarty/libs/plugins/function.eval.php:1.11	Thu Jul 17 10:23:18 2003
+++ smarty/libs/plugins/function.eval.php	Wed Jul 23 12:14:47 2003
@@ -32,7 +32,7 @@
     $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
 
     ob_start();
-    $smarty->smarty_eval('?>' . $_var_compiled);
+    $smarty->_eval('?>' . $_var_compiled);
     $_contents = ob_get_contents();
     ob_end_clean();
 



-- 
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