cvs: smarty /libs Smarty.class.php /libs/core core.smarty_include.php core.smarty_include_php.php /libs/plugins function.eval.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1056927453@cvsserver>
messju		Sun Jun 29 18:57:33 2003 EDT

  Modified files:              
    /smarty/libs	Smarty.class.php 
    /smarty/libs/core	core.smarty_include.php 
                     	core.smarty_include_php.php 
    /smarty/libs/plugins	function.eval.php 
  Log:
  removed $this from smarty_include and smarty_include_php
  added cleaner handling of $this to {eval}

-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
messju-20030629185733.txt (text/plain, 9.3 KB)
Index: smarty/libs/Smarty.class.php
diff -u smarty/libs/Smarty.class.php:1.420 smarty/libs/Smarty.class.php:1.421
--- smarty/libs/Smarty.class.php:1.420	Wed Jun 25 17:50:34 2003
+++ smarty/libs/Smarty.class.php	Sun Jun 29 18:57:33 2003
@@ -42,7 +42,7 @@
  * @version 2.5.0-cvs
  */
 
-/* $Id: Smarty.class.php,v 1.420 2003/06/25 21:50:34 mohrt Exp $ */
+/* $Id: Smarty.class.php,v 1.421 2003/06/29 22:57:33 messju Exp $ */
 
 /**
  * DIR_SEP isn't used anymore, but third party apps might
@@ -1492,15 +1492,16 @@
 		$_resource_timestamp = $_params['resource_timestamp'];
 
         if ($this->_compile_source($resource_name, $_source_content, $_compiled_content)) {
-			$_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
-			require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');
-			smarty_core_write_compiled_resource($_params, $this);
-            
             // if a _cache_serial was set, we also have to write an include-file:
             if ($this->_cache_include_info) {
                 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php');
                 smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)),  $this);
             }          
+
+			$_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
+			require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');
+			smarty_core_write_compiled_resource($_params, $this);
+            
             return true;
         } else {
             $this->trigger_error($smarty_compiler->_error_msg);
@@ -1526,6 +1527,7 @@
             require_once($this->compiler_file);
         }
 
+
         $smarty_compiler = new $this->compiler_class;
 
         $smarty_compiler->template_dir      = $this->template_dir;
@@ -1771,8 +1773,6 @@
         return (is_array($function)) ?
             method_exists($function[0], $function[1]) : function_exists($function);
     }
-    /**#@-*/
-
 
 
     /**
@@ -1787,6 +1787,31 @@
         ob_end_clean();
         return $_ret;
     }
+
+
+    /**
+     * wrapper for include() retaining $this
+     * @return mixed
+     */
+    function smarty_include($filename, $once=false)
+    {
+        if ($once) {
+            return include_once($filename);
+        } else {
+            return include($filename);
+        }
+    }
+
+
+    /**
+     * wrapper for eval() retaining $this
+     * @return mixed
+     */
+    function smarty_eval($code)
+    {
+        return eval($code);
+    }
+    /**#@-*/
 
 }
 
Index: smarty/libs/core/core.smarty_include.php
diff -u smarty/libs/core/core.smarty_include.php:1.5 smarty/libs/core/core.smarty_include.php:1.6
--- smarty/libs/core/core.smarty_include.php:1.5	Sat Jun 21 13:35:15 2003
+++ smarty/libs/core/core.smarty_include.php	Sun Jun 29 18:57:33 2003
@@ -14,47 +14,47 @@
  
 // $_smarty_include_tpl_file, $_smarty_include_vars
 
