Source for file debug.php

Documentation is available at debug.php

  1. <?php
  2. /**
  3. @version        $Id: debug.php 9764 2007-12-30 07:48:11Z ircmaxell $
  4. @package        Joomla
  5. @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. @license        GNU/GPL, see LICENSE.php
  7. *  Joomla! is free software. This version may have been modified pursuant
  8. *  to the GNU General Public License, and as distributed it includes or
  9. *  is derivative of works licensed under the GNU General Public License or
  10. *  other free or open source software licenses.
  11. *  See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. // no direct access
  15. defined'_JEXEC' or die'Restricted access' );
  16.  
  17. jimport'joomla.plugin.plugin' );
  18.  
  19. /**
  20.  * Joomla! Debug plugin
  21.  *
  22.  * @author        Johan Janssens <johan.janssens@joomla.org>
  23.  * @package        Joomla
  24.  * @subpackage    System
  25.  */
  26. class  plgSystemDebug extends JPlugin
  27. {
  28.     /**
  29.      * Constructor
  30.      *
  31.      * For php4 compatability we must not use the __constructor as a constructor for plugins
  32.      * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  33.      * This causes problems with cross-referencing necessary for the observer design pattern.
  34.      *
  35.      * @access    protected
  36.      * @param    object $subject The object to observe
  37.      * @param     array  $config  An array that holds the plugin configuration
  38.      * @since    1.0
  39.      */
  40.     function plgSystemDebug($subject$config)
  41.     {
  42.         parent::__construct($subject$config);
  43.  
  44.         //load the translation
  45.         $this->loadLanguage);
  46.     }
  47.  
  48.     /**
  49.     * Converting the site URL to fit to the HTTP request
  50.     *
  51.     */
  52.     function onAfterRender()
  53.     {
  54.         global $_PROFILER$mainframe$database;
  55.  
  56.         // Do not render if debugging is not enabled
  57.         if(!JDEBUGreturn}
  58.  
  59.         $document    =JFactory::getDocument();
  60.         $doctype    $document->getType();
  61.  
  62.         // Only render for HTML output
  63.         if $doctype !== 'html' return}
  64.  
  65.         $profiler    =$_PROFILER;
  66.  
  67.         ob_start();
  68.         echo '<div id="system-debug" class="profiler">';
  69.         echo '<h4>'.JText::_'Profile Information' ).'</h4>';
  70.         foreach $profiler->getBuffer(as $mark {
  71.             echo '<div>'.$mark.'</div>';
  72.         }
  73.  
  74.         if ($this->params->get('memory'1)) {
  75.             echo '<h4>'.JText::_'Memory Usage' ).'</h4>';
  76.             echo $profiler->getMemory();
  77.         }
  78.  
  79.         if ($this->params->get('queries'1))
  80.         {
  81.             jimport('geshi.geshi');
  82.  
  83.             $geshi new GeSHi'''sql' );
  84.             $geshi->set_header_type(GESHI_HEADER_DIV);
  85.             //$geshi->enable_line_numbers( GESHI_FANCY_LINE_NONE );
  86.  
  87.             $newlineKeywords '/<span style="color: #993333; font-weight: bold;">'
  88.                 .'(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)'
  89.                 .'<\\/span>/i'
  90.             ;
  91.  
  92.             $db    =JFactory::getDBO();
  93.  
  94.             echo '<h4>'.JText::sprintf'Queries logged',  $db->getTicker() ).'</h4>';
  95.  
  96.             if ($log $db->getLog())
  97.             {
  98.                 echo '<ol>';
  99.                 foreach ($log as $k=>$sql)
  100.                 {
  101.                     $geshi->set_source($sql);
  102.                     $text $geshi->parse_code();
  103.                     $text preg_replace($newlineKeywords'<br />&nbsp;&nbsp;\\0'$text);
  104.                     echo '<li>'.$text.'</li>';
  105.                 }
  106.                 echo '</ol>';
  107.             }
  108.  
  109.             if(isset($database))
  110.             {
  111.                 echo '<h4>'.JText::sprintf'Legacy Queries logged',  $database->getTicker() ).'</h4>';
  112.                 echo '<ol>';
  113.  
  114.                     foreach ($database->getLog(as $k=>$sql)
  115.                     {
  116.                         $geshi->set_source($sql);
  117.                         $text $geshi->parse_code();
  118.                         $text preg_replace($newlineKeywords'<br />&nbsp;&nbsp;\\0'$text);
  119.                         echo '<li>'.$text.'</li>';
  120.                     }
  121.  
  122.                 echo '</ol>';
  123.             }
  124.         }
  125.  
  126.         if ($this->params->get('language'1))
  127.         {
  128.             echo '<h4>'.JText::_'Language Files Loaded' ).'</h4>';
  129.             echo '<ul>';
  130.             $lang &JFactory::getLanguage();
  131.             $extensions    $lang->getPaths();
  132.             foreach $extensions as $extension => $files)
  133.             {
  134.                 foreach $files as $file => $status )
  135.                 {
  136.                     echo "<li>$file $status</li>";
  137.                 }
  138.             }
  139.             echo '</ul>';
  140.  
  141.             echo '<h4>'.JText::_'Untranslated strings' ).'</h4>';
  142.             echo '<pre>';
  143.             $orphans $lang->getOrphans();
  144.             if (count$orphans ))
  145.             {
  146.                 ksort$orphansSORT_STRING );
  147.                 foreach ($orphans as $key => $occurance{
  148.                     foreach $occurance as $i => $info{
  149.                         $class    $info['class'];
  150.                         $func    $info['function'];
  151.                         $file    $info['file'];
  152.                         $line    $info['line'];
  153.                         echo strtoupper$key )."\t$class::$func()\t[$file:$line]\n";
  154.                     }
  155.                 }
  156.             }
  157.             else {
  158.                 echo JText::_'None' );
  159.             }
  160.             echo '</pre>';
  161.         }
  162.         echo '</div>';
  163.  
  164.         $debug ob_get_clean();
  165.  
  166.         $body JResponse::getBody();
  167.         $body str_replace('</body>'$debug.'</body>'$body);
  168.         JResponse::setBody($body);
  169.     }
  170. }

Documentation generated on Sun, 06 Apr 2008 07:13:31 +0200 by phpDocumentor 1.4.0a2