afd427219bd78babee4744cef6c3d95c0aba3a7c
2 /***************************************************************
5 * (c) 2009-2010 Rupert Germann <rupi@gmx.li>
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 which collects and renders flash messages.
32 * @author Rupert Germann <rupi@gmx.li>
36 class t3lib_FlashMessageQueue
{
38 static $messages = array();
41 * Static class, no instances allowed.
43 protected function __construct() {}
47 * Adds a message either to the BE_USER session (if the $message has the storeInSession flag set)
48 * or it adds the message to self::$messages.
50 * @param object instance of t3lib_FlashMessage, representing a message
53 public static function addMessage(t3lib_FlashMessage
$message) {
54 if ($message->isSessionMessage() === TRUE) {
55 $queuedFlashMessages = self
::getFlashMessagesFromSession();
56 $queuedFlashMessages[] = $message;
58 $GLOBALS['BE_USER']->setAndSaveSessionData(
59 'core.template.flashMessages',
63 self
::$messages[] = $message;
68 * Returns all messages from the current PHP session and from the current request.
69 * After fetching the messages the internal queue and the message queue in the session
72 * @return array array of t3lib_FlashMessage objects
74 public static function getAllMessagesAndFlush() {
75 // get messages from user session
76 $queuedFlashMessagesFromSession = self
::getFlashMessagesFromSession();
77 if (!empty($queuedFlashMessagesFromSession)) {
78 // reset messages in user session
79 $GLOBALS['BE_USER']->setAndSaveSessionData(
80 'core.template.flashMessages',
85 $queuedFlashMessages = array_merge($queuedFlashMessagesFromSession, self
::$messages);
87 // reset internal messages
88 self
::$messages = array();
90 return $queuedFlashMessages;
94 * Returns current flash messages from the session, making sure to always
97 * @return array An array of t3lib_FlashMessage flash messages.
99 protected static function getFlashMessagesFromSession() {
100 $flashMessages = $GLOBALS['BE_USER']->getSessionData('core.template.flashMessages');
101 return is_array($flashMessages) ?
$flashMessages : array();
105 * Fetches and renders all available flash messages from the queue.
107 * @return string All flash messages in the queue rendered as HTML.
109 public static function renderFlashMessages() {
111 $flashMessages = self
::getAllMessagesAndFlush();
113 if (count($flashMessages)) {
114 foreach ($flashMessages as $flashMessage) {
115 $content .= $flashMessage->render();
125 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_flashmessagequeue.php']) {
126 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_flashmessagequeue.php']);