[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/system/ -> debug.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: debug.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 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   * @package        Joomla
  23   * @subpackage    System
  24   */
  25  class  plgSystemDebug extends JPlugin
  26  {
  27      /**
  28       * Constructor
  29       *
  30       * For php4 compatability we must not use the __constructor as a constructor for plugins
  31       * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  32       * This causes problems with cross-referencing necessary for the observer design pattern.
  33       *
  34       * @access    protected
  35       * @param    object $subject The object to observe
  36       * @param     array  $config  An array that holds the plugin configuration
  37       * @since    1.0
  38       */
  39  	function plgSystemDebug(& $subject, $config)
  40      {
  41          parent::__construct($subject, $config);
  42  
  43          //load the translation
  44          $this->loadLanguage( );
  45      }
  46  
  47      /**
  48      * Converting the site URL to fit to the HTTP request
  49      *
  50      */
  51  	function onAfterRender()
  52      {
  53          global $_PROFILER, $mainframe, $database;
  54  
  55          // Do not render if debugging is not enabled
  56          if(!JDEBUG) { return; }
  57  
  58          $document    =& JFactory::getDocument();
  59          $doctype    = $document->getType();
  60  
  61          // Only render for HTML output
  62          if ( $doctype !== 'html' ) { return; }
  63  
  64          $profiler    =& $_PROFILER;
  65  
  66          ob_start();
  67          echo '<div id="system-debug" class="profiler">';
  68          if ($this->params->get('profile', 1)) {
  69              echo '<h4>'.JText::_( 'Profile Information' ).'</h4>';
  70              foreach ( $profiler->getBuffer() as $mark ) {
  71                  echo '<div>'.$mark.'</div>';
  72              }
  73          }
  74  
  75          if ($this->params->get('memory', 1)) {
  76              echo '<h4>'.JText::_( 'Memory Usage' ).'</h4>';
  77              echo $profiler->getMemory();
  78          }
  79  
  80          if ($this->params->get('queries', 1))
  81          {
  82              jimport('geshi.geshi');
  83  
  84              $geshi = new GeSHi( '', 'sql' );
  85              $geshi->set_header_type(GESHI_HEADER_DIV);
  86              //$geshi->enable_line_numbers( GESHI_FANCY_LINE_NONE );
  87  
  88              $newlineKeywords = '/<span style="color: #993333; font-weight: bold;">'
  89                  .'(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)'
  90                  .'<\\/span>/i'
  91              ;
  92  
  93              $db    =& JFactory::getDBO();
  94  
  95              echo '<h4>'.JText::sprintf( 'Queries logged',  $db->getTicker() ).'</h4>';
  96  
  97              if ($log = $db->getLog())
  98              {
  99                  echo '<ol>';
 100                  foreach ($log as $k=>$sql)
 101                  {
 102                      $geshi->set_source($sql);
 103                      $text = $geshi->parse_code();
 104                      $text = preg_replace($newlineKeywords, '<br />&nbsp;&nbsp;\\0', $text);
 105                      echo '<li>'.$text.'</li>';
 106                  }
 107                  echo '</ol>';
 108              }
 109  
 110              if(isset($database))
 111              {
 112                  echo '<h4>'.JText::sprintf( 'Legacy Queries logged',  $database->getTicker() ).'</h4>';
 113                  echo '<ol>';
 114  
 115                      foreach ($database->getLog() as $k=>$sql)
 116                      {
 117                          $geshi->set_source($sql);
 118                          $text = $geshi->parse_code();
 119                          $text = preg_replace($newlineKeywords, '<br />&nbsp;&nbsp;\\0', $text);
 120                          echo '<li>'.$text.'</li>';
 121                      }
 122  
 123                  echo '</ol>';
 124              }
 125          }
 126  
 127          $lang = &JFactory::getLanguage();
 128          if ($this->params->get('language_files', 1))
 129          {
 130              echo '<h4>'.JText::_( 'Language Files Loaded' ).'</h4>';
 131              echo '<ul>';
 132              $extensions    = $lang->getPaths();
 133              foreach ( $extensions as $extension => $files)
 134              {
 135                  foreach ( $files as $file => $status )
 136                  {
 137                      echo "<li>$file $status</li>";
 138                  }
 139              }
 140              echo '</ul>';
 141          }
 142  
 143          $langStrings = $this->params->get('language_strings', -1);
 144          if ($langStrings < 0 OR $langStrings == 1) {
 145              echo '<h4>'.JText::_( 'Untranslated Strings Diagnostic' ).'</h4>';
 146              echo '<pre>';
 147              $orphans = $lang->getOrphans();
 148              if (count( $orphans ))
 149              {
 150                  ksort( $orphans, SORT_STRING );
 151                  foreach ($orphans as $key => $occurance) {
 152                      foreach ( $occurance as $i => $info) {
 153                          $class    = @$info['class'];
 154                          $func    = @$info['function'];
 155                          $file    = @$info['file'];
 156                          $line    = @$info['line'];
 157                          echo strtoupper( $key )."\t$class::$func()\t[$file:$line]\n";
 158                      }
 159                  }
 160              }
 161              else {
 162                  echo JText::_( 'None' );
 163              }
 164              echo '</pre>';
 165          }
 166          if ($langStrings < 0 OR $langStrings == 2) {
 167              echo '<h4>'.JText::_( 'Untranslated Strings Designer' ).'</h4>';
 168              echo '<pre>';
 169              $orphans = $lang->getOrphans();
 170              if (count( $orphans ))
 171              {
 172                  ksort( $orphans, SORT_STRING );
 173                  $guesses = array();
 174                  foreach ($orphans as $key => $occurance) {
 175                      if (is_array( $occurance ) AND isset( $occurance[0] )) {
 176                          $info = &$occurance[0];
 177                          $file = @$info['file'];
 178                          if (!isset( $guesses[$file] )) {
 179                              $guesses[$file] = array();
 180                          }
 181  
 182                          $guess = str_replace( '_', ' ', $info['string'] );
 183                          if ($strip = $this->params->get('language_prefix')) {
 184                              $guess = trim( preg_replace( chr(1).'^'.$strip.chr(1), '', $guess ) );
 185                          }
 186                          $guesses[$file][] = trim( strtoupper( $key ) ).'='.$guess;
 187                      }
 188                  }
 189                  foreach ($guesses as $file => $keys) {
 190                      echo "\n\n# ".($file ? $file : JText::_( 'Unknown file' ))."\n\n";
 191                      echo implode( "\n", $keys );
 192                  }
 193              }
 194              else {
 195                  echo JText::_( 'None' );
 196              }
 197              echo '</pre>';
 198          }
 199          echo '</div>';
 200  
 201          $debug = ob_get_clean();
 202  
 203          $body = JResponse::getBody();
 204          $body = str_replace('</body>', $debug.'</body>', $body);
 205          JResponse::setBody($body);
 206      }
 207  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1