TYPO3 CMS  TYPO3_6-2
AbstractStandaloneMessage.php
Go to the documentation of this file.
1 <?php
3 
22 
28  protected $htmlTemplate;
29 
35  protected $defaultMarkers = array();
36 
42  protected $markers = array();
43 
51  public function __construct($message = '', $title = '', $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR) {
52  if (!empty($message)) {
53  $this->setMessage($message);
54  }
55  $this->setTitle(!empty($title) ? $title : 'Error!');
56  $this->setSeverity($severity);
57  }
58 
66  public function setMarkers(array $markers) {
67  $this->markers = array_merge($this->markers, $markers);
68  }
69 
75  protected function getDefaultMarkers() {
76  $classes = array(
77  self::NOTICE => 'notice',
78  self::INFO => 'information',
79  self::OK => 'ok',
80  self::WARNING => 'warning',
81  self::ERROR => 'error'
82  );
83  $defaultMarkers = array(
84  '###CSS_CLASS###' => $classes[$this->severity],
85  '###TITLE###' => $this->title,
86  '###MESSAGE###' => $this->message,
87  // Avoid calling TYPO3_SITE_URL here to get the base URL as it might be that we output an exception message with
88  // invalid trusted host, which would lead to a nested exception! See: #30377
89  // Instead we calculate the relative path to the document root without involving HTTP request parameters.
90  '###BASEURL###' => substr(PATH_site, strlen(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'))),
91  '###TYPO3_mainDir###' => TYPO3_mainDir,
92  '###TYPO3_copyright_year###' => TYPO3_copyright_year
93  );
94  return $defaultMarkers;
95  }
96 
102  public function getHtmlTemplate() {
103  if (!$this->htmlTemplate) {
104  throw new \RuntimeException('No HTML template file has been defined, yet', 1314390127);
105  }
106  return $this->htmlTemplate;
107  }
108 
115  public function setHtmlTemplate($htmlTemplate) {
116  $this->htmlTemplate = PATH_site . $htmlTemplate;
117  if (!file_exists($this->htmlTemplate)) {
118  throw new \RuntimeException('Template file "' . $this->htmlTemplate . '" not found', 1312830504);
119  }
120  }
121 
127  public function render() {
128  $markers = array_merge($this->getDefaultMarkers(), $this->markers);
129  $content = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($this->htmlTemplate);
130  $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $markers, '', FALSE, TRUE);
131  return $content;
132  }
133 
139  public function output() {
140  $content = $this->render();
141  echo $content;
142  }
143 
144 }
__construct($message='', $title='', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR)
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
static substituteMarkerArray($content, $markContentArray, $wrap='', $uppercase=FALSE, $deleteUnused=FALSE)
Definition: HtmlParser.php:189