Plugin Directory

Changeset 646871


Ignore:
Timestamp:
01/02/2013 04:40:50 AM (13 years ago)
Author:
misternifty
Message:

Added debug menu links functionality

Location:
debug-this/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • debug-this/trunk/_inc/css/debug-this.css

    r645456 r646871  
    4141    text-decoration: none;
    4242}
     43
     44.header-links{
     45    margin-left:0;
     46}
     47
     48.header-links li{
     49    list-style: none;
     50    display:inline-block;
     51    margin-right:10px;
     52    border-right:1px solid #777;
     53    padding-right:10px;
     54}
     55
     56.header-links li:last-child{
     57    border:none;
     58}
  • debug-this/trunk/_inc/debug-template.php

    r646297 r646871  
    1212<body>
    1313<div class='debug-this'>
    14     <a href="/<?php echo Debug_This::get_escape_link();?>" class="escape">x</a>
     14    <a href="/<?php echo Debug_This::get_escape_url();?>" class="escape">x</a>
    1515    <div class='debug'>
    1616        %DEBUG%
  • debug-this/trunk/_inc/extensions.php

    r646731 r646871  
    295295            $debug = print_r($dropins, true);
    296296        else
    297             $debug = __("No dropins found. To learn more, please see: <a href='http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/'>http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/</a>", 'debug-this');
     297            $debug = sprintf(__("No dropins found. To learn more, please see: %s", 'debug-this'), "<a href='http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/'>http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/</a>");
    298298        return $debug;
    299299    }
     
    742742
    743743    public function wp_debug(){
    744         if(defined('WP_DEBUG') && WP_DEBUG !== true && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG !== true){
     744        if(defined('WP_DEBUG') && WP_DEBUG === true && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG === true){
     745            $path = WP_CONTENT_DIR.'/debug.log';
     746            $debug = '';
     747            if(file_exists($path) && is_writeable($path)){
     748                add_debug_header_link(Debug_This::get_current_debug_url().'&clear-debug-log=true', __('Reset log file', 'debug-this'));
     749                if(isset($_GET['clear-debug-log'])){
     750                    if(file_put_contents($path, '') === 0)
     751                        $debug .= __('Debug log was successfully cleared.', 'debug-this');
     752                    else
     753                        $debug .= __('Debug log could not be reset. Please try again', 'debug-this');
     754                }
     755                $debug .= file_get_contents($path);
     756                if(!$debug)
     757                    $debug .= __('Looking good! No notices were logged.', 'debug-this');
     758            }
     759            elseif(touch($path))
     760                $debug = __('Looking good! No notices were logged.', 'debug-this'); #Better reporting. If nothing was found, it's not a file perms error.
     761            else
     762                $debug = __('Could not open debug.log. Please make sure your wp-content folder is writeable by the web server user.', 'debug-this');
     763            return $debug;
     764        }
     765        else{
    745766            $debug = __("Please add the following to wp-config.php to use this mode.\ndefine('WP_DEBUG', true);\ndefine('WP_DEBUG_LOG', true);\ndefine('WP_DEBUG_DISPLAY', false);", 'debug-this');
    746767            return $debug;
    747768        }
    748         $path = WP_CONTENT_DIR.'/debug.log';
    749 
    750         if(file_exists($path) && is_writeable($path)){
    751             $debug = file_get_contents($path);
    752             if(!$debug)
    753                 $debug = __('Looking good! No notices were logged.', 'debug-this');
    754             file_put_contents($path, ''); #Clear contents for next page load
    755         }
    756         elseif(touch($path))
    757             $debug = __('Looking good! No notices were logged.', 'debug-this'); #Better reporting. If nothing was found, it's not a file perms error.
    758         else
    759             $debug = __('Could not open debug.log. Please make sure your wp-content folder is writeable by the web server user.', 'debug-this');
    760         return $debug;
    761769    }
    762770
  • debug-this/trunk/debug-this.php

    r646381 r646871  
    3232    protected $description;
    3333    public static $mode;
    34     protected $query_var = 'debug-this';
     34    public static $query_var = 'debug-this';
    3535    public static $no_pre = false;
    3636    protected $default_mode = 'wp_query';
     
    3939    public static $queries;
    4040    protected $nonce_action = 'dEbUg-ThIs';
     41    public static $debug_header;
    4142
    4243    public function __construct(){
     
    7980            'defaultMode' => $this->default_mode,
    8081            'template'    => $this->original_template,
    81             'queryVar'    => $this->query_var
     82            'queryVar'    => self::$query_var
    8283        );
    8384        wp_localize_script('debug-this', 'debugThis', $l10n);
     
    8687
    8788    public function add_query_var($vars){
    88         $vars[] = $this->query_var;
    89         $vars[] = "$this->query_var-fetch";
    90         $vars[] = "$this->query_var-key";
    91         $vars[] = "$this->query_var-ts";
    92         $vars[] = "$this->query_var-nonce";
     89        $vars[] = self::$query_var;
     90        $vars[] = self::$query_var."-fetch";
     91        $vars[] = self::$query_var."-key";
     92        $vars[] = self::$query_var."-ts";
     93        $vars[] = self::$query_var."-nonce";
    9394        return $vars;
    9495    }
     
    103104    protected function is_fetch(){
    104105        if(
    105             get_query_var("$this->query_var-fetch") &&
    106             get_query_var("$this->query_var-ts")    &&
    107             get_query_var("$this->query_var-key")   &&
    108             get_query_var("$this->query_var-nonce")
     106            get_query_var(self::$query_var."-fetch") &&
     107            get_query_var(self::$query_var."-ts")   &&
     108            get_query_var(self::$query_var."-key")   &&
     109            get_query_var(self::$query_var."-nonce")
    109110        ){
    110             $time  = get_query_var("$this->query_var-ts");
    111             $nonce = get_query_var("$this->query_var-nonce");
    112             $key   = get_query_var("$this->query_var-key");
     111            $time  = get_query_var(self::$query_var."-ts");
     112            $nonce = get_query_var(self::$query_var."-nonce");
     113            $key   = get_query_var(self::$query_var."-key");
    113114
    114115            //Security #1 - Time range
     
    154155
    155156        $fetch_vars = array(
    156             "$this->query_var-fetch" => true,
    157             "$this->query_var-key"   => md5($time . wp_salt('logged_in') . $nonce),
    158             "$this->query_var-ts"    => $time,
    159             "$this->query_var-nonce" => $nonce
     157            self::$query_var."-fetch" => true,
     158            self::$query_var."-key"   => md5($time . wp_salt('logged_in') . $nonce),
     159            self::$query_var."-ts"    => $time,
     160            self::$query_var."-nonce" => $nonce
    160161        );
    161162
    162163        $query_vars = $wp->query_vars;
    163         unset($query_vars[$this->query_var]);
     164        unset($query_vars[self::$query_var]);
    164165
    165166        $vars = array_merge($fetch_vars, $query_vars);
     
    194195
    195196    protected function is_debug(){
    196         if(isset($_GET[$this->query_var])){
    197             self::$mode = $_GET[$this->query_var] ? $_GET[$this->query_var] : apply_filters('debug_this_default_mode', $this->default_mode);
     197        if(isset($_GET[self::$query_var])){
     198            self::$mode = $_GET[self::$query_var] ? $_GET[self::$query_var] : apply_filters('debug_this_default_mode', $this->default_mode);
    198199            return true;
    199200        }
     
    228229        $description = $this->description ? ' - '. $this->description : '';
    229230        echo '<p>'.__('Debug This Mode', 'debug_this').': '.self::$mode.$description.'</p>';
     231        echo '<ul class="header-links">'.self::$debug_header.'</ul>';
    230232        if(self::$no_pre)
    231233            echo $this->debug;
     
    248250        #Build out query string
    249251        $vars = $wp->query_vars;
    250         $vars[$this->query_var] = $this->default_mode;
     252        $vars[self::$query_var] = $this->default_mode;
    251253        $query_string = http_build_query($vars);
    252254
     
    260262            foreach($extensions as $id => $values){
    261263                #Update query string
    262                 $vars[$this->query_var] = $id;
     264                $vars[self::$query_var] = $id;
    263265                $query_string = http_build_query($vars);
    264266                $wp_admin_bar->add_menu(array('id' => $id, 'parent' => $group, 'title' => $values['name'], 'href' => "?$query_string"));
     
    284286    }
    285287
    286     public function get_escape_link(){
     288    public function get_escape_url(){
    287289        global $wp;
    288290
    289291        $permalinks = get_option('permalink_structure');
    290292        if($permalinks)
    291             $link = $wp->request;
     293            $url = $wp->request;
    292294        else{
    293295            $vars = $wp->query_vars;
     
    295297                if($v === self::$mode)
    296298                    unset($vars[$k]);
    297             $link = !empty($vars) ? '?' . http_build_query($vars) : '';
    298         }
    299         return $link;
     299            $url = !empty($vars) ? '?' . http_build_query($vars) : '';
     300        }
     301        return $url;
     302    }
     303
     304    public function get_current_debug_url(){
     305        $url = self::get_escape_url();
     306        $url .= '&'.self::$query_var.'='.self::$mode;
     307        return $url;
    300308    }
    301309
     
    320328    if(isset($_debugger_extensions[$id]))
    321329        unset($_debugger_extensions[$id]);
     330}
     331
     332function add_debug_header_link($url, $label, $classes = ''){
     333    Debug_This::$debug_header = Debug_This::$debug_header."<li><a href='$url' class='$classes'>$label</a></li>";
    322334}
    323335
Note: See TracChangeset for help on using the changeset viewer.