efd3b3bc57c6a6283be3ac44fdf49dfd9e7bcba5
[Packages/TYPO3.CMS.git] / t3lib / message / class.t3lib_message_errorpagemessage.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Benjamin Mack <benni@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * A class representing error messages shown on a page.
30 * Classic Example: "No pages are found on rootlevel"
31 *
32 * @author Benjamin Mack <benni@typo3.org>
33 * @package TYPO3
34 * @subpackage t3lib/message
35 */
36 class t3lib_message_ErrorpageMessage extends t3lib_message_AbstractMessage {
37
38 /**
39 * defines whether the message should be stored in the session
40 * (to survive redirects) or only for one request (default)
41 *
42 * @var string
43 */
44 protected $htmlTemplate;
45
46 /**
47 * Constructor for a error message
48 *
49 * @param string The message.
50 * @param string message title.
51 * @param integer Optional severity, must be either of t3lib_message_ErrorpageMessage::INFO, t3lib_message_ErrorpageMessage::OK,
52 * t3lib_message_ErrorpageMessage::WARNING or t3lib_message_ErrorpageMessage::ERROR. Default is t3lib_message_ErrorpageMessage::ERROR.
53 * @return void
54 */
55 public function __construct($message, $title, $severity = self::ERROR) {
56 $this->htmlTemplate = TYPO3_mainDir . 'templates/errorpage.html';
57 $this->setMessage($message);
58 $this->setTitle(strlen($title) > 0 ? $title : 'Error!');
59 $this->setSeverity($severity);
60 }
61
62
63 /**
64 * Gets the filename of the HTML template.
65 *
66 * @return string The filename of the HTML template.
67 */
68 public function getHtmlTemplate() {
69 return $this->htmlTemplate;
70 }
71
72 /**
73 * Sets the filename to the HTML template
74 *
75 * @param string The filename to the HTML template.
76 * @return void
77 */
78 public function setHtmlTemplate($htmlTemplate) {
79 $this->htmlTemplate = (string) $htmlTemplate;
80 }
81
82 /**
83 * Renders the flash message.
84 *
85 * @return string The flash message as HTML.
86 */
87 public function render() {
88 $classes = array(
89 self::NOTICE => 'notice',
90 self::INFO => 'information',
91 self::OK => 'ok',
92 self::WARNING => 'warning',
93 self::ERROR => 'error',
94 );
95
96 $markers = array(
97 '###CSS_CLASS###' => $classes[$this->severity],
98 '###LOGO###' => '<img src="' . TYPO3_mainDir . 'gfx/typo3logo.gif" width="123" height="34" alt="" />',
99 '###TITLE###' => $this->title,
100 '###MESSAGE###' => $this->message,
101 '###BASEURL###' => t3lib_div::getIndpEnv('TYPO3_SITE_URL')
102 );
103
104 $content = t3lib_div::getUrl(PATH_site . $this->htmlTemplate);
105 $content = t3lib_parseHtml::substituteMarkerArray($content, $markers, '', FALSE, TRUE);
106 return $content;
107 }
108
109 /**
110 * Renders the flash message and echoes it.
111 *
112 * @return void
113 */
114 public function output() {
115 $content = $this->render();
116 echo $content;
117 }
118
119 }
120
121
122 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php']) {
123 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php']);
124 }
125
126 ?>
127 <?php
128 /***************************************************************
129 * Copyright notice
130 *
131 * (c) 2010 Benjamin Mack <benni@typo3.org>
132 * All rights reserved
133 *
134 * This script is part of the TYPO3 project. The TYPO3 project is
135 * free software; you can redistribute it and/or modify
136 * it under the terms of the GNU General Public License as published by
137 * the Free Software Foundation; either version 2 of the License, or
138 * (at your option) any later version.
139 *
140 * The GNU General Public License can be found at
141 * http://www.gnu.org/copyleft/gpl.html.
142 * A copy is found in the textfile GPL.txt and important notices to the license
143 * from the author is found in LICENSE.txt distributed with these scripts.
144 *
145 *
146 * This script is distributed in the hope that it will be useful,
147 * but WITHOUT ANY WARRANTY; without even the implied warranty of
148 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149 * GNU General Public License for more details.
150 *
151 * This copyright notice MUST APPEAR in all copies of the script!
152 ***************************************************************/
153
154 /**
155 * A class representing error messages shown on a page.
156 * Classic Example: "No pages are found on rootlevel"
157 *
158 * @author Benjamin Mack <benni@typo3.org>
159 * @package TYPO3
160 * @subpackage t3lib/message
161 */
162 class t3lib_message_ErrorpageMessage extends t3lib_message_AbstractMessage {
163
164 /**
165 * defines whether the message should be stored in the session
166 * (to survive redirects) or only for one request (default)
167 *
168 * @var string
169 */
170 protected $htmlTemplate;
171
172 /**
173 * Constructor for a error message
174 *
175 * @param string The message.
176 * @param string message title.
177 * @param integer Optional severity, must be either of t3lib_message_ErrorpageMessage::INFO, t3lib_message_ErrorpageMessage::OK,
178 * t3lib_message_ErrorpageMessage::WARNING or t3lib_message_ErrorpageMessage::ERROR. Default is t3lib_message_ErrorpageMessage::ERROR.
179 * @return void
180 */
181 public function __construct($message, $title, $severity = self::ERROR) {
182 $this->htmlTemplate = TYPO3_mainDir . 'templates/errorpage.html';
183 $this->setMessage($message);
184 $this->setTitle(strlen($title) > 0 ? $title : 'Error!');
185 $this->setSeverity($severity);
186 }
187
188
189 /**
190 * Gets the filename of the HTML template.
191 *
192 * @return string The filename of the HTML template.
193 */
194 public function getHtmlTemplate() {
195 return $this->htmlTemplate;
196 }
197
198 /**
199 * Sets the filename to the HTML template
200 *
201 * @param string The filename to the HTML template.
202 * @return void
203 */
204 public function setHtmlTemplate($htmlTemplate) {
205 $this->htmlTemplate = (string) $htmlTemplate;
206 }
207
208 /**
209 * Renders the flash message.
210 *
211 * @return string The flash message as HTML.
212 */
213 public function render() {
214 $classes = array(
215 self::NOTICE => 'notice',
216 self::INFO => 'information',
217 self::OK => 'ok',
218 self::WARNING => 'warning',
219 self::ERROR => 'error',
220 );
221
222 $markers = array(
223 '###CSS_CLASS###' => $classes[$this->severity],
224 '###LOGO###' => '<img src="' . TYPO3_mainDir . 'gfx/typo3logo.gif" width="123" height="34" alt="" />',
225 '###TITLE###' => $this->title,
226 '###MESSAGE###' => $this->message,
227 '###BASEURL###' => t3lib_div::getIndpEnv('TYPO3_SITE_URL')
228 );
229
230 $content = t3lib_div::getUrl(PATH_site . $this->htmlTemplate);
231 $content = t3lib_parseHtml::substituteMarkerArray($content, $markers, '', FALSE, TRUE);
232 return $content;
233 }
234
235 /**
236 * Renders the flash message and echoes it.
237 *
238 * @return void
239 */
240 public function output() {
241 $content = $this->render();
242 echo $content;
243 }
244
245 }
246
247
248 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php']) {
249 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php']);
250 }
251
252 ?>