Exemplo n.º 1
0
 public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
 {
     $params = $compiler->getCompiledParams($params);
     $func = $params['__funcname'];
     $pluginType = $params['__functype'];
     $params = $params['*'];
     if ($pluginType & Dwoo_Core::CUSTOM_PLUGIN) {
         $customPlugins = $compiler->getDwoo()->getCustomPlugins();
         $callback = $customPlugins[$func]['callback'];
         if (is_array($callback)) {
             if (is_object($callback[0])) {
                 $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '(';
             } else {
                 $callback = '' . $callback[0] . '::' . $callback[1] . '(';
             }
         } else {
             $callback = $callback . '(';
         }
     } else {
         $callback = 'smarty_block_' . $func . '(';
     }
     $paramsOut = '';
     foreach ($params as $i => $p) {
         $paramsOut .= var_export($i, true) . ' => ' . $p . ',';
     }
     $curBlock =& $compiler->getCurrentBlock();
     $curBlock['params']['postOut'] = Dwoo_Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Dwoo_Compiler::PHP_CLOSE;
     return Dwoo_Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Dwoo_Compiler::PHP_CLOSE;
 }
Exemplo n.º 2
0
/**
 * Checks whether an extended file has been modified, and if so recompiles the current template. This is for internal use only, do not use.
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.1.0
 * @date       2009-07-18
 * @package    Dwoo
 */
function Dwoo_Plugin_extendsCheck_compile(Dwoo_Compiler $compiler, $file)
{
    preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
    $resource = $m[1];
    $identifier = $m[2];
    $tpl = $compiler->getDwoo()->templateFactory($resource, $identifier);
    if ($tpl === null) {
        throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
    } elseif ($tpl === false) {
        throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
    }
    $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
    $modCheck = $tpl->getIsModifiedCode();
    if ($modCheck) {
        $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
    } else {
        $out .= 'try {
	$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo_Exception $e) {
	$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
	$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
	$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
    }
    return $out;
}
Exemplo n.º 3
0
 /**
  * utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes
  *
  * this is to be used in preProcessing or postProcessing functions, example :
  *  $p = $compiler->getCompiledParams($params);
  *  // get only the rest array as attributes
  *  $attributes = Dwoo_Plugin::paramsToAttributes($p['*']);
  *  // get all the parameters as attributes (if there is a rest array, it will be included)
  *  $attributes = Dwoo_Plugin::paramsToAttributes($p);
  *
  * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
  * @param string $delim the string delimiter you want to use (defaults to ')
  * @param Dwoo_Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior)
  * @return string
  */
 public static function paramsToAttributes(array $params, $delim = '\'', Dwoo_Compiler $compiler = null)
 {
     if (isset($params['*'])) {
         $params = array_merge($params, $params['*']);
         unset($params['*']);
     }
     $out = '';
     foreach ($params as $attr => $val) {
         $out .= ' ' . $attr . '=';
         if (trim($val, '"\'') == '' || $val == 'null') {
             $out .= str_replace($delim, '\\' . $delim, '""');
         } elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) {
             $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, -1) . '"');
         } else {
             if (!$compiler) {
                 // disable double encoding since it can not be determined if it was encoded
                 $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
             } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
                 // escape if auto escaping is disabled, or there was no variable in the string
                 $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
             } else {
                 // print as is
                 $escapedVal = '.' . $val . '.';
             }
             $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
         }
     }
     return ltrim($out);
 }
Exemplo n.º 4
0
 public function testSmartyCompat()
 {
     $tpl = new Dwoo_Template_String('{ldelim}{$smarty.version}{rdelim}');
     $tpl->forceCompilation();
     $cmp = new Dwoo_Compiler();
     $cmp->addPreProcessor('smarty_compat', true);
     $this->assertEquals('{' . Dwoo::VERSION . '}', $this->dwoo->get($tpl, array(), $cmp));
 }
