503028c343dd0f59c73ce64c6939685976d34ac0
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / Classes / Report / ServicesListReport.php
1 <?php
2 namespace TYPO3\CMS\Sv\Report;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * This class provides a report displaying a list of all installed services
19 * Code inspired by EXT:dam/lib/class.tx_dam_svlist.php by René Fritz
20 *
21 * @author Francois Suter <francois@typo3.org>
22 */
23 class ServicesListReport implements \TYPO3\CMS\Reports\ReportInterface {
24
25 /**
26 * Back-reference to the calling reports module
27 *
28 * @var \TYPO3\CMS\Reports\Controller\ReportController
29 */
30 protected $reportsModule;
31
32 /**
33 * Constructor for class tx_sv_reports_ServicesList
34 *
35 * @param tx_reports_Module $reportsModule Back-reference to the calling reports module
36 */
37 public function __construct(\TYPO3\CMS\Reports\Controller\ReportController $reportsModule) {
38 $this->reportsModule = $reportsModule;
39 $GLOBALS['LANG']->includeLLFile('EXT:sv/Resources/Private/Language/locallang.xlf');
40 }
41
42 /**
43 * This method renders the report
44 *
45 * @return string The status report as HTML
46 */
47 public function getReport() {
48 $content = '';
49 $content .= $this->renderHelp();
50 $content .= $this->renderServicesList();
51 $content .= $this->renderExecutablesSearchPathList();
52 return $content;
53 }
54
55 /**
56 * Renders the help comments at the top of the module.
57 *
58 * @return string The help content for this module.
59 */
60 protected function renderHelp() {
61 $help = '<p class="lead">' . $GLOBALS['LANG']->getLL('report_explanation') . '</p>';
62 $help .= '<p class="help">' . $GLOBALS['LANG']->getLL('externals_explanation') . '</p><br />';
63 return $help;
64 }
65
66 /**
67 * This method assembles a list of all installed services
68 *
69 * @return string HTML to display
70 */
71 protected function renderServicesList() {
72 $servicesList = '';
73 $services = $this->getInstalledServices();
74 foreach ($services as $serviceType => $installedServices) {
75 $servicesList .= $this->renderServiceTypeList($serviceType, $installedServices);
76 }
77 return $servicesList;
78 }
79
80 /**
81 * Renders the services list for a single service type.
82 *
83 * @param string $serviceType The service type to render the installed services list for
84 * @param array $services List of services for the given type
85 * @return string Service list as HTML for one service type
86 */
87 protected function renderServiceTypeList($serviceType, $services) {
88 $header = '<h3 class="divider">' . sprintf($GLOBALS['LANG']->getLL('service_type'), $serviceType) . '</h3>';
89 $serviceList = '
90 <table class="t3-table tx_sv_reportlist">
91 <thead><tr class="t3-row-header">
92 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('service') . '</td>
93 <td>' . $GLOBALS['LANG']->getLL('priority') . '</td>
94 <td>' . $GLOBALS['LANG']->getLL('quality') . '</td>
95 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>
96 <td>' . $GLOBALS['LANG']->getLL('os') . '</td>
97 <td>' . $GLOBALS['LANG']->getLL('externals') . '</td>
98 <td>' . $GLOBALS['LANG']->getLL('available') . '</td>
99 </tr></thead><tbody>';
100 foreach ($services as $serviceKey => $serviceInformation) {
101 $serviceList .= $this->renderServiceRow($serviceKey, $serviceInformation);
102 }
103 $serviceList .= '
104 </tbody>
105 </table>
106 ';
107 return $header . $serviceList;
108 }
109
110 /**
111 * Renders a single service's row.
112 *
113 * @param string $serviceKey The service key to access the service.
114 * @param array $serviceInformation registration information of the service.
115 * @return string HTML row for the service.
116 */
117 protected function renderServiceRow($serviceKey, $serviceInformation) {
118 $serviceDescription = '
119 <p class="service-header">
120 <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
121 </p>';
122 if (!empty($serviceInformation['description'])) {
123 $serviceDescription .= '<p class="service-description">' . $serviceInformation['description'] . '</p>';
124 }
125 $serviceSubtypes = $serviceInformation['serviceSubTypes'] ? implode(', ', $serviceInformation['serviceSubTypes']) : '-';
126 $serviceOperatingSystem = $serviceInformation['os'] ?: $GLOBALS['LANG']->getLL('any');
127 $serviceRequiredExecutables = $serviceInformation['exec'] ?: '-';
128 $serviceAvailabilityClass = 'typo3-message message-error';
129 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
130 try {
131 $serviceDetails = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::findServiceByKey($serviceKey);
132 if ($serviceDetails['available']) {
133 $serviceAvailabilityClass = 'typo3-message message-ok';
134 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
135 }
136 } catch (\TYPO3\CMS\Core\Exception $e) {
137
138 }
139 $serviceRow = '
140 <tr class="service">
141 <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
142 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
143 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
144 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceSubtypes . '</td>
145 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
146 <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
147 <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>
148 </tr>';
149 return $serviceRow;
150 }
151
152 /**
153 * This method assembles a list of all defined executables search paths
154 *
155 * @return string HTML to display
156 */
157 protected function renderExecutablesSearchPathList() {
158 $searchPaths = \TYPO3\CMS\Core\Utility\CommandUtility::getPaths(TRUE);
159 $content = '<h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
160 if (count($searchPaths) == 0) {
161 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
162 } else {
163 $content .= '
164 <table class="t3-table tx_sv_reportlist">
165 <thead>
166 <tr class="t3-row-header">
167 <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
168 <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
169 </tr>
170 </thead>
171 <tbody>';
172 foreach ($searchPaths as $path => $isValid) {
173 $pathAccessibleClass = 'typo3-message message-error';
174 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
175 if ($isValid) {
176 $pathAccessibleClass = 'typo3-message message-ok';
177 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
178 }
179 $content .= '
180 <tr>
181 <td class="first-cell ' . $pathAccessibleClass . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixWindowsFilePath($path) . '</td>
182 <td class="last-cell ' . $pathAccessibleClass . '">' . $pathAccessible . '</td>
183 </tr>';
184 }
185 $content .= '
186 </tbody>
187 </table>';
188 }
189 return $content;
190 }
191
192 /**
193 * This method filters the $T3_SERVICES global array to return a relevant,
194 * ordered list of installed services.
195 *
196 * Every installed service appears twice in $T3_SERVICES: once as a service key
197 * for a given service type, and once a service type all by itself
198 * The list of services to display must avoid these duplicates
199 *
200 * Furthermore, inside each service type, installed services must be
201 * ordered by priority and quality
202 *
203 * @return array List of filtered and ordered services
204 */
205 protected function getInstalledServices() {
206 $filteredServices = array();
207 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
208 // If the (first) key of the service list is not the same as the service type,
209 // it's a "true" service type. Keep it and sort it.
210 if (key($serviceList) !== $serviceType) {
211 uasort($serviceList, array($this, 'sortServices'));
212 $filteredServices[$serviceType] = $serviceList;
213 }
214 }
215 return $filteredServices;
216 }
217
218 /**
219 * Utility method used to sort services according to their priority and
220 * quality.
221 *
222 * @param array $a First service to compare
223 * @param array $b Second service to compare
224 * @return integer 1, 0 or -1 if a is smaller, equal or greater than b, respectively
225 */
226 protected function sortServices(array $a, array $b) {
227 $result = 0;
228 // If priorities are the same, test quality
229 if ($a['priority'] == $b['priority']) {
230 if ($a['quality'] != $b['quality']) {
231 // Service with highest quality should come first,
232 // thus it must be marked as smaller
233 $result = $a['quality'] > $b['quality'] ? -1 : 1;
234 }
235 } else {
236 // Service with highest priority should come first,
237 // thus it must be marked as smaller
238 $result = $a['priority'] > $b['priority'] ? -1 : 1;
239 }
240 return $result;
241 }
242
243 }