Fixed bug #17184: Disable the CSRF protection in ExtDirect calls coming from the...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_flashmessage.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Ingo Renner <ingo@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 /**
30 * A class representing flash messages.
31 *
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class t3lib_FlashMessage extends t3lib_message_AbstractMessage {
37
38 /**
39 * defines whether the message should be stored in the session (to survive redirects) or only for one request (default)
40 *
41 * @var bool
42 */
43 protected $storeInSession = FALSE;
44
45 /**
46 * Constructor for a flash message
47 *
48 * @param string The message.
49 * @param string Optional message title.
50 * @param integer Optional severity, must be either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK,
51 * t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR. Default is t3lib_FlashMessage::OK.
52 * @param bool Optional, defines whether the message should be stored in the session or only for one request (default)
53 * @return void
54 */
55 public function __construct($message, $title = '', $severity = self::OK, $storeInSession = FALSE) {
56 $this->setMessage($message);
57 $this->setTitle($title);
58 $this->setSeverity($severity);
59 $this->setStoreInSession($storeInSession);
60 }
61
62
63 /**
64 * Gets the message's storeInSession flag.
65 *
66 * @return bool true if message should be stored in the session, otherwise false.
67 */
68 public function isSessionMessage() {
69 return $this->storeInSession;
70 }
71
72 /**
73 * Sets the message's storeInSession flag
74 *
75 * @param bool The persistence flag
76 * @return void
77 */
78 public function setStoreInSession($storeInSession) {
79 $this->storeInSession = (bool) $storeInSession;
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 $title = '';
97 if (!empty($this->title)) {
98 $title = '<div class="message-header">' . $this->title . '</div>';
99 }
100
101 $message = '<div class="typo3-message message-' . $classes[$this->severity] . '">'
102 . $title
103 . '<div class="message-body">' . $this->message . '</div>'
104 . '</div>';
105
106 return $message;
107 }
108
109 }
110
111
112 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_flashmessage.php'])) {
113 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_flashmessage.php']);
114 }
115
116 ?>