Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / EscapeViewHelper.php
1 <?php
2
3 /* *
4 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License, either version 3 *
8 * of the License, or (at your option) any later version. *
9 * *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * The EscapeViewHelper is used to escape variable content in various ways. By
25 * default HTML is the target.
26 *
27 * = Examples =
28 *
29 * <code title="HTML">
30 * <f:escape>{text}</f:escape>
31 * </code>
32 * <output>
33 * Text with & " ' < > * replaced by HTML entities (htmlspecialchars applied).
34 * </output>
35 *
36 * <code title="Entities">
37 * <f:escape type="entities">{text}</f:escape>
38 * </code>
39 * <output>
40 * Text with all possible chars replaced by HTML entities (htmlentities applied).
41 * </output>
42 *
43 * <code title="URL">
44 * <f:escape type="url">{text}</f:escape>
45 * </code>
46 * <output>
47 * Text encoded for URL use (rawurlencode applied).
48 * </output>
49 *
50 * @deprecated since Extbase 1.4.0; will be removed in Extbase 1.6.0. Please use the <f:format.*> ViewHelpers instead.
51 */
52 class Tx_Fluid_ViewHelpers_EscapeViewHelper extends Tx_Fluid_ViewHelpers_Format_AbstractEncodingViewHelper {
53
54 /**
55 * Escapes special characters with their escaped counterparts as needed.
56 *
57 * @param string $value
58 * @param string $type The type, one of html, entities, url
59 * @param string $encoding
60 * @return string the altered string.
61 */
62 public function render($value = NULL, $type = 'html', $encoding = NULL) {
63 t3lib_div::logDeprecatedFunction('<f:escape> is deprecated. Please use the <f:format.*> ViewHelpers instead.');
64 if ($value === NULL) {
65 $value = $this->renderChildren();
66 }
67
68 if (!is_string($value)) {
69 return $value;
70 }
71
72 if ($encoding === NULL) {
73 $encoding = $this->resolveDefaultEncoding();
74 }
75
76 switch ($type) {
77 case 'html':
78 return htmlspecialchars($value, ENT_COMPAT, $encoding);
79 break;
80 case 'entities':
81 return htmlentities($value, ENT_COMPAT, $encoding);
82 break;
83 case 'url':
84 return rawurlencode($value);
85 default:
86 return $value;
87 break;
88 }
89 }
90 }
91 ?>