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