Exemplo n.º 5
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     if (!isset($params['initialized'])) {
         return '';
     }
     $block =& $compiler->getCurrentBlock();
     $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN . "else {\n" . Dwoo_Compiler::PHP_CLOSE . $content . Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
     return '';
 }
Exemplo n.º 6
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $rparams = $compiler->getRealParams($params);
     $cparams = $compiler->getCompiledParams($params);
     $compiler->setScope($rparams['var']);
     $pre = Dwoo_Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . self::$cnt . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Dwoo_Compiler::PHP_CLOSE;
     $post = Dwoo_Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . self::$cnt++ . ', true);' . "\n}\n" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     return $pre . $content . $post;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     parent::__construct();
     $compiler = new Dwoo_Compiler();
     $compiler->setDelimiters('<?', '?>');
     // add preprocessor
     // add custom plugins, functions, blocks, etc
     $this->setCompiler($compiler);
     $this->setCompileDir(PROJECT_RUNTIME . '/' . $type . '_c');
     $this->assign('this', $page);
     $this->assign('context', $context);
 }
Exemplo n.º 8
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $params = isset($params['*']) ? $params['*'] : array();
     $params_php = array();
     foreach ($params as $key => $val) {
         $params_php[] = var_export($key, true) . ' => ' . $val;
     }
     $params_php = 'array(' . implode(', ', $params_php) . ')';
     $pre = Dwoo_Compiler::PHP_OPEN . 'ob_start();' . Dwoo_Compiler::PHP_CLOSE;
     $post = Dwoo_Compiler::PHP_OPEN . __CLASS__ . '::_process(ob_get_clean(), ' . $params_php . ');' . Dwoo_Compiler::PHP_CLOSE;
     return $pre . $content . $post;
 }
Exemplo n.º 9
0
 public function testAutoEscape()
 {
     $cmp = new Dwoo_Compiler();
     $cmp->setAutoEscape(true);
     $tpl = new Dwoo_Template_String('{$foo}{auto_escape off}{$foo}{/}');
     $tpl->forceCompilation();
     $this->assertEquals("a&lt;b&gt;ca<b>c", $this->dwoo->get($tpl, array('foo' => 'a<b>c'), $cmp));
     $tpl = new Dwoo_Template_String('{$foo}{auto_escape true}{$foo}{/}');
     $tpl->forceCompilation();
     $this->assertEquals("a<b>ca&lt;b&gt;c", $this->dwoo->get($tpl, array('foo' => 'a<b>c')));
     // fixes the init call not being called (which is normal)
     $fixCall = new Dwoo_Plugin_auto_escape($this->dwoo);
     $fixCall->init('');
 }
Exemplo n.º 10
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $mode = trim($params['mode'], '"\'');
     switch ($mode) {
         case 'js':
         case 'javascript':
             $content = preg_replace('#(?<!:)//\\s[^\\r\\n]*|/\\*.*?\\*/#', '', $content);
         case 'default':
         default:
     }
     $content = preg_replace(array("/\n/", "/\r/", '/(<\\?(?:php)?|<%)\\s*/'), array('', '', '$1 '), preg_replace('#^\\s*(.+?)\\s*$#m', '$1', $content));
     return $content;
 }
Exemplo n.º 11
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $p = $compiler->getCompiledParams($params);
     // no content was provided so use the url as display text
     if ($content == "") {
         // merge </a> into the href if href is a string
         if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') {
             return Dwoo_Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, -1) . '</a>' . substr($p['href'], -1) . ';' . Dwoo_Compiler::PHP_CLOSE;
         }
         // otherwise append
         return Dwoo_Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Dwoo_Compiler::PHP_CLOSE;
     }
     // return content
     return $content . '</a>';
 }
Exemplo n.º 12
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $out = $content . Dwoo_Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();';
     if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
         $out .= "\n" . '$tmp = trim($tmp);';
     }
     if ($params['cat'] === 'true' || $params['cat'] === 1) {
         $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;';
     }
     if ($params['assign'] !== 'null') {
         $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;';
     }
     return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Dwoo_Compiler::PHP_CLOSE;
 }
