1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * This file is part of Twig. |
---|
5 | * |
---|
6 | * (c) 2009 Fabien Potencier |
---|
7 | * |
---|
8 | * For the full copyright and license information, please view the LICENSE |
---|
9 | * file that was distributed with this source code. |
---|
10 | */ |
---|
11 | class Twig_Extension_Escaper extends Twig_Extension |
---|
12 | { |
---|
13 | protected $autoescape; |
---|
14 | |
---|
15 | public function __construct($autoescape = true) |
---|
16 | { |
---|
17 | $this->autoescape = $autoescape; |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * Returns the token parser instances to add to the existing list. |
---|
22 | * |
---|
23 | * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances |
---|
24 | */ |
---|
25 | public function getTokenParsers() |
---|
26 | { |
---|
27 | return array(new Twig_TokenParser_AutoEscape()); |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|
31 | * Returns the node visitor instances to add to the existing list. |
---|
32 | * |
---|
33 | * @return array An array of Twig_NodeVisitorInterface instances |
---|
34 | */ |
---|
35 | public function getNodeVisitors() |
---|
36 | { |
---|
37 | return array(new Twig_NodeVisitor_Escaper()); |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * Returns a list of filters to add to the existing list. |
---|
42 | * |
---|
43 | * @return array An array of filters |
---|
44 | */ |
---|
45 | public function getFilters() |
---|
46 | { |
---|
47 | return array( |
---|
48 | 'raw' => new Twig_Filter_Function('twig_raw_filter', array('is_safe' => array('all'))), |
---|
49 | ); |
---|
50 | } |
---|
51 | |
---|
52 | public function isGlobal() |
---|
53 | { |
---|
54 | return $this->autoescape; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Returns the name of the extension. |
---|
59 | * |
---|
60 | * @return string The extension name |
---|
61 | */ |
---|
62 | public function getName() |
---|
63 | { |
---|
64 | return 'escaper'; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | // tells the escaper node visitor that the string is safe |
---|
69 | function twig_raw_filter($string) |
---|
70 | { |
---|
71 | return $string; |
---|
72 | } |
---|
73 | |
---|