TYPO3 API  SVNRelease
class.tx_sv_reports_serviceslist.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Francois Suter <francois@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  * This class provides a report displaying a list of all installed services
00028  * Code inspired by EXT:dam/lib/class.tx_dam_svlist.php by René Fritz
00029  *
00030  * @author  Francois Suter <francois@typo3.org>
00031  * @package TYPO3
00032  * @subpackage sv
00033  *
00034  * $Id: class.tx_sv_reports_serviceslist.php 10120 2011-01-18 20:03:36Z ohader $
00035  */
00036 class tx_sv_reports_ServicesList implements tx_reports_Report {
00037 
00038     /**
00039      * Back-reference to the calling reports module
00040      *
00041      * @var tx_reports_Module   $reportsModule
00042      */
00043     protected $reportsModule;
00044 
00045     /**
00046      * Constructor for class tx_sv_reports_ServicesList
00047      *
00048      * @param   tx_reports_Module   Back-reference to the calling reports module
00049      */
00050     public function __construct(tx_reports_Module $reportsModule) {
00051         $this->reportsModule = $reportsModule;
00052         $GLOBALS['LANG']->includeLLFile('EXT:sv/reports/locallang.xml');
00053     }
00054 
00055     /**
00056      * This method renders the report
00057      *
00058      * @return  string  The status report as HTML
00059      */
00060     public function getReport() {
00061         $content = '';
00062 
00063             // Add custom stylesheet
00064         $this->reportsModule->doc->getPageRenderer()->addCssFile(
00065             t3lib_extMgm::extRelPath('sv') . 'reports/tx_sv_report.css'
00066         );
00067 
00068         $content .= $this->renderHelp();
00069         $content .= $this->reportsModule->doc->spacer(10);
00070         $content .= $this->renderServicesList();
00071         $content .= $this->reportsModule->doc->spacer(10);
00072         $content .= $this->renderExecutablesSearchPathList();
00073 
00074         return $content;
00075     }
00076 
00077     /**
00078      * Renders the help comments at the top of the module.
00079      *
00080      * @return  string  The help content for this module.
00081      */
00082     protected function renderHelp() {
00083         $help .= '<p class="help">'
00084             . $GLOBALS['LANG']->getLL('report_explanation')
00085             . '</p>';
00086         $help .= '<p class="help">'
00087             . $GLOBALS['LANG']->getLL('externals_explanation')
00088             . '</p>';
00089 
00090         return $help;
00091     }
00092 
00093     /**
00094      * This method assembles a list of all installed services
00095      *
00096      * @return  string  HTML to display
00097      */
00098     protected function renderServicesList() {
00099         $servicesList = '';
00100         $services = $this->getInstalledServices();
00101 
00102         foreach ($services as $serviceType => $installedServices) {
00103             $servicesList .= $this->renderServiceTypeList($serviceType, $installedServices);
00104         }
00105 
00106         return $servicesList;
00107     }
00108 
00109     /**
00110      * Renders the services list for a single service type.
00111      *
00112      * @param   string  $serviceType the service type to render the installed services list for.
00113      * @return  string  Service list as HTML for one service type.
00114      */
00115     protected function renderServiceTypeList($serviceType, $services) {
00116         $header = '<h4>' . sprintf(
00117             $GLOBALS['LANG']->getLL('service_type'),
00118             $serviceType
00119         ) . '</h4>';
00120 
00121         $serviceList .= '
00122         <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist services">
00123             <tr class="t3-row-header">
00124                 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('service') . '</td>
00125                 <td>' . $GLOBALS['LANG']->getLL('priority') . '</td>
00126                 <td>' . $GLOBALS['LANG']->getLL('quality') . '</td>
00127                 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>
00128                 <td>' . $GLOBALS['LANG']->getLL('os') . '</td>
00129                 <td>' . $GLOBALS['LANG']->getLL('externals') . '</td>
00130                 <td>' . $GLOBALS['LANG']->getLL('available') . '</td>
00131             </tr>';
00132 
00133         foreach ($services as $serviceKey => $serviceInformation) {
00134             $serviceList .= $this->renderServiceRow($serviceKey, $serviceInformation);
00135         }
00136 
00137         $serviceList .= '
00138         </table>
00139         ';
00140 
00141         return $header . $serviceList . $this->reportsModule->doc->spacer(10);
00142     }
00143 
00144     /**
00145      * Renders a single service's row.
00146      *
00147      * @param   string  $sericeKey The service key to access the service.
00148      * @param   array   $serviceInformation registration information of the service.
00149      * @return  string  HTML row for the service.
00150      */
00151     protected function renderServiceRow($serviceKey, $serviceInformation) {
00152         $serviceDescription = '
00153             <p class="service-header">
00154                 <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
00155             </p>';
00156         if (!empty($serviceInformation['description'])) {
00157             $serviceDescription .= '<p class="service-description">' . $serviceInformation['description']. '</p>';
00158         }
00159 
00160         $sericeSubtypes = empty($serviceInformation['serviceSubTypes']) ?
00161             '-' :
00162             implode(', ', $serviceInformation['serviceSubTypes']);
00163 
00164         $serviceOperatingSystem = empty($serviceInformation['os']) ?
00165             $GLOBALS['LANG']->getLL('any') :
00166             $serviceInformation['os'];
00167 
00168         $serviceRequiredExecutables = empty($serviceInformation['exec']) ?
00169             '-' :
00170             $serviceInformation['exec'];
00171 
00172         $serviceAvailabilityClass = 'typo3-message message-error';
00173         $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
00174         if (t3lib_extmgm::findService($serviceKey, '*')) {
00175             $serviceAvailabilityClass = 'typo3-message message-ok';
00176             $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
00177         }
00178 
00179         $serviceRow = '
00180         <tr class="service">
00181             <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
00182             <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
00183             <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
00184             <td class="cell ' . $serviceAvailabilityClass . '">' . $sericeSubtypes . '</td>
00185             <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
00186             <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
00187             <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>
00188         </tr>';
00189 
00190         return $serviceRow;
00191     }
00192 
00193     /**
00194      * This method assembles a list of all defined executables search paths
00195      *
00196      * @return  string  HTML to display
00197      */
00198     protected function renderExecutablesSearchPathList() {
00199         $searchPaths = t3lib_exec::getPaths(TRUE);
00200 
00201         $content = '<h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
00202 
00203         if (count($searchPaths) == 0) {
00204             $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
00205         } else {
00206             $content .= '
00207             <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist paths">
00208                 <thead>
00209                     <tr class="t3-row-header">
00210                         <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
00211                         <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
00212                     </tr>
00213                 </thead>
00214                 <tbody>';
00215 
00216             foreach ($searchPaths as $path => $isValid) {
00217                 $pathAccessibleClass = 'typo3-message message-error';
00218                 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
00219                 if ($isValid) {
00220                     $pathAccessibleClass = 'typo3-message message-ok';
00221                     $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
00222                 }
00223 
00224                 $content .= '
00225                     <tr>
00226                         <td class="first-cell ' . $pathAccessibleClass . '">' . t3lib_div::fixWindowsFilePath($path) . '</td>
00227                         <td class="last-cell ' . $pathAccessibleClass . '">' . $pathAccessible . '</td>
00228                     </tr>';
00229             }
00230 
00231             $content .= '
00232                 </tbody>
00233             </table>';
00234         }
00235 
00236         return $content;
00237     }
00238 
00239     /**
00240      * This method filters the $T3_SERVICES global array to return a relevant,
00241      * ordered list of installed services.
00242      *
00243      * Every installed service appears twice in $T3_SERVICES: once as a service key
00244      * for a given service type, and once a service type all by itself
00245      * The list of services to display must avoid these duplicates
00246      *
00247      * Furthermore, inside each service type, installed services must be
00248      * ordered by priority and quality
00249      *
00250      * @return  array   List of filtered and ordered services
00251      */
00252     protected function getInstalledServices() {
00253         $filteredServices = array();
00254 
00255         foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
00256                 // If the (first) key of the service list is not the same as the service type,
00257                 // it's a "true" service type. Keep it and sort it.
00258             if (key($serviceList) !== $serviceType) {
00259                 uasort($serviceList, array($this, 'sortServices'));
00260                 $filteredServices[$serviceType] = $serviceList;
00261             }
00262         }
00263 
00264         return $filteredServices;
00265     }
00266 
00267     /**
00268      * Utility method used to sort services according to their priority and
00269      * quality.
00270      *
00271      * @param   array       First service to compare
00272      * @param   array       Second service to compare
00273      *
00274      * @return  integer     1, 0 or -1 if a is smaller, equal or greater than b, respectively
00275      */
00276     protected function sortServices(array $a, array $b) {
00277         $result = 0;
00278 
00279             // If priorities are the same, test quality
00280         if ($a['priority'] == $b['priority']) {
00281             if ($a['quality'] != $b['quality']) {
00282                     // Service with highest quality should come first,
00283                     // thus it must be marked as smaller
00284                 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
00285             }
00286         } else {
00287                 // Service with highest priority should come first,
00288                 // thus it must be marked as smaller
00289             $result = ($a['priority'] > $b['priority']) ? -1 : 1;
00290         }
00291 
00292         return $result;
00293     }
00294 }
00295 
00296 
00297 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php'])) {
00298     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
00299 }
00300 
00301 ?>