Exemplo n.º 13
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     if (!isset($params['initialized'])) {
         return '';
     }
     $params = $compiler->getCompiledParams($params);
     $pre = Dwoo_Compiler::PHP_OPEN . "elseif (" . implode(' ', self::replaceKeywords($params['*'], $compiler)) . ") {\n" . Dwoo_Compiler::PHP_CLOSE;
     $post = Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     $block =& $compiler->getCurrentBlock();
     $block['params']['hasElse'] = $pre . $content . $post;
     return '';
 }
Exemplo n.º 14
0
 public static function compilerFactory()
 {
     if (!isset(static::$_instance_compiler)) {
         static::$_instance_compiler = \Dwoo_Compiler::compilerFactory();
     }
     return static::$_instance_compiler;
 }
Exemplo n.º 15
0
/**
 * Ternary if operation
 *
 * It evaluates the first argument and returns the second if it's true, or the third if it's false
 * <pre>
 *  * rest : you can not use named parameters to call this, use it either with three arguments in the correct order (expression, true result, false result) or write it as in php (expression ? true result : false result)
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.0.0
 * @date       2008-10-23
 * @package    Dwoo
 */
function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
{
    // load if plugin
    if (!class_exists('Dwoo_Plugin_if', false)) {
        try {
            $compiler->getDwoo()->getLoader()->loadPlugin('if');
        } catch (Exception $e) {
            throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif');
        }
    }
    if (count($rest) == 1) {
        return $rest[0];
    }
    // fetch false result and remove the ":" if it was present
    $falseResult = array_pop($rest);
    if (trim(end($rest), '"\'') === ':') {
        // remove the ':' if present
        array_pop($rest);
    } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) {
        if ($falseResult === '?' || $falseResult === ':') {
            throw new Dwoo_Compilation_Exception($compiler, 'Tif: incomplete tif statement, value missing after ' . $falseResult);
        }
        // there was in fact no false result provided, so we move it to be the true result instead
        $trueResult = $falseResult;
        $falseResult = "''";
    }
    // fetch true result if needed
    if (!isset($trueResult)) {
        $trueResult = array_pop($rest);
        // no true result provided so we use the expression arg
        if ($trueResult === '?') {
            $trueResult = true;
        }
    }
    // remove the '?' if present
    if (trim(end($rest), '"\'') === '?') {
        array_pop($rest);
    }
    // check params were correctly provided
    if (empty($rest) || $trueResult === null || $falseResult === null) {
        throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
    }
    // parse condition
    $condition = Dwoo_Plugin_if::replaceKeywords($rest, $compiler);
    return '((' . implode(' ', $condition) . ') ? ' . ($trueResult === true ? implode(' ', $condition) : $trueResult) . ' : ' . $falseResult . ')';
}
Exemplo n.º 16
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $paramstr = 'Dwoo $dwoo';
     $init = 'static $_callCnt = 0;' . "\n" . '$dwoo->scope[\' ' . $params['uuid'] . '\'.$_callCnt] = array();' . "\n" . '$_scope = $dwoo->setScope(array(\' ' . $params['uuid'] . '\'.($_callCnt++)));' . "\n";
     $cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);';
     foreach ($params['*'] as $param => $defValue) {
         if ($defValue === null) {
             $paramstr .= ', $' . $param;
         } else {
             $paramstr .= ', $' . $param . ' = ' . $defValue;
         }
         $init .= '$dwoo->scope[\'' . $param . '\'] = $' . $param . ";\n";
     }
     $init .= '/* -- template start output */';
     $funcName = 'Dwoo_Plugin_' . $params['name'] . '_' . $params['uuid'];
     $body = 'if (!function_exists(\'' . $funcName . "')) {\nfunction " . $funcName . '(' . $paramstr . ') {' . "\n{$init}" . Dwoo_Compiler::PHP_CLOSE . $prepend . str_replace(array('$this->', '$this,'), array('$dwoo->', '$dwoo,'), $content) . $append . Dwoo_Compiler::PHP_OPEN . $cleanup . "\n}\n}";
     $compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
 }
