Source for file dynamic.php

Documentation is available at dynamic.php

  1. <?php
  2.  
  3. /**
  4.  * Marks the contents of the block as dynamic. Which means that it will not be cached.
  5.  *
  6.  * This software is provided 'as-is', without any express or implied warranty.
  7.  * In no event will the authors be held liable for any damages arising from the use of this software.
  8.  *
  9.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  10.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  11.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  12.  * @link       http://dwoo.org/
  13.  * @version    1.0.0
  14.  * @date       2008-10-23
  15.  * @package    Dwoo
  16.  */
  17. {
  18.     public function init()
  19.     {
  20.     }
  21.  
  22.     public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
  23.     {
  24.         return '';
  25.     }
  26.  
  27.     public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
  28.     {
  29.         $output = Dwoo_Compiler::PHP_OPEN .
  30.             'if($doCache) {'."\n\t".
  31.                 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>'.
  32.                 str_replace('\'', '\\\'', $content) .
  33.                 '</dwoo:dynamic_\'.$dynamicId.\'>\';'.
  34.             "\n} else {\n\t";
  35.                 if(substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
  36.                     $output .= substr($content, strlen(Dwoo_Compiler::PHP_OPEN));
  37.                 } else {
  38.                     $output .= Dwoo_Compiler::PHP_CLOSE . $content;
  39.                 }
  40.                 if(substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
  41.                     $output = substr($output, 0, -strlen(Dwoo_Compiler::PHP_CLOSE));
  42.                 } else {
  43.                     $output .= Dwoo_Compiler::PHP_OPEN;
  44.                 }
  45.             $output .= "\n}". Dwoo_Compiler::PHP_CLOSE;
  46.  
  47.         return $output;
  48.     }
  49.  
  50.     public static function unescape($output, $dynamicId, $compiledFile)
  51.     {
  52.         $output = preg_replace_callback('/<dwoo:dynamic_('.$dynamicId.')>(.+?)<\/dwoo:dynamic_'.$dynamicId.'>/s', array('self', 'unescapePhp'), $output, -1, $count);
  53.         // re-add the includes on top of the file
  54.         if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
  55.             $output = '<?php '.$m[1].' ?>'.$output;
  56.         }
  57.         return $output;
  58.     }
  59.  
  60.     public static function unescapePhp($match)
  61.     {
  62.         return preg_replace('{<\?php /\*'.$match[1].'\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
  63.     }
  64. }

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