source: trunk/include/smarty/libs/plugins/modifiercompiler.unescape.php @ 23384

Last change on this file since 23384 was 23384, checked in by rvelices, 11 years ago

smarty 3 - first pass for tests

File size: 1.2 KB
Line 
1<?php
2/**
3 * Smarty plugin
4 *
5 * @package Smarty
6 * @subpackage PluginsModifierCompiler
7 */
8
9/**
10 * Smarty unescape modifier plugin
11 *
12 * Type:     modifier<br>
13 * Name:     unescape<br>
14 * Purpose:  unescape html entities
15 *
16 * @author Rodney Rehm
17 * @param array $params parameters
18 * @return string with compiled code
19 */
20function smarty_modifiercompiler_unescape($params, $compiler)
21{
22    if (!isset($params[1])) {
23        $params[1] = 'html';
24    }
25    if (!isset($params[2])) {
26        $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
27    } else {
28        $params[2] = "'" . $params[2] . "'";
29    }
30
31    switch (trim($params[1], '"\'')) {
32        case 'entity':
33        case 'htmlall':
34            if (Smarty::$_MBSTRING) {
35                return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
36            }
37
38            return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')';
39
40        case 'html':
41            return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
42
43        case 'url':
44            return 'rawurldecode(' . $params[0] . ')';
45
46        default:
47            return $params[0];
48    }
49}
50
51?>
Note: See TracBrowser for help on using the repository browser.