Exemplo n.º 17
0
/**
 * Loads sub-templates contained in an external file
 * <pre>
 *  * file : the resource name of the file to load
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.1.0
 * @date       2009-07-18
 * @package    Dwoo
 */
function Dwoo_Plugin_load_templates_compile(Dwoo_Compiler $compiler, $file)
{
    $file = substr($file, 1, -1);
    if ($file === '') {
        return;
    }
    if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
        // resource:identifier given, extract them
        $resource = $m[1];
        $identifier = $m[2];
    } else {
        // get the current template's resource
        $resource = $compiler->getDwoo()->getTemplate()->getResourceName();
        $identifier = $file;
    }
    $tpl = $compiler->getDwoo()->templateFactory($resource, $identifier);
    if ($tpl === null) {
        throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
    } elseif ($tpl === false) {
        throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
    }
    $cmp = clone $compiler;
    $cmp->compile($compiler->getDwoo(), $tpl);
    foreach ($cmp->getTemplatePlugins() as $template => $args) {
        $compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
    }
    $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
    $modCheck = $tpl->getIsModifiedCode();
    if ($modCheck) {
        $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
    } else {
        $out .= 'try {
	$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo_Exception $e) {
	$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
	$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
	$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
    }
    return $out;
}
Exemplo n.º 18
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     try {
         $compiler->findBlock('dynamic');
         return $content;
     } catch (Dwoo_Compilation_Exception $e) {
     }
     $output = Dwoo_Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
     if (substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
         $output .= substr($content, strlen(Dwoo_Compiler::PHP_OPEN));
     } else {
         $output .= Dwoo_Compiler::PHP_CLOSE . $content;
     }
     if (substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
         $output = substr($output, 0, -strlen(Dwoo_Compiler::PHP_CLOSE));
     } else {
         $output .= Dwoo_Compiler::PHP_OPEN;
     }
     $output .= "\n}" . Dwoo_Compiler::PHP_CLOSE;
     return $output;
 }
 /**
  * Called when Dwoo hits the closing {ifconfig} tag. Returns a PHP string that will make the
  * appropriate get_config(), get_config_plugin() or get_config_plugin_instance() call when the
  * compiled template is executed.
  *
  * @param Dwoo_Compiler $compiler
  * @param array $params
  * @param unknown_type $prepend
  * @param unknown_type $append
  * @param string $content The contents between the opening and closing tags
  */
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $key = $params['key'];
     $plugintype = $params['plugintype'];
     $pluginname = $params['pluginname'];
     $pluginid = trim($params['pluginid'], '\'"');
     $compareTo = $params['compareTo'];
     if ($plugintype != 'null' && $pluginname != 'null') {
         $function = "get_config_plugin({$plugintype}, {$pluginname}, {$key})";
     } else {
         if ($plugintype != 'null' && $pluginid != 'null') {
             $function = "get_config_plugin_instance({$plugintype}, {$pluginid}, {$key})";
         } else {
             $function = "get_config({$key})";
         }
     }
     $pre = Dwoo_Compiler::PHP_OPEN . "if ({$function} == {$compareTo}) {\n" . Dwoo_Compiler::PHP_CLOSE;
     $post = Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     return $pre . $content . $post;
 }
