/joomla/administrator/components/com_admin/views/sysinfo/view.text.php

https://gitlab.com/ricardosanchez/prueba · PHP · 176 lines · 104 code · 21 blank · 51 comment · 12 complexity · d15294a4edf0b34ec81c78938a291e5d MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_admin
  5. *
  6. * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Sysinfo View class for the Admin component
  12. *
  13. * @since 3.5
  14. */
  15. class AdminViewSysinfo extends JViewLegacy
  16. {
  17. /**
  18. * Execute and display a template script.
  19. *
  20. * @param string $tpl The name of the template file to parse; automatically searches through the template paths.
  21. *
  22. * @return mixed A string if successful, otherwise an Error object.
  23. *
  24. * @since 3.5
  25. */
  26. public function display($tpl = null)
  27. {
  28. // Access check.
  29. if (!JFactory::getUser()->authorise('core.admin'))
  30. {
  31. return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
  32. }
  33. header('Content-Type: text/plain; charset=utf-8');
  34. header('Content-Description: File Transfer');
  35. header('Content-Disposition: attachment; filename="systeminfo-' . date("c") . '.txt"');
  36. header('Cache-Control: must-revalidate');
  37. $data = $this->getLayoutData();
  38. $lines = array();
  39. foreach ($data as $sectionName => $section)
  40. {
  41. $customRenderingMethod = 'render' . ucfirst($sectionName);
  42. if (method_exists($this, $customRenderingMethod))
  43. {
  44. $lines[] = $this->$customRenderingMethod($section['title'], $section['data']);
  45. }
  46. else
  47. {
  48. $lines[] = $this->renderSection($section['title'], $section['data']);
  49. }
  50. }
  51. echo str_replace(JPATH_ROOT, 'xxxxxx', implode("\n\n", $lines));
  52. JFactory::getApplication()->close();
  53. }
  54. /**
  55. * Get the data for the view
  56. *
  57. * @return array
  58. *
  59. * @since 3.5
  60. */
  61. protected function getLayoutData()
  62. {
  63. $model = $this->getModel();
  64. return array(
  65. 'info' => array(
  66. 'title' => JText::_('COM_ADMIN_SYSTEM_INFORMATION', true),
  67. 'data' => $model->getSafeData('info')
  68. ),
  69. 'phpSettings' => array(
  70. 'title' => JText::_('COM_ADMIN_PHP_SETTINGS', true),
  71. 'data' => $model->getSafeData('phpSettings')
  72. ),
  73. 'config' => array(
  74. 'title' => JText::_('COM_ADMIN_CONFIGURATION_FILE', true),
  75. 'data' => $model->getSafeData('config')
  76. ),
  77. 'directories' => array(
  78. 'title' => JText::_('COM_ADMIN_DIRECTORY_PERMISSIONS', true),
  79. 'data' => $model->getSafeData('directory', true)
  80. ),
  81. 'phpInfo' => array(
  82. 'title' => JText::_('COM_ADMIN_PHP_INFORMATION', true),
  83. 'data' => $model->getSafeData('phpInfoArray')
  84. ),
  85. 'extensions' => array(
  86. 'title' => JText::_('COM_ADMIN_EXTENSIONS', true),
  87. 'data' => $model->getSafeData('extensions')
  88. )
  89. );
  90. }
  91. /**
  92. * Render a section
  93. *
  94. * @param string $sectionName Name of the section to render
  95. * @param array $sectionData Data of the section to render
  96. * @param integer $level Depth level for indentation
  97. *
  98. * @return string
  99. *
  100. * @since 3.5
  101. */
  102. protected function renderSection($sectionName, $sectionData, $level = 0)
  103. {
  104. $lines = array();
  105. $margin = ($level > 0) ? str_repeat("\t", $level) : null;
  106. $lines[] = $margin . "=============";
  107. $lines[] = $margin . $sectionName;
  108. $lines[] = $margin . "=============";
  109. $level++;
  110. foreach ($sectionData as $name => $value)
  111. {
  112. if (is_array($value))
  113. {
  114. if ($name == 'Directive')
  115. {
  116. continue;
  117. }
  118. $lines[] = "";
  119. $lines[] = $this->renderSection($name, $value, $level);
  120. }
  121. else
  122. {
  123. if (is_bool($value))
  124. {
  125. $value = $value ? 'true' : 'false';
  126. }
  127. if (is_int($name) && ($name == 0 || $name == 1))
  128. {
  129. $name = ($name == 0 ? 'Local Value' : 'Master Value');
  130. }
  131. $lines[] = $margin . $name . ': ' . $value;
  132. }
  133. }
  134. return implode("\n", $lines);
  135. }
  136. /**
  137. * Specific rendering for directories
  138. *
  139. * @param string $sectionName Name of the section
  140. * @param array $sectionData Directories information
  141. * @param integer $level Starting level
  142. *
  143. * @return string
  144. *
  145. * @since 3.5
  146. */
  147. protected function renderDirectories($sectionName, $sectionData, $level = -1)
  148. {
  149. foreach ($sectionData as $directory => $data)
  150. {
  151. $sectionData[$directory] = $data['writable'] ? ' writable' : ' NOT writable';
  152. }
  153. return $this->renderSection($sectionName, $sectionData, $level);
  154. }
  155. }