-function smarty_core_smarty_include($params, &$this)
+function smarty_core_smarty_include($params, &$smarty)
 {
-    if ($this->debugging) {
-		$_params = array();
-		require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
-        $debug_start_time = smarty_core_get_microtime($_params, $this);
-        $this->_smarty_debug_info[] = array('type'      => 'template',
+    if ($smarty->debugging) {
+        $_params = array();
+        require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
+        $debug_start_time = smarty_core_get_microtime($_params, $smarty);
+        $smarty->_smarty_debug_info[] = array('type'      => 'template',
                                             'filename'  => $params['smarty_include_tpl_file'],
-                                            'depth'     => ++$this->_inclusion_depth);
-        $included_tpls_idx = count($this->_smarty_debug_info) - 1;
+                                            'depth'     => ++$smarty->_inclusion_depth);
+        $included_tpls_idx = count($smarty->_smarty_debug_info) - 1;
     }
 
-    $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);
+    $smarty->_tpl_vars = array_merge($smarty->_tpl_vars, $params['smarty_include_vars']);
 
     // config vars are treated as local, so push a copy of the
     // current ones onto the front of the stack
-    array_unshift($this->_config, $this->_config[0]);
+    array_unshift($smarty->_config, $smarty->_config[0]);
 
-    $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);
+    $_smarty_compile_path = $smarty->_get_compile_path($params['smarty_include_tpl_file']);
 
 
-    if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
-        || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
+    if ($smarty->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
+        || $smarty->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
     {
-        include($_smarty_compile_path);
+        $smarty->smarty_include($_smarty_compile_path);
     }
 
     // pop the local vars off the front of the stack
-    array_shift($this->_config);
+    array_shift($smarty->_config);
 
-    $this->_inclusion_depth--;
+    $smarty->_inclusion_depth--;
 
-    if ($this->debugging) {
+    if ($smarty->debugging) {
         // capture time for debugging info
-		$_params = array();
-		require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
-        $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;
+        $_params = array();
+        require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
+        $smarty->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $smarty) - $debug_start_time;
     }
 
-    if ($this->caching) {
-        $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
+    if ($smarty->caching) {
+        $smarty->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
     }
 }
 
Index: smarty/libs/core/core.smarty_include_php.php
diff -u smarty/libs/core/core.smarty_include_php.php:1.4 smarty/libs/core/core.smarty_include_php.php:1.5
--- smarty/libs/core/core.smarty_include_php.php:1.4	Sat Jun 21 13:35:15 2003
+++ smarty/libs/core/core.smarty_include_php.php	Sun Jun 29 18:57:33 2003
@@ -16,40 +16,32 @@
  *              {include file="blah" var=$var}
  */    
 
-// 	$file, $assign, $once, $_smarty_include_vars	 		  
-		 
-function smarty_core_smarty_include_php($params, &$this)
+//  $file, $assign, $once, $_smarty_include_vars
+
+function smarty_core_smarty_include_php($params, &$smarty)
 {
-	$_params = array('resource_name' => $params['smarty_file']);
-	require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php');
-	smarty_core_get_php_resource($_params, $this);
-	$_smarty_resource_type = $_params['resource_type'];
-	$_smarty_php_resource = $_params['php_resource'];
+    $_params = array('resource_name' => $params['smarty_file']);
+    require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php');
+    smarty_core_get_php_resource($_params, $smarty);
+    $_smarty_resource_type = $_params['resource_type'];
+    $_smarty_php_resource = $_params['php_resource'];
 
     extract($params['smarty_include_vars'], EXTR_PREFIX_SAME, 'include_php_');
 
     if (!empty($params['smarty_assign'])) {
         ob_start();
         if ($_smarty_resource_type == 'file') {
-            if($params['smarty_once']) {
-                include_once($_smarty_php_resource);
-            } else {
-                include($_smarty_php_resource);                    
-            }
+            $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
         } else {
-            eval($_smarty_php_resource);
+            $smarty->smarty_eval($_smarty_php_resource);
         }
-        $this->assign($params['smarty_assign'], ob_get_contents());
+        $smarty->assign($params['smarty_assign'], ob_get_contents());
         ob_end_clean();
     } else {
         if ($_smarty_resource_type == 'file') {
-            if($params['smarty_once']) {
-                include_once($_smarty_php_resource);
-            } else {
-                include($_smarty_php_resource);                    
-            }
+            $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
         } else {
-            eval($_smarty_php_resource);
+            $smarty->smarty_eval($_smarty_php_resource);
         }
     }
 }
Index: smarty/libs/plugins/function.eval.php
diff -u smarty/libs/plugins/function.eval.php:1.9 smarty/libs/plugins/function.eval.php:1.10
--- smarty/libs/plugins/function.eval.php:1.9	Sun Jun 22 19:05:36 2003
+++ smarty/libs/plugins/function.eval.php	Sun Jun 29 18:57:33 2003
@@ -32,8 +32,7 @@
 	$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
 
     ob_start();
-    $this =& $smarty; /* this should be done nicer, maybe */
-	eval('?>' . $_var_compiled);
+	$smarty->smarty_eval('?>' . $_var_compiled);
 	$_contents = ob_get_contents();
     ob_end_clean();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.