Exemplo n.º 20
0
 public static function compile(Dwoo_Compiler $compiler, $file)
 {
     list(self::$lraw, self::$rraw) = $compiler->getDelimiters();
     self::$l = preg_quote(self::$lraw, '/');
     self::$r = preg_quote(self::$rraw, '/');
     if ($compiler->getLooseOpeningHandling()) {
         self::$l .= '\\s*';
         self::$r = '\\s*' . self::$r;
     }
     $inheritanceTree = array(array('source' => $compiler->getTemplateSource()));
     $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR;
     $curTpl = $compiler->getDwoo()->getTemplate();
     while (!empty($file)) {
         if ($file === '""' || $file === "''" || substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'') {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : The file name must be a non-empty string');
             return;
         }
         if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
             // resource:identifier given, extract them
             $resource = $m[1];
             $identifier = $m[2];
         } else {
             // get the current template's resource
             $resource = $curTpl->getResourceName();
             $identifier = substr($file, 1, -1);
         }
         try {
             $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl);
         } catch (Dwoo_Security_Exception $e) {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : Security restriction : ' . $e->getMessage());
         } catch (Dwoo_Exception $e) {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : ' . $e->getMessage());
         }
         if ($parent === null) {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.');
         } elseif ($parent === false) {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "' . $resource . '" does not support extends.');
         }
         $curTpl = $parent;
         $newParent = array('source' => $parent->getSource(), 'resource' => $resource, 'identifier' => $parent->getResourceIdentifier(), 'uid' => $parent->getUid());
         if (array_search($newParent, $inheritanceTree, true) !== false) {
             throw new Dwoo_Compilation_Exception($compiler, 'Extends : Recursive template inheritance detected');
         }
         $inheritanceTree[] = $newParent;
         if (preg_match('/^' . self::$l . 'extends(?:\\(?\\s*|\\s+)(?:file=)?\\s*((["\']).+?\\2|\\S+?)\\s*\\)?\\s*?' . self::$r . '/i', $parent->getSource(), $match)) {
             $curPath = dirname($identifier) . DIRECTORY_SEPARATOR;
             if (isset($match[2]) && $match[2] == '"') {
                 $file = '"' . str_replace('"', '\\"', substr($match[1], 1, -1)) . '"';
             } elseif (isset($match[2]) && $match[2] == "'") {
                 $file = '"' . substr($match[1], 1, -1) . '"';
             } else {
                 $file = '"' . $match[1] . '"';
             }
         } else {
             $file = false;
         }
     }
     while (true) {
         $parent = array_pop($inheritanceTree);
         $child = end($inheritanceTree);
         self::$childSource = $child['source'];
         self::$lastReplacement = count($inheritanceTree) === 1;
         if (!isset($newSource)) {
             $newSource = $parent['source'];
         }
         // TODO parse blocks tree for child source and new source
         // TODO replace blocks that are found in the child and in the parent recursively
         $firstL = preg_quote(self::$lraw[0], '/');
         $restL = preg_quote(substr(self::$lraw, 1), '/');
         $newSource = preg_replace_callback('/' . self::$l . 'block (["\']?)(.+?)\\1' . self::$r . '(?:\\r?\\n?)((?:[^' . $firstL . ']*|' . $firstL . '(?!' . $restL . '\\/block' . self::$r . '))*)' . self::$l . '\\/block' . self::$r . '/is', array('Dwoo_Plugin_extends', 'replaceBlock'), $newSource);
         $newSource = self::$lraw . 'do extendsCheck("' . $parent['resource'] . ':' . $parent['identifier'] . '")' . self::$rraw . $newSource;
         if (self::$lastReplacement) {
             break;
         }
     }
     $compiler->setTemplateSource($newSource);
     $compiler->recompile();
 }
