[TASK] Sync CMS Fluid with Flow Fluid 1.1 (part1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / UrlencodeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Encodes the given string according to http://www.faqs.org/rfcs/rfc3986.html (applying PHPs rawurlencode() function)
16 * @see http://www.php.net/manual/function.rawurlencode.php
17 *
18 * = Examples =
19 *
20 * <code title="default notation">
21 * <f:format.rawurlencode>foo @+%/</f:format.rawurlencode>
22 * </code>
23 * <output>
24 * foo%20%40%2B%25%2F (rawurlencode() applied)
25 * </output>
26 *
27 * <code title="inline notation">
28 * {text -> f:format.urlencode()}
29 * </code>
30 * <output>
31 * Url encoded text (rawurlencode() applied)
32 * </output>
33 *
34 * @api
35 */
36 class UrlencodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
37
38 /**
39 * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
40 * can decode the text's entities.
41 *
42 * @var boolean
43 */
44 protected $escapingInterceptorEnabled = FALSE;
45
46 /**
47 * Escapes special characters with their escaped counterparts as needed using PHPs rawurlencode() function.
48 *
49 * @param string $value string to format
50 * @return mixed
51 * @see http://www.php.net/manual/function.rawurlencode.php
52 * @api
53 */
54 public function render($value = NULL) {
55 if ($value === NULL) {
56 $value = $this->renderChildren();
57 }
58 if (!is_string($value)) {
59 return $value;
60 }
61 return rawurlencode($value);
62 }
63 }
64
65 ?>