Source for file template.php

Documentation is available at template.php

  1. <?php
  2.  
  3. /**
  4.  * Defines a sub-template that can then be called (even recursively) with the defined arguments
  5.  * <pre>
  6.  *  * name : template name
  7.  *  * rest : list of arguments and optional default values
  8.  * </pre>
  9.  * This software is provided 'as-is', without any express or implied warranty.
  10.  * In no event will the authors be held liable for any damages arising from the use of this software.
  11.  *
  12.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  13.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  14.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  15.  * @link       http://dwoo.org/
  16.  * @version    1.1.0
  17.  * @date       2009-07-18
  18.  * @package    Dwoo
  19.  */
  20. {
  21.     public function init($namearray $rest array())
  22.     {
  23.     }
  24.  
  25.     public static function preProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$type)
  26.     {
  27.         $params $compiler->getCompiledParams($params);
  28.         $parsedParams array();
  29.         if (!isset($params['*']))
  30.             $params['*'array();
  31.         foreach ($params['*'as $param=>$defValue{
  32.             if (is_numeric($param)) {
  33.                 $param $defValue;
  34.                 $defValue null;
  35.             }
  36.             $param trim($param'\'"');
  37.             if (!preg_match('#^[a-z0-9_]+$#i'$param)) {
  38.                 throw new Dwoo_Compilation_Exception($compiler'Function : parameter names must contain only A-Z, 0-9 or _');
  39.             }
  40.             $parsedParams[$param$defValue;
  41.         }
  42.         $params['name'substr($params['name']1-1);
  43.         $params['*'$parsedParams;
  44.         $params['uuid'uniqid();
  45.         $compiler->addTemplatePlugin($params['name']$parsedParams$params['uuid']);
  46.         $currentBlock =$compiler->getCurrentBlock();
  47.         $currentBlock['params'$params;
  48.         return '';
  49.     }
  50.  
  51.     public static function postProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$content)
  52.     {
  53.         $paramstr 'Dwoo $dwoo';
  54.         $init 'static $_callCnt = 0;'."\n".
  55.         '$dwoo->scope[\' '.$params['uuid'].'\'.$_callCnt] = array();'."\n".
  56.         '$_scope = $dwoo->setScope(array(\' '.$params['uuid'].'\'.($_callCnt++)));'."\n";
  57.         $cleanup '/* -- template end output */ $dwoo->setScope($_scope, true);';
  58.         foreach ($params['*'as $param=>$defValue{
  59.             if ($defValue === null{
  60.                 $paramstr.=', $'.$param;
  61.             else {
  62.                 $paramstr.=', $'.$param.' = '.$defValue;
  63.             }
  64.             $init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n";
  65.         }
  66.         $init .= '/* -- template start output */';
  67.  
  68.         $funcName 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'];
  69.  
  70.         $search array(
  71.             '$this->charset',
  72.             '$this->',
  73.             '$this,',
  74.         );
  75.         $replacement array(
  76.             '$dwoo->getCharset()',
  77.             '$dwoo->',
  78.             '$dwoo,',
  79.         );
  80.         $content str_replace($search$replacement$content);
  81.  
  82.         $body 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE.
  83.             $prepend.$content.$append.
  84.             Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}";
  85.         $compiler->addTemplatePlugin($params['name']$params['*']$params['uuid']$body);
  86.     }
  87. }

Documentation generated on Sun, 07 Feb 2010 17:53:59 +0000 by phpDocumentor 1.4.0