Exemplo n.º 21
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $tpl = $compiler->getTemplateSource($params['tplPointer']);
     // assigns params
     $src = $params['from'];
     if ($params['item'] !== 'null') {
         if ($params['key'] !== 'null') {
             $key = $params['key'];
         }
         $val = $params['item'];
     } elseif ($params['key'] !== 'null') {
         $val = $params['key'];
     } else {
         throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter missing');
     }
     $name = $params['name'];
     if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
         throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter must be of type string');
     }
     if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
         throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>key</em> parameter must be of type string');
     }
     // evaluates which global variables have to be computed
     $varName = '$dwoo.foreach.' . trim($name, '"\'') . '.';
     $shortVarName = '$.foreach.' . trim($name, '"\'') . '.';
     $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
     $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
     $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
     $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
     $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
     $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
     $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
     if (strpos($name, '$this->scope[') !== false) {
         $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
     }
     // override globals vars if implode is used
     if ($params['implode'] !== 'null') {
         $implode = $params['implode'];
         $usesAny = true;
         $usesLast = true;
         $usesIteration = true;
         $usesTotal = true;
     }
     // gets foreach id
     $cnt = self::$cnt++;
     // build pre content output
     $pre = Dwoo_Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';';
     // adds foreach properties
     if ($usesAny) {
         $pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n(";
         if ($usesIndex) {
             $pre .= "\n\t" . '"index"		=> 0,';
         }
         if ($usesIteration) {
             $pre .= "\n\t" . '"iteration"		=> 1,';
         }
         if ($usesFirst) {
             $pre .= "\n\t" . '"first"		=> null,';
         }
         if ($usesLast) {
             $pre .= "\n\t" . '"last"		=> null,';
         }
         if ($usesShow) {
             $pre .= "\n\t" . '"show"		=> $this->isArray($_fh' . $cnt . '_data, true),';
         }
         if ($usesTotal) {
             $pre .= "\n\t" . '"total"		=> $this->isArray($_fh' . $cnt . '_data) ? count($_fh' . $cnt . '_data) : 0,';
         }
         $pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];';
     }
     // checks if foreach must be looped
     $pre .= "\n" . 'if ($this->isArray($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') === true)' . "\n{";
     // iterates over keys
     $pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{";
     // updates properties
     if ($usesFirst) {
         $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);';
     }
     if ($usesLast) {
         $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);';
     }
     $pre .= "\n/* -- foreach start output */\n" . Dwoo_Compiler::PHP_CLOSE;
     // build post content output
     $post = Dwoo_Compiler::PHP_OPEN . "\n";
     if (isset($implode)) {
         $post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n";
     }
     $post .= '/* -- foreach end output */';
     // update properties
     if ($usesIndex) {
         $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;';
     }
     if ($usesIteration) {
         $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;';
     }
     // end loop
     $post .= "\n\t}\n}" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     return $pre . $content . $post;
 }
Exemplo n.º 22
0
 /**
  * provides a custom compiler to the dwoo renderer with optional settings
  * you can set in the agavi output_types.xml config file
  *
  * @return Dwoo_Compiler
  */
 public function compilerFactory()
 {
     if (class_exists('Dwoo_Compiler', false) === false) {
         include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
     }
     $compiler = Dwoo_Compiler::compilerFactory();
     $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false));
     return $compiler;
 }
Exemplo n.º 23
0
 /**
  * returns a default instance of this compiler, used by default by all Dwoo templates that do not have a
  * specific compiler assigned and when you do not override the default compiler factory function
  *
  * @see Dwoo::setDefaultCompilerFactory()
  * @return Dwoo_Compiler
  */
 public static function compilerFactory()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 24
0
 public function __construct(Dwoo_Compiler $compiler, $message)
 {
     $this->compiler = $compiler;
     $this->template = $compiler->getDwoo()->getTemplate();
     parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message);
 }
