Exemplo n.º 1
0
 function _parse_function($function, $modifiers, $arguments)
 {
     switch ($function) {
         case 'include':
             if (!function_exists('compile_include')) {
                 require_once TEMPLATE_LITE_DIR . "internal/compile.include.php";
             }
             return compile_include($arguments, $this);
             break;
         case 'insert':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['name'])) {
                 $this->trigger_error("missing 'name' attribute in 'insert'", E_USER_ERROR, __FILE__, __LINE__);
             }
             foreach ($_args as $key => $value) {
                 if (is_bool($value)) {
                     $value = $value ? 'true' : 'false';
                 }
                 $arg_list[] = "'{$key}' => {$value}";
             }
             return '<?php echo $this->_run_insert(array(' . implode(', ', (array) $arg_list) . ')); ?>';
             break;
         case 'ldelim':
             return $this->left_delimiter;
             break;
         case 'rdelim':
             return $this->right_delimiter;
             break;
         case 'literal':
             list(, $literal) = each($this->_literal);
             $this->_linenum += substr_count($literal, "\n");
             return "<?php echo '" . str_replace("'", "\\'", str_replace("\\", "\\\\", $literal)) . "'; ?>";
             break;
         case 'php':
             list(, $php_block) = each($this->_php_blocks);
             $this->_linenum += substr_count($php_block, "\n");
             $php_extract = '';
             if ($this->php_extract_vars) {
                 if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
                     $php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n";
                 } else {
                     $php_extract = '<?php extract($this->_vars); ?>' . "\n";
                 }
             }
             return $php_extract . '<?php ' . $php_block . ' ?>';
             break;
         case 'foreach':
             array_push($this->_foreachelse_stack, false);
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value']) && !isset($_args['item'])) {
                 $this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (isset($_args['value'])) {
                 $_args['value'] = $this->_dequote($_args['value']);
             } elseif (isset($_args['item'])) {
                 $_args['value'] = $this->_dequote($_args['item']);
             }
             isset($_args['key']) ? $_args['key'] = "\$this->_vars['" . $this->_dequote($_args['key']) . "'] => " : ($_args['key'] = '');
             $_result = '<?php if (count((array)' . $_args['from'] . ')): ?>';
             if (isset($_args['name'])) {
                 $foreach_props = '$this->_templatelite_vars[\'foreach\'][' . $_args['name'] . ']';
                 $_result .= '<?php ' . $foreach_props . '[\'iteration\'] = 0; ' . $foreach_props . '[\'total\'] = count((array)' . $_args['from'] . '); ?>';
             }
             $_result .= '<?php foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']): ?>';
             if (isset($_args['name'])) {
                 $_result .= '<?php ' . $foreach_props . '[\'iteration\']++; ' . $foreach_props . '[\'first\'] = ' . $foreach_props . '[\'iteration\'] == 1 ? true : false; ' . $foreach_props . '[\'last\'] = ' . $foreach_props . '[\'iteration\'] == ' . $foreach_props . '[\'total\'] ? true : false; ' . '?>';
             }
             return $_result;
             break;
         case 'foreachelse':
             $this->_foreachelse_stack[count($this->_foreachelse_stack) - 1] = true;
             return "<?php endforeach; else: ?>";
             break;
         case '/foreach':
             if (array_pop($this->_foreachelse_stack)) {
                 return "<?php endif; ?>";
             } else {
                 return "<?php endforeach; endif; ?>";
             }
             break;
         case 'for':
             $this->_for_stack++;
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['start'])) {
                 $this->trigger_error("missing 'start' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['stop'])) {
                 $this->trigger_error("missing 'stop' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['step'])) {
                 $_args['step'] = 1;
             }
             $_result = '<?php for($for' . $this->_for_stack . ' = ' . $_args['start'] . '; ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ($for' . $this->_for_stack . ' < ' . $_args['stop'] . ') : ($for' . $this->_for_stack . ' > ' . $_args['stop'] . ')); $for' . $this->_for_stack . ' += ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ' . $_args['step'] . ' : -' . $_args['step'] . ')): ?>';
             if (isset($_args['value'])) {
                 $_result .= '<?php $this->assign(\'' . $this->_dequote($_args['value']) . '\', $for' . $this->_for_stack . '); ?>';
             }
             return $_result;
             break;
         case '/for':
             $this->_for_stack--;
             return "<?php endfor; ?>";
             break;
         case 'section':
             array_push($this->_sectionelse_stack, false);
             if (!function_exists('compile_section_start')) {
                 require_once TEMPLATE_LITE_DIR . "internal/compile.section_start.php";
             }
             return compile_section_start($arguments, $this);
             break;
         case 'sectionelse':
             $this->_sectionelse_stack[count($this->_sectionelse_stack) - 1] = true;
             return "<?php endfor; else: ?>";
             break;
         case '/section':
             if (array_pop($this->_sectionelse_stack)) {
                 return "<?php endif; ?>";
             } else {
                 return "<?php endfor; endif; ?>";
             }
             break;
         case 'while':
             $_args = $this->_compile_if($arguments, false, true);
             return '<?php while(' . $_args . '): ?>';
             break;
         case '/while':
             return "<?php endwhile; ?>";
             break;
         case 'if':
             return $this->_compile_if($arguments);
             break;
         case 'else':
             return "<?php else: ?>";
             break;
         case 'elseif':
             return $this->_compile_if($arguments, true);
             break;
         case '/if':
             return "<?php endif; ?>";
             break;
         case 'assign':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['var'])) {
                 $this->trigger_error("missing 'var' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value'])) {
                 $this->trigger_error("missing 'value' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             return '<?php $this->assign(\'' . $this->_dequote($_args['var']) . '\', ' . $_args['value'] . '); ?>';
             break;
         case 'switch':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
             return;
             break;
         case '/switch':
             array_pop($this->_switch_stack);
             return '<?php break; endswitch; ?>';
             break;
         case 'case':
             if (count($this->_switch_stack) > 0) {
                 $_result = "<?php ";
                 $_args = $this->_parse_arguments($arguments);
                 $_index = count($this->_switch_stack) - 1;
                 if (!$this->_switch_stack[$_index]["matched"]) {
                     $_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '): ';
                     $this->_switch_stack[$_index]["matched"] = true;
                 } else {
                     $_result .= 'break; ';
                 }
                 if (!empty($_args['value'])) {
                     $_result .= 'case ' . $_args['value'] . ': ';
                 } else {
                     $_result .= 'default: ';
                 }
                 return $_result . ' ?>';
             } else {
                 $this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             break;
         case 'config_load':
             $_args = $this->_parse_arguments($arguments);
             if (empty($_args['file'])) {
                 $this->trigger_error("missing 'file' attribute in 'config_load' tag", E_USER_ERROR, __FILE__, __LINE__);
             }
             isset($_args['section']) ? null : ($_args['section'] = 'null');
             isset($_args['var']) ? null : ($_args['var'] = 'null');
             return '<?php $this->config_load(' . $_args['file'] . ', ' . $_args['section'] . ', ' . $_args['var'] . '); ?>';
             break;
         default:
             $_result = "";
             if ($this->_compile_compiler_function($function, $arguments, $_result)) {
                 return $_result;
             } else {
                 if ($this->_compile_custom_block($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } elseif ($this->_compile_custom_function($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } else {
                     throw new Exception($function . " function does not exist");
                     $this->trigger_error($function . " function does not exist", E_USER_ERROR, __FILE__, __LINE__);
                 }
             }
             break;
     }
 }
Exemplo n.º 2
0
    function _parse_function($function, $modifiers, $arguments)
    {
        if (strpos($function, iPHP_TPL_VAR . ':') !== false) {
            list($function, $app, $method) = explode(':', $function);
        }
        //var_dump($function,$app,$method);
        switch ($function) {
            case 'include':
                $this->internal('compile_include');
                return $include_file = str_replace($this->_error_reporting, '', compile_include($arguments, $this));
                break;
            case iPHP_TPL_VAR:
                $arguments .= ' app="' . $app . '"';
                $method && ($arguments .= ' method="' . $method . '"');
                $_args = $this->_parse_arguments($arguments);
                if ($app && isset($_args['loop'])) {
                    $this->_iPHP_stack[count($this->_iPHP_stack) - 1] = true;
                    $_app = $this->_dequote($_args['app']);
                    $_args['method'] && ($_app .= '_' . $this->_dequote($_args['method']));
                    $_args['as'] && ($_app = $this->_dequote($_args['as']));
                    $arguments = 'app=$' . $_app;
                    isset($_args['start']) && ($arguments .= " start={$_args['start']} ");
                    isset($_args['step']) && ($arguments .= " step={$_args['step']} ");
                    isset($_args['max']) && ($arguments .= " max={$_args['max']} ");
                    $this->internal('compile_iPHP');
                    $compile_iPHP = compile_iPHP($arguments, $this);
                }
                isset($_args['app']) or $this->trigger_error("missing 'app' attribute in '" . iPHP_TPL_VAR . "'", E_USER_ERROR, __FILE__, __LINE__);
                foreach ($_args as $key => $value) {
                    $arg_list[] = "'{$key}' => {$value}";
                }
                return '<?php $this->_run_iPHP(array(' . implode(',', (array) $arg_list) . ')); ?>' . $compile_iPHP;
                break;
            case iPHP_TPL_VAR . 'else':
                $this->_iPHP_else_stack = true;
                return "<?php }}else{ ?>";
                break;
            case '/' . iPHP_TPL_VAR:
                array_pop($this->_iPHP_stack) or $this->trigger_error("missing 'loop' attribute in '" . iPHP_TPL_VAR . "'", E_USER_ERROR, __FILE__, __LINE__);
                if ($this->_iPHP_else_stack) {
                    $this->_iPHP_else_stack = false;
                    return "<?php } ?>";
                }
                return "<?php }} ?>";
                break;
            case 'ldelim':
                return $this->left_delimiter;
                break;
            case 'rdelim':
                return $this->right_delimiter;
                break;
            case 'literal':
                list(, $literal) = each($this->_literal);
                $this->_linenum += substr_count($literal, "\n");
                return "<?php echo '" . str_replace("'", "\\'", str_replace("\\", "\\\\", $literal)) . "'; ?>";
                break;
            case 'php':
                list(, $php_block) = each($this->_php_blocks);
                //¹ýÂËPHP 2007-7-23 0:13
                if ($this->php_handling != "PHP_ALLOW") {
                    return htmlspecialchars($php_extract . '<?php ' . $php_block . ' ?>');
                    break;
                }
                //¹ýÂËPHP 2007-7-23 0:13
                $this->_linenum += substr_count($php_block, "\n");
                $php_extract = '';
                $this->php_extract_vars && ($php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n");
                return $php_extract . '<?php ' . $php_block . ' ?>';
                break;
            case 'foreach':
                array_push($this->_foreachelse_stack, false);
                $_args = $this->_parse_arguments($arguments);
                isset($_args['from']) or $this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
                isset($_args['value']) or $this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
                isset($_args['value']) && ($_args['value'] = $this->_dequote($_args['value']));
                isset($_args['start']) && ($_args['start'] = $this->_dequote($_args['start']));
                isset($_args['end']) && ($_args['end'] = $this->_dequote($_args['end']));
                //				isset($_args['key']) ? $_args['key'] = "\$this->_vars['".$this->_dequote($_args['key'])."'] => " : $_args['key'] = '';
                isset($_args['key']) or $_args['key'] = 'key_' . rand(1, 999);
                $hash = rand(1, 999);
                $keystr = "\$this->_vars['" . $this->_dequote($_args['key']) . "'] => ";
                $_result = '<?php
				$_count_' . $hash . ' = count((array)' . $_args['from'] . ');
				$this->_vars[\'' . $_args['value'] . '_first\'] = false;
				$this->_vars[\'' . $_args['value'] . '_last\']  = false;
				$this->_vars[\'' . $_args['value'] . '_count\'] = $_count_' . $hash . ';
				$fec_' . $hash . ' = 1;
				if ($_count_' . $hash . '){
					foreach ((array)' . $_args['from'] . ' as ' . $keystr . '$this->_vars[\'' . $_args['value'] . '\']){
						$fec_' . $hash . ' == 1 && $this->_vars[\'' . $_args['value'] . '_first\'] = true;
						$fec_' . $hash . ' == $_count_' . $hash . ' && $this->_vars[\'' . $_args['value'] . '_last\'] = true;
				';
                if (isset($_args['start'])) {
                    $_result .= 'if($fec_' . $hash . '<' . $_args['start'] . '){$fec_' . $hash . '++;continue;}';
                }
                if (isset($_args['end'])) {
                    $_result .= 'if($fec_' . $hash . '>' . $_args['end'] . '){break;}';
                }
                $_result .= '$fec_' . $hash . '++;';
                $_result .= '?>';
                return $_result;
                break;
            case 'foreachelse':
                $this->_foreachelse_stack[count($this->_foreachelse_stack) - 1] = true;
                return "<?php }}else{ ?>";
                break;
            case '/foreach':
                if (array_pop($this->_foreachelse_stack)) {
                    return "<?php } ?>";
                } else {
                    return "<?php }} ?>";
                }
                break;
            case 'for':
                $this->_for_stack++;
                $_args = $this->_parse_arguments($arguments);
                isset($_args['stop']) && ($_args['count'] = $_args['stop']);
                isset($_args['start']) or $this->trigger_error("missing 'start' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
                isset($_args['count']) or $this->trigger_error("missing 'count' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
                isset($_args['step']) or $_args['step'] = 1;
                $_result = '<?php for($for' . $this->_for_stack . ' = ' . $_args['start'] . '; ((' . $_args['start'] . ' < ' . $_args['count'] . ') ? ($for' . $this->_for_stack . ' < ' . $_args['count'] . ') : ($for' . $this->_for_stack . ' > ' . $_args['count'] . ')); $for' . $this->_for_stack . ' += ((' . $_args['start'] . ' < ' . $_args['count'] . ') ? ' . $_args['step'] . ' : -' . $_args['step'] . ')){ ?>';
                isset($_args['value']) && ($_result .= '<?php $this->assign(\'' . $this->_dequote($_args['value']) . '\', $for' . $this->_for_stack . '); ?>');
                return $_result;
                break;
            case '/for':
                $this->_for_stack--;
                return "<?php } ?>";
                break;
            case 'section':
                array_push($this->_sectionelse_stack, false);
                $this->internal('compile_section_start');
                return compile_section_start($arguments, $this);
                break;
            case 'sectionelse':
                $this->_sectionelse_stack[count($this->_sectionelse_stack) - 1] = true;
                return "<?php }}else{ ?>";
                break;
            case '/section':
                if (array_pop($this->_sectionelse_stack)) {
                    return "<?php } ?>";
                } else {
                    return "<?php }} ?>";
                }
                break;
            case 'while':
                $_args = $this->_compile_if($arguments, false, true);
                return '<?php while(' . $_args . '){ ?>';
                break;
            case '/while':
                return "<?php } ?>";
                break;
            case 'if':
                return $this->_compile_if($arguments);
                break;
            case 'else':
                return "<?php }else{ ?>";
                break;
            case 'elseif':
                return $this->_compile_if($arguments, true);
                break;
            case '/if':
                return "<?php }; ?>";
                break;
            case 'assign':
                $_args = $this->_parse_arguments($arguments);
                if (!isset($_args['var'])) {
                    $this->trigger_error("missing 'var' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
                }
                if (!isset($_args['value'])) {
                    $this->trigger_error("missing 'value' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
                }
                return '<?php $this->assign(\'' . $this->_dequote($_args['var']) . '\', ' . $_args['value'] . '); ?>';
                break;
            case 'switch':
                $_args = $this->_parse_arguments($arguments);
                isset($_args['from']) or $this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
                array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
                return;
                break;
            case '/switch':
                array_pop($this->_switch_stack);
                return '<?php break; }; ?>';
                break;
            case 'case':
                if (count($this->_switch_stack) > 0) {
                    $_result = "<?php ";
                    $_args = $this->_parse_arguments($arguments);
                    $_index = count($this->_switch_stack) - 1;
                    if (!$this->_switch_stack[$_index]["matched"]) {
                        $_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '){';
                        $this->_switch_stack[$_index]["matched"] = true;
                    } else {
                        $_result .= 'break; ';
                    }
                    if (!empty($_args['value'])) {
                        $_result .= 'case ' . $_args['value'] . ': ';
                    } else {
                        $_result .= 'default: ';
                    }
                    return $_result . ' ?>';
                } else {
                    $this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
                }
                break;
            default:
                $_result = "";
                if ($this->_compile_compiler_function($function, $arguments, $_result)) {
                    return $_result;
                } else {
                    if ($this->_compile_custom_block($function, $modifiers, $arguments, $_result)) {
                        return $_result;
                    } elseif ($this->_compile_custom_function($function, $modifiers, $arguments, $_result)) {
                        return $_result;
                    } else {
                        $this->trigger_error($function . " function does not exist", E_USER_ERROR, __FILE__, __LINE__);
                    }
                }
                break;
        }
    }
Exemplo n.º 3
0
    function _parse_function($function, $arguments, $bundle_var_only = false)
    {
        switch ($function) {
            case 't':
            case '/t':
                return;
            case 'ldelim':
                return $this->left_delimiter;
            case 'rdelim':
                return $this->right_delimiter;
            case 'dump':
                $args = $this->_parse_arguments($arguments, false);
                return '<?php var_' . 'dump(' . $args['var'] . '); ?>';
            case 'foreachelse':
                return "<?php }else{ ?>";
            case 'break':
            case 'continue':
                return '<?php ' . $function . '; ?>';
                break;
            case 'if':
                $arguments = $this->_arguments_if($arguments, $bundle_var_only);
                if ($bundle_var_only) {
                    eval('$arguments=(' . $arguments . ');');
                    $this->_if_stack = ($arguments ? '106' : '206') . $this->_if_stack;
                    return;
                } else {
                    $this->_if_stack = '000' . $this->_if_stack;
                    return '<?php if(' . $arguments . '){ ?>';
                }
            case 'else':
                if ($this->_if_stack[1] == '5') {
                    $this->_if_stack[0] = '2';
                    return;
                } elseif ($this->_if_stack[0] == '0') {
                    $this->_if_stack[1] = '5';
                    return '<?php }else{ ?>';
                } elseif ($this->_if_stack[0] == '1') {
                    $this->_if_stack[0] = '2';
                    $this->_if_stack[1] = '5';
                    return;
                } elseif ($this->_if_stack[0] == '2') {
                    $this->_if_stack[0] = '1';
                    return;
                }
            case 'elseif':
                if ($this->_if_stack[1] == '5') {
                    $this->_if_stack[0] = '2';
                    return;
                } elseif ($this->_if_stack[0] == '0') {
                    //之前存在if判断
                    $arguments = $this->_arguments_if($arguments, $bundle_var_only);
                    if ($bundle_var_only) {
                        eval('$arguments=(' . $arguments . ');');
                        if ($arguments) {
                            return $this->_parse_function('else', $arguments, $bundle_var_only);
                        } else {
                            $this->_if_stack[0] = '2';
                            $this->_if_stack[2] = '6';
                            return;
                        }
                    } else {
                        return '<?php }elseif(' . $arguments . '){ ?>';
                    }
                } elseif ($this->_if_stack[0] == '2') {
                    //之前为否
                    $this->_parse_function('/if', $arguments, $bundle_var_only);
                    return $this->_parse_function('if', $arguments, $bundle_var_only);
                } elseif ($this->_if_stack[0] == '1') {
                    //之前为绝对是, 禁掉今后所有
                    return $this->_parse_function('else', $arguments, $bundle_var_only);
                }
            case '/if':
                if ($this->_if_stack[2] == '6') {
                    $_result = '';
                } else {
                    $_result = '<?php } ?>';
                }
                $this->_if_stack = isset($this->_if_stack[5]) ? substr($this->_if_stack, 3) : '';
                return $_result;
            case 'foreach':
                $_args = $this->_parse_arguments($arguments, $bundle_var_only);
                if (!isset($_args['from'])) {
                    $this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
                }
                if (!isset($_args['value']) && !isset($_args['item'])) {
                    $this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
                }
                if (isset($_args['value'])) {
                    $_args['value'] = $this->_dequote($_args['value']);
                } elseif (isset($_args['item'])) {
                    $_args['value'] = $this->_dequote($_args['item']);
                }
                isset($_args['key']) ? $_args['key'] = "\$this->_vars['" . $this->_dequote($_args['key']) . "'] => " : ($_args['key'] = '');
                if ($_args['name']) {
                    array_push($this->_foreachelse_stack, $_args['name']);
                    $_result = '<?php $this->_env_vars[\'foreach\'][' . $_args['name'] . ']=array(\'total\'=>count(' . $_args['from'] . '),\'iteration\'=>0);foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']){
                    $this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'first\'] = ($this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'iteration\']==0);
                    $this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'iteration\']++;
                    $this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'last\'] = ($this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'iteration\']==$this->_env_vars[\'foreach\'][' . $_args['name'] . '][\'total\']);
?>';
                } else {
                    array_push($this->_foreachelse_stack, false);
                    $_result = '<?php foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']){ ?>';
                }
                return $_result;
            case '/foreach':
                if ($name = array_pop($this->_foreachelse_stack)) {
                    return '<?php } unset($this->_env_vars[\'foreach\'][' . $name . ']); ?>';
                } else {
                    return '<?php } ?>';
                }
            case 'literal':
            case 'for':
            case '/for':
            case 'section':
            case 'sectionelse':
            case '/section':
            case 'while':
            case '/while':
                return;
            case 'switch':
                $_args = $this->_parse_arguments($arguments, $bundle_var_only);
                if (!isset($_args['from'])) {
                    $this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
                }
                array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
                return;
            case '/switch':
                array_pop($this->_switch_stack);
                return '<?php break; endswitch; ?>';
            case 'case':
                if (count($this->_switch_stack) > 0) {
                    $_result = "<?php ";
                    $_args = $this->_parse_arguments($arguments, $bundle_var_only);
                    $_index = count($this->_switch_stack) - 1;
                    if (!$this->_switch_stack[$_index]["matched"]) {
                        $_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '): ';
                        $this->_switch_stack[$_index]["matched"] = true;
                    } else {
                        $_result .= 'break; ';
                    }
                    if (!empty($_args['value'])) {
                        $_result .= 'case ' . $_args['value'] . ': ';
                    } else {
                        $_result .= 'default: ';
                    }
                    return $_result . ' ?>';
                } else {
                    $this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
                }
                break;
            case 'assign':
                $_args = $this->_parse_arguments($arguments, $bundle_var_only);
                if (!isset($_args['var'])) {
                    $this->trigger_error("missing 'var' attribute in 'pagedata'", E_USER_ERROR, __FILE__, __LINE__);
                }
                if (!isset($_args['value'])) {
                    $this->trigger_error("missing 'value' attribute in 'pagedata'", E_USER_ERROR, __FILE__, __LINE__);
                }
                if (false === $_args['value']) {
                    $_args['value'] = 'false';
                } elseif (null === $_args['value']) {
                    $_args['value'] = 'null';
                } elseif ('' === $_args['value']) {
                    $_args['value'] = '';
                }
                return '<?php $this->_vars[' . $_args['var'] . ']=' . $_args['value'] . '; ?>';
            case 'include':
                if (!function_exists('compile_include')) {
                    require CORE_INCLUDE_DIR . "/template/compile.include.php";
                }
                return compile_include($arguments, $this);
            default:
                $_result = "";
                if ($this->_compile_compiler_function($function, $arguments, $bundle_var_only, $_result)) {
                    return $_result;
                } elseif ($this->_compile_custom_block($function, $arguments, $_result)) {
                    return $_result;
                } elseif ($this->_compile_custom_function($function, $arguments, $_result)) {
                    return $_result;
                } else {
                    $this->trigger_error($function . " function does not exist", E_USER_ERROR, __FILE__, __LINE__);
                }
        }
    }
Exemplo n.º 4
0
 function _parse_function($function, $modifiers, $arguments)
 {
     if (strpos($function, 'iCMS:') !== false) {
         list($function, $module) = explode(':', $function);
     }
     switch ($function) {
         case 'include':
             if (!function_exists('compile_include')) {
                 include_once TEMPLATE_LITE_DIR . "internal/compile.include.php";
             }
             return compile_include($arguments, $this);
             break;
         case 'iCMS':
             $arguments .= ' module="' . $module . '"';
             $_args = $this->_parse_arguments($arguments);
             //				if(isset($_args['loop'])){
             //					$_args['loop']=in_array(strtolower($this->_dequote($_args['loop'])),array("y","yes",'true'))?true:false;
             //				}else{
             //					$_args['loop']=in_array(strtolower($module),array("list","catalog"))?true:false;
             //				}
             if ($module && isset($_args['loop'])) {
                 //2.0
                 //				if(isset($_args['module'])&&in_array($this->_dequote($_args['module']),$this->config['Loop_Module'])){//3.0
                 //				if(isset($_args['module'])){//3.0
                 $arguments = '';
                 //					$_args['loop'] && $arguments.="name=".str_replace('"','',str_replace("'",'',$_args['loop']))." ";
                 $arguments .= "loop=\$" . (isset($_args['alias']) ? $this->_dequote($_args['alias']) : $this->_dequote($_args['module']));
                 isset($_args['start']) && ($arguments .= " start={$_args['start']} ");
                 isset($_args['step']) && ($arguments .= " step={$_args['step']} ");
                 isset($_args['max']) && ($arguments .= " max={$_args['max']} ");
                 //	isset($_args['show']) && $arguments.='show="'.$_args['show'].'" ';
                 if (!function_exists('compile_iCMS')) {
                     include_once TEMPLATE_LITE_DIR . "internal/compile.iCMS.php";
                 }
                 $_iCMS_Loop = compile_iCMS($arguments, $this);
             }
             if (!isset($_args['module'])) {
                 $this->trigger_error("missing 'module' attribute in 'iCMS'", E_USER_ERROR, __FILE__, __LINE__);
             }
             foreach ($_args as $key => $value) {
                 if (is_bool($value)) {
                     $value = $value ? 'true' : 'false';
                 }
                 $arg_list[] = "'{$key}' => {$value}";
             }
             return '<?php $this->_run_iCMS(array(' . implode(', ', (array) $arg_list) . ')); ?>' . $_iCMS_Loop;
             break;
         case 'iCMSelse':
             $this->_iCMSelse_stack[count($this->_iCMSelse_stack) - 1] = true;
             return "<?php }}else{ ?>";
             break;
         case '/iCMS':
             if (array_pop($this->_iCMSelse_stack)) {
                 return "<?php }?>";
             } else {
                 return "<?php }}?>";
             }
             break;
         case 'ldelim':
             return $this->left_delimiter;
             break;
         case 'rdelim':
             return $this->right_delimiter;
             break;
         case 'literal':
             list(, $literal) = each($this->_literal);
             $this->_linenum += substr_count($literal, "\n");
             return "<?php echo '" . str_replace("'", "\\'", str_replace("\\", "\\\\", $literal)) . "'; ?>";
             break;
         case 'php':
             list(, $php_block) = each($this->_php_blocks);
             //¹ýÂËPHP 2007-7-23 0:13
             if ($this->php_handling != "iCMS_PHP_ALLOW") {
                 return htmlspecialchars($php_extract . '<?php ' . $php_block . ' ?>');
                 break;
             }
             //¹ýÂËPHP 2007-7-23 0:13
             $this->_linenum += substr_count($php_block, "\n");
             $php_extract = '';
             if ($this->php_extract_vars) {
                 if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
                     $php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n";
                 } else {
                     $php_extract = '<?php extract($this->_vars); ?>' . "\n";
                 }
             }
             return $php_extract . '<?php ' . $php_block . ' ?>';
             break;
         case 'foreach':
             array_push($this->_foreachelse_stack, false);
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value']) && !isset($_args['item'])) {
                 $this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (isset($_args['value'])) {
                 $_args['value'] = $this->_dequote($_args['value']);
             } elseif (isset($_args['item'])) {
                 $_args['value'] = $this->_dequote($_args['item']);
             }
             isset($_args['key']) ? $_args['key'] = "\$this->_vars['" . $this->_dequote($_args['key']) . "'] => " : ($_args['key'] = '');
             $_result = '<?php if (count((array)' . $_args['from'] . ')){ foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']){ ?>';
             return $_result;
             break;
         case 'foreachelse':
             $this->_foreachelse_stack[count($this->_foreachelse_stack) - 1] = true;
             return "<?php }}else{ ?>";
             break;
         case '/foreach':
             if (array_pop($this->_foreachelse_stack)) {
                 return "<?php } ?>";
             } else {
                 return "<?php }} ?>";
             }
             break;
         case 'for':
             $this->_for_stack++;
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['start'])) {
                 $this->trigger_error("missing 'start' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['stop'])) {
                 $this->trigger_error("missing 'stop' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['step'])) {
                 $_args['step'] = 1;
             }
             $_result = '<?php for($for' . $this->_for_stack . ' = ' . $_args['start'] . '; ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ($for' . $this->_for_stack . ' < ' . $_args['stop'] . ') : ($for' . $this->_for_stack . ' > ' . $_args['stop'] . ')); $for' . $this->_for_stack . ' += ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ' . $_args['step'] . ' : -' . $_args['step'] . ')){ ?>';
             if (isset($_args['value'])) {
                 $_result .= '<?php $this->assign(\'' . $this->_dequote($_args['value']) . '\', $for' . $this->_for_stack . '); ?>';
             }
             return $_result;
             break;
         case '/for':
             $this->_for_stack--;
             return "<?php } ?>";
             break;
         case 'section':
             array_push($this->_sectionelse_stack, false);
             if (!function_exists('compile_section_start')) {
                 require_once TEMPLATE_LITE_DIR . "internal/compile.section_start.php";
             }
             return compile_section_start($arguments, $this);
             break;
         case 'sectionelse':
             $this->_sectionelse_stack[count($this->_sectionelse_stack) - 1] = true;
             return "<?php endfor; else: ?>";
             break;
         case '/section':
             if (array_pop($this->_sectionelse_stack)) {
                 return "<?php endif; ?>";
             } else {
                 return "<?php endfor; endif; ?>";
             }
             break;
         case 'while':
             $_args = $this->_compile_if($arguments, false, true);
             return '<?php while(' . $_args . '){ ?>';
             break;
         case '/while':
             return "<?php } ?>";
             break;
         case 'if':
             return $this->_compile_if($arguments);
             break;
         case 'else':
             return "<?php else: ?>";
             break;
         case 'elseif':
             return $this->_compile_if($arguments, true);
             break;
         case '/if':
             return "<?php endif; ?>";
             break;
         case 'assign':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['var'])) {
                 $this->trigger_error("missing 'var' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value'])) {
                 $this->trigger_error("missing 'value' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             return '<?php $this->assign(\'' . $this->_dequote($_args['var']) . '\', ' . $_args['value'] . '); ?>';
             break;
         case 'switch':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
             return;
             break;
         case '/switch':
             array_pop($this->_switch_stack);
             return '<?php break; endswitch; ?>';
             break;
         case 'case':
             if (count($this->_switch_stack) > 0) {
                 $_result = "<?php ";
                 $_args = $this->_parse_arguments($arguments);
                 $_index = count($this->_switch_stack) - 1;
                 if (!$this->_switch_stack[$_index]["matched"]) {
                     $_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '): ';
                     $this->_switch_stack[$_index]["matched"] = true;
                 } else {
                     $_result .= 'break; ';
                 }
                 if (!empty($_args['value'])) {
                     $_result .= 'case ' . $_args['value'] . ': ';
                 } else {
                     $_result .= 'default: ';
                 }
                 return $_result . ' ?>';
             } else {
                 $this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             break;
         default:
             $_result = "";
             if ($this->_compile_compiler_function($function, $arguments, $_result)) {
                 return $_result;
             } else {
                 if ($this->_compile_custom_block($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } elseif ($this->_compile_custom_function($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } else {
                     $this->trigger_error($function . " function does not exist", E_USER_ERROR, __FILE__, __LINE__);
                 }
             }
             break;
     }
 }
Exemplo n.º 5
0
 function _parse_function($function, $modifiers, $arguments)
 {
     if (strpos($function, 'ZYM:') !== false) {
         //zhaoyanmin 将DreamCMS改成ZYM
         list($function, $module) = explode(':', $function);
     }
     switch ($function) {
         case 'include':
             if (!function_exists('compile_include')) {
                 include_once TEMPLATE_LITE_DIR . "internal/compile.include.php";
             }
             return compile_include($arguments, $this);
             break;
         case 'ZYM':
             //zhaoyanmin 将DeramCMS改成ZYM
             $arguments .= ' module="' . $module . '"';
             $_args = $this->_parse_arguments($arguments);
             //				if(isset($_args['loop'])){
             //					$_args['loop']=in_array(strtolower($this->_dequote($_args['loop'])),array("y","yes",'true'))?true:false;
             //				}else{
             //					$_args['loop']=in_array(strtolower($module),array("list","catalog"))?true:false;
             //				}
             if ($module && isset($_args['loop'])) {
                 //2.0
                 //				if(isset($_args['module'])&&in_array($this->_dequote($_args['module']),$this->config['Loop_Module'])){//3.0
                 //				if(isset($_args['module'])){//3.0
                 $arguments = '';
                 //					$_args['loop'] && $arguments.="name=".str_replace('"','',str_replace("'",'',$_args['loop']))." ";
                 $arguments .= "loop=\$" . (isset($_args['alias']) ? $this->_dequote($_args['alias']) : $this->_dequote($_args['module']));
                 isset($_args['start']) && ($arguments .= "start={$_args['start']} ");
                 isset($_args['step']) && ($arguments .= "step={$_args['step']} ");
                 isset($_args['max']) && ($arguments .= "max={$_args['max']} ");
                 //	isset($_args['show']) && $arguments.='show="'.$_args['show'].'" ';
                 if (!function_exists('compile_dreamcms')) {
                     include_once TEMPLATE_LITE_DIR . "internal/compile.dreamcms.php";
                 }
                 $_DreamCMS_Loop = compile_dreamcms($arguments, $this);
             }
             if (!isset($_args['module'])) {
                 $this->trigger_error("missing 'module' attribute in 'DreamCMS'", E_USER_ERROR, __FILE__, __LINE__);
             }
             foreach ($_args as $key => $value) {
                 if (is_bool($value)) {
                     $value = $value ? 'true' : 'false';
                 }
                 //$arg_list[] = "'$key' => $value";
                 //zhaoyanmin start
                 $valuestr = substr($value, 0, 1);
                 if ($valuestr !== '"' && $valuestr !== '$' && $valuestr !== "'") {
                     //$valuestr !== '"' 双引号中(传值中)写变量;$valuestr !== '$'单值传的时候除外; $valuestr !== "'"要想变量起作用,必须用""
                     $arg_list[] = "'{$key}' => \"" . trim(trim($value), '"') . "\"";
                 } else {
                     $arg_list[] = "'{$key}' => {$value}";
                 }
                 //zhaoyanmin end
             }
             return '<?php $this->_run_DreamCMS(array(' . implode(', ', (array) $arg_list) . ')); ?>' . $_DreamCMS_Loop;
             break;
         case 'ZYMelse':
             //zhaoyanmin 将DeramCMS改成ZYM
             $this->_DreamCMSelse_stack[count($this->_DreamCMSelse_stack) - 1] = true;
             return "<?php }}else{ ?>";
             break;
         case '/ZYM':
             //zhaoyanmin 将DeramCMS改成ZYM
             if (array_pop($this->_DreamCMSelse_stack)) {
                 return "<?php }?>";
             } else {
                 return "<?php }}?>";
             }
             break;
         case 'ldelim':
             return $this->left_delimiter;
             break;
         case 'rdelim':
             return $this->right_delimiter;
             break;
         case 'literal':
             list(, $literal) = each($this->_literal);
             $this->_linenum += substr_count($literal, "\n");
             return "<?php echo '" . str_replace("'", "\\'", str_replace("\\", "\\\\", $literal)) . "'; ?>";
             break;
         case 'php':
             list(, $php_block) = each($this->_php_blocks);
             //过滤PHP 2007-7-23 0:13
             if ($this->php_handling != "DreamCMS_PHP_ALLOW") {
                 return htmlspecialchars($php_extract . '<?php ' . $php_block . ' ?>');
                 break;
             }
             //过滤PHP 2007-7-23 0:13
             $this->_linenum += substr_count($php_block, "\n");
             $php_extract = '';
             if ($this->php_extract_vars) {
                 if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
                     $php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n";
                 } else {
                     $php_extract = '<?php extract($this->_vars); ?>' . "\n";
                 }
             }
             return $php_extract . '<?php ' . $php_block . ' ?>';
             break;
         case 'm_php':
             //此用法每个值和符号之间必须用空格隔开
             /*$_args = $this->_parse_arguments($arguments);
             		if($_args && is_array($_args)){
             			foreach($_args as $key=>$val){
             				$this->assign($key,$val);
             				$key = trim(trim($key),'$') ;
             				if($key){
             					$this->_vars[$key] = $val  ;
             				}
             			}
             		}*/
             $_result = "<?php ";
             if ($arguments) {
                 $arguments_arr = explode(' ', $arguments);
                 if ($arguments_arr && is_array($arguments_arr)) {
                     foreach ($arguments_arr as $key => $val) {
                         if ($val == '=') {
                             $_result .= " = ";
                         } elseif (strpos($val, '=') !== false) {
                             //包含等号
                             $dengarr = explode('=', $val);
                             if ($dengarr && is_array($dengarr)) {
                                 $deng_result = '';
                                 foreach ($dengarr as $keydeng => $valdeng) {
                                     if (strpos($valdeng, '$') !== false) {
                                         $valthis = str_replace('$', "\$this->_vars['", $valdeng) . "']";
                                         if (strpos($valthis, '.') !== false) {
                                             //用等号分割后包含.(点)
                                             $valthis = str_replace('.', "']['", $valthis);
                                         }
                                         $deng_result .= "=" . $valthis;
                                     } else {
                                         $deng_result .= "=" . $valdeng;
                                     }
                                 }
                                 $_result .= " " . trim($deng_result, '=') . " ";
                             }
                         } elseif (strpos($val, '$') !== false) {
                             //包含$--变量没有等号
                             $valthis = str_replace('$', "\$this->_vars['", $val) . "']";
                             if (strpos($val, '.') !== false) {
                                 //包含.(点)
                                 $valthis .= str_replace('.', "']['", $valthis);
                             }
                             $_result .= " " . $valthis;
                         } else {
                             $_result .= " " . $val;
                         }
                     }
                 }
             }
             $_result .= " ?>";
             return $_result;
             break;
         case 'foreach':
             array_push($this->_foreachelse_stack, false);
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value']) && !isset($_args['item'])) {
                 $this->trigger_error("missing 'value' attribute in 'foreach'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (isset($_args['value'])) {
                 $_args['value'] = $this->_dequote($_args['value']);
             } elseif (isset($_args['item'])) {
                 $_args['value'] = $this->_dequote($_args['item']);
             }
             isset($_args['key']) ? $_args['key'] = "\$this->_vars['" . $this->_dequote($_args['key']) . "'] => " : ($_args['key'] = '');
             $_result = '<?php if (count((array)' . $_args['from'] . ')){ foreach ((array)' . $_args['from'] . ' as ' . $_args['key'] . '$this->_vars[\'' . $_args['value'] . '\']){ ?>';
             return $_result;
             break;
         case 'foreachelse':
             $this->_foreachelse_stack[count($this->_foreachelse_stack) - 1] = true;
             return "<?php }}else{ ?>";
             break;
         case '/foreach':
             if (array_pop($this->_foreachelse_stack)) {
                 return "<?php } ?>";
             } else {
                 return "<?php }} ?>";
             }
             break;
         case 'for':
             $this->_for_stack++;
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['start'])) {
                 $this->trigger_error("missing 'start' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['stop'])) {
                 $this->trigger_error("missing 'stop' attribute in 'for'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['step'])) {
                 $_args['step'] = 1;
             }
             $_result = '<?php for($for' . $this->_for_stack . ' = ' . $_args['start'] . '; ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ($for' . $this->_for_stack . ' < ' . $_args['stop'] . ') : ($for' . $this->_for_stack . ' > ' . $_args['stop'] . ')); $for' . $this->_for_stack . ' += ((' . $_args['start'] . ' < ' . $_args['stop'] . ') ? ' . $_args['step'] . ' : -' . $_args['step'] . ')){ ?>';
             if (isset($_args['value'])) {
                 $_result .= '<?php $this->assign(\'' . $this->_dequote($_args['value']) . '\', $for' . $this->_for_stack . '); ?>';
             }
             return $_result;
             break;
         case '/for':
             $this->_for_stack--;
             return "<?php } ?>";
             break;
         case 'section':
             array_push($this->_sectionelse_stack, false);
             if (!function_exists('compile_section_start')) {
                 require_once TEMPLATE_LITE_DIR . "internal/compile.section_start.php";
             }
             return compile_section_start($arguments, $this);
             break;
         case 'sectionelse':
             $this->_sectionelse_stack[count($this->_sectionelse_stack) - 1] = true;
             return "<?php endfor; else: ?>";
             break;
         case '/section':
             if (array_pop($this->_sectionelse_stack)) {
                 return "<?php endif; ?>";
             } else {
                 return "<?php endfor; endif; ?>";
             }
             break;
         case 'while':
             $_args = $this->_compile_if($arguments, false, true);
             return '<?php while(' . $_args . '){ ?>';
             break;
         case '/while':
             return "<?php } ?>";
             break;
         case 'if':
             return $this->_compile_if($arguments);
             break;
         case 'else':
             return "<?php else: ?>";
             break;
         case 'elseif':
             return $this->_compile_if($arguments, true);
             break;
         case '/if':
             return "<?php endif; ?>";
             break;
         case 'assign':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['var'])) {
                 $this->trigger_error("missing 'var' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             if (!isset($_args['value'])) {
                 $this->trigger_error("missing 'value' attribute in 'assign'", E_USER_ERROR, __FILE__, __LINE__);
             }
             return '<?php $this->assign(\'' . $this->_dequote($_args['var']) . '\', ' . $_args['value'] . '); ?>';
             break;
         case 'switch':
             $_args = $this->_parse_arguments($arguments);
             if (!isset($_args['from'])) {
                 $this->trigger_error("missing 'from' attribute in 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             array_push($this->_switch_stack, array("matched" => false, "var" => $this->_dequote($_args['from'])));
             return;
             break;
         case '/switch':
             array_pop($this->_switch_stack);
             return '<?php break; endswitch; ?>';
             break;
         case 'case':
             if (count($this->_switch_stack) > 0) {
                 $_result = "<?php ";
                 $_args = $this->_parse_arguments($arguments);
                 $_index = count($this->_switch_stack) - 1;
                 if (!$this->_switch_stack[$_index]["matched"]) {
                     $_result .= 'switch(' . $this->_switch_stack[$_index]["var"] . '): ';
                     $this->_switch_stack[$_index]["matched"] = true;
                 } else {
                     $_result .= 'break; ';
                 }
                 if (!empty($_args['value'])) {
                     $_result .= 'case ' . $_args['value'] . ': ';
                 } else {
                     $_result .= 'default: ';
                 }
                 return $_result . ' ?>';
             } else {
                 $this->trigger_error("unexpected 'case', 'case' can only be in a 'switch'", E_USER_ERROR, __FILE__, __LINE__);
             }
             break;
         default:
             $_result = "";
             if ($this->_compile_compiler_function($function, $arguments, $_result)) {
                 return $_result;
             } else {
                 if ($this->_compile_custom_block($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } elseif ($this->_compile_custom_function($function, $modifiers, $arguments, $_result)) {
                     return $_result;
                 } else {
                     $this->trigger_error($function . " function does not exist", E_USER_ERROR, __FILE__, __LINE__);
                 }
             }
             break;
     }
 }