PageRenderTime 55ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/system/debug/debug.php

https://github.com/joebushi/joomla
PHP | 206 lines | 147 code | 29 blank | 30 comment | 20 complexity | 563929f98651e1ba51da6530b524bd38 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jimport('joomla.plugin.plugin');
  11. /**
  12. * Joomla! Debug plugin
  13. *
  14. * @package Joomla
  15. * @subpackage System
  16. */
  17. class plgSystemDebug extends JPlugin
  18. {
  19. /**
  20. * Constructor
  21. *
  22. * @access protected
  23. * @param object $subject The object to observe
  24. * @param array $config An array that holds the plugin configuration
  25. * @since 1.0
  26. */
  27. function __construct(&$subject, $config)
  28. {
  29. parent::__construct($subject, $config);
  30. }
  31. /**
  32. * Converting the site URL to fit to the HTTP request
  33. *
  34. */
  35. function onAfterRender()
  36. {
  37. global $_PROFILER;
  38. // Do not render if debugging is not enabled
  39. if (!JDEBUG) {
  40. return;
  41. }
  42. $document = &JFactory::getDocument();
  43. $doctype = $document->getType();
  44. // Only render for HTML output
  45. if ($doctype !== 'html') {
  46. return;
  47. }
  48. // If the user is not allowed to view the output then end here
  49. $filterGroups = (array) $this->params->get('filter_groups', null);
  50. if (!empty($filterGroups)) {
  51. $userGroups = JFactory::getUser()->get('groups');
  52. if (!array_intersect($filterGroups, array_keys($userGroups))) {
  53. return;
  54. }
  55. }
  56. $profiler = &$_PROFILER;
  57. ob_start();
  58. echo '<div id="system-debug" class="profiler">';
  59. $errors = JError::getErrors();
  60. if(!empty($errors)) {
  61. echo '<h4>'.JText::_('Errors').'</h4><ol>';
  62. while($error = JError::getError(true)) {
  63. echo '<li>'.$error->getMessage().'<br /><h4>'.JText::_('Info').'</h4><pre>'.print_r($error->get('info'), true).'</pre><br /><h4>'.JText::_('Backtrace').'</h4>'.JError::renderBacktrace($error).'</li>';
  64. }
  65. echo '</ol>';
  66. }
  67. if ($this->params->get('profile', 1)) {
  68. echo '<h4>'.JText::_('Debug_Profile_Information').'</h4>';
  69. foreach ($profiler->getBuffer() as $mark) {
  70. echo '<div>'.$mark.'</div>';
  71. }
  72. }
  73. if ($this->params->get('memory', 1)) {
  74. echo '<h4>'.JText::_('Debug_Memory_Usage').'</h4>';
  75. echo number_format($profiler->getMemory());
  76. }
  77. if ($this->params->get('queries', 1)) {
  78. $newlineKeywords = '#\b(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)\b#i';
  79. $db = &JFactory::getDbo();
  80. echo '<h4>'.JText::sprintf('Debug_Queries_logged', $db->getTicker()).'</h4>';
  81. if ($log = $db->getLog()) {
  82. echo '<ol>';
  83. foreach ($log as $k => $sql) {
  84. $text = preg_replace($newlineKeywords, '<br />&nbsp;&nbsp;\\0', $sql);
  85. echo '<li>'.$text.'</li>';
  86. }
  87. echo '</ol>';
  88. }
  89. }
  90. $lang = &JFactory::getLanguage();
  91. if ($this->params->get('language_files', 1))
  92. {
  93. echo '<h4>'.JText::_('Debug_Language_Files_Loaded').'</h4>';
  94. echo '<ul>';
  95. $extensions = $lang->getPaths();
  96. foreach ($extensions as $extension => $files)
  97. {
  98. foreach ($files as $file => $status)
  99. {
  100. echo "<li>$file $status</li>";
  101. }
  102. }
  103. echo '</ul>';
  104. }
  105. if ($this->params->get('language_strings'))
  106. {
  107. $stripFirst = $this->params->get('strip-first');
  108. $stripPref = $this->params->get('strip-prefix');
  109. $stripSuff = $this->params->get('strip-suffix');
  110. echo '<h4>'.JText::_('Debug_Untranslated_Strings').'</h4>';
  111. echo '<pre>';
  112. $orphans = $lang->getOrphans();
  113. if (count($orphans))
  114. {
  115. ksort($orphans, SORT_STRING);
  116. $guesses = array();
  117. foreach ($orphans as $key => $occurance)
  118. {
  119. if (is_array($occurance) AND isset($occurance[0]))
  120. {
  121. $info = &$occurance[0];
  122. $file = @$info['file'];
  123. if (!isset($guesses[$file])) {
  124. $guesses[$file] = array();
  125. }
  126. // Prepare the key
  127. if (($pos = strpos($info['string'], '=')) > 0)
  128. {
  129. $parts = explode('=', $info['string']);
  130. $key = $parts[0];
  131. $guess = $parts[1];
  132. }
  133. else
  134. {
  135. $guess = str_replace('_', ' ', $info['string']);
  136. if ($stripFirst)
  137. {
  138. $parts = explode(' ', $guess);
  139. if (count($parts) > 1)
  140. {
  141. array_shift($parts);
  142. $guess = implode(' ', $parts);
  143. }
  144. }
  145. $guess = trim($guess);
  146. if ($stripPref) {
  147. $guess = trim(preg_replace(chr(1).'^'.$stripPref.chr(1).'i', '', $guess));
  148. }
  149. if ($stripSuff) {
  150. $guess = trim(preg_replace(chr(1).$stripSuff.'$'.chr(1).'i', '', $guess));
  151. }
  152. }
  153. $key = trim(strtoupper($key));
  154. $key = preg_replace('#\s+#', '_', $key);
  155. $key = preg_replace('#\W#', '', $key);
  156. // Prepare the text
  157. $guesses[$file][] = $key.'='.$guess;
  158. }
  159. }
  160. foreach ($guesses as $file => $keys)
  161. {
  162. echo "\n\n# ".($file ? $file : JText::_('Debug_Unknown_file'))."\n\n";
  163. echo implode("\n", $keys);
  164. }
  165. }
  166. else {
  167. echo JText::_('JNone');
  168. }
  169. echo '</pre>';
  170. }
  171. echo '</div>';
  172. $debug = ob_get_clean();
  173. $body = JResponse::getBody();
  174. $body = str_replace('</body>', $debug.'</body>', $body);
  175. JResponse::setBody($body);
  176. }
  177. }