[TASK] Convert remaining ViewHelpers to static calling
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / PhpInfoViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers;
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 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20
21 /**
22 * Utility class for phpinfo()
23 * @internal
24 */
25 class PhpInfoViewHelper extends AbstractViewHelper
26 {
27 use CompileWithRenderStatic;
28
29 /**
30 * @var bool
31 */
32 protected $escapeOutput = false;
33
34 /**
35 * @var bool
36 */
37 protected $escapeChildren = false;
38
39 /**
40 * @param array $arguments
41 * @param \Closure $renderChildrenClosure
42 * @param RenderingContextInterface $renderingContext
43 *
44 * @return string
45 */
46 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
47 {
48 return self::removeAllHtmlOutsideBody(
49 self::changeHtmlToHtml5(
50 self::getPhpInfo()
51 )
52 );
53 }
54
55 /**
56 * Get information about PHP's configuration
57 *
58 * @return string HTML page with the configuration options
59 */
60 protected static function getPhpInfo()
61 {
62 ob_start();
63 phpinfo();
64
65 return ob_get_clean();
66 }
67
68 /**
69 * Remove all HTML outside the body tag from HTML string
70 *
71 * @param string $html Complete HTML markup for page
72 * @return string Content of the body tag
73 */
74 protected static function removeAllHtmlOutsideBody($html)
75 {
76 // Delete anything outside of the body tag and the body tag itself
77 $html = preg_replace('/^.*?<body.*?>/is', '', $html);
78 $html = preg_replace('/<\/body>.*?$/is', '', $html);
79
80 return $html;
81 }
82
83 /**
84 * Change HTML markup to HTML5
85 *
86 * @param string $html HTML markup to be cleaned
87 * @return string
88 */
89 protected static function changeHtmlToHtml5($html)
90 {
91 // Delete obsolete attributes
92 $html = preg_replace('#\s(cellpadding|border|width)="[^"]+"#', '', $html);
93
94 // Replace font tag with span
95 return str_replace(['<font', '</font>'], ['<span', '</span>'], $html);
96 }
97 }