[BUGFIX] Reports module: Available services broken
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / reports / class.tx_sv_reports_serviceslist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 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 René Fritz
29 *
30 * @author Francois Suter <francois@typo3.org>
31 * @package TYPO3
32 * @subpackage sv
33 */
34 class tx_sv_reports_ServicesList implements tx_reports_Report {
35
36 /**
37 * Back-reference to the calling reports module
38 *
39 * @var tx_reports_Module $reportsModule
40 */
41 protected $reportsModule;
42
43 /**
44 * Constructor for class tx_sv_reports_ServicesList
45 *
46 * @param tx_reports_Module $reportsModule Back-reference to the calling reports module
47 */
48 public function __construct(tx_reports_Module $reportsModule) {
49 $this->reportsModule = $reportsModule;
50 $GLOBALS['LANG']->includeLLFile('EXT:sv/reports/locallang.xml');
51 }
52
53 /**
54 * This method renders the report
55 *
56 * @return string The status report as HTML
57 */
58 public function getReport() {
59 $content = '';
60
61 // Add custom stylesheet
62 $this->reportsModule->doc->getPageRenderer()->addCssFile(
63 t3lib_extMgm::extRelPath('sv') . 'reports/tx_sv_report.css'
64 );
65
66 $content .= $this->renderHelp();
67 $content .= $this->reportsModule->doc->spacer(10);
68 $content .= $this->renderServicesList();
69 $content .= $this->reportsModule->doc->spacer(10);
70 $content .= $this->renderExecutablesSearchPathList();
71
72 return $content;
73 }
74
75 /**
76 * Renders the help comments at the top of the module.
77 *
78 * @return string The help content for this module.
79 */
80 protected function renderHelp() {
81 $help = '<p class="help">'
82 . $GLOBALS['LANG']->getLL('report_explanation')
83 . '</p>';
84 $help .= '<p class="help">'
85 . $GLOBALS['LANG']->getLL('externals_explanation')
86 . '</p>';
87
88 return $help;
89 }
90
91 /**
92 * This method assembles a list of all installed services
93 *
94 * @return string HTML to display
95 */
96 protected function renderServicesList() {
97 $servicesList = '';
98 $services = $this->getInstalledServices();
99
100 foreach ($services as $serviceType => $installedServices) {
101 $servicesList .= $this->renderServiceTypeList($serviceType, $installedServices);
102 }
103
104 return $servicesList;
105 }
106
107 /**
108 * Renders the services list for a single service type.
109 *
110 * @param string $serviceType The service type to render the installed services list for
111 * @param array $services List of services for the given type
112 * @return string Service list as HTML for one service type
113 */
114 protected function renderServiceTypeList($serviceType, $services) {
115 $header = '<h4>' . sprintf(
116 $GLOBALS['LANG']->getLL('service_type'),
117 $serviceType
118 ) . '</h4>';
119
120 $serviceList = '
121 <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist services">
122 <tr class="t3-row-header">
123 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('service') . '</td>
124 <td>' . $GLOBALS['LANG']->getLL('priority') . '</td>
125 <td>' . $GLOBALS['LANG']->getLL('quality') . '</td>
126 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>
127 <td>' . $GLOBALS['LANG']->getLL('os') . '</td>
128 <td>' . $GLOBALS['LANG']->getLL('externals') . '</td>
129 <td>' . $GLOBALS['LANG']->getLL('available') . '</td>
130 </tr>';
131
132 foreach ($services as $serviceKey => $serviceInformation) {
133 $serviceList .= $this->renderServiceRow($serviceKey, $serviceInformation);
134 }
135
136 $serviceList .= '
137 </table>
138 ';
139
140 return $header . $serviceList . $this->reportsModule->doc->spacer(10);
141 }
142
143 /**
144 * Renders a single service's row.
145 *
146 * @param string $serviceKey The service key to access the service.
147 * @param array $serviceInformation registration information of the service.
148 * @return string HTML row for the service.
149 */
150 protected function renderServiceRow($serviceKey, $serviceInformation) {
151 $serviceDescription = '
152 <p class="service-header">
153 <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
154 </p>';
155
156 if (!empty($serviceInformation['description'])) {
157 $serviceDescription .= '<p class="service-description">' . $serviceInformation['description']. '</p>';
158 }
159
160 $serviceSubtypes = empty($serviceInformation['serviceSubTypes']) ?
161 '-' :
162 implode(', ', $serviceInformation['serviceSubTypes']);
163
164 $serviceOperatingSystem = empty($serviceInformation['os']) ?
165 $GLOBALS['LANG']->getLL('any') :
166 $serviceInformation['os'];
167
168 $serviceRequiredExecutables = empty($serviceInformation['exec']) ?
169 '-' :
170 $serviceInformation['exec'];
171
172 $serviceAvailabilityClass = 'typo3-message message-error';
173 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
174 try {
175 $serviceDetails = t3lib_extmgm::findServiceByKey($serviceKey);
176 if ($serviceDetails['available']) {
177 $serviceAvailabilityClass = 'typo3-message message-ok';
178 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
179 }
180 }
181 catch (t3lib_exception $e) {
182 // Nothing to do, the default display is already not available
183 }
184
185 $serviceRow = '
186 <tr class="service">
187 <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
188 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
189 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
190 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceSubtypes . '</td>
191 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
192 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
193 <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>
194 </tr>';
195
196 return $serviceRow;
197 }
198
199 /**
200 * This method assembles a list of all defined executables search paths
201 *
202 * @return string HTML to display
203 */
204 protected function renderExecutablesSearchPathList() {
205 $searchPaths = t3lib_exec::getPaths(TRUE);
206
207 $content = '<h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
208
209 if (count($searchPaths) == 0) {
210 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
211 } else {
212 $content .= '
213 <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist paths">
214 <thead>
215 <tr class="t3-row-header">
216 <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
217 <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
218 </tr>
219 </thead>
220 <tbody>';
221
222 foreach ($searchPaths as $path => $isValid) {
223 $pathAccessibleClass = 'typo3-message message-error';
224 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
225 if ($isValid) {
226 $pathAccessibleClass = 'typo3-message message-ok';
227 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
228 }
229
230 $content .= '
231 <tr>
232 <td class="first-cell ' . $pathAccessibleClass . '">' . t3lib_div::fixWindowsFilePath($path) . '</td>
233 <td class="last-cell ' . $pathAccessibleClass . '">' . $pathAccessible . '</td>
234 </tr>';
235 }
236
237 $content .= '
238 </tbody>
239 </table>';
240 }
241
242 return $content;
243 }
244
245 /**
246 * This method filters the $T3_SERVICES global array to return a relevant,
247 * ordered list of installed services.
248 *
249 * Every installed service appears twice in $T3_SERVICES: once as a service key
250 * for a given service type, and once a service type all by itself
251 * The list of services to display must avoid these duplicates
252 *
253 * Furthermore, inside each service type, installed services must be
254 * ordered by priority and quality
255 *
256 * @return array List of filtered and ordered services
257 */
258 protected function getInstalledServices() {
259 $filteredServices = array();
260
261 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
262 // If the (first) key of the service list is not the same as the service type,
263 // it's a "true" service type. Keep it and sort it.
264 if (key($serviceList) !== $serviceType) {
265 uasort($serviceList, array($this, 'sortServices'));
266 $filteredServices[$serviceType] = $serviceList;
267 }
268 }
269
270 return $filteredServices;
271 }
272
273 /**
274 * Utility method used to sort services according to their priority and
275 * quality.
276 *
277 * @param array $a First service to compare
278 * @param array $b Second service to compare
279 *
280 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
281 */
282 protected function sortServices(array $a, array $b) {
283 $result = 0;
284
285 // If priorities are the same, test quality
286 if ($a['priority'] == $b['priority']) {
287 if ($a['quality'] != $b['quality']) {
288 // Service with highest quality should come first,
289 // thus it must be marked as smaller
290 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
291 }
292 } else {
293 // Service with highest priority should come first,
294 // thus it must be marked as smaller
295 $result = ($a['priority'] > $b['priority']) ? -1 : 1;
296 }
297
298 return $result;
299 }
300 }
301
302
303 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php'])) {
304 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
305 }
306
307 ?>