8b631c7b49b809bfbc99e4f7040272048ead5c75
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / PhpInfoViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Patrick Broens <patrick@patrickbroens.nl>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Utility class for phpinfo()
29 *
30 * @author Patrick Broens <patrick@patrickbroens.nl>
31 */
32 class PhpInfoViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
33
34 /**
35 * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
36 * can decode the text's entities.
37 *
38 * @var boolean
39 */
40 protected $escapingInterceptorEnabled = FALSE;
41
42 /**
43 * Render PHP info
44 *
45 * @return string
46 */
47 public function render() {
48 return $this->removeAllHtmlOutsideBody(
49 $this->changeHtmlToHtml5(
50 $this->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 public function getPhpInfo() {
61 ob_start();
62 phpinfo();
63
64 return ob_get_clean();
65 }
66
67 /**
68 * Remove all HTML outside the body tag from HTML string
69 *
70 * @param string $html Complete HTML markup for page
71 * @return string Content of the body tag
72 */
73 protected function removeAllHtmlOutsideBody($html) {
74 // Delete anything outside of the body tag and the body tag itself
75 $html = preg_replace('/^.*?<body.*?>/is', '', $html);
76 $html = preg_replace('/<\/body>.*?$/is', '', $html);
77
78 return $html;
79 }
80
81 /**
82 * Change HTML markup to HTML5
83 *
84 * @param string $html HTML markup to be cleaned
85 * @return string
86 */
87 protected function changeHtmlToHtml5($html) {
88 // Delete obsolete attributes
89 $html = preg_replace('#\s(cellpadding|border|width)="[^"]+"#', '', $html);
90
91 // Replace font tag with span
92 return str_replace(array('<font', '</font>'), array('<span', '</span>'), $html);
93 }
94 }