Exemplo n.º 25
0
logincheck();
$g_objAdmin->checkEditViewAccess();
$objView = AROView::finder()->byPK($_REQUEST['id']);
$szViewFile = PROJECT_VIEWS . '/' . $objView->id . '.php';
if (!empty($_GET['deleteme'])) {
    $objView->delete();
    unlink($szViewFile);
    header('Location: ../');
    exit;
} else {
    if (isset($_POST['title'], $_POST['content'], $_POST['type'])) {
        require_once PROJECT_INCLUDE . '/Dwoo-1.1.1/Dwoo/dwooAutoload.php';
        $template_source = $_POST['content'];
        $template = new Dwoo_Template_String($template_source);
        $dwoo = new Dwoo();
        $compiler = new Dwoo_Compiler();
        $compiler->setDelimiters('<?', '?>');
        $dwoo->setCompiler($compiler);
        try {
            $compiled_template_source = $dwoo->testTemplate($template);
            //	echo '<pre>'.htmlspecialchars($template_source).'</pre>';
            //	echo '<p>is a valid template:</p>';
            //	exit('<pre>'.htmlspecialchars(file_get_contents($compiled_template_source)).'</pre>');
        } catch (Dwoo_Exception $exc) {
            echo '<pre style="background-color:pink;">' . htmlspecialchars($template_source) . '</pre>';
            echo '<p>is NOT a valid template:</p>';
            exit('<pre style="background-color:pink;">' . $exc->getMessage() . '</pre>');
        }
        $objView->title = $_POST['title'];
        $objView->type = implode(',', $_POST['type']);
        $objView->save();
Exemplo n.º 26
0
 /**
  * returns the compiled template file name
  *
  * @param Dwoo $dwoo the dwoo instance that requests it
  * @param Dwoo_ICompiler $compiler the compiler that must be used
  * @return string
  */
 public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
 {
     $compiledFile = $this->getCompiledFilename($dwoo);
     if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
         // already checked, return compiled file
     } elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
         // template is compiled
         self::$cache['compiled'][$this->compileId] = true;
     } else {
         // compiles the template
         $this->compilationEnforced = false;
         if ($compiler === null) {
             $compiler = $dwoo->getDefaultCompilerFactory($this->getResourceName());
             if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) {
                 if (class_exists('Dwoo_Compiler', false) === false) {
                     include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
                 }
                 $compiler = Dwoo_Compiler::compilerFactory();
             } else {
                 $compiler = call_user_func($compiler);
             }
         }
         $this->compiler = $compiler;
         $compiler->setCustomPlugins($dwoo->getCustomPlugins());
         $compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
         $this->makeDirectory(dirname($compiledFile));
         file_put_contents($compiledFile, $compiler->compile($dwoo, $this));
         if ($this->chmod !== null) {
             chmod($compiledFile, $this->chmod);
         }
         self::$cache['compiled'][$this->compileId] = true;
     }
     return $compiledFile;
 }
Exemplo n.º 27
0
 /**
  * Return the Dwoo compiler object
  *
  * @return Dwoo_Data
  */
 public function getCompiler()
 {
     if (null === $this->_compiler) {
         $this->_compiler = Dwoo_Compiler::compilerFactory();
     }
     return $this->_compiler;
 }
Exemplo n.º 28
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $tokens = $compiler->getParamTokens($params);
     $params = $compiler->getCompiledParams($params);
     $pre = Dwoo_Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Dwoo_Compiler::PHP_CLOSE;
     $post = Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     return $pre . $content . $post;
 }
