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