TYPO3 CMS  TYPO3_6-2
Status.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $statusProviders = array();
27 
31  public function __construct() {
32  $this->getStatusProviders();
33  $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xlf');
34  }
35 
41  public function getReport() {
42  $content = '';
43  $status = $this->getSystemStatus();
44  $highestSeverity = $this->getHighestSeverity($status);
45  // Updating the registry
47  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
48  $content .= '<p class="lead">' . $GLOBALS['LANG']->getLL('status_report_explanation') . '</p>';
49  return $content . $this->renderStatus($status);
50  }
51 
57  protected function getStatusProviders() {
58  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
59  $this->statusProviders[$key] = array();
60  foreach ($statusProvidersList as $statusProvider) {
61  $statusProviderInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($statusProvider);
62  if ($statusProviderInstance instanceof \TYPO3\CMS\Reports\StatusProviderInterface) {
63  $this->statusProviders[$key][] = $statusProviderInstance;
64  }
65  }
66  }
67  }
68 
74  public function getSystemStatus() {
75  $status = array();
76  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
77  $status[$statusProviderId] = array();
78  foreach ($statusProviderList as $statusProvider) {
79  $statuses = $statusProvider->getStatus();
80  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
81  }
82  }
83  return $status;
84  }
85 
92  public function getHighestSeverity(array $statusCollection) {
93  $highestSeverity = \TYPO3\CMS\Reports\Status::NOTICE;
94  foreach ($statusCollection as $statusProvider => $providerStatuses) {
96  foreach ($providerStatuses as $status) {
97  if ($status->getSeverity() > $highestSeverity) {
98  $highestSeverity = $status->getSeverity();
99  }
100  // Reached the highest severity level, no need to go on
101  if ($highestSeverity == \TYPO3\CMS\Reports\Status::ERROR) {
102  break;
103  }
104  }
105  }
106  return $highestSeverity;
107  }
108 
115  protected function renderStatus(array $statusCollection) {
116  // TODO refactor into separate methods, status list and single status
117  $content = '';
118  $template = '
119  <div class="typo3-message message-###CLASS###">
120  <div class="header-container">
121  <div class="message-header message-left">###HEADER###</div>
122  <div class="message-header message-right">###STATUS###</div>
123  </div>
124  <div class="message-body">###CONTENT###</div>
125  </div>';
126  $statuses = $this->sortStatusProviders($statusCollection);
127  foreach ($statuses as $provider => $providerStatus) {
128  $providerState = $this->sortStatuses($providerStatus);
129  $id = str_replace(' ', '-', $provider);
130  $classes = array(
131  \TYPO3\CMS\Reports\Status::NOTICE => 'notice',
132  \TYPO3\CMS\Reports\Status::INFO => 'information',
133  \TYPO3\CMS\Reports\Status::OK => 'ok',
134  \TYPO3\CMS\Reports\Status::WARNING => 'warning',
135  \TYPO3\CMS\Reports\Status::ERROR => 'error'
136  );
139  $messages = '';
140  $headerIcon = '';
141  $sectionSeverity = 0;
143  foreach ($providerState as $status) {
144  $severity = $status->getSeverity();
145  $sectionSeverity = $severity > $sectionSeverity ? $severity : $sectionSeverity;
146  $messages .= strtr($template, array(
147  '###CLASS###' => $classes[$severity],
148  '###HEADER###' => $status->getTitle(),
149  '###STATUS###' => $status->getValue(),
150  '###CONTENT###' => $status->getMessage()
151  ));
152  }
153  if ($sectionSeverity > 0) {
154  $headerIcon = $icon[$sectionSeverity];
155  }
156  $content .= $GLOBALS['TBE_TEMPLATE']->collapseableSection($headerIcon . $provider, $messages, $id, 'reports.states');
157  }
158  return $content;
159  }
160 
167  protected function sortStatusProviders(array $statusCollection) {
168  // Extract the primary status collections, i.e. the status groups
169  // that must appear on top of the status report
170  // Change their keys to localized collection titles
171  $primaryStatuses = array(
172  $GLOBALS['LANG']->getLL('status_typo3') => $statusCollection['typo3'],
173  $GLOBALS['LANG']->getLL('status_system') => $statusCollection['system'],
174  $GLOBALS['LANG']->getLL('status_security') => $statusCollection['security'],
175  $GLOBALS['LANG']->getLL('status_configuration') => $statusCollection['configuration']
176  );
177  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
178  // Assemble list of secondary status collections with left-over collections
179  // Change their keys using localized labels if available
180  // TODO extract into getLabel() method
181  $secondaryStatuses = array();
182  foreach ($statusCollection as $statusProviderId => $collection) {
183  $label = '';
184  if (strpos($statusProviderId, 'LLL:') === 0) {
185  // Label provided by extension
186  $label = $GLOBALS['LANG']->sL($statusProviderId);
187  } else {
188  // Generic label
189  $label = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
190  }
191  $providerLabel = empty($label) ? $statusProviderId : $label;
192  $secondaryStatuses[$providerLabel] = $collection;
193  }
194  // Sort the secondary status collections alphabetically
195  ksort($secondaryStatuses);
196  $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
197  return $orderedStatusCollection;
198  }
199 
206  protected function sortStatuses(array $statusCollection) {
207  $statuses = array();
208  $sortTitle = array();
210  foreach ($statusCollection as $status) {
211  if ($status->getTitle() === 'TYPO3') {
212  $header = $status;
213  continue;
214  }
215  $statuses[] = $status;
216  $sortTitle[] = $status->getSeverity();
217  }
218  array_multisort($sortTitle, SORT_DESC, $statuses);
219  // Making sure that the core version information is always on the top
220  if (is_object($header)) {
221  array_unshift($statuses, $header);
222  }
223  return $statuses;
224  }
225 
226 }
sortStatusProviders(array $statusCollection)
Definition: Status.php:167
$registry
Definition: ext_tables.php:46
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]