Fixed bug #12695: Added some space between sections of the "Installed services" report
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / reports / class.tx_sv_reports_serviceslist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Francois Suter <francois@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * This class provides a report displaying a list of all installed services
28 * Code inspired by EXT:dam/lib/class.tx_dam_svlist.php by Rene Fritz
29 *
30 * @author Francois Suter <francois@typo3.org>
31 * @package TYPO3
32 * @subpackage sv
33 *
34 * $Id: $
35 */
36 class tx_sv_reports_ServicesList implements tx_reports_Report {
37 /**
38 * Back-reference to the calling reports module
39 *
40 * @var tx_reports_Module $reportObject
41 */
42 protected $reportObject;
43
44 /**
45 * Constructor for class tx_sv_reports_ServicesList
46 *
47 * @param tx_reports_Module Back-reference to the calling reports module
48 */
49 public function __construct(tx_reports_Module $reportObject) {
50 $this->reportObject = $reportObject;
51 $GLOBALS['LANG']->includeLLFile('EXT:sv/reports/locallang.xml');
52 }
53
54 /**
55 * This method renders the report
56 *
57 * @return string The status report as HTML
58 */
59 public function getReport() {
60 $content = '';
61
62 // Add custom stylesheet
63 $this->reportObject->doc->getPageRenderer()->addCssFile(t3lib_extMgm::extRelPath('sv') . 'reports/tx_sv_report.css');
64 // Start assembling content
65 $content .= '<p class="help">'
66 . $GLOBALS['LANG']->getLL('report_explanation')
67 . '</p>';
68 $content .= '<p class="help">'
69 . $GLOBALS['LANG']->getLL('externals_explanation')
70 . '</p>';
71
72 // Get list of installed services
73 $content .= $this->displayServiceList();
74 // Get list of binaries search paths
75 $content .= $this->reportObject->doc->spacer(10);
76 $content .= $this->displaySearchPaths();
77
78 return $content;
79 }
80
81 /**
82 * This method assembles a list of all installed services
83 *
84 * @return string HTML to display
85 */
86 protected function displayServiceList() {
87 $content = '';
88 $services = $this->getInstalledServices();
89 $content .= '<table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist">';
90 foreach ($services as $serviceType => $installedServices) {
91 $content .= '<tr><td colspans="7">';
92 $content .= '<h4>' . sprintf($GLOBALS['LANG']->getLL('service_type'), $serviceType) . '</h4>';
93 $content .= '</td></tr>';
94 $content .= '<tr class="bgColor2">';
95 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('service') . '</td>';
96 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('priority') . '</td>';
97 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('quality') . '</td>';
98 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>';
99 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('os') . '</td>';
100 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('externals') . '</td>';
101 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('available') . '</td>';
102 $content .= '</tr>';
103 foreach ($installedServices as $serviceKey => $serviceInfo) {
104 $content .= '<tr class="bgColor3-20">';
105 $cellContent = '<p class="service-header"><span class="service-title">' . $serviceInfo['title'] . '</span> (' . $serviceInfo['extKey'] . ': ' . $serviceKey . ')</p>';
106 if (!empty($serviceInfo['description'])) {
107 $cellContent .= '<p class="service-description">' . $serviceInfo['description']. '</p>';
108 }
109 $content .= '<td class="cell">' . $cellContent . '</td>';
110 $content .= '<td class="cell">' . $serviceInfo['priority'] . '</td>';
111 $content .= '<td class="cell">' . $serviceInfo['quality'] . '</td>';
112 $content .= '<td class="cell">' . ((empty($serviceInfo['serviceSubTypes'])) ? '-' : implode(', ', $serviceInfo['serviceSubTypes'])) . '</td>';
113 $content .= '<td class="cell">' . ((empty($serviceInfo['os'])) ? $GLOBALS['LANG']->getLL('any') : $serviceInfo['os']) . '</td>';
114 $content .= '<td class="cell">' . ((empty($serviceInfo['exec'])) ? '-' : $serviceInfo['exec']) . '</td>';
115 $class = 'typo3-message message-error';
116 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
117 if (t3lib_extmgm::findService($serviceKey, '*')) {
118 $class = 'typo3-message message-ok';
119 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
120 }
121 $content .= '<td class="cell ' . $class . '">' . $message . '</td>';
122 $content .= '</tr>';
123 }
124 }
125 $content .= '</table>';
126 return $content;
127 }
128
129 /**
130 * This method assembles a list of all defined search paths
131 *
132 * @return string HTML to display
133 */
134 protected function displaySearchPaths() {
135 $content = '<h3 class="uppercase">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
136 $searchPaths = t3lib_exec::getPaths(true);
137 if (count($searchPaths) == 0) {
138 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
139 } else {
140 $content .= '<table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist">';
141 $content .= '<thead>';
142 $content .= '<tr class="bgColor2">';
143 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('path') . '</td>';
144 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('valid') . '</td>';
145 $content .= '</tr>';
146 $content .= '</thead>';
147 $content .= '<tbody>';
148 foreach ($searchPaths as $path => $isValid) {
149 $content .= '<tr class="bgColor3-20">';
150 $content .= '<td class="cell">' . t3lib_div::fixWindowsFilePath($path) . '</td>';
151 $class = 'typo3-message message-error';
152 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
153 if ($isValid) {
154 $class = 'typo3-message message-ok';
155 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
156 }
157 $content .= '<td class="cell ' . $class . '">' . $message . '</td>';
158 $content .= '</tr>';
159 }
160 $content .= '</tbody>';
161 $content .= '</table>';
162 }
163 return $content;
164 }
165
166 /**
167 * This method filters the $T3_SERVICES global array to return a relevant,
168 * ordered list of installed services
169 *
170 * Every installed service appears twice in $T3_SERVICES: once as a service key
171 * for a given service type, and once a service type all by itself
172 * The list of services to display must avoid these duplicates
173 *
174 * Furthermore, inside each service type, installed services must be
175 * ordered by priority and quality
176 *
177 * @return array List of filtered and ordered services
178 */
179 protected function getInstalledServices() {
180 $filteredServices = array();
181
182 // Loop on all installed services
183 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
184 // If the (first) key of the service list is not the same as the service type,
185 // it's a "true" service type. Keep it and sort it.
186 if (key($serviceList) !== $serviceType) {
187 uasort($serviceList, array('tx_sv_reports_ServicesList', 'sortServices'));
188 $filteredServices[$serviceType] = $serviceList;
189 }
190 }
191 return $filteredServices;
192 }
193
194 /**
195 * Utility method used to sort services according to their priority and quality
196 *
197 * @param array First service to compare
198 * @param array Second service to compare
199 *
200 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
201 */
202 public function sortServices(array $a, array $b) {
203 $result = 0;
204 // If priorities are the same, test quality
205 if ($a['priority'] == $b['priority']) {
206 if ($a['quality'] != $b['quality']) {
207 // Service with highest quality should come first,
208 // thus it must be marked as smaller
209 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
210 }
211 } else {
212 // Service with highest priority should come first,
213 // thus it must be marked as smaller
214 $result = ($a['priority'] > $b['priority']) ? -1 : 1;
215 }
216 return $result;
217 }
218 }
219
220
221 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
222 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
223 }
224
225 ?>