joomla /plugins/system/debug/debug.php

Language PHP Lines 206
MD5 Hash aecf8d53a20d44ea4dbeab9fbc407490
Repository https://github.com/cosmocommerce/joomla.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
 * @version		$Id$
 * @package		Joomla
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

/**
 * Joomla! Debug plugin
 *
 * @package		Joomla
 * @subpackage	System
 */
class plgSystemDebug extends JPlugin
{
	/**
	 * Constructor
	 *
	 * @access	protected
	 * @param	object $subject The object to observe
	 * @param	array  $config  An array that holds the plugin configuration
	 * @since	1.0
	 */
	function __construct(&$subject, $config)
	{
		parent::__construct($subject, $config);

	}

	/**
	* Converting the site URL to fit to the HTTP request
	*
	*/
	function onAfterRender()
	{
		global $_PROFILER;

		// Do not render if debugging is not enabled
		if (!JDEBUG) {
			return;
		}

		$document	= &JFactory::getDocument();
		$doctype	= $document->getType();

		// Only render for HTML output
		if ($doctype !== 'html') {
			return;
		}

		// If the user is not allowed to view the output then end here
		$filterGroups = (array) $this->params->get('filter_groups', null);
		if (!empty($filterGroups)) {
			$userGroups = JFactory::getUser()->get('groups');
			if (!array_intersect($filterGroups, array_keys($userGroups))) {
				return;
			}
		}

		$profiler	= &$_PROFILER;

		ob_start();
		echo '<div id="system-debug" class="profiler">';
		$errors = JError::getErrors();
		if(!empty($errors)) {
			echo '<h4>'.JText::_('Errors').'</h4><ol>';
			while($error = JError::getError(true)) {
				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>';
			}
			echo '</ol>';
		}
		if ($this->params->get('profile', 1)) {
			echo '<h4>'.JText::_('PLG_DEBUG_PROFILE_INFORMATION').'</h4>';
			foreach ($profiler->getBuffer() as $mark) {
				echo '<div>'.$mark.'</div>';
			}
		}

		if ($this->params->get('memory', 1)) {
			echo '<h4>'.JText::_('PLG_DEBUG_MEMORY_USAGE').'</h4>';
			echo number_format($profiler->getMemory());
		}

		if ($this->params->get('queries', 1)) {
			$newlineKeywords = '#\b(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)\b#i';

			$db	= &JFactory::getDbo();

			echo '<h4>'.JText::sprintf('PLG_DEBUG_QUERIES_LOGGED',  $db->getTicker()).'</h4>';

			if ($log = $db->getLog()) {
				echo '<ol>';
				foreach ($log as $k => $sql) {
					$text = preg_replace($newlineKeywords, '<br />&nbsp;&nbsp;\\0', $sql);
					echo '<li>'.$text.'</li>';
				}
				echo '</ol>';
			}
		}

		$lang = &JFactory::getLanguage();
		if ($this->params->get('language_files', 1))
		{
			echo '<h4>'.JText::_('PLG_DEBUG_LANGUAGE_FILES_LOADED').'</h4>';
			echo '<ul>';
			$extensions	= $lang->getPaths();
			foreach ($extensions as $extension => $files)
			{
				foreach ($files as $file => $status)
				{
					echo "<li>$file $status</li>";
				}
			}
			echo '</ul>';
		}

		if ($this->params->get('language_strings'))
		{
			$stripFirst	= $this->params->get('strip-first');
			$stripPref	= $this->params->get('strip-prefix');
			$stripSuff	= $this->params->get('strip-suffix');

			echo '<h4>'.JText::_('PLG_DEBUG_UNTRANSLATED_STRINGS').'</h4>';
			echo '<pre>';
			$orphans = $lang->getOrphans();
			if (count($orphans))
			{
				ksort($orphans, SORT_STRING);
				$guesses = array();
				foreach ($orphans as $key => $occurance)
				{
					if (is_array($occurance) AND isset($occurance[0]))
					{
						$info = &$occurance[0];
						$file = @$info['file'];
						if (!isset($guesses[$file])) {
							$guesses[$file] = array();
						}

						// Prepare the key

						if (($pos = strpos($info['string'], '=')) > 0)
						{
							$parts	= explode('=', $info['string']);
							$key	= $parts[0];
							$guess	= $parts[1];
						}
						else
						{
							$guess = str_replace('_', ' ', $info['string']);
							if ($stripFirst)
							{
								$parts = explode(' ', $guess);
								if (count($parts) > 1)
								{
									array_shift($parts);
									$guess = implode(' ', $parts);
								}
							}

							$guess = trim($guess);

							if ($stripPref) {
								$guess = trim(preg_replace(chr(1).'^'.$stripPref.chr(1).'i', '', $guess));
							}

							if ($stripSuff) {
								$guess = trim(preg_replace(chr(1).$stripSuff.'$'.chr(1).'i', '', $guess));
							}
						}

						$key = trim(strtoupper($key));
						$key = preg_replace('#\s+#', '_', $key);
						$key = preg_replace('#\W#', '', $key);

						// Prepare the text

						$guesses[$file][] = $key.'='.$guess;
					}
				}
				foreach ($guesses as $file => $keys)
				{
					echo "\n\n# ".($file ? $file : JText::_('PLG_DEBUG_UNKNOWN_FILE'))."\n\n";
					echo implode("\n", $keys);
				}
			}
			else {
				echo JText::_('JNone');
			}
			echo '</pre>';
		}
		echo '</div>';

		$debug = ob_get_clean();

		$body = JResponse::getBody();
		$body = str_replace('</body>', $debug.'</body>', $body);
		JResponse::setBody($body);
	}
}
Back to Top