[TASK] Re-work/simplify copyright header in PHP files - Part 1
[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 /**
18 * Utility class for phpinfo()
19 *
20 * @author Patrick Broens <patrick@patrickbroens.nl>
21 */
22 class PhpInfoViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
23
24 /**
25 * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
26 * can decode the text's entities.
27 *
28 * @var boolean
29 */
30 protected $escapingInterceptorEnabled = FALSE;
31
32 /**
33 * Render PHP info
34 *
35 * @return string
36 */
37 public function render() {
38 return $this->removeAllHtmlOutsideBody(
39 $this->changeHtmlToHtml5(
40 $this->getPhpInfo()
41 )
42 );
43 }
44
45 /**
46 * Get information about PHP's configuration
47 *
48 * @return string HTML page with the configuration options
49 */
50 public function getPhpInfo() {
51 ob_start();
52 phpinfo();
53
54 return ob_get_clean();
55 }
56
57 /**
58 * Remove all HTML outside the body tag from HTML string
59 *
60 * @param string $html Complete HTML markup for page
61 * @return string Content of the body tag
62 */
63 protected function removeAllHtmlOutsideBody($html) {
64 // Delete anything outside of the body tag and the body tag itself
65 $html = preg_replace('/^.*?<body.*?>/is', '', $html);
66 $html = preg_replace('/<\/body>.*?$/is', '', $html);
67
68 return $html;
69 }
70
71 /**
72 * Change HTML markup to HTML5
73 *
74 * @param string $html HTML markup to be cleaned
75 * @return string
76 */
77 protected function changeHtmlToHtml5($html) {
78 // Delete obsolete attributes
79 $html = preg_replace('#\s(cellpadding|border|width)="[^"]+"#', '', $html);
80
81 // Replace font tag with span
82 return str_replace(array('<font', '</font>'), array('<span', '</span>'), $html);
83 }
84 }