[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_admin 6 * 7 * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Admin\Administrator\View\Sysinfo; 12 13 use Exception; 14 use Joomla\CMS\Access\Exception\NotAllowed; 15 use Joomla\CMS\Factory; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\MVC\View\AbstractView; 18 use Joomla\Component\Admin\Administrator\Model\SysinfoModel; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Sysinfo View class for the Admin component 26 * 27 * @since 3.5 28 */ 29 class TextView extends AbstractView 30 { 31 /** 32 * Execute and display a template script. 33 * 34 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 35 * 36 * @return mixed A string if successful, otherwise an Error object. 37 * 38 * @since 3.5 39 * 40 * @throws Exception 41 */ 42 public function display($tpl = null): void 43 { 44 // Access check. 45 if (!Factory::getUser()->authorise('core.admin')) { 46 throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403); 47 } 48 49 header('Content-Type: text/plain; charset=utf-8'); 50 header('Content-Description: File Transfer'); 51 header('Content-Disposition: attachment; filename="systeminfo-' . date('c') . '.txt"'); 52 header('Cache-Control: must-revalidate'); 53 54 $data = $this->getLayoutData(); 55 56 $lines = []; 57 58 foreach ($data as $sectionName => $section) { 59 $customRenderingMethod = 'render' . ucfirst($sectionName); 60 61 if (method_exists($this, $customRenderingMethod)) { 62 $lines[] = $this->$customRenderingMethod($section['title'], $section['data']); 63 } else { 64 $lines[] = $this->renderSection($section['title'], $section['data']); 65 } 66 } 67 68 echo str_replace(JPATH_ROOT, 'xxxxxx', implode("\n\n", $lines)); 69 70 Factory::getApplication()->close(); 71 } 72 73 /** 74 * Get the data for the view 75 * 76 * @return array 77 * 78 * @since 3.5 79 */ 80 protected function getLayoutData(): array 81 { 82 /** @var SysinfoModel $model */ 83 $model = $this->getModel(); 84 85 return [ 86 'info' => [ 87 'title' => Text::_('COM_ADMIN_SYSTEM_INFORMATION', true), 88 'data' => $model->getSafeData('info') 89 ], 90 'phpSettings' => [ 91 'title' => Text::_('COM_ADMIN_PHP_SETTINGS', true), 92 'data' => $model->getSafeData('phpSettings') 93 ], 94 'config' => [ 95 'title' => Text::_('COM_ADMIN_CONFIGURATION_FILE', true), 96 'data' => $model->getSafeData('config') 97 ], 98 'directories' => [ 99 'title' => Text::_('COM_ADMIN_DIRECTORY_PERMISSIONS', true), 100 'data' => $model->getSafeData('directory', true) 101 ], 102 'phpInfo' => [ 103 'title' => Text::_('COM_ADMIN_PHP_INFORMATION', true), 104 'data' => $model->getSafeData('phpInfoArray') 105 ], 106 'extensions' => [ 107 'title' => Text::_('COM_ADMIN_EXTENSIONS', true), 108 'data' => $model->getSafeData('extensions') 109 ] 110 ]; 111 } 112 113 /** 114 * Render a section 115 * 116 * @param string $sectionName Name of the section to render 117 * @param array $sectionData Data of the section to render 118 * @param integer $level Depth level for indentation 119 * 120 * @return string 121 * 122 * @since 3.5 123 */ 124 protected function renderSection(string $sectionName, array $sectionData, int $level = 0): string 125 { 126 $lines = []; 127 128 $margin = ($level > 0) ? str_repeat("\t", $level) : null; 129 130 $lines[] = $margin . '============='; 131 $lines[] = $margin . $sectionName; 132 $lines[] = $margin . '============='; 133 $level++; 134 135 foreach ($sectionData as $name => $value) { 136 if (\is_array($value)) { 137 if ($name == 'Directive') { 138 continue; 139 } 140 141 $lines[] = ''; 142 $lines[] = $this->renderSection($name, $value, $level); 143 } else { 144 if (\is_bool($value)) { 145 $value = $value ? 'true' : 'false'; 146 } 147 148 if (\is_int($name) && ($name == 0 || $name == 1)) { 149 $name = ($name == 0 ? 'Local Value' : 'Master Value'); 150 } 151 152 $lines[] = $margin . $name . ': ' . $value; 153 } 154 } 155 156 return implode("\n", $lines); 157 } 158 159 /** 160 * Specific rendering for directories 161 * 162 * @param string $sectionName Name of the section 163 * @param array $sectionData Directories information 164 * @param integer $level Starting level 165 * 166 * @return string 167 * 168 * @since 3.5 169 */ 170 protected function renderDirectories(string $sectionName, array $sectionData, int $level = -1): string 171 { 172 foreach ($sectionData as $directory => $data) { 173 $sectionData[$directory] = $data['writable'] ? ' writable' : ' NOT writable'; 174 } 175 176 return $this->renderSection($sectionName, $sectionData, $level); 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |