Source for file pre.smarty_compat.php

Documentation is available at pre.smarty_compat.php

  1. <?php
  2.  
  3. /**
  4.  * Performs some template conversions to allow smarty templates to be used by
  5.  * the Dwoo compiler.
  6.  *
  7.  * This software is provided 'as-is', without any express or implied warranty.
  8.  * In no event will the authors be held liable for any damages arising from the use of this software.
  9.  *
  10.  * This file is released under the LGPL
  11.  * "GNU Lesser General Public License"
  12.  * More information can be found here:
  13.  * {@link http://www.gnu.org/copyleft/lesser.html}
  14.  *
  15.  * @author     Jordi Boggiano <[email protected]>
  16.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  17.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  18.  * @link       http://dwoo.org/
  19.  * @version    0.9.1
  20.  * @date       2008-05-30
  21.  * @package    Dwoo
  22.  */
  23. {
  24.     public function process($input)
  25.     {
  26.         list($l$r$this->compiler->getDelimiters();
  27.  
  28.         $rl preg_quote($l,'/');
  29.         $rr preg_quote($r,'/');
  30.         $sectionParam '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*';
  31.         $input preg_replace_callback('/'.$rl.'\s*section '.str_repeat($sectionParam6).'\s*'.$rr.'(.+?)(?:'.$rl.'\s*sectionelse\s*'.$rr.'(.+?))?'.$rl.'\s*\/section\s*'.$rr.'/is'array($this'convertSection')$input);
  32.         $input str_replace('$smarty.section.''$smarty.for.'$input);
  33.  
  34.         $smarty array
  35.         (
  36.             '/'.$rl.'\s*ldelim\s*'.$rr.'/',
  37.             '/'.$rl.'\s*rdelim\s*'.$rr.'/',
  38.             '/'.$rl.'\s*\$smarty\.ldelim\s*'.$rr.'/',
  39.             '/'.$rl.'\s*\$smarty\.rdelim\s*'.$rr.'/',
  40.             '/\$smarty\./',
  41.             '/'.$rl.'\s*php\s*'.$rr.'/',
  42.             '/'.$rl.'\s*\/php\s*'.$rr.'/',
  43.             '/\|(@?)strip/',
  44.         );
  45.  
  46.         $dwoo array
  47.         (
  48.             '\\'.$l,
  49.             $r,
  50.             '\\'.$l,
  51.             $r,
  52.             '$dwoo.',
  53.             '<?php ',
  54.             ' ?>',
  55.             '|$1whitespace',
  56.         );
  57.  
  58.         if (preg_match('{\|@([a-z][a-z0-9_]*)}i'$input$matches)) {
  59.             trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator'E_USER_NOTICE);
  60.         }
  61.  
  62.         return preg_replace($smarty$dwoo$input);
  63.     }
  64.  
  65.     protected function convertSection(array $matches)
  66.     {
  67.         $params array();
  68.         $index 1;
  69.         while (!empty($matches[$index]&& $index 13{
  70.             $params[$matches[$index]] $matches[$index+1];
  71.             $index += 2;
  72.         }
  73.         $params['content'$matches[13];
  74.         if (isset($matches[14]&& !empty($matches[14])) {
  75.             $params['altcontent'$matches[14];
  76.         }
  77.  
  78.         if (empty($params['name'])) {
  79.             throw new Dwoo_Compilation_Exception($this->compiler'Missing parameter <em>name</em> for section tag');
  80.         }
  81.         $name $params['name'];
  82.  
  83.         if (isset($params['loop'])) {
  84.             $loops $params['loop'];
  85.         }
  86.  
  87.         if (isset($params['max'])) {
  88.             $max $params['max'];
  89.         }
  90.  
  91.         if (isset($params['start'])) {
  92.             $start $params['start'];
  93.         }
  94.  
  95.         if (isset($params['step'])) {
  96.             $step $params['step'];
  97.         }
  98.  
  99.         if (!isset($loops))
  100.             $loops null;
  101.  
  102.         if (!isset($max|| $max 0{
  103.             if (is_numeric($loops)) {
  104.                 $max $loops;
  105.             else {
  106.                 $max 'null';
  107.             }
  108.         }
  109.  
  110.         if (!isset($step))
  111.             $step 1;
  112.         if (!isset($start))
  113.             $start $loops 1;
  114.         elseif (!is_numeric($loops)) {
  115.             $start 0;
  116.         }
  117.  
  118.         list($l$r$this->compiler->getDelimiters();
  119.  
  120.         if (is_numeric($loops)) {
  121.             if (isset($params['start']&& isset($params['loop']&& !isset($params['max'])) {
  122.                 $output $l.'for '.$name.' '.$start.' '.($loops-$step).' '.$step.$r;
  123.             else {
  124.                 $output $l.'for '.$name.' '.$start.' '.($start+floor($step*$max+($step>0?-1:1))).' '.$step.$r;
  125.             }
  126.         else {
  127.             $output $l.'for '.$name.' '.$loops.' '.($start+floor($max/$step)).' '.$step.' '.$start.$r;
  128.         }
  129.  
  130.         $output .= str_replace('['.trim($name'"\'').']''[$'.trim($name'"\'').']'$params['content']);
  131.  
  132.         if (isset($params['altcontent'])) {
  133.             $output .= $l.'forelse'.$r.$params['altcontent'];
  134.         }
  135.  
  136.         $output .= $l.'/for'.$r;
  137.  
  138.         return $output;
  139.     }
  140. }

Documentation generated on Sun, 03 Aug 2008 15:12:43 +0200 by phpDocumentor 1.4.0