Exemplo n.º 29
0
 public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
 {
     $params = $compiler->getCompiledParams($params);
     $tpl = $compiler->getTemplateSource($params['tplPointer']);
     // assigns params
     $src = $params['from'];
     $name = $params['name'];
     // evaluates which global variables have to be computed
     $varName = '$dwoo.loop.' . trim($name, '"\'') . '.';
     $shortVarName = '$.loop.' . trim($name, '"\'') . '.';
     $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
     $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
     $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
     $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
     $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
     $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
     $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
     if (strpos($name, '$this->scope[') !== false) {
         $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
     }
     // gets foreach id
     $cnt = self::$cnt++;
     // builds pre processing output
     $pre = Dwoo_Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
     // adds foreach properties
     if ($usesAny) {
         $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
         if ($usesIndex) {
             $pre .= "\n\t" . '"index"		=> 0,';
         }
         if ($usesIteration) {
             $pre .= "\n\t" . '"iteration"		=> 1,';
         }
         if ($usesFirst) {
             $pre .= "\n\t" . '"first"		=> null,';
         }
         if ($usesLast) {
             $pre .= "\n\t" . '"last"		=> null,';
         }
         if ($usesShow) {
             $pre .= "\n\t" . '"show"		=> $this->isTraversable($_loop' . $cnt . '_data, true),';
         }
         if ($usesTotal) {
             $pre .= "\n\t" . '"total"		=> $this->count($_loop' . $cnt . '_data),';
         }
         $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
     }
     // checks if the loop must be looped
     $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
     // iterates over keys
     $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
     // updates properties
     if ($usesFirst) {
         $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
     }
     if ($usesLast) {
         $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
     }
     $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Dwoo_Compiler::PHP_CLOSE;
     // build post processing output and cache it
     $post = Dwoo_Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
     // update properties
     if ($usesIndex) {
         $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
     }
     if ($usesIteration) {
         $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
     }
     // end loop
     $post .= "\n\t}\n}\n" . Dwoo_Compiler::PHP_CLOSE;
     if (isset($params['hasElse'])) {
         $post .= $params['hasElse'];
     }
     return $pre . $content . $post;
 }
Exemplo n.º 30
0
    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
    {
        $params = $compiler->getCompiledParams($params);
        $tpl = $compiler->getTemplateSource($params['tplPointer']);
        // assigns params
        $from = $params['from'];
        $name = $params['name'];
        $step = $params['step'];
        $to = $params['to'];
        // evaluates which global variables have to be computed
        $varName = '$dwoo.for.' . trim($name, '"\'') . '.';
        $shortVarName = '$.for.' . trim($name, '"\'') . '.';
        $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
        $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
        $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
        $usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
        $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
        $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
        $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
        // gets foreach id
        $cnt = self::$cnt++;
        // builds pre processing output for
        $out = Dwoo_Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));';
        // adds foreach properties
        if ($usesAny) {
            $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n(";
            if ($usesIndex) {
                $out .= "\n\t" . '"index"		=> 0,';
            }
            if ($usesIteration) {
                $out .= "\n\t" . '"iteration"		=> 1,';
            }
            if ($usesFirst) {
                $out .= "\n\t" . '"first"		=> null,';
            }
            if ($usesLast) {
                $out .= "\n\t" . '"last"		=> null,';
            }
            if ($usesShow) {
                $out .= "\n\t" . '"show"		=> $tmp_shows,';
            }
            if ($usesTotal) {
                $out .= "\n\t" . '"total"		=> $this->isArray($_for' . $cnt . '_from) ? floor(count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),';
            }
            $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
        }
        // checks if for must be looped
        $out .= "\n" . 'if ($tmp_shows)' . "\n{";
        // set from/to to correct values if an array was given
        $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from, true)) {
		$_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : count($_for' . $cnt . '_from) - 1;
		$_for' . $cnt . '_from = 0;
	}';
        // reverse from and to if needed
        $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
		$tmp = $_for' . $cnt . '_from;
		$_for' . $cnt . '_from = $_for' . $cnt . '_to;
		$_for' . $cnt . '_to = $tmp;
	}
	for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] <= $_for' . $cnt . '_to; $this->scope[' . $name . '] += $_for' . $cnt . '_step)' . "\n\t{";
        // updates properties
        if ($usesIndex) {
            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
        }
        if ($usesFirst) {
            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
        }
        if ($usesLast) {
            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
        }
        $out .= "\n/* -- for start output */\n" . Dwoo_Compiler::PHP_CLOSE;
        // build post processing output and cache it
        $postOut = Dwoo_Compiler::PHP_OPEN . '/* -- for end output */';
        // update properties
        if ($usesIteration) {
            $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
        }
        // end loop
        $postOut .= "\n\t}\n}\n" . Dwoo_Compiler::PHP_CLOSE;
        if (isset($params['hasElse'])) {
            $postOut .= $params['hasElse'];
        }
        return $out . $content . $postOut;
    }