Plugin Directory

Changeset 225354


Ignore:
Timestamp:
04/04/2010 10:27:43 PM (16 years ago)
Author:
silasco
Message:

Adapting debug class to new structure

Location:
wp-pear-debug/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-pear-debug/trunk/readme.txt

    r210592 r225354  
    44Tags: debug, pear, php_debug, debugging, database debug, performance debug, performance
    55Requires at least: 2.8
    6 Tested up to: 2.9.1
    7 Stable tag: 1.4.6
     6Tested up to: 2.9.2
     7Stable tag: 1.4.7
    88
    99This plugin incorporates the pear php_debug library into wordpress.
  • wp-pear-debug/trunk/wp-pear-debug.php

    r202102 r225354  
    66 * Author: Community Modder
    77 * Plugin URI: http://www.communitymodder.com
    8  * Version: 1.4.6
     8 * Version: 1.4.7
    99 * =======================================================================
    1010 */
     11//include class loader and let the magic happen
     12//Loads class from format dir1.dirN.className
     13//className can be folder with same name as class
     14require_once(WP_PLUGIN_DIR.'/wp-pear-debug/lib/util/wpdutil.class.php');
    1115
    1216
     
    6973    //Configuration options for debug library
    7074    //These really should not change for wordpress needs
     75    //Shis should probably be somewhere else
    7176    public static function getConf()
    7277    {
     
    7984            'enable_watch'         => false,
    8085            'replace_errorhandler' => true,
    81             'HTML_DIV_images_path' => self::url()."/images",
     86            'HTML_DIV_images_path' => self::url()."/lib/PHP_Debug/images",
    8287        );
    8388    }   
    84     //include a class file
    85     //neat way of loading classes relative to base folder
    86     public static function loadClass($sClassPath)
    87     {
    88         $aParts = explode(".",$sClassPath);
    89         $sFile = self::path()."/";
    90         $iCount = 0;
    91        
    92         foreach($aParts as $sPart )
    93         {
    94             if( $iCount != count($aParts)-1 )
    95             {
    96                 $sFile.= $sPart."/";
    97             }   
    98             else
    99             {           
    100                 $sFile.= $sPart.".class.php";
    101                 break;
    102             }           
    103             $iCount++;
    104         }
    105        
    106         if( file_exists($sFile) && !is_dir($sFile) )
    107         {
    108             include_once($sFile);
    109         }
    110         else
    111         {
    112             throw new Exception($sFile);
    113         }
    114    
    115     }
    116     //return instance of class from file
    117     public static function getClass($sClassPath)
    118     {
    119         self::loadClass($sClassPath);
    120        
    121         $aParts = explode(".",$sClassPath);
    122         $sClass = $aParts[count($aParts)-1];
    123         $oClass =  new $sClass;
    124         //Use exisiting instance if possible
    125         if(method_exists($oClass,'singleton'))
    126         {
    127             $oClass = $oClass->singleton();
    128         }   
    129         return $oClass;
    130     }
    13189   
    13290    //Class initialization
     
    145103            }
    146104            //register javascript
    147             wp_register_script(self::WPD_JS, "".self::url()."/js/html_div.js");
     105            wp_register_script(self::WPD_JS, "".self::url()."/lib/PHP_Debug/js/html_div.js");
    148106            //register css
    149             wp_register_style(self::WPD_CSS, "".self::url()."/css/html_div.css");
     107            wp_register_style(self::WPD_CSS, "".self::url()."/lib/PHP_Debug/css/html_div.css");
    150108                   
    151109            //Include debug output for admin
     
    172130        add_action('admin_init',array('wp_pear_debug','settings'));
    173131       
     132        //This needs to be standardized
     133        //Adapted from sample so I am just happen that it works...for now
    174134        $plugin_dir = basename(dirname(__FILE__));
    175         //load language files
     135        //load language files (internationalize me)
    176136        load_plugin_textdomain( 'wp-pear-debug', 'wp-content/plugins/' . $plugin_dir.'/lang', $plugin_dir.'/lang' );
    177137
     
    180140        //self::add("Begin Debugging");
    181141    }
     142   
    182143    //not using globals
    183144    //use this to get single instance of debug class
    184     //All this drama just to load one class library!
    185145    public static function get()
    186146    {   
    187147        //return current instance of the pear debug class   
    188         return self::getClass('PHP_Debug');
     148        //using utility class to load libraries
     149        return wpdutil::getClass('PHP_Debug');
     150       
    189151    }
    190152   
     
    213175    private static function _processQueries()
    214176    {
    215         foreach(self::getDB()->queries as $query)
     177        foreach(wpdutil::getDB()->queries as $query)
    216178        {   
    217             self::get()->query('[ '.self::queryCaller($query[2]).' ] '.' [ '.self::toSeconds($query[1]).' '.__('seconds','wp-pear-debug').' ] '.$query[0]);
     179            self::get()->query('[ '.self::queryCaller($query[2]).' ] '.' [ '.wpdutil::toSeconds($query[1]).' '.__('seconds','wp-pear-debug').' ] '.$query[0]);
    218180        }   
    219181    }
     
    226188    }
    227189   
    228     //Database data in millionseconds. Change to seconds before output to user.
    229     public static function toSeconds($milli)
    230     {
    231         return $milli * 1000;
    232     }
    233    
    234     //don't ask...umm cause its pretty?
    235     //This call provides a standard access method for the database
    236     //May be a long way away but we might see the end of global wpdb
    237     public static function getDB()
    238     {
    239         global $wpdb;
    240         return $wpdb;
    241     }
     190
    242191   
    243192    protected static function enabled()
     
    325274    }   
    326275
    327 //Add in admin options with link under settings "Debugger"
    328 //Indent this big mess? Thank wordpress for that...This should all be javascript
     276    //Add in admin options with link under settings "Debugger"
     277    //Indent this big mess? Thank wordpress for that...This should all be javascript
    329278    public static function admin()
    330279    {
     
    352301        $aSettings = self::$settings;
    353302        //generate dynamic user role settings
    354         foreach(get_option(self::getDB()->prefix . 'user_roles')  as $key => $value)
     303        foreach(get_option(wpdutil::getDB()->prefix . 'user_roles')  as $key => $value)
    355304        {
    356305            $aSettings[] = array('type'=> self::WPD_SETTING_ROLE, 'key' => $key);
     
    373322    }
    374323
    375 //Print options page
    376 public static function options()
    377 {
    378 
     324    //Print options page
     325    public static function options()
     326    {
     327   
     328        ?>
     329    <div class=wrap>
     330      <form method="post" action="options.php">
     331   
     332        <h3><?php _e('Debugger Settings','wp-pear-debug') ?></h3>
     333    <div>
     334    <div class="postbox">
     335   
     336   
     337   
     338    <select name="<?php echo self::opt(self::WPD_STATUS);?>">
     339    <option value="<?php echo self::WPD_DISABLE;?>" <?php  if( get_option(self::opt(self::WPD_STATUS))== self::WPD_DISABLE ) echo "selected"; ?> ><?php _e('Disable Debugging','wp-pear-debug') ?></option>
     340    <option  value="<?php echo self::WPD_ENABLE;?>" <?php  if( get_option(self::opt(self::WPD_STATUS))== self::WPD_ENABLE ) echo "selected"; ?> ><?php _e('Enable Debugging','wp-pear-debug') ?></option>
     341    </select>
     342   
     343   
     344    </div>
     345    <h3> <?php _e('Display Debug for Roles:','wp-pear-debug') ?></h3>
     346    <div class="postbox">
     347    <table>
     348   
     349    <?php
     350   
     351    foreach(self::getSettingFeilds() as $sField):
     352   
     353            //we only want settings for roles
     354            if($sField['type'] != self::WPD_SETTING_ROLE):
     355                continue;
     356            endif; 
     357           
     358               
     359        ?>
     360        <tr>
     361        <td>
     362    <strong><?php echo ucfirst($sField['def']); ?></strong>
     363    </td>
     364    <td>
     365    <select name="<?php echo $sField['key']; ?>">   
     366    <option value="<?php echo self::WPD_STATUS_DISABLE;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_DISABLE) echo "selected"; ?> >
     367        <?php _e('Disable','wp-pear-debug','wp-pear-debug') ?>
     368    </option>   
     369    <option value="<?php echo self::WPD_STATUS_FRONT;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_FRONT) echo "selected"; ?> >
     370        <?php _e('Front End Only','wp-pear-debug') ?>
     371    </option>   
     372   
     373    <? if($sField['def'] != self::WPD_GUEST_ROLE): ?>
     374    <option value="<?php echo self::WPD_STATUS_ADMIN;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_ADMIN) echo "selected"; ?> >
     375        <?php _e('Admin Only','wp-pear-debug') ?>
     376    </option>   
     377    <option value="<?php echo self::WPD_STATUS_BOTH;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_BOTH) echo "selected"; ?> >
     378        <?php _e('Admin & Front End','wp-pear-debug') ?>
     379    </option>   
     380    <?php endif; ?>
     381    </select>   
     382   
     383    </td>
     384    </tr>
     385    <?php endforeach; ?>
     386    </table>
     387    </div>
     388    <?php
     389    //output hidden fields for settings (sweet)
     390    settings_fields(self::WPD_OPTIONS_GROUP);
    379391    ?>
    380 <div class=wrap>
    381   <form method="post" action="options.php">
    382 
    383     <h3><?php _e('Debugger Settings','wp-pear-debug') ?></h3>
    384 <div>
    385 <div class="postbox">
    386 
    387 
    388 
    389 <select name="<?php echo self::opt(self::WPD_STATUS);?>">
    390 <option value="<?php echo self::WPD_DISABLE;?>" <?php  if( get_option(self::opt(self::WPD_STATUS))== self::WPD_DISABLE ) echo "selected"; ?> ><?php _e('Disable Debugging','wp-pear-debug') ?></option>
    391 <option  value="<?php echo self::WPD_ENABLE;?>" <?php  if( get_option(self::opt(self::WPD_STATUS))== self::WPD_ENABLE ) echo "selected"; ?> ><?php _e('Enable Debugging','wp-pear-debug') ?></option>
    392 </select>
    393 
    394 
    395 </div>
    396 <h3> <?php _e('Display Debug for Roles:','wp-pear-debug') ?></h3>
    397 <div class="postbox">
    398 <table>
    399 
    400 <?php
    401 
    402 foreach(self::getSettingFeilds() as $sField):
    403 
    404         //we only want settings for roles
    405         if($sField['type'] != self::WPD_SETTING_ROLE):
    406             continue;
    407         endif; 
    408        
    409            
    410     ?>
    411     <tr>
    412     <td>
    413 <strong><?php echo ucfirst($sField['def']); ?></strong>
    414 </td>
    415 <td>
    416 <select name="<?php echo $sField['key']; ?>">   
    417 <option value="<?php echo self::WPD_STATUS_DISABLE;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_DISABLE) echo "selected"; ?> >
    418     <?php _e('Disable','wp-pear-debug','wp-pear-debug') ?>
    419 </option>   
    420 <option value="<?php echo self::WPD_STATUS_FRONT;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_FRONT) echo "selected"; ?> >
    421     <?php _e('Front End Only','wp-pear-debug') ?>
    422 </option>   
    423 
    424 <? if($sField['def'] != self::WPD_GUEST_ROLE): ?>
    425 <option value="<?php echo self::WPD_STATUS_ADMIN;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_ADMIN) echo "selected"; ?> >
    426     <?php _e('Admin Only','wp-pear-debug') ?>
    427 </option>   
    428 <option value="<?php echo self::WPD_STATUS_BOTH;?>" <?php  if(get_option($sField['key'])== self::WPD_STATUS_BOTH) echo "selected"; ?> >
    429     <?php _e('Admin & Front End','wp-pear-debug') ?>
    430 </option>   
    431 <?php endif; ?>
    432 </select>   
    433 
    434 </td>
    435 </tr>
    436 <?php endforeach; ?>
    437 </table>
    438 </div>
    439 <?php
    440 //output hidden fields for settings (sweet)
    441 settings_fields(self::WPD_OPTIONS_GROUP);
     392   
     393    </div>
     394    <div class="submit">
     395    <input type="submit" name="Submit" value="<?php _e('Save Changes','wp-pear-debug') ?>" />
     396    </div>
     397   
     398      </form>
     399     </div>
     400   
     401     <?php
     402    }
     403   
     404       
     405   
     406}   
     407
     408
     409
     410
     411
     412
    442413?>
    443 
    444 </div>
    445 <div class="submit">
    446 <input type="submit" name="Submit" value="<?php _e('Save Changes','wp-pear-debug') ?>" />
    447 </div>
    448 
    449   </form>
    450  </div>
    451 
    452  <?php
    453 }
    454 
    455    
    456    
    457 }   
    458 
    459 
    460 
    461 
    462 
    463 
    464 ?>
Note: See TracChangeset for help on using the changeset viewer.