TYPO3 CMS  TYPO3_7-6
SystemInformationToolbarItem.php
Go to the documentation of this file.
1 <?php
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 
31 
36 {
40  protected $standaloneView = null;
41 
45  const TOOLBAR_MENU_TEMPLATE = 'SystemInformation.html';
46 
52  protected $totalCount = 0;
53 
59  protected $highestSeverity;
60 
66  protected $severityBadgeClass = '';
67 
71  protected $systemInformation = [];
72 
76  protected $systemMessages = [];
77 
81  protected $signalSlotDispatcher = null;
82 
86  protected $iconFactory;
87 
91  protected $maximumCountInBadge = 99;
92 
96  public function __construct()
97  {
98  if (!$this->checkAccess()) {
99  return;
100  }
101  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
102 
103  $extPath = ExtensionManagementUtility::extPath('backend');
104  /* @var $view StandaloneView */
105  $this->standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
106  $this->standaloneView->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/ToolbarMenu/' . static::TOOLBAR_MENU_TEMPLATE);
107 
108  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu');
109 
111  }
112 
116  protected function collectInformation()
117  {
118  $this->getWebServer();
119  $this->getPhpVersion();
120  $this->getDatabase();
121  $this->getApplicationContext();
122  $this->getComposerMode();
123  $this->getGitRevision();
124  $this->getOperatingSystem();
125 
126  $this->emitGetSystemInformation();
127  $this->emitLoadMessages();
128 
129  $this->severityBadgeClass = !$this->highestSeverity->equals(InformationStatus::STATUS_NOTICE) ? 'badge-' . (string)$this->highestSeverity : '';
130  }
131 
139  public function renderMenuAction(ServerRequestInterface $request, ResponseInterface $response)
140  {
141  $this->collectInformation();
142 
143  $response->getBody()->write($this->getDropDown());
144  $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
145  return $response;
146  }
147 
153  protected function getPhpVersion()
154  {
155  $this->systemInformation[] = [
156  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.phpversion', true),
157  'value' => PHP_VERSION,
158  'icon' => $this->iconFactory->getIcon('sysinfo-php-version', Icon::SIZE_SMALL)->render()
159  ];
160  }
161 
167  protected function getDatabase()
168  {
169  $this->systemInformation[] = [
170  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.database', true),
171  'value' => $this->getDatabaseConnection()->getServerVersion(),
172  'icon' => $this->iconFactory->getIcon('sysinfo-database', Icon::SIZE_SMALL)->render()
173  ];
174  }
175 
181  protected function getApplicationContext()
182  {
183  $applicationContext = GeneralUtility::getApplicationContext();
184  $this->systemInformation[] = [
185  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.applicationcontext', true),
186  'value' => (string)$applicationContext,
187  'status' => $applicationContext->isProduction() ? InformationStatus::STATUS_OK : InformationStatus::STATUS_WARNING,
188  'icon' => $this->iconFactory->getIcon('sysinfo-application-context', Icon::SIZE_SMALL)->render()
189  ];
190  }
191 
195  protected function getComposerMode()
196  {
198  return;
199  }
200 
201  $languageService = $this->getLanguageService();
202  $this->systemInformation[] = [
203  'title' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.composerMode', true),
204  'value' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.enabled', true),
205  'icon' => $this->iconFactory->getIcon('sysinfo-composer-mode', Icon::SIZE_SMALL)->render()
206  ];
207  }
208 
214  protected function getGitRevision()
215  {
216  if (!StringUtility::endsWith(TYPO3_version, '-dev') || \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::isFunctionDisabled('exec')) {
217  return;
218  }
219  // check if git exists
220  CommandUtility::exec('git --version', $_, $returnCode);
221  if ((int)$returnCode !== 0) {
222  // git is not available
223  return;
224  }
225 
226  $revision = trim(CommandUtility::exec('git rev-parse --short HEAD'));
227  $branch = trim(CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
228  if (!empty($revision) && !empty($branch)) {
229  $this->systemInformation[] = [
230  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.gitrevision', true),
231  'value' => sprintf('%s [%s]', $revision, $branch),
232  'icon' => $this->iconFactory->getIcon('sysinfo-git', Icon::SIZE_SMALL)->render()
233  ];
234  }
235  }
236 
242  protected function getOperatingSystem()
243  {
244  $kernelName = php_uname('s');
245  switch (strtolower($kernelName)) {
246  case 'linux':
247  $icon = 'linux';
248  break;
249  case 'darwin':
250  $icon = 'apple';
251  break;
252  default:
253  $icon = 'windows';
254  }
255  $this->systemInformation[] = [
256  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.operatingsystem', true),
257  'value' => $kernelName . ' ' . php_uname('r'),
258  'icon' => $this->iconFactory->getIcon('sysinfo-os-' . $icon, Icon::SIZE_SMALL)->render()
259  ];
260  }
261 
265  protected function getWebServer()
266  {
267  $this->systemInformation[] = [
268  'title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo.webserver', true),
269  'value' => htmlspecialchars($_SERVER['SERVER_SOFTWARE']),
270  'icon' => $this->iconFactory->getIcon('sysinfo-webserver', Icon::SIZE_SMALL)->render()
271  ];
272  }
273 
279  protected function emitGetSystemInformation()
280  {
281  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'getSystemInformation', [$this]);
282  }
283 
289  protected function emitLoadMessages()
290  {
291  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'loadMessages', [$this]);
292  }
293 
303  public function addSystemMessage($text, $status = InformationStatus::STATUS_OK, $count = 0, $module = '')
304  {
305  $this->totalCount += (int)$count;
306 
308  $messageSeverity = InformationStatus::cast($status);
309  // define the severity for the badge
310  if ($messageSeverity->isGreaterThan($this->highestSeverity)) {
311  $this->highestSeverity = $messageSeverity;
312  }
313 
314  $this->systemMessages[] = [
315  'module' => $module,
316  'count' => (int)$count,
317  'status' => $messageSeverity,
318  'text' => $text
319  ];
320  }
321 
330  public function addSystemInformation($title, $value, $icon)
331  {
332  $this->systemInformation[] = [
333  'title' => $title,
334  'value' => $value,
335  'icon' => $icon
336  ];
337  }
338 
344  public function checkAccess()
345  {
346  return $this->getBackendUserAuthentication()->isAdmin();
347  }
348 
354  public function getItem()
355  {
356  $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo', true);
357  $icon = $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render('inline');
358  return '<span title="' . $title . '">' . $icon . '<span id="t3js-systeminformation-counter" class="badge"></span></span>';
359  }
360 
366  public function getDropDown()
367  {
368  if (!$this->checkAccess()) {
369  return '';
370  }
371 
372  $request = $this->standaloneView->getRequest();
373  $request->setControllerExtensionName('backend');
374  $this->standaloneView->assignMultiple([
375  'installToolUrl' => BackendUtility::getModuleUrl('system_InstallInstall'),
376  'messages' => $this->systemMessages,
377  'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount,
378  'severityBadgeClass' => $this->severityBadgeClass,
379  'systemInformation' => $this->systemInformation
380  ]);
381  return $this->standaloneView->render();
382  }
383 
389  public function getAdditionalAttributes()
390  {
391  return [];
392  }
393 
399  public function hasDropDown()
400  {
401  return true;
402  }
403 
409  public function getIndex()
410  {
411  return 75;
412  }
413 
419  protected function getBackendUserAuthentication()
420  {
421  return $GLOBALS['BE_USER'];
422  }
423 
429  protected function getDatabaseConnection()
430  {
431  return $GLOBALS['TYPO3_DB'];
432  }
433 
439  protected function getPageRenderer()
440  {
441  return GeneralUtility::makeInstance(PageRenderer::class);
442  }
443 
449  protected function getLanguageService()
450  {
451  return $GLOBALS['LANG'];
452  }
453 
459  protected function getSignalSlotDispatcher()
460  {
461  if (!isset($this->signalSlotDispatcher)) {
462  $this->signalSlotDispatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class)
463  ->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
464  }
466  }
467 }
renderMenuAction(ServerRequestInterface $request, ResponseInterface $response)
static exec($command, &$output=null, &$returnValue=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static endsWith($haystack, $needle)