<?php
/**
* debug view function
*
* @author Hendrik Hamming <hendrik@madscripter.eu>
*
* @param type $var
* @param string $label
* @return type
*/
function debug($var, $label = false){
if(!WP_DEBUG)return;
echo '<pre style="border:1px solid #222; padding: 5px;max-width: 800px;margin: 40px 20px;">';
$debug = DEBUG::i($var, $label);
echo '<span style="border-bottom:1px solid #777;display:block; padding: 4px;font-style:italic; margin-bottom:10px;">'.$debug->getLabel().'</span>';
echo '<div style="">';
} else {
}
echo '</div>';
echo '<span style="font-style:italic; border-top: 1px solid #777; padding: 4px; margin-top: 10px;display:block;font-size: 12px;">' . $debug->footer .'</span>';
echo "</pre>";
}
/**
* debug view function
*
* @author Hendrik Hamming <hendrik@madscripter.eu>
*
* @param array $array
* @uses DEBUG
* @return type
*/
function debug_array
(array $array)
{
foreach ($array as $key => $value)
{
if(!WP_DEBUG)return;
echo '<pre style="border:1px solid #222; padding: 5px;max-width: 800px;margin: 40px 20px;">';
$debug = DEBUG::i($value, $key);
echo '<span style="border-bottom:1px solid #777;display:block; padding: 4px;font-style:italic; margin-bottom:10px;">'.$debug->getLabel().'</span>';
echo '<div style="">';
} else {
}
echo '</div>';
echo '<span style="font-style:italic; border-top: 1px solid #777; padding: 4px; margin-top: 10px;display:block;font-size: 12px;">' . $debug->footer .'</span>';
echo "</pre>";
}
}
class DEBUG {
private static $instance = false;
private static
$instances = array();
private $label = array();
public static $counter = 0;
private $var;
private $file;
public $footer = '';
private $contents;
private $backtrace;
public function __construct($var, $label = false) {
$this->var = $var;
$this->parse_backtrace();
$this->setLabel($label);
$this->setFooter();
}
private function parse_backtrace (){
$this->backtrace = $b;
$this->file = new stdClass
();
$this->file->path = str_replace(__DIR__
.'/', '', $b[3]['file']);
$this->file->line = $b[3]['line'];
$line = trim(file($b[3]['file'])[$b[3]['line']-1]);
$this->contents = $matches[2][DEBUG::$counter-1];
if(count($matches[2])==DEBUG
::$counter){
}
}
private function setLabel ($label = false){
if($label !== false){
$this->label[] = '<b>Label:</b> ' . (string)$label;
}
if(isset($this->backtrace[4])){
if( isset($this->backtrace[4]['class'])){
$this->label[] = '<b>Class:</b> ' . $this->backtrace[4]['class'] . '';
}
if(isset($this->backtrace[4]['function'])){
$this->label[] = '<b>Function:</b> ' . $this->backtrace[4]['function'];
}
}
$this->label[] = '<b>Var:</b> ' . $this->contents;
}
}
public function getLabel (){
return (string
)join($this->label, "\r\n");
}
private function setFooter (){
$this->footer = $this->file->path . ' Line: ' . $this->file->line;
}
private static
function reset(){
self::$instances = array();
self::$counter =0;
}
public static function getInstances(){
return self::$instances;
}
public static function countInstances(){
return count(self::$instances);
}
public static function i($var, $label = false){
self::$counter++;
self::$instance = new DEBUG($var, $label);
self::$instances[] = self::$instance;
return self::$instance;
}
}