|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Filter |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: HtmlEntities.php 21060 2010-02-15 21:56:07Z thomas $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Filter_Interface |
|
24 */ |
|
25 require_once 'Zend/Filter/Interface.php'; |
|
26 |
|
27 /** |
|
28 * @category Zend |
|
29 * @package Zend_Filter |
|
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
32 */ |
|
33 class Zend_Filter_HtmlEntities implements Zend_Filter_Interface |
|
34 { |
|
35 /** |
|
36 * Corresponds to the second htmlentities() argument |
|
37 * |
|
38 * @var integer |
|
39 */ |
|
40 protected $_quoteStyle; |
|
41 |
|
42 /** |
|
43 * Corresponds to the third htmlentities() argument |
|
44 * |
|
45 * @var string |
|
46 */ |
|
47 protected $_encoding; |
|
48 |
|
49 /** |
|
50 * Corresponds to the forth htmlentities() argument |
|
51 * |
|
52 * @var unknown_type |
|
53 */ |
|
54 protected $_doubleQuote; |
|
55 |
|
56 /** |
|
57 * Sets filter options |
|
58 * |
|
59 * @param integer|array $quoteStyle |
|
60 * @param string $charSet |
|
61 * @return void |
|
62 */ |
|
63 public function __construct($options = array()) |
|
64 { |
|
65 if ($options instanceof Zend_Config) { |
|
66 $options = $options->toArray(); |
|
67 } else if (!is_array($options)) { |
|
68 $options = func_get_args(); |
|
69 $temp['quotestyle'] = array_shift($options); |
|
70 if (!empty($options)) { |
|
71 $temp['charset'] = array_shift($options); |
|
72 } |
|
73 |
|
74 $options = $temp; |
|
75 } |
|
76 |
|
77 if (!isset($options['quotestyle'])) { |
|
78 $options['quotestyle'] = ENT_COMPAT; |
|
79 } |
|
80 |
|
81 if (!isset($options['encoding'])) { |
|
82 $options['encoding'] = 'UTF-8'; |
|
83 } |
|
84 if (isset($options['charset'])) { |
|
85 $options['encoding'] = $options['charset']; |
|
86 } |
|
87 |
|
88 if (!isset($options['doublequote'])) { |
|
89 $options['doublequote'] = true; |
|
90 } |
|
91 |
|
92 $this->setQuoteStyle($options['quotestyle']); |
|
93 $this->setEncoding($options['encoding']); |
|
94 $this->setDoubleQuote($options['doublequote']); |
|
95 } |
|
96 |
|
97 /** |
|
98 * Returns the quoteStyle option |
|
99 * |
|
100 * @return integer |
|
101 */ |
|
102 public function getQuoteStyle() |
|
103 { |
|
104 return $this->_quoteStyle; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Sets the quoteStyle option |
|
109 * |
|
110 * @param integer $quoteStyle |
|
111 * @return Zend_Filter_HtmlEntities Provides a fluent interface |
|
112 */ |
|
113 public function setQuoteStyle($quoteStyle) |
|
114 { |
|
115 $this->_quoteStyle = $quoteStyle; |
|
116 return $this; |
|
117 } |
|
118 |
|
119 |
|
120 /** |
|
121 * Get encoding |
|
122 * |
|
123 * @return string |
|
124 */ |
|
125 public function getEncoding() |
|
126 { |
|
127 return $this->_encoding; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Set encoding |
|
132 * |
|
133 * @param string $value |
|
134 * @return Zend_Filter_HtmlEntities |
|
135 */ |
|
136 public function setEncoding($value) |
|
137 { |
|
138 $this->_encoding = (string) $value; |
|
139 return $this; |
|
140 } |
|
141 |
|
142 /** |
|
143 * Returns the charSet option |
|
144 * |
|
145 * Proxies to {@link getEncoding()} |
|
146 * |
|
147 * @return string |
|
148 */ |
|
149 public function getCharSet() |
|
150 { |
|
151 return $this->getEncoding(); |
|
152 } |
|
153 |
|
154 /** |
|
155 * Sets the charSet option |
|
156 * |
|
157 * Proxies to {@link setEncoding()} |
|
158 * |
|
159 * @param string $charSet |
|
160 * @return Zend_Filter_HtmlEntities Provides a fluent interface |
|
161 */ |
|
162 public function setCharSet($charSet) |
|
163 { |
|
164 return $this->setEncoding($charSet); |
|
165 } |
|
166 |
|
167 /** |
|
168 * Returns the doubleQuote option |
|
169 * |
|
170 * @return boolean |
|
171 */ |
|
172 public function getDoubleQuote() |
|
173 { |
|
174 return $this->_doubleQuote; |
|
175 } |
|
176 |
|
177 /** |
|
178 * Sets the doubleQuote option |
|
179 * |
|
180 * @param boolean $doubleQuote |
|
181 * @return Zend_Filter_HtmlEntities Provides a fluent interface |
|
182 */ |
|
183 public function setDoubleQuote($doubleQuote) |
|
184 { |
|
185 $this->_doubleQuote = (boolean) $doubleQuote; |
|
186 return $this; |
|
187 } |
|
188 |
|
189 /** |
|
190 * Defined by Zend_Filter_Interface |
|
191 * |
|
192 * Returns the string $value, converting characters to their corresponding HTML entity |
|
193 * equivalents where they exist |
|
194 * |
|
195 * @param string $value |
|
196 * @return string |
|
197 */ |
|
198 public function filter($value) |
|
199 { |
|
200 return htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote()); |
|
201 } |
|
202 } |