a94583de21a0330cf72d6138001dd53edb3333cd
[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->displaySearchPaths();
76
77 return $content;
78 }
79
80 /**
81 * This method assembles a list of all installed services
82 *
83 * @return string HTML to display
84 */
85 protected function displayServiceList() {
86 $content = '';
87 $services = $this->getInstalledServices();
88 $content .= '<table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist">';
89 foreach ($services as $serviceType => $installedServices) {
90 $content .= '<tr><td colspans="7">';
91 $content .= '<h4>' . sprintf($GLOBALS['LANG']->getLL('service_type'), $serviceType) . '</h4>';
92 $content .= '</td></tr>';
93 $content .= '<tr class="bgColor2">';
94 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('service') . '</td>';
95 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('priority') . '</td>';
96 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('quality') . '</td>';
97 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>';
98 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('os') . '</td>';
99 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('externals') . '</td>';
100 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('available') . '</td>';
101 $content .= '</tr>';
102 foreach ($installedServices as $serviceKey => $serviceInfo) {
103 $content .= '<tr class="bgColor3-20">';
104 $cellContent = '<p class="service-header"><span class="service-title">' . $serviceInfo['title'] . '</span> (' . $serviceInfo['extKey'] . ': ' . $serviceKey . ')</p>';
105 if (!empty($serviceInfo['description'])) {
106 $cellContent .= '<p class="service-description">' . $serviceInfo['description']. '</p>';
107 }
108 $content .= '<td class="cell">' . $cellContent . '</td>';
109 $content .= '<td class="cell">' . $serviceInfo['priority'] . '</td>';
110 $content .= '<td class="cell">' . $serviceInfo['quality'] . '</td>';
111 $content .= '<td class="cell">' . ((empty($serviceInfo['serviceSubTypes'])) ? '-' : implode(', ', $serviceInfo['serviceSubTypes'])) . '</td>';
112 $content .= '<td class="cell">' . ((empty($serviceInfo['os'])) ? $GLOBALS['LANG']->getLL('any') : $serviceInfo['os']) . '</td>';
113 $content .= '<td class="cell">' . ((empty($serviceInfo['exec'])) ? '-' : $serviceInfo['exec']) . '</td>';
114 $class = 'typo3-message message-error';
115 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
116 if (t3lib_extmgm::findService($serviceKey, '*')) {
117 $class = 'typo3-message message-ok';
118 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
119 }
120 $content .= '<td class="cell ' . $class . '">' . $message . '</td>';
121 $content .= '</tr>';
122 }
123 }
124 $content .= '</table>';
125 return $content;
126 }
127
128 /**
129 * This method assembles a list of all defined search paths
130 *
131 * @return string HTML to display
132 */
133 protected function displaySearchPaths() {
134 $content = '<h3 class="uppercase">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
135 $searchPaths = t3lib_exec::getPaths(true);
136 if (count($searchPaths) == 0) {
137 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
138 } else {
139 $content .= '<table cellspacing="1" cellpadding="2" border="0" class="tx_sv_reportlist">';
140 $content .= '<thead>';
141 $content .= '<tr class="bgColor2">';
142 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('path') . '</td>';
143 $content .= '<td class="cell">' . $GLOBALS['LANG']->getLL('valid') . '</td>';
144 $content .= '</tr>';
145 $content .= '</thead>';
146 $content .= '<tbody>';
147 foreach ($searchPaths as $path => $isValid) {
148 $content .= '<tr class="bgColor3-20">';
149 $content .= '<td class="cell">' . t3lib_div::fixWindowsFilePath($path) . '</td>';
150 $class = 'typo3-message message-error';
151 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
152 if ($isValid) {
153 $class = 'typo3-message message-ok';
154 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
155 }
156 $content .= '<td class="cell ' . $class . '">' . $message . '</td>';
157 $content .= '</tr>';
158 }
159 $content .= '</tbody>';
160 $content .= '</table>';
161 }
162 return $content;
163 }
164
165 /**
166 * This method filters the $T3_SERVICES global array to return a relevant,
167 * ordered list of installed services
168 *
169 * Every installed service appears twice in $T3_SERVICES: once as a service key
170 * for a given service type, and once a service type all by itself
171 * The list of services to display must avoid these duplicates
172 *
173 * Furthermore, inside each service type, installed services must be
174 * ordered by priority and quality
175 *
176 * @return array List of filtered and ordered services
177 */
178 protected function getInstalledServices() {
179 $filteredServices = array();
180
181 // Loop on all installed services
182 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
183 // If the (first) key of the service list is not the same as the service type,
184 // it's a "true" service type. Keep it and sort it.
185 if (key($serviceList) !== $serviceType) {
186 uasort($serviceList, array('tx_sv_reports_ServicesList', 'sortServices'));
187 $filteredServices[$serviceType] = $serviceList;
188 }
189 }
190 return $filteredServices;
191 }
192
193 /**
194 * Utility method used to sort services according to their priority and quality
195 *
196 * @param array First service to compare
197 * @param array Second service to compare
198 *
199 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
200 */
201 public function sortServices(array $a, array $b) {
202 $result = 0;
203 // If priorities are the same, test quality
204 if ($a['priority'] == $b['priority']) {
205 if ($a['quality'] != $b['quality']) {
206 // Service with highest quality should come first,
207 // thus it must be marked as smaller
208 $result = ($a['quality'] > $b['quality']) ? -1 : 1;
209 }
210 } else {
211 // Service with highest priority should come first,
212 // thus it must be marked as smaller
213 $result = ($a['priority'] > $b['priority']) ? -1 : 1;
214 }
215 return $result;
216 }
217 }
218
219
220 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
221 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
222 }
223
224 ?>