@@ -98,7 +98,6 @@ |
||
98 | 98 | * @param string $pubkey A public key for reCAPTCHA |
99 | 99 | * @param string $error The error given by reCAPTCHA (optional, default is null) |
100 | 100 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) |
101 | - |
|
102 | 101 | * @return string - The HTML to be embedded in the user's form. |
103 | 102 | */ |
104 | 103 | function recaptcha_get_html($pubkey, $error = null, $use_ssl = false) |
@@ -37,419 +37,419 @@ |
||
37 | 37 | */ |
38 | 38 | class SmartyBC extends Smarty |
39 | 39 | { |
40 | - /** |
|
41 | - * Smarty 2 BC |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $_version = self::SMARTY_VERSION; |
|
46 | - |
|
47 | - /** |
|
48 | - * This is an array of directories where trusted php scripts reside. |
|
49 | - * |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - public $trusted_dir = array(); |
|
53 | - |
|
54 | - /** |
|
55 | - * Initialize new SmartyBC object |
|
56 | - * |
|
57 | - */ |
|
58 | - public function __construct() |
|
59 | - { |
|
60 | - parent::__construct(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * wrapper for assign_by_ref |
|
65 | - * |
|
66 | - * @param string $tpl_var the template variable name |
|
67 | - * @param mixed &$value the referenced value to assign |
|
68 | - */ |
|
69 | - public function assign_by_ref($tpl_var, &$value) |
|
70 | - { |
|
71 | - $this->assignByRef($tpl_var, $value); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * wrapper for append_by_ref |
|
76 | - * |
|
77 | - * @param string $tpl_var the template variable name |
|
78 | - * @param mixed &$value the referenced value to append |
|
79 | - * @param boolean $merge flag if array elements shall be merged |
|
80 | - */ |
|
81 | - public function append_by_ref($tpl_var, &$value, $merge = false) |
|
82 | - { |
|
83 | - $this->appendByRef($tpl_var, $value, $merge); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * clear the given assigned template variable. |
|
88 | - * |
|
89 | - * @param string $tpl_var the template variable to clear |
|
90 | - */ |
|
91 | - public function clear_assign($tpl_var) |
|
92 | - { |
|
93 | - $this->clearAssign($tpl_var); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Registers custom function to be used in templates |
|
98 | - * |
|
99 | - * @param string $function the name of the template function |
|
100 | - * @param string $function_impl the name of the PHP function to register |
|
101 | - * @param bool $cacheable |
|
102 | - * @param mixed $cache_attrs |
|
103 | - */ |
|
104 | - public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null) |
|
105 | - { |
|
106 | - $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Unregister custom function |
|
111 | - * |
|
112 | - * @param string $function name of template function |
|
113 | - */ |
|
114 | - public function unregister_function($function) |
|
115 | - { |
|
116 | - $this->unregisterPlugin('function', $function); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Registers object to be used in templates |
|
121 | - * |
|
122 | - * @param string $object name of template object |
|
123 | - * @param object $object_impl the referenced PHP object to register |
|
124 | - * @param array $allowed list of allowed methods (empty = all) |
|
125 | - * @param boolean $smarty_args smarty argument format, else traditional |
|
126 | - * @param array $block_methods list of methods that are block format |
|
127 | - * |
|
128 | - * @throws SmartyException |
|
129 | - * @internal param array $block_functs list of methods that are block format |
|
130 | - */ |
|
131 | - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, |
|
132 | - $block_methods = array()) |
|
133 | - { |
|
134 | - settype($allowed, 'array'); |
|
135 | - settype($smarty_args, 'boolean'); |
|
136 | - $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Unregister object |
|
141 | - * |
|
142 | - * @param string $object name of template object |
|
143 | - */ |
|
144 | - public function unregister_object($object) |
|
145 | - { |
|
146 | - $this->unregisterObject($object); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Registers block function to be used in templates |
|
151 | - * |
|
152 | - * @param string $block name of template block |
|
153 | - * @param string $block_impl PHP function to register |
|
154 | - * @param bool $cacheable |
|
155 | - * @param mixed $cache_attrs |
|
156 | - */ |
|
157 | - public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null) |
|
158 | - { |
|
159 | - $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Unregister block function |
|
164 | - * |
|
165 | - * @param string $block name of template function |
|
166 | - */ |
|
167 | - public function unregister_block($block) |
|
168 | - { |
|
169 | - $this->unregisterPlugin('block', $block); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Registers compiler function |
|
174 | - * |
|
175 | - * @param string $function name of template function |
|
176 | - * @param string $function_impl name of PHP function to register |
|
177 | - * @param bool $cacheable |
|
178 | - */ |
|
179 | - public function register_compiler_function($function, $function_impl, $cacheable = true) |
|
180 | - { |
|
181 | - $this->registerPlugin('compiler', $function, $function_impl, $cacheable); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Unregister compiler function |
|
186 | - * |
|
187 | - * @param string $function name of template function |
|
188 | - */ |
|
189 | - public function unregister_compiler_function($function) |
|
190 | - { |
|
191 | - $this->unregisterPlugin('compiler', $function); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Registers modifier to be used in templates |
|
196 | - * |
|
197 | - * @param string $modifier name of template modifier |
|
198 | - * @param string $modifier_impl name of PHP function to register |
|
199 | - */ |
|
200 | - public function register_modifier($modifier, $modifier_impl) |
|
201 | - { |
|
202 | - $this->registerPlugin('modifier', $modifier, $modifier_impl); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Unregister modifier |
|
207 | - * |
|
208 | - * @param string $modifier name of template modifier |
|
209 | - */ |
|
210 | - public function unregister_modifier($modifier) |
|
211 | - { |
|
212 | - $this->unregisterPlugin('modifier', $modifier); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Registers a resource to fetch a template |
|
217 | - * |
|
218 | - * @param string $type name of resource |
|
219 | - * @param array $functions array of functions to handle resource |
|
220 | - */ |
|
221 | - public function register_resource($type, $functions) |
|
222 | - { |
|
223 | - $this->registerResource($type, $functions); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Unregister a resource |
|
228 | - * |
|
229 | - * @param string $type name of resource |
|
230 | - */ |
|
231 | - public function unregister_resource($type) |
|
232 | - { |
|
233 | - $this->unregisterResource($type); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Registers a prefilter function to apply |
|
238 | - * to a template before compiling |
|
239 | - * |
|
240 | - * @param callable $function |
|
241 | - */ |
|
242 | - public function register_prefilter($function) |
|
243 | - { |
|
244 | - $this->registerFilter('pre', $function); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Unregister a prefilter function |
|
249 | - * |
|
250 | - * @param callable $function |
|
251 | - */ |
|
252 | - public function unregister_prefilter($function) |
|
253 | - { |
|
254 | - $this->unregisterFilter('pre', $function); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Registers a postfilter function to apply |
|
259 | - * to a compiled template after compilation |
|
260 | - * |
|
261 | - * @param callable $function |
|
262 | - */ |
|
263 | - public function register_postfilter($function) |
|
264 | - { |
|
265 | - $this->registerFilter('post', $function); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Unregister a postfilter function |
|
270 | - * |
|
271 | - * @param callable $function |
|
272 | - */ |
|
273 | - public function unregister_postfilter($function) |
|
274 | - { |
|
275 | - $this->unregisterFilter('post', $function); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Registers an output filter function to apply |
|
280 | - * to a template output |
|
281 | - * |
|
282 | - * @param callable $function |
|
283 | - */ |
|
284 | - public function register_outputfilter($function) |
|
285 | - { |
|
286 | - $this->registerFilter('output', $function); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Unregister an outputfilter function |
|
291 | - * |
|
292 | - * @param callable $function |
|
293 | - */ |
|
294 | - public function unregister_outputfilter($function) |
|
295 | - { |
|
296 | - $this->unregisterFilter('output', $function); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * load a filter of specified type and name |
|
301 | - * |
|
302 | - * @param string $type filter type |
|
303 | - * @param string $name filter name |
|
304 | - */ |
|
305 | - public function load_filter($type, $name) |
|
306 | - { |
|
307 | - $this->loadFilter($type, $name); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * clear cached content for the given template and cache id |
|
312 | - * |
|
313 | - * @param string $tpl_file name of template file |
|
314 | - * @param string $cache_id name of cache_id |
|
315 | - * @param string $compile_id name of compile_id |
|
316 | - * @param string $exp_time expiration time |
|
317 | - * |
|
318 | - * @return boolean |
|
319 | - */ |
|
320 | - public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) |
|
321 | - { |
|
322 | - return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * clear the entire contents of cache (all templates) |
|
327 | - * |
|
328 | - * @param string $exp_time expire time |
|
329 | - * |
|
330 | - * @return boolean |
|
331 | - */ |
|
332 | - public function clear_all_cache($exp_time = null) |
|
333 | - { |
|
334 | - return $this->clearCache(null, null, null, $exp_time); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * test to see if valid cache exists for this template |
|
339 | - * |
|
340 | - * @param string $tpl_file name of template file |
|
341 | - * @param string $cache_id |
|
342 | - * @param string $compile_id |
|
343 | - * |
|
344 | - * @return boolean |
|
345 | - */ |
|
346 | - public function is_cached($tpl_file, $cache_id = null, $compile_id = null) |
|
347 | - { |
|
348 | - return $this->isCached($tpl_file, $cache_id, $compile_id); |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * clear all the assigned template variables. |
|
353 | - */ |
|
354 | - public function clear_all_assign() |
|
355 | - { |
|
356 | - $this->clearAllAssign(); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * clears compiled version of specified template resource, |
|
361 | - * or all compiled template files if one is not specified. |
|
362 | - * This function is for advanced use only, not normally needed. |
|
363 | - * |
|
364 | - * @param string $tpl_file |
|
365 | - * @param string $compile_id |
|
366 | - * @param string $exp_time |
|
367 | - * |
|
368 | - * @return boolean results of {@link smarty_core_rm_auto()} |
|
369 | - */ |
|
370 | - public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) |
|
371 | - { |
|
372 | - return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Checks whether requested template exists. |
|
377 | - * |
|
378 | - * @param string $tpl_file |
|
379 | - * |
|
380 | - * @return boolean |
|
381 | - */ |
|
382 | - public function template_exists($tpl_file) |
|
383 | - { |
|
384 | - return $this->templateExists($tpl_file); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Returns an array containing template variables |
|
389 | - * |
|
390 | - * @param string $name |
|
391 | - * |
|
392 | - * @return array |
|
393 | - */ |
|
394 | - public function get_template_vars($name = null) |
|
395 | - { |
|
396 | - return $this->getTemplateVars($name); |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Returns an array containing config variables |
|
401 | - * |
|
402 | - * @param string $name |
|
403 | - * |
|
404 | - * @return array |
|
405 | - */ |
|
406 | - public function get_config_vars($name = null) |
|
407 | - { |
|
408 | - return $this->getConfigVars($name); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * load configuration values |
|
413 | - * |
|
414 | - * @param string $file |
|
415 | - * @param string $section |
|
416 | - * @param string $scope |
|
417 | - */ |
|
418 | - public function config_load($file, $section = null, $scope = 'global') |
|
419 | - { |
|
420 | - $this->ConfigLoad($file, $section, $scope); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * return a reference to a registered object |
|
425 | - * |
|
426 | - * @param string $name |
|
427 | - * |
|
428 | - * @return object |
|
429 | - */ |
|
430 | - public function get_registered_object($name) |
|
431 | - { |
|
432 | - return $this->getRegisteredObject($name); |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * clear configuration values |
|
437 | - * |
|
438 | - * @param string $var |
|
439 | - */ |
|
440 | - public function clear_config($var = null) |
|
441 | - { |
|
442 | - $this->clearConfig($var); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * trigger Smarty error |
|
447 | - * |
|
448 | - * @param string $error_msg |
|
449 | - * @param integer $error_type |
|
450 | - */ |
|
451 | - public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
452 | - { |
|
453 | - trigger_error("Smarty error: $error_msg", $error_type); |
|
454 | - } |
|
40 | + /** |
|
41 | + * Smarty 2 BC |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $_version = self::SMARTY_VERSION; |
|
46 | + |
|
47 | + /** |
|
48 | + * This is an array of directories where trusted php scripts reside. |
|
49 | + * |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + public $trusted_dir = array(); |
|
53 | + |
|
54 | + /** |
|
55 | + * Initialize new SmartyBC object |
|
56 | + * |
|
57 | + */ |
|
58 | + public function __construct() |
|
59 | + { |
|
60 | + parent::__construct(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * wrapper for assign_by_ref |
|
65 | + * |
|
66 | + * @param string $tpl_var the template variable name |
|
67 | + * @param mixed &$value the referenced value to assign |
|
68 | + */ |
|
69 | + public function assign_by_ref($tpl_var, &$value) |
|
70 | + { |
|
71 | + $this->assignByRef($tpl_var, $value); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * wrapper for append_by_ref |
|
76 | + * |
|
77 | + * @param string $tpl_var the template variable name |
|
78 | + * @param mixed &$value the referenced value to append |
|
79 | + * @param boolean $merge flag if array elements shall be merged |
|
80 | + */ |
|
81 | + public function append_by_ref($tpl_var, &$value, $merge = false) |
|
82 | + { |
|
83 | + $this->appendByRef($tpl_var, $value, $merge); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * clear the given assigned template variable. |
|
88 | + * |
|
89 | + * @param string $tpl_var the template variable to clear |
|
90 | + */ |
|
91 | + public function clear_assign($tpl_var) |
|
92 | + { |
|
93 | + $this->clearAssign($tpl_var); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Registers custom function to be used in templates |
|
98 | + * |
|
99 | + * @param string $function the name of the template function |
|
100 | + * @param string $function_impl the name of the PHP function to register |
|
101 | + * @param bool $cacheable |
|
102 | + * @param mixed $cache_attrs |
|
103 | + */ |
|
104 | + public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null) |
|
105 | + { |
|
106 | + $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Unregister custom function |
|
111 | + * |
|
112 | + * @param string $function name of template function |
|
113 | + */ |
|
114 | + public function unregister_function($function) |
|
115 | + { |
|
116 | + $this->unregisterPlugin('function', $function); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Registers object to be used in templates |
|
121 | + * |
|
122 | + * @param string $object name of template object |
|
123 | + * @param object $object_impl the referenced PHP object to register |
|
124 | + * @param array $allowed list of allowed methods (empty = all) |
|
125 | + * @param boolean $smarty_args smarty argument format, else traditional |
|
126 | + * @param array $block_methods list of methods that are block format |
|
127 | + * |
|
128 | + * @throws SmartyException |
|
129 | + * @internal param array $block_functs list of methods that are block format |
|
130 | + */ |
|
131 | + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, |
|
132 | + $block_methods = array()) |
|
133 | + { |
|
134 | + settype($allowed, 'array'); |
|
135 | + settype($smarty_args, 'boolean'); |
|
136 | + $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Unregister object |
|
141 | + * |
|
142 | + * @param string $object name of template object |
|
143 | + */ |
|
144 | + public function unregister_object($object) |
|
145 | + { |
|
146 | + $this->unregisterObject($object); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Registers block function to be used in templates |
|
151 | + * |
|
152 | + * @param string $block name of template block |
|
153 | + * @param string $block_impl PHP function to register |
|
154 | + * @param bool $cacheable |
|
155 | + * @param mixed $cache_attrs |
|
156 | + */ |
|
157 | + public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null) |
|
158 | + { |
|
159 | + $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Unregister block function |
|
164 | + * |
|
165 | + * @param string $block name of template function |
|
166 | + */ |
|
167 | + public function unregister_block($block) |
|
168 | + { |
|
169 | + $this->unregisterPlugin('block', $block); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Registers compiler function |
|
174 | + * |
|
175 | + * @param string $function name of template function |
|
176 | + * @param string $function_impl name of PHP function to register |
|
177 | + * @param bool $cacheable |
|
178 | + */ |
|
179 | + public function register_compiler_function($function, $function_impl, $cacheable = true) |
|
180 | + { |
|
181 | + $this->registerPlugin('compiler', $function, $function_impl, $cacheable); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Unregister compiler function |
|
186 | + * |
|
187 | + * @param string $function name of template function |
|
188 | + */ |
|
189 | + public function unregister_compiler_function($function) |
|
190 | + { |
|
191 | + $this->unregisterPlugin('compiler', $function); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Registers modifier to be used in templates |
|
196 | + * |
|
197 | + * @param string $modifier name of template modifier |
|
198 | + * @param string $modifier_impl name of PHP function to register |
|
199 | + */ |
|
200 | + public function register_modifier($modifier, $modifier_impl) |
|
201 | + { |
|
202 | + $this->registerPlugin('modifier', $modifier, $modifier_impl); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Unregister modifier |
|
207 | + * |
|
208 | + * @param string $modifier name of template modifier |
|
209 | + */ |
|
210 | + public function unregister_modifier($modifier) |
|
211 | + { |
|
212 | + $this->unregisterPlugin('modifier', $modifier); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Registers a resource to fetch a template |
|
217 | + * |
|
218 | + * @param string $type name of resource |
|
219 | + * @param array $functions array of functions to handle resource |
|
220 | + */ |
|
221 | + public function register_resource($type, $functions) |
|
222 | + { |
|
223 | + $this->registerResource($type, $functions); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Unregister a resource |
|
228 | + * |
|
229 | + * @param string $type name of resource |
|
230 | + */ |
|
231 | + public function unregister_resource($type) |
|
232 | + { |
|
233 | + $this->unregisterResource($type); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Registers a prefilter function to apply |
|
238 | + * to a template before compiling |
|
239 | + * |
|
240 | + * @param callable $function |
|
241 | + */ |
|
242 | + public function register_prefilter($function) |
|
243 | + { |
|
244 | + $this->registerFilter('pre', $function); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Unregister a prefilter function |
|
249 | + * |
|
250 | + * @param callable $function |
|
251 | + */ |
|
252 | + public function unregister_prefilter($function) |
|
253 | + { |
|
254 | + $this->unregisterFilter('pre', $function); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Registers a postfilter function to apply |
|
259 | + * to a compiled template after compilation |
|
260 | + * |
|
261 | + * @param callable $function |
|
262 | + */ |
|
263 | + public function register_postfilter($function) |
|
264 | + { |
|
265 | + $this->registerFilter('post', $function); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Unregister a postfilter function |
|
270 | + * |
|
271 | + * @param callable $function |
|
272 | + */ |
|
273 | + public function unregister_postfilter($function) |
|
274 | + { |
|
275 | + $this->unregisterFilter('post', $function); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Registers an output filter function to apply |
|
280 | + * to a template output |
|
281 | + * |
|
282 | + * @param callable $function |
|
283 | + */ |
|
284 | + public function register_outputfilter($function) |
|
285 | + { |
|
286 | + $this->registerFilter('output', $function); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Unregister an outputfilter function |
|
291 | + * |
|
292 | + * @param callable $function |
|
293 | + */ |
|
294 | + public function unregister_outputfilter($function) |
|
295 | + { |
|
296 | + $this->unregisterFilter('output', $function); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * load a filter of specified type and name |
|
301 | + * |
|
302 | + * @param string $type filter type |
|
303 | + * @param string $name filter name |
|
304 | + */ |
|
305 | + public function load_filter($type, $name) |
|
306 | + { |
|
307 | + $this->loadFilter($type, $name); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * clear cached content for the given template and cache id |
|
312 | + * |
|
313 | + * @param string $tpl_file name of template file |
|
314 | + * @param string $cache_id name of cache_id |
|
315 | + * @param string $compile_id name of compile_id |
|
316 | + * @param string $exp_time expiration time |
|
317 | + * |
|
318 | + * @return boolean |
|
319 | + */ |
|
320 | + public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) |
|
321 | + { |
|
322 | + return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * clear the entire contents of cache (all templates) |
|
327 | + * |
|
328 | + * @param string $exp_time expire time |
|
329 | + * |
|
330 | + * @return boolean |
|
331 | + */ |
|
332 | + public function clear_all_cache($exp_time = null) |
|
333 | + { |
|
334 | + return $this->clearCache(null, null, null, $exp_time); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * test to see if valid cache exists for this template |
|
339 | + * |
|
340 | + * @param string $tpl_file name of template file |
|
341 | + * @param string $cache_id |
|
342 | + * @param string $compile_id |
|
343 | + * |
|
344 | + * @return boolean |
|
345 | + */ |
|
346 | + public function is_cached($tpl_file, $cache_id = null, $compile_id = null) |
|
347 | + { |
|
348 | + return $this->isCached($tpl_file, $cache_id, $compile_id); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * clear all the assigned template variables. |
|
353 | + */ |
|
354 | + public function clear_all_assign() |
|
355 | + { |
|
356 | + $this->clearAllAssign(); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * clears compiled version of specified template resource, |
|
361 | + * or all compiled template files if one is not specified. |
|
362 | + * This function is for advanced use only, not normally needed. |
|
363 | + * |
|
364 | + * @param string $tpl_file |
|
365 | + * @param string $compile_id |
|
366 | + * @param string $exp_time |
|
367 | + * |
|
368 | + * @return boolean results of {@link smarty_core_rm_auto()} |
|
369 | + */ |
|
370 | + public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) |
|
371 | + { |
|
372 | + return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Checks whether requested template exists. |
|
377 | + * |
|
378 | + * @param string $tpl_file |
|
379 | + * |
|
380 | + * @return boolean |
|
381 | + */ |
|
382 | + public function template_exists($tpl_file) |
|
383 | + { |
|
384 | + return $this->templateExists($tpl_file); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Returns an array containing template variables |
|
389 | + * |
|
390 | + * @param string $name |
|
391 | + * |
|
392 | + * @return array |
|
393 | + */ |
|
394 | + public function get_template_vars($name = null) |
|
395 | + { |
|
396 | + return $this->getTemplateVars($name); |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Returns an array containing config variables |
|
401 | + * |
|
402 | + * @param string $name |
|
403 | + * |
|
404 | + * @return array |
|
405 | + */ |
|
406 | + public function get_config_vars($name = null) |
|
407 | + { |
|
408 | + return $this->getConfigVars($name); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * load configuration values |
|
413 | + * |
|
414 | + * @param string $file |
|
415 | + * @param string $section |
|
416 | + * @param string $scope |
|
417 | + */ |
|
418 | + public function config_load($file, $section = null, $scope = 'global') |
|
419 | + { |
|
420 | + $this->ConfigLoad($file, $section, $scope); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * return a reference to a registered object |
|
425 | + * |
|
426 | + * @param string $name |
|
427 | + * |
|
428 | + * @return object |
|
429 | + */ |
|
430 | + public function get_registered_object($name) |
|
431 | + { |
|
432 | + return $this->getRegisteredObject($name); |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * clear configuration values |
|
437 | + * |
|
438 | + * @param string $var |
|
439 | + */ |
|
440 | + public function clear_config($var = null) |
|
441 | + { |
|
442 | + $this->clearConfig($var); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * trigger Smarty error |
|
447 | + * |
|
448 | + * @param string $error_msg |
|
449 | + * @param integer $error_type |
|
450 | + */ |
|
451 | + public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
452 | + { |
|
453 | + trigger_error("Smarty error: $error_msg", $error_type); |
|
454 | + } |
|
455 | 455 | } |
@@ -19,89 +19,89 @@ |
||
19 | 19 | */ |
20 | 20 | class Smarty_Autoloader |
21 | 21 | { |
22 | - /** |
|
23 | - * Filepath to Smarty root |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public static $SMARTY_DIR = ''; |
|
22 | + /** |
|
23 | + * Filepath to Smarty root |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public static $SMARTY_DIR = ''; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Filepath to Smarty internal plugins |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - public static $SMARTY_SYSPLUGINS_DIR = ''; |
|
29 | + /** |
|
30 | + * Filepath to Smarty internal plugins |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + public static $SMARTY_SYSPLUGINS_DIR = ''; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Array with Smarty core classes and their filename |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); |
|
36 | + /** |
|
37 | + * Array with Smarty core classes and their filename |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Registers Smarty_Autoloader backward compatible to older installations. |
|
45 | - * |
|
46 | - * @param bool $prepend Whether to prepend the autoloader or not. |
|
47 | - */ |
|
48 | - public static function registerBC($prepend = false) |
|
49 | - { |
|
50 | - /** |
|
51 | - * register the class autoloader |
|
52 | - */ |
|
53 | - if (!defined('SMARTY_SPL_AUTOLOAD')) { |
|
54 | - define('SMARTY_SPL_AUTOLOAD', 0); |
|
55 | - } |
|
56 | - if (SMARTY_SPL_AUTOLOAD && |
|
57 | - set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false |
|
58 | - ) { |
|
59 | - $registeredAutoLoadFunctions = spl_autoload_functions(); |
|
60 | - if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { |
|
61 | - spl_autoload_register(); |
|
62 | - } |
|
63 | - } else { |
|
64 | - self::register($prepend); |
|
65 | - } |
|
66 | - } |
|
43 | + /** |
|
44 | + * Registers Smarty_Autoloader backward compatible to older installations. |
|
45 | + * |
|
46 | + * @param bool $prepend Whether to prepend the autoloader or not. |
|
47 | + */ |
|
48 | + public static function registerBC($prepend = false) |
|
49 | + { |
|
50 | + /** |
|
51 | + * register the class autoloader |
|
52 | + */ |
|
53 | + if (!defined('SMARTY_SPL_AUTOLOAD')) { |
|
54 | + define('SMARTY_SPL_AUTOLOAD', 0); |
|
55 | + } |
|
56 | + if (SMARTY_SPL_AUTOLOAD && |
|
57 | + set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false |
|
58 | + ) { |
|
59 | + $registeredAutoLoadFunctions = spl_autoload_functions(); |
|
60 | + if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) { |
|
61 | + spl_autoload_register(); |
|
62 | + } |
|
63 | + } else { |
|
64 | + self::register($prepend); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Registers Smarty_Autoloader as an SPL autoloader. |
|
70 | - * |
|
71 | - * @param bool $prepend Whether to prepend the autoloader or not. |
|
72 | - */ |
|
73 | - public static function register($prepend = false) |
|
74 | - { |
|
75 | - self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; |
|
76 | - self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : |
|
77 | - self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; |
|
78 | - if (version_compare(phpversion(), '5.3.0', '>=')) { |
|
79 | - spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); |
|
80 | - } else { |
|
81 | - spl_autoload_register(array(__CLASS__, 'autoload')); |
|
82 | - } |
|
83 | - } |
|
68 | + /** |
|
69 | + * Registers Smarty_Autoloader as an SPL autoloader. |
|
70 | + * |
|
71 | + * @param bool $prepend Whether to prepend the autoloader or not. |
|
72 | + */ |
|
73 | + public static function register($prepend = false) |
|
74 | + { |
|
75 | + self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; |
|
76 | + self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : |
|
77 | + self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; |
|
78 | + if (version_compare(phpversion(), '5.3.0', '>=')) { |
|
79 | + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); |
|
80 | + } else { |
|
81 | + spl_autoload_register(array(__CLASS__, 'autoload')); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Handles auto loading of classes. |
|
87 | - * |
|
88 | - * @param string $class A class name. |
|
89 | - */ |
|
90 | - public static function autoload($class) |
|
91 | - { |
|
92 | - $_class = strtolower($class); |
|
93 | - if (strpos($_class, 'smarty') !== 0) { |
|
94 | - return; |
|
95 | - } |
|
96 | - $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; |
|
97 | - if (is_file($file)) { |
|
98 | - include $file; |
|
99 | - } else if (isset(self::$rootClasses[ $_class ])) { |
|
100 | - $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ]; |
|
101 | - if (is_file($file)) { |
|
102 | - include $file; |
|
103 | - } |
|
104 | - } |
|
105 | - return; |
|
106 | - } |
|
85 | + /** |
|
86 | + * Handles auto loading of classes. |
|
87 | + * |
|
88 | + * @param string $class A class name. |
|
89 | + */ |
|
90 | + public static function autoload($class) |
|
91 | + { |
|
92 | + $_class = strtolower($class); |
|
93 | + if (strpos($_class, 'smarty') !== 0) { |
|
94 | + return; |
|
95 | + } |
|
96 | + $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; |
|
97 | + if (is_file($file)) { |
|
98 | + include $file; |
|
99 | + } else if (isset(self::$rootClasses[ $_class ])) { |
|
100 | + $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ]; |
|
101 | + if (is_file($file)) { |
|
102 | + include $file; |
|
103 | + } |
|
104 | + } |
|
105 | + return; |
|
106 | + } |
|
107 | 107 | } |
@@ -17,5 +17,5 @@ |
||
17 | 17 | */ |
18 | 18 | function smarty_modifiercompiler_noprint() |
19 | 19 | { |
20 | - return "''"; |
|
20 | + return "''"; |
|
21 | 21 | } |
@@ -35,170 +35,170 @@ |
||
35 | 35 | */ |
36 | 36 | function smarty_function_html_options($params) |
37 | 37 | { |
38 | - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); |
|
39 | - |
|
40 | - $name = null; |
|
41 | - $values = null; |
|
42 | - $options = null; |
|
43 | - $selected = null; |
|
44 | - $output = null; |
|
45 | - $id = null; |
|
46 | - $class = null; |
|
47 | - |
|
48 | - $extra = ''; |
|
49 | - |
|
50 | - foreach ($params as $_key => $_val) { |
|
51 | - switch ($_key) { |
|
52 | - case 'name': |
|
53 | - case 'class': |
|
54 | - case 'id': |
|
55 | - $$_key = (string) $_val; |
|
56 | - break; |
|
57 | - |
|
58 | - case 'options': |
|
59 | - $options = (array) $_val; |
|
60 | - break; |
|
61 | - |
|
62 | - case 'values': |
|
63 | - case 'output': |
|
64 | - $$_key = array_values((array) $_val); |
|
65 | - break; |
|
66 | - |
|
67 | - case 'selected': |
|
68 | - if (is_array($_val)) { |
|
69 | - $selected = array(); |
|
70 | - foreach ($_val as $_sel) { |
|
71 | - if (is_object($_sel)) { |
|
72 | - if (method_exists($_sel, "__toString")) { |
|
73 | - $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); |
|
74 | - } else { |
|
75 | - trigger_error("html_options: selected attribute contains an object of class '" . |
|
76 | - get_class($_sel) . "' without __toString() method", E_USER_NOTICE); |
|
77 | - continue; |
|
78 | - } |
|
79 | - } else { |
|
80 | - $_sel = smarty_function_escape_special_chars((string) $_sel); |
|
81 | - } |
|
82 | - $selected[ $_sel ] = true; |
|
83 | - } |
|
84 | - } elseif (is_object($_val)) { |
|
85 | - if (method_exists($_val, "__toString")) { |
|
86 | - $selected = smarty_function_escape_special_chars((string) $_val->__toString()); |
|
87 | - } else { |
|
88 | - trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) . |
|
89 | - "' without __toString() method", E_USER_NOTICE); |
|
90 | - } |
|
91 | - } else { |
|
92 | - $selected = smarty_function_escape_special_chars((string) $_val); |
|
93 | - } |
|
94 | - break; |
|
95 | - |
|
96 | - case 'strict': |
|
97 | - break; |
|
98 | - |
|
99 | - case 'disabled': |
|
100 | - case 'readonly': |
|
101 | - if (!empty($params[ 'strict' ])) { |
|
102 | - if (!is_scalar($_val)) { |
|
103 | - trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", |
|
104 | - E_USER_NOTICE); |
|
105 | - } |
|
106 | - |
|
107 | - if ($_val === true || $_val === $_key) { |
|
108 | - $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; |
|
109 | - } |
|
110 | - |
|
111 | - break; |
|
112 | - } |
|
113 | - // omit break; to fall through! |
|
114 | - |
|
115 | - default: |
|
116 | - if (!is_array($_val)) { |
|
117 | - $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; |
|
118 | - } else { |
|
119 | - trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); |
|
120 | - } |
|
121 | - break; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - if (!isset($options) && !isset($values)) { |
|
126 | - /* raise error here? */ |
|
127 | - |
|
128 | - return ''; |
|
129 | - } |
|
130 | - |
|
131 | - $_html_result = ''; |
|
132 | - $_idx = 0; |
|
133 | - |
|
134 | - if (isset($options)) { |
|
135 | - foreach ($options as $_key => $_val) { |
|
136 | - $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); |
|
137 | - } |
|
138 | - } else { |
|
139 | - foreach ($values as $_i => $_key) { |
|
140 | - $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; |
|
141 | - $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - if (!empty($name)) { |
|
146 | - $_html_class = !empty($class) ? ' class="' . $class . '"' : ''; |
|
147 | - $_html_id = !empty($id) ? ' id="' . $id . '"' : ''; |
|
148 | - $_html_result = |
|
149 | - '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . |
|
150 | - '</select>' . "\n"; |
|
151 | - } |
|
152 | - |
|
153 | - return $_html_result; |
|
38 | + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); |
|
39 | + |
|
40 | + $name = null; |
|
41 | + $values = null; |
|
42 | + $options = null; |
|
43 | + $selected = null; |
|
44 | + $output = null; |
|
45 | + $id = null; |
|
46 | + $class = null; |
|
47 | + |
|
48 | + $extra = ''; |
|
49 | + |
|
50 | + foreach ($params as $_key => $_val) { |
|
51 | + switch ($_key) { |
|
52 | + case 'name': |
|
53 | + case 'class': |
|
54 | + case 'id': |
|
55 | + $$_key = (string) $_val; |
|
56 | + break; |
|
57 | + |
|
58 | + case 'options': |
|
59 | + $options = (array) $_val; |
|
60 | + break; |
|
61 | + |
|
62 | + case 'values': |
|
63 | + case 'output': |
|
64 | + $$_key = array_values((array) $_val); |
|
65 | + break; |
|
66 | + |
|
67 | + case 'selected': |
|
68 | + if (is_array($_val)) { |
|
69 | + $selected = array(); |
|
70 | + foreach ($_val as $_sel) { |
|
71 | + if (is_object($_sel)) { |
|
72 | + if (method_exists($_sel, "__toString")) { |
|
73 | + $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); |
|
74 | + } else { |
|
75 | + trigger_error("html_options: selected attribute contains an object of class '" . |
|
76 | + get_class($_sel) . "' without __toString() method", E_USER_NOTICE); |
|
77 | + continue; |
|
78 | + } |
|
79 | + } else { |
|
80 | + $_sel = smarty_function_escape_special_chars((string) $_sel); |
|
81 | + } |
|
82 | + $selected[ $_sel ] = true; |
|
83 | + } |
|
84 | + } elseif (is_object($_val)) { |
|
85 | + if (method_exists($_val, "__toString")) { |
|
86 | + $selected = smarty_function_escape_special_chars((string) $_val->__toString()); |
|
87 | + } else { |
|
88 | + trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) . |
|
89 | + "' without __toString() method", E_USER_NOTICE); |
|
90 | + } |
|
91 | + } else { |
|
92 | + $selected = smarty_function_escape_special_chars((string) $_val); |
|
93 | + } |
|
94 | + break; |
|
95 | + |
|
96 | + case 'strict': |
|
97 | + break; |
|
98 | + |
|
99 | + case 'disabled': |
|
100 | + case 'readonly': |
|
101 | + if (!empty($params[ 'strict' ])) { |
|
102 | + if (!is_scalar($_val)) { |
|
103 | + trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", |
|
104 | + E_USER_NOTICE); |
|
105 | + } |
|
106 | + |
|
107 | + if ($_val === true || $_val === $_key) { |
|
108 | + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; |
|
109 | + } |
|
110 | + |
|
111 | + break; |
|
112 | + } |
|
113 | + // omit break; to fall through! |
|
114 | + |
|
115 | + default: |
|
116 | + if (!is_array($_val)) { |
|
117 | + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; |
|
118 | + } else { |
|
119 | + trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); |
|
120 | + } |
|
121 | + break; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + if (!isset($options) && !isset($values)) { |
|
126 | + /* raise error here? */ |
|
127 | + |
|
128 | + return ''; |
|
129 | + } |
|
130 | + |
|
131 | + $_html_result = ''; |
|
132 | + $_idx = 0; |
|
133 | + |
|
134 | + if (isset($options)) { |
|
135 | + foreach ($options as $_key => $_val) { |
|
136 | + $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); |
|
137 | + } |
|
138 | + } else { |
|
139 | + foreach ($values as $_i => $_key) { |
|
140 | + $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; |
|
141 | + $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + if (!empty($name)) { |
|
146 | + $_html_class = !empty($class) ? ' class="' . $class . '"' : ''; |
|
147 | + $_html_id = !empty($id) ? ' id="' . $id . '"' : ''; |
|
148 | + $_html_result = |
|
149 | + '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . |
|
150 | + '</select>' . "\n"; |
|
151 | + } |
|
152 | + |
|
153 | + return $_html_result; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx) |
157 | 157 | { |
158 | - if (!is_array($value)) { |
|
159 | - $_key = smarty_function_escape_special_chars($key); |
|
160 | - $_html_result = '<option value="' . $_key . '"'; |
|
161 | - if (is_array($selected)) { |
|
162 | - if (isset($selected[ $_key ])) { |
|
163 | - $_html_result .= ' selected="selected"'; |
|
164 | - } |
|
165 | - } elseif ($_key === $selected) { |
|
166 | - $_html_result .= ' selected="selected"'; |
|
167 | - } |
|
168 | - $_html_class = !empty($class) ? ' class="' . $class . ' option"' : ''; |
|
169 | - $_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : ''; |
|
170 | - if (is_object($value)) { |
|
171 | - if (method_exists($value, "__toString")) { |
|
172 | - $value = smarty_function_escape_special_chars((string) $value->__toString()); |
|
173 | - } else { |
|
174 | - trigger_error("html_options: value is an object of class '" . get_class($value) . |
|
175 | - "' without __toString() method", E_USER_NOTICE); |
|
176 | - |
|
177 | - return ''; |
|
178 | - } |
|
179 | - } else { |
|
180 | - $value = smarty_function_escape_special_chars((string) $value); |
|
181 | - } |
|
182 | - $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n"; |
|
183 | - $idx ++; |
|
184 | - } else { |
|
185 | - $_idx = 0; |
|
186 | - $_html_result = |
|
187 | - smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, |
|
188 | - $class, $_idx); |
|
189 | - $idx ++; |
|
190 | - } |
|
191 | - |
|
192 | - return $_html_result; |
|
158 | + if (!is_array($value)) { |
|
159 | + $_key = smarty_function_escape_special_chars($key); |
|
160 | + $_html_result = '<option value="' . $_key . '"'; |
|
161 | + if (is_array($selected)) { |
|
162 | + if (isset($selected[ $_key ])) { |
|
163 | + $_html_result .= ' selected="selected"'; |
|
164 | + } |
|
165 | + } elseif ($_key === $selected) { |
|
166 | + $_html_result .= ' selected="selected"'; |
|
167 | + } |
|
168 | + $_html_class = !empty($class) ? ' class="' . $class . ' option"' : ''; |
|
169 | + $_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : ''; |
|
170 | + if (is_object($value)) { |
|
171 | + if (method_exists($value, "__toString")) { |
|
172 | + $value = smarty_function_escape_special_chars((string) $value->__toString()); |
|
173 | + } else { |
|
174 | + trigger_error("html_options: value is an object of class '" . get_class($value) . |
|
175 | + "' without __toString() method", E_USER_NOTICE); |
|
176 | + |
|
177 | + return ''; |
|
178 | + } |
|
179 | + } else { |
|
180 | + $value = smarty_function_escape_special_chars((string) $value); |
|
181 | + } |
|
182 | + $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n"; |
|
183 | + $idx ++; |
|
184 | + } else { |
|
185 | + $_idx = 0; |
|
186 | + $_html_result = |
|
187 | + smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, |
|
188 | + $class, $_idx); |
|
189 | + $idx ++; |
|
190 | + } |
|
191 | + |
|
192 | + return $_html_result; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | function smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx) |
196 | 196 | { |
197 | - $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; |
|
198 | - foreach ($values as $key => $value) { |
|
199 | - $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx); |
|
200 | - } |
|
201 | - $optgroup_html .= "</optgroup>\n"; |
|
197 | + $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; |
|
198 | + foreach ($values as $key => $value) { |
|
199 | + $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx); |
|
200 | + } |
|
201 | + $optgroup_html .= "</optgroup>\n"; |
|
202 | 202 | |
203 | - return $optgroup_html; |
|
203 | + return $optgroup_html; |
|
204 | 204 | } |
@@ -25,9 +25,9 @@ |
||
25 | 25 | |
26 | 26 | function smarty_modifiercompiler_strip($params) |
27 | 27 | { |
28 | - if (!isset($params[ 1 ])) { |
|
29 | - $params[ 1 ] = "' '"; |
|
30 | - } |
|
28 | + if (!isset($params[ 1 ])) { |
|
29 | + $params[ 1 ] = "' '"; |
|
30 | + } |
|
31 | 31 | |
32 | - return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; |
|
32 | + return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; |
|
33 | 33 | } |
@@ -24,198 +24,198 @@ |
||
24 | 24 | */ |
25 | 25 | function smarty_function_fetch($params, $template) |
26 | 26 | { |
27 | - if (empty($params[ 'file' ])) { |
|
28 | - trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE); |
|
29 | - |
|
30 | - return; |
|
31 | - } |
|
32 | - |
|
33 | - // strip file protocol |
|
34 | - if (stripos($params[ 'file' ], 'file://') === 0) { |
|
35 | - $params[ 'file' ] = substr($params[ 'file' ], 7); |
|
36 | - } |
|
37 | - |
|
38 | - $protocol = strpos($params[ 'file' ], '://'); |
|
39 | - if ($protocol !== false) { |
|
40 | - $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); |
|
41 | - } |
|
42 | - |
|
43 | - if (isset($template->smarty->security_policy)) { |
|
44 | - if ($protocol) { |
|
45 | - // remote resource (or php stream, …) |
|
46 | - if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) { |
|
47 | - return; |
|
48 | - } |
|
49 | - } else { |
|
50 | - // local file |
|
51 | - if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) { |
|
52 | - return; |
|
53 | - } |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - $content = ''; |
|
58 | - if ($protocol == 'http') { |
|
59 | - // http fetch |
|
60 | - if ($uri_parts = parse_url($params[ 'file' ])) { |
|
61 | - // set defaults |
|
62 | - $host = $server_name = $uri_parts[ 'host' ]; |
|
63 | - $timeout = 30; |
|
64 | - $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
65 | - $agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION; |
|
66 | - $referer = ""; |
|
67 | - $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/'; |
|
68 | - $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : ''; |
|
69 | - $_is_proxy = false; |
|
70 | - if (empty($uri_parts[ 'port' ])) { |
|
71 | - $port = 80; |
|
72 | - } else { |
|
73 | - $port = $uri_parts[ 'port' ]; |
|
74 | - } |
|
75 | - if (!empty($uri_parts[ 'user' ])) { |
|
76 | - $user = $uri_parts[ 'user' ]; |
|
77 | - } |
|
78 | - if (!empty($uri_parts[ 'pass' ])) { |
|
79 | - $pass = $uri_parts[ 'pass' ]; |
|
80 | - } |
|
81 | - // loop through parameters, setup headers |
|
82 | - foreach ($params as $param_key => $param_value) { |
|
83 | - switch ($param_key) { |
|
84 | - case "file": |
|
85 | - case "assign": |
|
86 | - case "assign_headers": |
|
87 | - break; |
|
88 | - case "user": |
|
89 | - if (!empty($param_value)) { |
|
90 | - $user = $param_value; |
|
91 | - } |
|
92 | - break; |
|
93 | - case "pass": |
|
94 | - if (!empty($param_value)) { |
|
95 | - $pass = $param_value; |
|
96 | - } |
|
97 | - break; |
|
98 | - case "accept": |
|
99 | - if (!empty($param_value)) { |
|
100 | - $accept = $param_value; |
|
101 | - } |
|
102 | - break; |
|
103 | - case "header": |
|
104 | - if (!empty($param_value)) { |
|
105 | - if (!preg_match('![\w\d-]+: .+!', $param_value)) { |
|
106 | - trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE); |
|
107 | - |
|
108 | - return; |
|
109 | - } else { |
|
110 | - $extra_headers[] = $param_value; |
|
111 | - } |
|
112 | - } |
|
113 | - break; |
|
114 | - case "proxy_host": |
|
115 | - if (!empty($param_value)) { |
|
116 | - $proxy_host = $param_value; |
|
117 | - } |
|
118 | - break; |
|
119 | - case "proxy_port": |
|
120 | - if (!preg_match('!\D!', $param_value)) { |
|
121 | - $proxy_port = (int) $param_value; |
|
122 | - } else { |
|
123 | - trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE); |
|
124 | - |
|
125 | - return; |
|
126 | - } |
|
127 | - break; |
|
128 | - case "agent": |
|
129 | - if (!empty($param_value)) { |
|
130 | - $agent = $param_value; |
|
131 | - } |
|
132 | - break; |
|
133 | - case "referer": |
|
134 | - if (!empty($param_value)) { |
|
135 | - $referer = $param_value; |
|
136 | - } |
|
137 | - break; |
|
138 | - case "timeout": |
|
139 | - if (!preg_match('!\D!', $param_value)) { |
|
140 | - $timeout = (int) $param_value; |
|
141 | - } else { |
|
142 | - trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE); |
|
143 | - |
|
144 | - return; |
|
145 | - } |
|
146 | - break; |
|
147 | - default: |
|
148 | - trigger_error("[plugin] unrecognized attribute '" . $param_key . "'", E_USER_NOTICE); |
|
149 | - |
|
150 | - return; |
|
151 | - } |
|
152 | - } |
|
153 | - if (!empty($proxy_host) && !empty($proxy_port)) { |
|
154 | - $_is_proxy = true; |
|
155 | - $fp = fsockopen($proxy_host, $proxy_port, $errno, $errstr, $timeout); |
|
156 | - } else { |
|
157 | - $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); |
|
158 | - } |
|
159 | - |
|
160 | - if (!$fp) { |
|
161 | - trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); |
|
162 | - |
|
163 | - return; |
|
164 | - } else { |
|
165 | - if ($_is_proxy) { |
|
166 | - fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n"); |
|
167 | - } else { |
|
168 | - fputs($fp, "GET $uri HTTP/1.0\r\n"); |
|
169 | - } |
|
170 | - if (!empty($host)) { |
|
171 | - fputs($fp, "Host: $host\r\n"); |
|
172 | - } |
|
173 | - if (!empty($accept)) { |
|
174 | - fputs($fp, "Accept: $accept\r\n"); |
|
175 | - } |
|
176 | - if (!empty($agent)) { |
|
177 | - fputs($fp, "User-Agent: $agent\r\n"); |
|
178 | - } |
|
179 | - if (!empty($referer)) { |
|
180 | - fputs($fp, "Referer: $referer\r\n"); |
|
181 | - } |
|
182 | - if (isset($extra_headers) && is_array($extra_headers)) { |
|
183 | - foreach ($extra_headers as $curr_header) { |
|
184 | - fputs($fp, $curr_header . "\r\n"); |
|
185 | - } |
|
186 | - } |
|
187 | - if (!empty($user) && !empty($pass)) { |
|
188 | - fputs($fp, "Authorization: BASIC " . base64_encode("$user:$pass") . "\r\n"); |
|
189 | - } |
|
190 | - |
|
191 | - fputs($fp, "\r\n"); |
|
192 | - while (!feof($fp)) { |
|
193 | - $content .= fgets($fp, 4096); |
|
194 | - } |
|
195 | - fclose($fp); |
|
196 | - $csplit = preg_split("!\r\n\r\n!", $content, 2); |
|
197 | - |
|
198 | - $content = $csplit[ 1 ]; |
|
199 | - |
|
200 | - if (!empty($params[ 'assign_headers' ])) { |
|
201 | - $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); |
|
202 | - } |
|
203 | - } |
|
204 | - } else { |
|
205 | - trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); |
|
206 | - |
|
207 | - return; |
|
208 | - } |
|
209 | - } else { |
|
210 | - $content = @file_get_contents($params[ 'file' ]); |
|
211 | - if ($content === false) { |
|
212 | - throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - if (!empty($params[ 'assign' ])) { |
|
217 | - $template->assign($params[ 'assign' ], $content); |
|
218 | - } else { |
|
219 | - return $content; |
|
220 | - } |
|
27 | + if (empty($params[ 'file' ])) { |
|
28 | + trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE); |
|
29 | + |
|
30 | + return; |
|
31 | + } |
|
32 | + |
|
33 | + // strip file protocol |
|
34 | + if (stripos($params[ 'file' ], 'file://') === 0) { |
|
35 | + $params[ 'file' ] = substr($params[ 'file' ], 7); |
|
36 | + } |
|
37 | + |
|
38 | + $protocol = strpos($params[ 'file' ], '://'); |
|
39 | + if ($protocol !== false) { |
|
40 | + $protocol = strtolower(substr($params[ 'file' ], 0, $protocol)); |
|
41 | + } |
|
42 | + |
|
43 | + if (isset($template->smarty->security_policy)) { |
|
44 | + if ($protocol) { |
|
45 | + // remote resource (or php stream, …) |
|
46 | + if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) { |
|
47 | + return; |
|
48 | + } |
|
49 | + } else { |
|
50 | + // local file |
|
51 | + if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) { |
|
52 | + return; |
|
53 | + } |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + $content = ''; |
|
58 | + if ($protocol == 'http') { |
|
59 | + // http fetch |
|
60 | + if ($uri_parts = parse_url($params[ 'file' ])) { |
|
61 | + // set defaults |
|
62 | + $host = $server_name = $uri_parts[ 'host' ]; |
|
63 | + $timeout = 30; |
|
64 | + $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
65 | + $agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION; |
|
66 | + $referer = ""; |
|
67 | + $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/'; |
|
68 | + $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : ''; |
|
69 | + $_is_proxy = false; |
|
70 | + if (empty($uri_parts[ 'port' ])) { |
|
71 | + $port = 80; |
|
72 | + } else { |
|
73 | + $port = $uri_parts[ 'port' ]; |
|
74 | + } |
|
75 | + if (!empty($uri_parts[ 'user' ])) { |
|
76 | + $user = $uri_parts[ 'user' ]; |
|
77 | + } |
|
78 | + if (!empty($uri_parts[ 'pass' ])) { |
|
79 | + $pass = $uri_parts[ 'pass' ]; |
|
80 | + } |
|
81 | + // loop through parameters, setup headers |
|
82 | + foreach ($params as $param_key => $param_value) { |
|
83 | + switch ($param_key) { |
|
84 | + case "file": |
|
85 | + case "assign": |
|
86 | + case "assign_headers": |
|
87 | + break; |
|
88 | + case "user": |
|
89 | + if (!empty($param_value)) { |
|
90 | + $user = $param_value; |
|
91 | + } |
|
92 | + break; |
|
93 | + case "pass": |
|
94 | + if (!empty($param_value)) { |
|
95 | + $pass = $param_value; |
|
96 | + } |
|
97 | + break; |
|
98 | + case "accept": |
|
99 | + if (!empty($param_value)) { |
|
100 | + $accept = $param_value; |
|
101 | + } |
|
102 | + break; |
|
103 | + case "header": |
|
104 | + if (!empty($param_value)) { |
|
105 | + if (!preg_match('![\w\d-]+: .+!', $param_value)) { |
|
106 | + trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE); |
|
107 | + |
|
108 | + return; |
|
109 | + } else { |
|
110 | + $extra_headers[] = $param_value; |
|
111 | + } |
|
112 | + } |
|
113 | + break; |
|
114 | + case "proxy_host": |
|
115 | + if (!empty($param_value)) { |
|
116 | + $proxy_host = $param_value; |
|
117 | + } |
|
118 | + break; |
|
119 | + case "proxy_port": |
|
120 | + if (!preg_match('!\D!', $param_value)) { |
|
121 | + $proxy_port = (int) $param_value; |
|
122 | + } else { |
|
123 | + trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE); |
|
124 | + |
|
125 | + return; |
|
126 | + } |
|
127 | + break; |
|
128 | + case "agent": |
|
129 | + if (!empty($param_value)) { |
|
130 | + $agent = $param_value; |
|
131 | + } |
|
132 | + break; |
|
133 | + case "referer": |
|
134 | + if (!empty($param_value)) { |
|
135 | + $referer = $param_value; |
|
136 | + } |
|
137 | + break; |
|
138 | + case "timeout": |
|
139 | + if (!preg_match('!\D!', $param_value)) { |
|
140 | + $timeout = (int) $param_value; |
|
141 | + } else { |
|
142 | + trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE); |
|
143 | + |
|
144 | + return; |
|
145 | + } |
|
146 | + break; |
|
147 | + default: |
|
148 | + trigger_error("[plugin] unrecognized attribute '" . $param_key . "'", E_USER_NOTICE); |
|
149 | + |
|
150 | + return; |
|
151 | + } |
|
152 | + } |
|
153 | + if (!empty($proxy_host) && !empty($proxy_port)) { |
|
154 | + $_is_proxy = true; |
|
155 | + $fp = fsockopen($proxy_host, $proxy_port, $errno, $errstr, $timeout); |
|
156 | + } else { |
|
157 | + $fp = fsockopen($server_name, $port, $errno, $errstr, $timeout); |
|
158 | + } |
|
159 | + |
|
160 | + if (!$fp) { |
|
161 | + trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE); |
|
162 | + |
|
163 | + return; |
|
164 | + } else { |
|
165 | + if ($_is_proxy) { |
|
166 | + fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n"); |
|
167 | + } else { |
|
168 | + fputs($fp, "GET $uri HTTP/1.0\r\n"); |
|
169 | + } |
|
170 | + if (!empty($host)) { |
|
171 | + fputs($fp, "Host: $host\r\n"); |
|
172 | + } |
|
173 | + if (!empty($accept)) { |
|
174 | + fputs($fp, "Accept: $accept\r\n"); |
|
175 | + } |
|
176 | + if (!empty($agent)) { |
|
177 | + fputs($fp, "User-Agent: $agent\r\n"); |
|
178 | + } |
|
179 | + if (!empty($referer)) { |
|
180 | + fputs($fp, "Referer: $referer\r\n"); |
|
181 | + } |
|
182 | + if (isset($extra_headers) && is_array($extra_headers)) { |
|
183 | + foreach ($extra_headers as $curr_header) { |
|
184 | + fputs($fp, $curr_header . "\r\n"); |
|
185 | + } |
|
186 | + } |
|
187 | + if (!empty($user) && !empty($pass)) { |
|
188 | + fputs($fp, "Authorization: BASIC " . base64_encode("$user:$pass") . "\r\n"); |
|
189 | + } |
|
190 | + |
|
191 | + fputs($fp, "\r\n"); |
|
192 | + while (!feof($fp)) { |
|
193 | + $content .= fgets($fp, 4096); |
|
194 | + } |
|
195 | + fclose($fp); |
|
196 | + $csplit = preg_split("!\r\n\r\n!", $content, 2); |
|
197 | + |
|
198 | + $content = $csplit[ 1 ]; |
|
199 | + |
|
200 | + if (!empty($params[ 'assign_headers' ])) { |
|
201 | + $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ])); |
|
202 | + } |
|
203 | + } |
|
204 | + } else { |
|
205 | + trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE); |
|
206 | + |
|
207 | + return; |
|
208 | + } |
|
209 | + } else { |
|
210 | + $content = @file_get_contents($params[ 'file' ]); |
|
211 | + if ($content === false) { |
|
212 | + throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + if (!empty($params[ 'assign' ])) { |
|
217 | + $template->assign($params[ 'assign' ], $content); |
|
218 | + } else { |
|
219 | + return $content; |
|
220 | + } |
|
221 | 221 | } |
@@ -8,68 +8,68 @@ |
||
8 | 8 | |
9 | 9 | if (!function_exists('smarty_mb_wordwrap')) { |
10 | 10 | |
11 | - /** |
|
12 | - * Wrap a string to a given number of characters |
|
13 | - * |
|
14 | - * @link http://php.net/manual/en/function.wordwrap.php for similarity |
|
15 | - * |
|
16 | - * @param string $str the string to wrap |
|
17 | - * @param int $width the width of the output |
|
18 | - * @param string $break the character used to break the line |
|
19 | - * @param boolean $cut ignored parameter, just for the sake of |
|
20 | - * |
|
21 | - * @return string wrapped string |
|
22 | - * @author Rodney Rehm |
|
23 | - */ |
|
24 | - function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false) |
|
25 | - { |
|
26 | - // break words into tokens using white space as a delimiter |
|
27 | - $tokens = |
|
28 | - preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); |
|
29 | - $length = 0; |
|
30 | - $t = ''; |
|
31 | - $_previous = false; |
|
32 | - $_space = false; |
|
11 | + /** |
|
12 | + * Wrap a string to a given number of characters |
|
13 | + * |
|
14 | + * @link http://php.net/manual/en/function.wordwrap.php for similarity |
|
15 | + * |
|
16 | + * @param string $str the string to wrap |
|
17 | + * @param int $width the width of the output |
|
18 | + * @param string $break the character used to break the line |
|
19 | + * @param boolean $cut ignored parameter, just for the sake of |
|
20 | + * |
|
21 | + * @return string wrapped string |
|
22 | + * @author Rodney Rehm |
|
23 | + */ |
|
24 | + function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false) |
|
25 | + { |
|
26 | + // break words into tokens using white space as a delimiter |
|
27 | + $tokens = |
|
28 | + preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); |
|
29 | + $length = 0; |
|
30 | + $t = ''; |
|
31 | + $_previous = false; |
|
32 | + $_space = false; |
|
33 | 33 | |
34 | - foreach ($tokens as $_token) { |
|
35 | - $token_length = mb_strlen($_token, Smarty::$_CHARSET); |
|
36 | - $_tokens = array($_token); |
|
37 | - if ($token_length > $width) { |
|
38 | - if ($cut) { |
|
39 | - $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, |
|
40 | - PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); |
|
41 | - } |
|
42 | - } |
|
34 | + foreach ($tokens as $_token) { |
|
35 | + $token_length = mb_strlen($_token, Smarty::$_CHARSET); |
|
36 | + $_tokens = array($_token); |
|
37 | + if ($token_length > $width) { |
|
38 | + if ($cut) { |
|
39 | + $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, |
|
40 | + PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - foreach ($_tokens as $token) { |
|
45 | - $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); |
|
46 | - $token_length = mb_strlen($token, Smarty::$_CHARSET); |
|
47 | - $length += $token_length; |
|
44 | + foreach ($_tokens as $token) { |
|
45 | + $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); |
|
46 | + $token_length = mb_strlen($token, Smarty::$_CHARSET); |
|
47 | + $length += $token_length; |
|
48 | 48 | |
49 | - if ($length > $width) { |
|
50 | - // remove space before inserted break |
|
51 | - if ($_previous) { |
|
52 | - $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); |
|
53 | - } |
|
49 | + if ($length > $width) { |
|
50 | + // remove space before inserted break |
|
51 | + if ($_previous) { |
|
52 | + $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); |
|
53 | + } |
|
54 | 54 | |
55 | - if (!$_space) { |
|
56 | - // add the break before the token |
|
57 | - if (!empty($t)) { |
|
58 | - $t .= $break; |
|
59 | - } |
|
60 | - $length = $token_length; |
|
61 | - } |
|
62 | - } elseif ($token == "\n") { |
|
63 | - // hard break must reset counters |
|
64 | - $_previous = 0; |
|
65 | - $length = 0; |
|
66 | - } |
|
67 | - $_previous = $_space; |
|
68 | - // add the token |
|
69 | - $t .= $token; |
|
70 | - } |
|
71 | - } |
|
55 | + if (!$_space) { |
|
56 | + // add the break before the token |
|
57 | + if (!empty($t)) { |
|
58 | + $t .= $break; |
|
59 | + } |
|
60 | + $length = $token_length; |
|
61 | + } |
|
62 | + } elseif ($token == "\n") { |
|
63 | + // hard break must reset counters |
|
64 | + $_previous = 0; |
|
65 | + $length = 0; |
|
66 | + } |
|
67 | + $_previous = $_space; |
|
68 | + // add the token |
|
69 | + $t .= $token; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - return $t; |
|
74 | - } |
|
73 | + return $t; |
|
74 | + } |
|
75 | 75 | } |
@@ -24,177 +24,177 @@ |
||
24 | 24 | */ |
25 | 25 | function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) |
26 | 26 | { |
27 | - static $_double_encode = null; |
|
28 | - if ($_double_encode === null) { |
|
29 | - $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); |
|
30 | - } |
|
31 | - |
|
32 | - if (!$char_set) { |
|
33 | - $char_set = Smarty::$_CHARSET; |
|
34 | - } |
|
35 | - |
|
36 | - switch ($esc_type) { |
|
37 | - case 'html': |
|
38 | - if ($_double_encode) { |
|
39 | - // php >=5.3.2 - go native |
|
40 | - return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); |
|
41 | - } else { |
|
42 | - if ($double_encode) { |
|
43 | - // php <5.2.3 - only handle double encoding |
|
44 | - return htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
45 | - } else { |
|
46 | - // php <5.2.3 - prevent double encoding |
|
47 | - $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
48 | - $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
49 | - $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
50 | - |
|
51 | - return $string; |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - case 'htmlall': |
|
56 | - if (Smarty::$_MBSTRING) { |
|
57 | - // mb_convert_encoding ignores htmlspecialchars() |
|
58 | - if ($_double_encode) { |
|
59 | - // php >=5.3.2 - go native |
|
60 | - $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); |
|
61 | - } else { |
|
62 | - if ($double_encode) { |
|
63 | - // php <5.2.3 - only handle double encoding |
|
64 | - $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
65 | - } else { |
|
66 | - // php <5.2.3 - prevent double encoding |
|
67 | - $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
68 | - $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
69 | - $string = |
|
70 | - str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
71 | - |
|
72 | - return $string; |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - // htmlentities() won't convert everything, so use mb_convert_encoding |
|
77 | - return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); |
|
78 | - } |
|
79 | - |
|
80 | - // no MBString fallback |
|
81 | - if ($_double_encode) { |
|
82 | - return htmlentities($string, ENT_QUOTES, $char_set, $double_encode); |
|
83 | - } else { |
|
84 | - if ($double_encode) { |
|
85 | - return htmlentities($string, ENT_QUOTES, $char_set); |
|
86 | - } else { |
|
87 | - $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
88 | - $string = htmlentities($string, ENT_QUOTES, $char_set); |
|
89 | - $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
90 | - |
|
91 | - return $string; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - case 'url': |
|
96 | - return rawurlencode($string); |
|
97 | - |
|
98 | - case 'urlpathinfo': |
|
99 | - return str_replace('%2F', '/', rawurlencode($string)); |
|
100 | - |
|
101 | - case 'quotes': |
|
102 | - // escape unescaped single quotes |
|
103 | - return preg_replace("%(?<!\\\\)'%", "\\'", $string); |
|
104 | - |
|
105 | - case 'hex': |
|
106 | - // escape every byte into hex |
|
107 | - // Note that the UTF-8 encoded character ä will be represented as %c3%a4 |
|
108 | - $return = ''; |
|
109 | - $_length = strlen($string); |
|
110 | - for ($x = 0; $x < $_length; $x ++) { |
|
111 | - $return .= '%' . bin2hex($string[ $x ]); |
|
112 | - } |
|
113 | - |
|
114 | - return $return; |
|
115 | - |
|
116 | - case 'hexentity': |
|
117 | - $return = ''; |
|
118 | - if (Smarty::$_MBSTRING) { |
|
119 | - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
120 | - $return = ''; |
|
121 | - foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
122 | - $return .= '&#x' . strtoupper(dechex($unicode)) . ';'; |
|
123 | - } |
|
124 | - |
|
125 | - return $return; |
|
126 | - } |
|
127 | - // no MBString fallback |
|
128 | - $_length = strlen($string); |
|
129 | - for ($x = 0; $x < $_length; $x ++) { |
|
130 | - $return .= '&#x' . bin2hex($string[ $x ]) . ';'; |
|
131 | - } |
|
132 | - |
|
133 | - return $return; |
|
134 | - |
|
135 | - case 'decentity': |
|
136 | - $return = ''; |
|
137 | - if (Smarty::$_MBSTRING) { |
|
138 | - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
139 | - $return = ''; |
|
140 | - foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
141 | - $return .= '&#' . $unicode . ';'; |
|
142 | - } |
|
143 | - |
|
144 | - return $return; |
|
145 | - } |
|
146 | - // no MBString fallback |
|
147 | - $_length = strlen($string); |
|
148 | - for ($x = 0; $x < $_length; $x ++) { |
|
149 | - $return .= '&#' . ord($string[ $x ]) . ';'; |
|
150 | - } |
|
151 | - |
|
152 | - return $return; |
|
153 | - |
|
154 | - case 'javascript': |
|
155 | - // escape quotes and backslashes, newlines, etc. |
|
156 | - return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', |
|
157 | - '</' => '<\/')); |
|
158 | - |
|
159 | - case 'mail': |
|
160 | - if (Smarty::$_MBSTRING) { |
|
161 | - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); |
|
162 | - |
|
163 | - return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); |
|
164 | - } |
|
165 | - // no MBString fallback |
|
166 | - return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); |
|
167 | - |
|
168 | - case 'nonstd': |
|
169 | - // escape non-standard chars, such as ms document quotes |
|
170 | - $return = ''; |
|
171 | - if (Smarty::$_MBSTRING) { |
|
172 | - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
173 | - foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
174 | - if ($unicode >= 126) { |
|
175 | - $return .= '&#' . $unicode . ';'; |
|
176 | - } else { |
|
177 | - $return .= chr($unicode); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - return $return; |
|
182 | - } |
|
183 | - |
|
184 | - $_length = strlen($string); |
|
185 | - for ($_i = 0; $_i < $_length; $_i ++) { |
|
186 | - $_ord = ord(substr($string, $_i, 1)); |
|
187 | - // non-standard char, escape it |
|
188 | - if ($_ord >= 126) { |
|
189 | - $return .= '&#' . $_ord . ';'; |
|
190 | - } else { |
|
191 | - $return .= substr($string, $_i, 1); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - return $return; |
|
196 | - |
|
197 | - default: |
|
198 | - return $string; |
|
199 | - } |
|
27 | + static $_double_encode = null; |
|
28 | + if ($_double_encode === null) { |
|
29 | + $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); |
|
30 | + } |
|
31 | + |
|
32 | + if (!$char_set) { |
|
33 | + $char_set = Smarty::$_CHARSET; |
|
34 | + } |
|
35 | + |
|
36 | + switch ($esc_type) { |
|
37 | + case 'html': |
|
38 | + if ($_double_encode) { |
|
39 | + // php >=5.3.2 - go native |
|
40 | + return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); |
|
41 | + } else { |
|
42 | + if ($double_encode) { |
|
43 | + // php <5.2.3 - only handle double encoding |
|
44 | + return htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
45 | + } else { |
|
46 | + // php <5.2.3 - prevent double encoding |
|
47 | + $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
48 | + $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
49 | + $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
50 | + |
|
51 | + return $string; |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + case 'htmlall': |
|
56 | + if (Smarty::$_MBSTRING) { |
|
57 | + // mb_convert_encoding ignores htmlspecialchars() |
|
58 | + if ($_double_encode) { |
|
59 | + // php >=5.3.2 - go native |
|
60 | + $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); |
|
61 | + } else { |
|
62 | + if ($double_encode) { |
|
63 | + // php <5.2.3 - only handle double encoding |
|
64 | + $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
65 | + } else { |
|
66 | + // php <5.2.3 - prevent double encoding |
|
67 | + $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
68 | + $string = htmlspecialchars($string, ENT_QUOTES, $char_set); |
|
69 | + $string = |
|
70 | + str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
71 | + |
|
72 | + return $string; |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + // htmlentities() won't convert everything, so use mb_convert_encoding |
|
77 | + return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); |
|
78 | + } |
|
79 | + |
|
80 | + // no MBString fallback |
|
81 | + if ($_double_encode) { |
|
82 | + return htmlentities($string, ENT_QUOTES, $char_set, $double_encode); |
|
83 | + } else { |
|
84 | + if ($double_encode) { |
|
85 | + return htmlentities($string, ENT_QUOTES, $char_set); |
|
86 | + } else { |
|
87 | + $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); |
|
88 | + $string = htmlentities($string, ENT_QUOTES, $char_set); |
|
89 | + $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); |
|
90 | + |
|
91 | + return $string; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + case 'url': |
|
96 | + return rawurlencode($string); |
|
97 | + |
|
98 | + case 'urlpathinfo': |
|
99 | + return str_replace('%2F', '/', rawurlencode($string)); |
|
100 | + |
|
101 | + case 'quotes': |
|
102 | + // escape unescaped single quotes |
|
103 | + return preg_replace("%(?<!\\\\)'%", "\\'", $string); |
|
104 | + |
|
105 | + case 'hex': |
|
106 | + // escape every byte into hex |
|
107 | + // Note that the UTF-8 encoded character ä will be represented as %c3%a4 |
|
108 | + $return = ''; |
|
109 | + $_length = strlen($string); |
|
110 | + for ($x = 0; $x < $_length; $x ++) { |
|
111 | + $return .= '%' . bin2hex($string[ $x ]); |
|
112 | + } |
|
113 | + |
|
114 | + return $return; |
|
115 | + |
|
116 | + case 'hexentity': |
|
117 | + $return = ''; |
|
118 | + if (Smarty::$_MBSTRING) { |
|
119 | + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
120 | + $return = ''; |
|
121 | + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
122 | + $return .= '&#x' . strtoupper(dechex($unicode)) . ';'; |
|
123 | + } |
|
124 | + |
|
125 | + return $return; |
|
126 | + } |
|
127 | + // no MBString fallback |
|
128 | + $_length = strlen($string); |
|
129 | + for ($x = 0; $x < $_length; $x ++) { |
|
130 | + $return .= '&#x' . bin2hex($string[ $x ]) . ';'; |
|
131 | + } |
|
132 | + |
|
133 | + return $return; |
|
134 | + |
|
135 | + case 'decentity': |
|
136 | + $return = ''; |
|
137 | + if (Smarty::$_MBSTRING) { |
|
138 | + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
139 | + $return = ''; |
|
140 | + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
141 | + $return .= '&#' . $unicode . ';'; |
|
142 | + } |
|
143 | + |
|
144 | + return $return; |
|
145 | + } |
|
146 | + // no MBString fallback |
|
147 | + $_length = strlen($string); |
|
148 | + for ($x = 0; $x < $_length; $x ++) { |
|
149 | + $return .= '&#' . ord($string[ $x ]) . ';'; |
|
150 | + } |
|
151 | + |
|
152 | + return $return; |
|
153 | + |
|
154 | + case 'javascript': |
|
155 | + // escape quotes and backslashes, newlines, etc. |
|
156 | + return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', |
|
157 | + '</' => '<\/')); |
|
158 | + |
|
159 | + case 'mail': |
|
160 | + if (Smarty::$_MBSTRING) { |
|
161 | + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); |
|
162 | + |
|
163 | + return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); |
|
164 | + } |
|
165 | + // no MBString fallback |
|
166 | + return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); |
|
167 | + |
|
168 | + case 'nonstd': |
|
169 | + // escape non-standard chars, such as ms document quotes |
|
170 | + $return = ''; |
|
171 | + if (Smarty::$_MBSTRING) { |
|
172 | + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); |
|
173 | + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { |
|
174 | + if ($unicode >= 126) { |
|
175 | + $return .= '&#' . $unicode . ';'; |
|
176 | + } else { |
|
177 | + $return .= chr($unicode); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + return $return; |
|
182 | + } |
|
183 | + |
|
184 | + $_length = strlen($string); |
|
185 | + for ($_i = 0; $_i < $_length; $_i ++) { |
|
186 | + $_ord = ord(substr($string, $_i, 1)); |
|
187 | + // non-standard char, escape it |
|
188 | + if ($_ord >= 126) { |
|
189 | + $return .= '&#' . $_ord . ';'; |
|
190 | + } else { |
|
191 | + $return .= substr($string, $_i, 1); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + return $return; |
|
196 | + |
|
197 | + default: |
|
198 | + return $string; |
|
199 | + } |
|
200 | 200 | } |