TYPO3 API  SVNRelease
class.t3lib_message_errorpagemessage.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Benjamin Mack <benni@typo3.org>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * A class representing error messages shown on a page.
00030  * Classic Example: "No pages are found on rootlevel"
00031  *
00032  * @author  Benjamin Mack <benni@typo3.org>
00033  * @package TYPO3
00034  * @subpackage t3lib/message
00035  */
00036 class t3lib_message_ErrorpageMessage extends t3lib_message_AbstractMessage {
00037 
00038     /**
00039      * defines whether the message should be stored in the session
00040      * (to survive redirects) or only for one request (default)
00041      *
00042      * @var string
00043      */
00044     protected $htmlTemplate;
00045 
00046     /**
00047      * Constructor for a error message
00048      *
00049      * @param   string  The message.
00050      * @param   string  message title.
00051      * @param   integer Optional severity, must be either of t3lib_message_ErrorpageMessage::INFO, t3lib_message_ErrorpageMessage::OK,
00052      *                t3lib_message_ErrorpageMessage::WARNING or t3lib_message_ErrorpageMessage::ERROR. Default is t3lib_message_ErrorpageMessage::ERROR.
00053      * @return  void
00054      */
00055     public function __construct($message, $title, $severity = self::ERROR) {
00056         $this->htmlTemplate = TYPO3_mainDir . 'sysext/t3skin/templates/errorpage-message.html';
00057         $this->setMessage($message);
00058         $this->setTitle(strlen($title) > 0 ? $title : 'Error!');
00059         $this->setSeverity($severity);
00060     }
00061 
00062 
00063     /**
00064      * Gets the filename of the HTML template.
00065      *
00066      * @return  string  The filename of the HTML template.
00067      */
00068     public function getHtmlTemplate() {
00069         return $this->htmlTemplate;
00070     }
00071 
00072     /**
00073      * Sets the filename to the HTML template
00074      *
00075      * @param   string  The filename to the HTML template.
00076      * @return  void
00077      */
00078     public function setHtmlTemplate($htmlTemplate) {
00079         $this->htmlTemplate = (string) $htmlTemplate;
00080     }
00081 
00082     /**
00083      * Renders the flash message.
00084      *
00085      * @return  string  The flash message as HTML.
00086      */
00087     public function render() {
00088         $classes = array(
00089             self::NOTICE  => 'notice',
00090             self::INFO    => 'information',
00091             self::OK      => 'ok',
00092             self::WARNING => 'warning',
00093             self::ERROR   => 'error',
00094         );
00095 
00096         $markers = array(
00097             '###CSS_CLASS###'     => $classes[$this->severity],
00098             '###TITLE###'         => $this->title,
00099             '###MESSAGE###'       => $this->message,
00100             '###BASEURL###'       => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
00101             '###TYPO3_mainDir###' => TYPO3_mainDir,
00102             '###TYPO3_copyright_year###' => TYPO3_copyright_year,
00103         );
00104 
00105         $content = t3lib_div::getUrl(PATH_site . $this->htmlTemplate);
00106         $content = t3lib_parseHtml::substituteMarkerArray($content, $markers, '', FALSE, TRUE);
00107         return $content;
00108     }
00109 
00110     /**
00111      * Renders the flash message and echoes it.
00112      *
00113      * @return  void
00114      */
00115     public function output() {
00116         $content = $this->render();
00117         echo $content;
00118     }
00119 
00120 }
00121 
00122 
00123 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php'])) {
00124     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/message/class.t3lib_message_errorpagemessage.php']);
00125 }
00126 
00127 ?>