|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Ingo Renner <ingo@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 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 00026 /** 00027 * The status report 00028 * 00029 * @author Ingo Renner <ingo@typo3.org> 00030 * @package TYPO3 00031 * @subpackage reports 00032 * 00033 * $Id: class.tx_reports_reports_status.php 10120 2011-01-18 20:03:36Z ohader $ 00034 */ 00035 class tx_reports_reports_Status implements tx_reports_Report { 00036 00037 protected $statusProviders = array(); 00038 00039 /** 00040 * Constructor for class tx_reports_report_Status 00041 */ 00042 public function __construct() { 00043 $this->getStatusProviders(); 00044 00045 $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xml'); 00046 } 00047 00048 /** 00049 * Takes care of creating / rendering the status report 00050 * 00051 * @return string The status report as HTML 00052 */ 00053 public function getReport() { 00054 $content = ''; 00055 00056 foreach ($this->statusProviders as $statusProviderId => $statusProvidersList) { 00057 $status[$statusProviderId] = array(); 00058 foreach ($statusProvidersList as $statusProvider) { 00059 $statuses = $statusProvider->getStatus(); 00060 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses); 00061 } 00062 } 00063 00064 $status = $this->getSystemStatus(); 00065 $highestSeverity = $this->getHighestSeverity($status); 00066 00067 // updating the registry 00068 $registry = t3lib_div::makeInstance('t3lib_Registry'); 00069 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity); 00070 00071 $content .= '<p class="help">' 00072 . $GLOBALS['LANG']->getLL('status_report_explanation') 00073 . '</p>'; 00074 00075 return $content . $this->renderStatus($status); 00076 } 00077 00078 /** 00079 * Gets all registered status providers and creates instances of them. 00080 * 00081 */ 00082 protected function getStatusProviders() { 00083 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) { 00084 $this->statusProviders[$key] = array(); 00085 00086 foreach ($statusProvidersList as $statusProvider) { 00087 $statusProviderInstance = t3lib_div::makeInstance($statusProvider); 00088 00089 if ($statusProviderInstance instanceof tx_reports_StatusProvider) { 00090 $this->statusProviders[$key][] = $statusProviderInstance; 00091 } 00092 } 00093 } 00094 } 00095 00096 /** 00097 * Runs through all status providers and returns all statuses collected. 00098 * 00099 * @return array An array of tx_reports_reports_status_Status objects 00100 */ 00101 public function getSystemStatus() { 00102 $status = array(); 00103 00104 foreach ($this->statusProviders as $statusProviderId => $statusProviderList) { 00105 $status[$statusProviderId] = array(); 00106 00107 foreach ($statusProviderList as $statusProvider) { 00108 $statuses = $statusProvider->getStatus(); 00109 $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses); 00110 } 00111 } 00112 00113 return $status; 00114 } 00115 00116 /** 00117 * Determines the highest severity from the given statuses. 00118 * 00119 * @param array An array of tx_reports_reports_status_Status objects. 00120 * @return integer The highest severity found from the statuses. 00121 */ 00122 public function getHighestSeverity(array $statusCollection) { 00123 $highestSeverity = tx_reports_reports_status_Status::NOTICE; 00124 00125 foreach ($statusCollection as $statusProvider => $providerStatuses) { 00126 foreach ($providerStatuses as $status) { 00127 if ($status->getSeverity() > $highestSeverity) { 00128 $highestSeverity = $status->getSeverity(); 00129 } 00130 00131 // reached the highest severity level, no need to go on 00132 if ($highestSeverity == tx_reports_reports_status_Status::ERROR) { 00133 break; 00134 } 00135 } 00136 } 00137 00138 return $highestSeverity; 00139 } 00140 00141 /** 00142 * Renders the system's status 00143 * 00144 * @param array An array of statuses as returned by the available status providers 00145 * @return string The system status as an HTML table 00146 */ 00147 protected function renderStatus(array $statusCollection) { 00148 00149 // TODO refactor into separate methods, status list and single status 00150 00151 $content = ''; 00152 $template = ' 00153 <div class="typo3-message message-###CLASS###"> 00154 <div class="header-container"> 00155 <div class="message-header message-left">###HEADER###</div> 00156 <div class="message-header message-right">###STATUS###</div> 00157 </div> 00158 <div class="message-body">###CONTENT###</div> 00159 </div>'; 00160 00161 $statuses = $this->sortStatusProviders($statusCollection); 00162 00163 foreach($statuses as $provider => $providerStatus) { 00164 $providerState = $this->sortStatuses($providerStatus); 00165 00166 $id = str_replace(' ', '-', $provider); 00167 $classes = array( 00168 tx_reports_reports_status_Status::NOTICE => 'notice', 00169 tx_reports_reports_status_Status::INFO => 'information', 00170 tx_reports_reports_status_Status::OK => 'ok', 00171 tx_reports_reports_status_Status::WARNING => 'warning', 00172 tx_reports_reports_status_Status::ERROR => 'error', 00173 ); 00174 00175 $icon[tx_reports_reports_status_Status::WARNING] = t3lib_iconWorks::getSpriteIcon('status-dialog-warning'); 00176 $icon[tx_reports_reports_status_Status::ERROR] = t3lib_iconWorks::getSpriteIcon('status-dialog-error'); 00177 $messages = ''; 00178 $headerIcon = ''; 00179 $sectionSeverity = 0; 00180 00181 foreach ($providerState as $status) { 00182 $severity = $status->getSeverity(); 00183 $sectionSeverity = $severity > $sectionSeverity ? $severity : $sectionSeverity; 00184 $messages .= strtr($template, array( 00185 '###CLASS###' => $classes[$severity], 00186 '###HEADER###' => $status->getTitle(), 00187 '###STATUS###' => $status->getValue(), 00188 '###CONTENT###' => $status->getMessage(), 00189 )); 00190 } 00191 if ($sectionSeverity > 0) { 00192 $headerIcon = $icon[$sectionSeverity]; 00193 } 00194 $content .= $GLOBALS['TBE_TEMPLATE']->collapseableSection($headerIcon . $provider, $messages, $id, 'reports.states'); 00195 } 00196 00197 return $content; 00198 } 00199 00200 /** 00201 * Sorts the status providers (alphabetically and puts primary status providers at the beginning) 00202 * 00203 * @param array A collection of statuses (with providers) 00204 * @return array The collection of statuses sorted by provider (beginning with provider "_install") 00205 */ 00206 protected function sortStatusProviders(array $statusCollection) { 00207 // Extract the primary status collections, i.e. the status groups 00208 // that must appear on top of the status report 00209 // Change their keys to localized collection titles 00210 $primaryStatuses = array( 00211 $GLOBALS['LANG']->getLL('status_typo3') => $statusCollection['typo3'], 00212 $GLOBALS['LANG']->getLL('status_system') => $statusCollection['system'], 00213 $GLOBALS['LANG']->getLL('status_security') => $statusCollection['security'], 00214 $GLOBALS['LANG']->getLL('status_configuration') => $statusCollection['configuration'] 00215 ); 00216 unset( 00217 $statusCollection['typo3'], 00218 $statusCollection['system'], 00219 $statusCollection['security'], 00220 $statusCollection['configuration'] 00221 ); 00222 00223 // Assemble list of secondary status collections with left-over collections 00224 // Change their keys using localized labels if available 00225 // TODO extract into getLabel() method 00226 $secondaryStatuses = array(); 00227 foreach ($statusCollection as $statusProviderId => $collection) { 00228 $label = ''; 00229 00230 if (strpos($statusProviderId, 'LLL:') === 0) { 00231 // Label provided by extension 00232 $label = $GLOBALS['LANG']->sL($statusProviderId); 00233 } else { 00234 // Generic label 00235 $label = $GLOBALS['LANG']->getLL('status_' . $statusProviderId); 00236 } 00237 00238 $providerLabel = (empty($label)) ? $statusProviderId : $label; 00239 $secondaryStatuses[$providerLabel] = $collection; 00240 } 00241 // Sort the secondary status collections alphabetically 00242 ksort($secondaryStatuses); 00243 $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses); 00244 00245 return $orderedStatusCollection; 00246 } 00247 00248 /** 00249 * Sorts the statuses by severity 00250 * 00251 * @param array A collection of statuses per provider 00252 * @return array The collection of statuses sorted by severity 00253 */ 00254 protected function sortStatuses(array $statusCollection) { 00255 $statuses = array(); 00256 $sortTitle = array(); 00257 00258 foreach ($statusCollection as $status) { 00259 if ($status->getTitle() === 'TYPO3') { 00260 $header = $status; 00261 continue; 00262 } 00263 00264 $statuses[] = $status; 00265 $sortTitle[] = $status->getSeverity(); 00266 } 00267 array_multisort($sortTitle, SORT_DESC, $statuses); 00268 00269 // making sure that the core version information is always on the top 00270 if (is_object($header)) { 00271 array_unshift($statuses, $header); 00272 } 00273 return $statuses; 00274 } 00275 00276 } 00277 00278 00279 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php'])) { 00280 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']); 00281 } 00282 00283 ?>
1.8.0