2 /***************************************************************
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
30 * A class representing flash messages.
32 * @author Ingo Renner <ingo@typo3.org>
36 class t3lib_FlashMessage
{
44 protected $title = '';
45 protected $message = '';
46 protected $severity = self
::OK
;
49 * Constructor for a flash message
51 * @param string The message.
52 * @param string Optional message title.
53 * @param integer Optional severity, must be either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK, t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR. Default is t3lib_FlashMessage::OK.
56 public function __construct($message, $title = '', $severity = self
::OK
) {
57 $this->setMessage($message);
58 $this->setTitle($title);
59 $this->setSeverity($severity);
63 * Gets the message's title.
65 * @return string The message's title.
67 public function getTitle() {
72 * Sets the message's title
74 * @param string The message's title
77 public function setTitle($title) {
78 $this->title
= (string) $title;
84 * @return string The message.
86 public function getMessage() {
87 return $this->message
;
93 * @param string The message
96 public function setMessage($message) {
97 $this->message
= (string) $message;
101 * Gets the message' severity.
103 * @return integer The message' severity, either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK, t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR
105 public function getSeverity() {
106 return $this->severity
;
110 * Sets the message' severity
112 * @param string The severity, must be either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK, t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR. Default is t3lib_FlashMessage::OK.
115 public function setSeverity($severity = self
::OK
) {
116 $this->severity
= t3lib_div
::intInRange(
118 self
::NOTICE
, // minimum
119 self
::ERROR
, // maximum
120 self
::OK
// default if out of bounds
125 * Renders the flash message.
127 * @return string The flash message as HTML.
129 public function render() {
131 t3lib_FlashMessage
::NOTICE
=> 'notice',
132 t3lib_FlashMessage
::INFO
=> 'information',
133 t3lib_FlashMessage
::OK
=> 'ok',
134 t3lib_FlashMessage
::WARNING
=> 'warning',
135 t3lib_FlashMessage
::ERROR
=> 'error',
139 if (!empty($this->title
)) {
140 $title = '<div class="message-header">' . $this->title
. '</div>';
143 $message = '<div class="typo3-message message-' . $classes[$this->severity
] . '">'
145 . '<div class="message-body">' . $this->message
. '</div>'
153 * Creates a string representation of the flash message. Useful for command
156 * @return string A string representation of the flash message.
158 public function __toString() {
160 t3lib_FlashMessage
::INFO
=> 'INFO',
161 t3lib_FlashMessage
::OK
=> 'OK',
162 t3lib_FlashMessage
::WARNING
=> 'WARNING',
163 t3lib_FlashMessage
::ERROR
=> 'ERROR',
167 if (!empty($this->title
)) {
168 $title = ' - ' . $this->title
;
171 return $severities[$this->severity
] . $title . ': ' . $this->message
;
177 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_flashmessage.php']) {
178 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_flashmessage.php']);