home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / smarty / xoops_plugins / compiler.includeq.php < prev    next >
Encoding:
PHP Script  |  2006-05-27  |  3.4 KB  |  86 lines

  1. <?php
  2. /**
  3.  * includeq Smarty compiler plug-in
  4.  *
  5.  * See the enclosed file LICENSE for licensing information.
  6.  * If you did not receive this file, get it at http://www.fsf.org/copyleft/gpl.html
  7.  *
  8.  * @copyright   The XOOPS project http://www.xoops.org/
  9.  * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
  10.  * @author        Skalpa Keo <skalpa@xoops.org>
  11.  * @package        xos_opal
  12.  * @subpackage    xos_opal_Smarty
  13.  * @since       2.0.14
  14.  * @version        $Id: compiler.includeq.php 506 2006-05-26 23:10:37Z skalpa $
  15.  */
  16.  
  17. /**
  18.  * Quick include template plug-in
  19.  *
  20.  * Like {@link smarty_compiler_foreachq() foreachq}, this plug-in has been written to provide
  21.  * a faster version of an already existing Smarty function. <var>includeq</var> can be used
  22.  * as a replacement for the Smarty 
  23.  * {@link http://smarty.php.net/manual/en/language.function.include.php include} function as long
  24.  * as you are aware of the differences between them.
  25.  * 
  26.  * Normally, when you include a template, Smarty does the following:
  27.  * - Backup all your template variables in an array
  28.  * - Include the template you specified
  29.  * - Restore the template variables from the previously created backup array
  30.  * 
  31.  * The advantage of this method is that it makes the main template variables <i>safe</i>: if your
  32.  * main template uses a variable called <var>$stuff</var> and the included template modifies it
  33.  * value, the main template will recover the original value automatically.
  34.  * 
  35.  * While this can be useful in some cases (for example, when you include templates you have absolutely
  36.  * no control over), some may consider this a limitation and it has the disadvantage of slowing down
  37.  * the inclusion mechanism a lot.
  38.  * 
  39.  * <var>includeq</var> fixes that: the code it generates doesn't contain the variables backup/recovery
  40.  * mechanism and thus makes templates inclusion faster. Note that however, this new behavior may
  41.  * create problems in some cases (but you can prevent them most of the times, for example by always
  42.  * using a <var>tmp_</var> prefix for the variables you create in included templates looping sections).
  43.  */
  44. function smarty_compiler_includeq( $tag_args, &$comp ) {
  45.  
  46.     $attrs = $comp->_parse_attrs($tag_args);
  47.     $arg_list = array();
  48.  
  49.     if (empty($attrs['file'])) {
  50.         $comp->_syntax_error("missing 'file' attribute in includeq tag", E_USER_ERROR, __FILE__, __LINE__);
  51.     }
  52.  
  53.     foreach ($attrs as $arg_name => $arg_value) {
  54.         if ($arg_name == 'file') {
  55.             $include_file = $arg_value;
  56.             continue;
  57.         } else if ($arg_name == 'assign') {
  58.             $assign_var = $arg_value;
  59.             continue;
  60.         }
  61.         if (is_bool($arg_value))
  62.             $arg_value = $arg_value ? 'true' : 'false';
  63.         $arg_list[] = "'$arg_name' => $arg_value";
  64.     }
  65.  
  66.     $output = '';
  67.  
  68.     if (isset($assign_var)) {
  69.         $output .= "ob_start();\n";
  70.     }
  71.  
  72.     //$output .= "\$_smarty_tpl_vars = \$this->_tpl_vars;\n";
  73.     $_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
  74.     $output .= "\$this->_smarty_include($_params);\n";
  75.     //"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
  76.     //"unset(\$_smarty_tpl_vars);\n";
  77.  
  78.     if (isset($assign_var)) {
  79.         $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n";
  80.     }
  81.     //$output .= '';
  82.     return $output;
  83. }
  84.  
  85.     
  86. ?>