source: branches/0.4/web/addons/job_monarch/dwoo/plugins/builtin/blocks/auto_escape.php @ 755

Last change on this file since 755 was 755, checked in by ramonb, 11 years ago
  • add Dwoo
File size: 1.7 KB
Line 
1<?php
2
3/**
4 * Overrides the compiler auto-escape setting within the block
5 * <pre>
6 *  * enabled : if set to "on", "enable", true or 1 then the compiler autoescaping is enabled inside this block. set to "off", "disable", false or 0 to disable it
7 * </pre>
8 * This software is provided 'as-is', without any express or implied warranty.
9 * In no event will the authors be held liable for any damages arising from the use of this software.
10 *
11 * @author     Jordi Boggiano <j.boggiano@seld.be>
12 * @copyright  Copyright (c) 2008, Jordi Boggiano
13 * @license    http://dwoo.org/LICENSE   Modified BSD License
14 * @link       http://dwoo.org/
15 * @version    1.0.0
16 * @date       2008-10-23
17 * @package    Dwoo
18 */
19class Dwoo_Plugin_auto_escape extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
20{
21        protected static $stack = array();
22
23        public function init($enabled)
24        {
25        }
26
27        public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
28        {
29                $params = $compiler->getCompiledParams($params);
30                switch(strtolower(trim((string) $params['enabled'], '"\''))) {
31
32                case 'on':
33                case 'true':
34                case 'enabled':
35                case 'enable':
36                case '1':
37                        $enable = true;
38                        break;
39                case 'off':
40                case 'false':
41                case 'disabled':
42                case 'disable':
43                case '0':
44                        $enable = false;
45                        break;
46                default:
47                        throw new Dwoo_Compilation_Exception($compiler, 'Auto_Escape : Invalid parameter ('.$params['enabled'].'), valid parameters are "enable"/true or "disable"/false');
48
49                }
50
51                self::$stack[] = $compiler->getAutoEscape();
52                $compiler->setAutoEscape($enable);
53                return '';
54        }
55
56        public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
57        {
58                $compiler->setAutoEscape(array_pop(self::$stack));
59                return $content;
60        }
61}
Note: See TracBrowser for help on using the repository browser.