| Current Path : /proc/thread-self/root/proc/thread-self/root/proc/2411249/root/tmp/ |
| Current File : //proc/thread-self/root/proc/thread-self/root/proc/2411249/root/tmp/phpSdtYAq |
debug.php 0000644 00000141542 15234441123 0006351 0 ustar 00 <?php
/**
* @package Joomla.Plugin
* @subpackage System.Debug
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
/**
* Joomla! Debug plugin.
*
* @since 1.5
*/
class PlgSystemDebug extends JPlugin
{
/**
* xdebug.file_link_format from the php.ini.
*
* @var string
* @since 1.7
*/
protected $linkFormat = '';
/**
* True if debug lang is on.
*
* @var boolean
* @since 3.0
*/
private $debugLang = false;
/**
* Holds log entries handled by the plugin.
*
* @var array
* @since 3.1
*/
private $logEntries = array();
/**
* Holds SHOW PROFILES of queries.
*
* @var array
* @since 3.1.2
*/
private $sqlShowProfiles = array();
/**
* Holds all SHOW PROFILE FOR QUERY n, indexed by n-1.
*
* @var array
* @since 3.1.2
*/
private $sqlShowProfileEach = array();
/**
* Holds all EXPLAIN EXTENDED for all queries.
*
* @var array
* @since 3.1.2
*/
private $explains = array();
/**
* Holds total amount of executed queries.
*
* @var int
* @since 3.2
*/
private $totalQueries = 0;
/**
* Application object.
*
* @var JApplicationCms
* @since 3.3
*/
protected $app;
/**
* Database object.
*
* @var JDatabaseDriver
* @since 3.8.0
*/
protected $db;
/**
* Container for callback functions to be triggered when rendering the console.
*
* @var callable[]
* @since 3.7.0
*/
private static $displayCallbacks = array();
/**
* Constructor.
*
* @param object &$subject The object to observe.
* @param array $config An optional associative array of configuration settings.
*
* @since 1.5
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Log the deprecated API.
if ($this->params->get('log-deprecated', 0))
{
JLog::addLogger(array('text_file' => 'deprecated.php'), JLog::ALL, array('deprecated'));
}
// Log everything (except deprecated APIs, these are logged separately with the option above).
if ($this->params->get('log-everything', 0))
{
JLog::addLogger(array('text_file' => 'everything.php'), JLog::ALL, array('deprecated', 'databasequery'), true);
}
// Get the application if not done by JPlugin. This may happen during upgrades from Joomla 2.5.
if (!$this->app)
{
$this->app = JFactory::getApplication();
}
// Get the db if not done by JPlugin. This may happen during upgrades from Joomla 2.5.
if (!$this->db)
{
$this->db = JFactory::getDbo();
}
$this->debugLang = $this->app->get('debug_lang');
// Skip the plugin if debug is off
if ($this->debugLang == '0' && $this->app->get('debug') == '0')
{
return;
}
// Only if debugging or language debug is enabled.
if (JDEBUG || $this->debugLang)
{
JFactory::getConfig()->set('gzip', 0);
ob_start();
ob_implicit_flush(false);
}
$this->linkFormat = ini_get('xdebug.file_link_format');
if ($this->params->get('logs', 1))
{
$priority = 0;
foreach ($this->params->get('log_priorities', array()) as $p)
{
$const = 'JLog::' . strtoupper($p);
if (!defined($const))
{
continue;
}
$priority |= constant($const);
}
// Split into an array at any character other than alphabet, numbers, _, ., or -
$categories = preg_split('/[^\w.-]+/', $this->params->get('log_categories', ''), -1, PREG_SPLIT_NO_EMPTY);
$mode = $this->params->get('log_category_mode', 0);
JLog::addLogger(array('logger' => 'callback', 'callback' => array($this, 'logger')), $priority, $categories, $mode);
}
// Prepare disconnect handler for SQL profiling.
$db = $this->db;
$db->addDisconnectHandler(array($this, 'mysqlDisconnectHandler'));
// Log deprecated class aliases
foreach (JLoader::getDeprecatedAliases() as $deprecation)
{
JLog::add(
sprintf(
'%1$s has been aliased to %2$s and the former class name is deprecated. The alias will be removed in %3$s.',
$deprecation['old'],
$deprecation['new'],
$deprecation['version']
),
JLog::WARNING,
'deprecated'
);
}
}
/**
* Add the CSS for debug.
* We can't do this in the constructor because stuff breaks.
*
* @return void
*
* @since 2.5
*/
public function onAfterDispatch()
{
// Only if debugging or language debug is enabled.
if ((JDEBUG || $this->debugLang) && $this->isAuthorisedDisplayDebug())
{
JHtml::_('stylesheet', 'cms/debug.css', array('version' => 'auto', 'relative' => true));
}
// Disable asset media version if needed.
if (JDEBUG && (int) $this->params->get('refresh_assets', 1) === 0)
{
$this->app->getDocument()->setMediaVersion(null);
}
// Only if debugging is enabled for SQL query popovers.
if (JDEBUG && $this->isAuthorisedDisplayDebug())
{
JHtml::_('bootstrap.tooltip');
JHtml::_('bootstrap.popover', '.hasPopover', array('placement' => 'top'));
}
}
/**
* Show the debug info.
*
* @return void
*
* @since 1.6
*/
public function onAfterRespond()
{
// Do not render if debugging or language debug is not enabled.
if (!JDEBUG && !$this->debugLang)
{
return;
}
// User has to be authorised to see the debug information.
if (!$this->isAuthorisedDisplayDebug())
{
return;
}
// Only render for HTML output.
if (JFactory::getDocument()->getType() !== 'html')
{
return;
}
// Capture output.
$contents = ob_get_contents();
if ($contents)
{
ob_end_clean();
}
// No debug for Safari and Chrome redirection.
if (strpos($contents, '<html><head><meta http-equiv="refresh" content="0;') === 0
&& strpos(strtolower(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''), 'webkit') !== false)
{
echo $contents;
return;
}
// Load language.
$this->loadLanguage();
$html = array();
// Some "mousewheel protecting" JS.
$html[] = "<script>function toggleContainer(name)
{
var e = document.getElementById(name);// MooTools might not be available ;)
e.style.display = e.style.display === 'none' ? 'block' : 'none';
}</script>";
$html[] = '<div id="system-debug" class="profiler">';
$html[] = '<h2>' . JText::_('PLG_DEBUG_TITLE') . '</h2>';
if (JDEBUG)
{
if (JError::getErrors())
{
$html[] = $this->display('errors');
}
if ($this->params->get('session', 1))
{
$html[] = $this->display('session');
}
if ($this->params->get('profile', 1))
{
$html[] = $this->display('profile_information');
}
if ($this->params->get('memory', 1))
{
$html[] = $this->display('memory_usage');
}
if ($this->params->get('queries', 1))
{
$html[] = $this->display('queries');
}
if (!empty($this->logEntries) && $this->params->get('logs', 1))
{
$html[] = $this->display('logs');
}
}
if ($this->debugLang)
{
if ($this->params->get('language_errorfiles', 1))
{
$languageErrors = JFactory::getLanguage()->getErrorFiles();
$html[] = $this->display('language_files_in_error', $languageErrors);
}
if ($this->params->get('language_files', 1))
{
$html[] = $this->display('language_files_loaded');
}
if ($this->params->get('language_strings', 1))
{
$html[] = $this->display('untranslated_strings');
}
}
foreach (self::$displayCallbacks as $name => $callable)
{
$html[] = $this->displayCallback($name, $callable);
}
$html[] = '</div>';
echo str_replace('</body>', implode('', $html) . '</body>', $contents);
}
/**
* Add a display callback to be rendered with the debug console.
*
* @param string $name The name of the callable, this is used to generate the section title.
* @param callable $callable The callback function to be added.
*
* @return boolean
*
* @since 3.7.0
* @throws InvalidArgumentException
*/
public static function addDisplayCallback($name, $callable)
{
// TODO - When PHP 5.4 is the minimum the parameter should be typehinted "callable" and this