Project

General

Profile

Bug #21195 ยป 12130_v5.diff

Administrator Admin, 2009-10-07 13:24

View differences:

t3lib/class.t3lib_messagequeue.php (Revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 Rupert Germann <rupi@gmx.li>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* A class which collects and renders flash messages.
*
* @author Rupert Germann <rupi@gmx.li>
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_MessageQueue {
static $messages = array();
/**
* Static class, no instances allowed.
*/
protected function __construct() {}
/**
* Adds a message to self::$messages
*
* @param object instance of t3lib_FlashMessage, representing a message
* @return void
*/
public static function addMessage(t3lib_FlashMessage $message) {
self::$messages[] = $message;
}
/**
* Returns all messages from the current php session
*
* @return array array of t3lib_FlashMessage objects
*/
public static function getMessages() {
$messages = self::$messages;
self::$messages = array();
return $messages;
}
/**
* Renders all available flash messages in the queue.
*
* @return string All flash messages in the queue rendered as HTML.
*/
public static function renderFlashMessages() {
$content = '';
$flashMessages = self::getMessages();
if (count($flashMessages)) {
foreach ($flashMessages as $flashMessage) {
$content .= $flashMessage->render();
}
}
return $content;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_messagequeue.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_messagequeue.php']);
}
?>
t3lib/core_autoload.php (Arbeitskopie)
't3lib_extmgm' => PATH_t3lib . 'class.t3lib_extmgm.php',
't3lib_extobjbase' => PATH_t3lib . 'class.t3lib_extobjbase.php',
't3lib_flashmessage' => PATH_t3lib . 'class.t3lib_flashmessage.php',
't3lib_messagequeue' => PATH_t3lib . 'class.t3lib_messagequeue.php',
't3lib_flexformtools' => PATH_t3lib . 'class.t3lib_flexformtools.php',
't3lib_foldertree' => PATH_t3lib . 'class.t3lib_foldertree.php',
't3lib_formmail' => PATH_t3lib . 'class.t3lib_formmail.php',
typo3/template.php (Arbeitskopie)
}
/**
* Adds a flash message to the queue. It will live until the next call to
* popFlashMessages() in the current session.
*
* @param t3lib_FlashMessage A flash message object.
* @return void
* @author Karsten Dambekalns <karsten@typo3.org>
* @author Ingo Renner <ingo@typo3.org>
*/
public function pushFlashMessage(t3lib_FlashMessage $message) {
$queuedFlashMessages = $this->getFlashMessagesFromSession();
$queuedFlashMessages[] = $message;
$GLOBALS['BE_USER']->setAndSaveSessionData(
'core.template.flashMessages',
$queuedFlashMessages
);
}
/**
* Returns queued flash messages and clears the queue.
*
* @return array An array with t3lib_FlashMessage flash messages.
* @author Karsten Dambekalns <karsten@typo3.org>
* @author Ingo Renner <ingo@typo3.org>
*/
public function popFlashMessages() {
$queuedFlashMessages = $this->getFlashMessagesFromSession();
if (!empty($queuedFlashMessages)) {
$GLOBALS['BE_USER']->setAndSaveSessionData(
'core.template.flashMessages',
null
);
}
return $queuedFlashMessages;
}
/**
* Returns current flash messages from the session, making sure to always
* return an array.
*
* @return array An array of t3lib_FlashMessage flash messages.
* @author Karsten Dambekalns <karsten@typo3.org>
* @author Ingo Renner <ingo@typo3.org>
*/
protected function getFlashMessagesFromSession() {
$flashMessages = $GLOBALS['BE_USER']->getSessionData('core.template.flashMessages');
return is_array($flashMessages) ? $flashMessages : array();
}
/**
* Renders all available flash messages in the queue.
*
* @return string All flash messages in the queue rendered as HTML.
* @author Ingo Renner <ingo@typo3.org>
*/
public function renderFlashMessages() {
$content = '';
$flashMessages = $this->popFlashMessages();
foreach ($flashMessages as $flashMessage) {
$content .= $flashMessage->render();
}
return $content;
}
/**
* Function to load a HTML template file with markers.
* When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
*
......
}
// adding flash messages
$flashMessages = $this->renderFlashMessages();
$flashMessages = t3lib_messageQueue::renderFlashMessages();
if (!empty($flashMessages)) {
$flashMessages = '<div id="typo3-messages">' . $flashMessages . '</div>';
}
typo3/alt_doc.php (Arbeitskopie)
'',
t3lib_FlashMessage::WARNING
);
$this->doc->pushFlashMessage($lockedMessage);
t3lib_messageQueue::addMessage($lockedMessage);
}
// Combine it all:
typo3/mod/web/perm/index.php (Arbeitskopie)
$LANG->getLL('WorkspaceWarning'),
t3lib_FlashMessage::WARNING
);
$this->doc->pushFlashMessage($lockedMessage);
t3lib_messageQueue::addMessage($lockedMessage);
}
// Get usernames and groupnames
typo3/sysext/tstemplate_objbrowser/class.tx_tstemplateobjbrowser.php (Arbeitskopie)
$GLOBALS['LANG']->getLL('badProperty'),
t3lib_FlashMessage::ERROR
);
$this->pObj->doc->pushFlashMessage($badPropertyMessage);
t3lib_messageQueue::addMessage($badPropertyMessage);
} else {
$pline = $name . '.' . $property . ' = '
. trim($POST['data'][$name]['propertyValue']);
......
htmlspecialchars($pline),
$GLOBALS['LANG']->getLL('propertyAdded')
);
$this->pObj->doc->pushFlashMessage($propertyAddedMessage);
t3lib_messageQueue::addMessage($propertyAddedMessage);
$line.=chr(10).$pline;
}
......
htmlspecialchars($pline),
$GLOBALS['LANG']->getLL('valueUpdated')
);
$this->pObj->doc->pushFlashMessage($updatedMessage);
t3lib_messageQueue::addMessage($updatedMessage);
$line .= chr(10) . $pline;
} elseif ($POST['clear_object']) {
......
htmlspecialchars($pline),
$GLOBALS['LANG']->getLL('objectCleared')
);
$this->pObj->doc->pushFlashMessage($objectClearedMessage);
t3lib_messageQueue::addMessage($objectClearedMessage);
$line .= chr(10) . $pline;
}
......
t3lib_FlashMessage::ERROR
);
$this->pObj->doc->pushFlashMessage($noTemplateMessage);
t3lib_messageQueue::addMessage($noTemplateMessage);
}
// Links:
$out = '';
typo3/sysext/cms/layout/db_layout.php (Arbeitskopie)
'',
t3lib_FlashMessage::WARNING
);
$this->doc->pushFlashMessage($lockedMessage);
t3lib_messageQueue::addMessage($lockedMessage);
}
// Add whole form as a document section:
typo3/sysext/scheduler/mod1/index.php (Arbeitskopie)
$severity
);
$this->doc->pushFlashMessage($message);
t3lib_messageQueue::addMessage($message);
}
/**
    (1-1/1)