Implemented an override of allowed language per workspace. This is an expert feature...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_flashmessage.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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 {
37
38 const NOTICE = -2;
39 const INFO = -1;
40 const OK = 0;
41 const WARNING = 1;
42 const ERROR = 2;
43
44 protected $title = '';
45 protected $message = '';
46 protected $severity = self::OK;
47
48 /**
49 * Constructor for a flash message
50 *
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.
54 * @return void
55 */
56 public function __construct($message, $title = '', $severity = self::OK) {
57 $this->setMessage($message);
58 $this->setTitle($title);
59 $this->setSeverity($severity);
60 }
61
62 /**
63 * Gets the message's title.
64 *
65 * @return string The message's title.
66 */
67 public function getTitle() {
68 return $this->title;
69 }
70
71 /**
72 * Sets the message's title
73 *
74 * @param string The message's title
75 * @return void
76 */
77 public function setTitle($title) {
78 $this->title = (string) $title;
79 }
80
81 /**
82 * Gets the message.
83 *
84 * @return string The message.
85 */
86 public function getMessage() {
87 return $this->message;
88 }
89
90 /**
91 * Sets the message
92 *
93 * @param string The message
94 * @return void
95 */
96 public function setMessage($message) {
97 $this->message = (string) $message;
98 }
99
100 /**
101 * Gets the message' severity.
102 *
103 * @return integer The message' severity, either of t3lib_FlashMessage::INFO, t3lib_FlashMessage::OK, t3lib_FlashMessage::WARNING or t3lib_FlashMessage::ERROR
104 */
105 public function getSeverity() {
106 return $this->severity;
107 }
108
109 /**
110 * Sets the message' severity
111 *
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.
113 * @return void
114 */
115 public function setSeverity($severity = self::OK) {
116 $this->severity = t3lib_div::intInRange(
117 $severity,
118 self::NOTICE, // minimum
119 self::ERROR, // maximum
120 self::OK // default if out of bounds
121 );
122 }
123
124 /**
125 * Renders the flash message.
126 *
127 * @return string The flash message as HTML.
128 */
129 public function render() {
130 $classes = array(
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',
136 );
137
138 $title = '';
139 if (!empty($this->title)) {
140 $title = '<div class="message-header">' . $this->title . '</div>';
141 }
142
143 $message = '<div class="typo3-message message-' . $classes[$this->severity] . '">'
144 . $title
145 . '<div class="message-body">' . $this->message . '</div>'
146 . '</div>';
147
148 return $message;
149 }
150
151
152 /**
153 * Creates a string representation of the flash message. Useful for command
154 * line use.
155 *
156 * @return string A string representation of the flash message.
157 */
158 public function __toString() {
159 $severities = array(
160 t3lib_FlashMessage::INFO => 'INFO',
161 t3lib_FlashMessage::OK => 'OK',
162 t3lib_FlashMessage::WARNING => 'WARNING',
163 t3lib_FlashMessage::ERROR => 'ERROR',
164 );
165
166 $title = '';
167 if (!empty($this->title)) {
168 $title = ' - ' . $this->title;
169 }
170
171 return $severities[$this->severity] . $title . ': ' . $this->message;
172 }
173
174 }
175
176
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']);
179 }
180
181 ?>