d9860f859816c5bfd473fbb48a212b4f2b6614fd
[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 if (!empty($serviceInformation['description'])) {
156 $serviceDescription .= '<p class="service-description">' . $serviceInformation['description']. '</p>';
157 }
158
159 $sericeSubtypes = 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 if (t3lib_extmgm::findService($serviceKey, '*')) {
174 $serviceAvailabilityClass = 'typo3-message message-ok';
175 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
176 }
177
178 $serviceRow = '
179 <tr class="service">
180 <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
181 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
182 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
183 <td class="cell ' . $serviceAvailabilityClass . '">' . $sericeSubtypes . '</td>
184 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
185 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
186 <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>
187 </tr>';
188
189 return $serviceRow;
190 }
191
192 /**
193 * This method assembles a list of all defined executables search paths
194 *
195 * @return string HTML to display
196 */
197 protected function renderExecutablesSearchPathList() {
198 $searchPaths = t3lib_exec::getPaths(TRUE);
199
200 $content = '<h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
201
202 if (count($searchPaths) == 0) {
203 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
204 } else {
205 $content .= '
206 <table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist paths">
207 <thead>
208 <tr class="t3-row-header">
209 <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
210 <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
211 </tr>
212 </thead>
213 <tbody>';
214
215 foreach ($searchPaths as $path => $isValid) {
216 $pathAccessibleClass = 'typo3-message message-error';
217 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
218 if ($isValid) {
219 $pathAccessibleClass = 'typo3-message message-ok';
220 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
221 }
222
223 $content .= '
224 <tr>
225 <td class="first-cell ' . $pathAccessibleClass . '">' . t3lib_div::fixWindowsFilePath($path) . '</td>
226 <td class="last-cell ' . $pathAccessibleClass . '">' . $pathAccessible . '</td>
227 </tr>';
228 }
229
230 $content .= '
231 </tbody>
232 </table>';
233 }
234
235 return $content;
236 }
237
238 /**
239 * This method filters the $T3_SERVICES global array to return a relevant,
240 * ordered list of installed services.
241 *
242 * Every installed service appears twice in $T3_SERVICES: once as a service key
243 * for a given service type, and once a service type all by itself
244 * The list of services to display must avoid these duplicates
245 *
246 * Furthermore, inside each service type, installed services must be
247 * ordered by priority and quality
248 *
249 * @return array List of filtered and ordered services
250 */
251 protected function getInstalledServices() {
252 $filteredServices = array();
253
254 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
255 // If the (first) key of the service list is not the same as the service type,
256 // it's a "true" service type. Keep it and sort it.
257 if (key($serviceList) !== $serviceType) {
258 uasort($serviceList, array($this, 'sortServices'));
259 $filteredServices[$serviceType] = $serviceList;
260 }
261 }
262
263 return $filteredServices;
264 }
265
266 /**
267 * Utility method used to sort services according to their priority and
268 * quality.
269 *
270 * @param array $a First service to compare
271 * @param array $b Second service to compare
272 *
273 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
274 */
275 protected function sortServices(array $a, array $b) {
276 $result = 0;
277
278 // If priorities are the same, test quality
279 if ($a['priority'] == $b['priority']) {
280 if ($a['quality'] != $b['quality']) {
281 // Service with highest quality should come first,
282 // thus it must be marked as smaller
283 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
284 }
285 } else {
286 // Service with highest priority should come first,
287 // thus it must be marked as smaller
288 $result = ($a['priority'] > $b['priority']) ? -1 : 1;
289 }
290
291 return $result;
292 }
293 }
294
295
296 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php'])) {
297 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
298 }
299
300 ?>