[BUGFIX] Deactivate EscapeInterceptor for certain ViewHelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / DateViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "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 as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
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 * Formats a DateTime object.
25 *
26 * = Examples =
27 *
28 * <code title="Defaults">
29 * <f:format.date>{dateObject}</f:format.date>
30 * </code>
31 * <output>
32 * 1980-12-13
33 * (depending on the current date)
34 * </output>
35 *
36 * <code title="Custom date format">
37 * <f:format.date format="H:i">{dateObject}</f:format.date>
38 * </code>
39 * <output>
40 * 01:23
41 * (depending on the current time)
42 * </output>
43 *
44 * <code title="strtotime string">
45 * <f:format.date format="d.m.Y - H:i:s">+1 week 2 days 4 hours 2 seconds</f:format.date>
46 * </code>
47 * <output>
48 * 13.12.1980 - 21:03:42
49 * (depending on the current time, see http://www.php.net/manual/en/function.strtotime.php)
50 * </output>
51 *
52 * <code title="output date from unix timestamp">
53 * <f:format.date format="d.m.Y - H:i:s">@{someTimestamp}</f:format.date>
54 * </code>
55 * <output>
56 * 13.12.1980 - 21:03:42
57 * (depending on the current time. Don't forget the "@" in front of the timestamp see http://www.php.net/manual/en/function.strtotime.php)
58 * </output>
59 *
60 * <code title="Inline notation">
61 * {f:format.date(date: dateObject)}
62 * </code>
63 * <output>
64 * 1980-12-13
65 * (depending on the value of {dateObject})
66 * </output>
67 *
68 * <code title="Inline notation (2nd variant)">
69 * {dateObject -> f:format.date()}
70 * </code>
71 * <output>
72 * 1980-12-13
73 * (depending on the value of {dateObject})
74 * </output>
75 *
76 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
77 * @api
78 */
79 class Tx_Fluid_ViewHelpers_Format_DateViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
80
81 /**
82 * @var boolean
83 */
84 protected $escapingInterceptorEnabled = FALSE;
85
86 /**
87 * Render the supplied DateTime object as a formatted date.
88 *
89 * @param mixed $date either a DateTime object or a string that is accepted by DateTime constructor
90 * @param string $format Format String which is taken to format the Date/Time
91 * @return string Formatted date
92 * @author Christopher Hlubek <hlubek@networkteam.com>
93 * @author Bastian Waidelich <bastian@typo3.org>
94 * @api
95 */
96 public function render($date = NULL, $format = 'Y-m-d') {
97 if ($date === NULL) {
98 $date = $this->renderChildren();
99 if ($date === NULL) {
100 return '';
101 }
102 }
103 if (!$date instanceof DateTime) {
104 try {
105 $date = new DateTime($date);
106 } catch (Exception $exception) {
107 throw new Tx_Fluid_Core_ViewHelper_Exception('"' . $date . '" could not be parsed by DateTime constructor.', 1241722579);
108 }
109 }
110 return $date->format($format);
111 }
112 }
113 ?>