diff --git a/dBug.php b/dBug.php index bc109b7..09107d2 100755 --- a/dBug.php +++ b/dBug.php @@ -2,16 +2,21 @@ /*********************************************************************************************************************\ * LAST UPDATE * ============ - * March 22, 2007 + * August 6th, 2012 * * * AUTHOR * ============= - * Kwaku Otchere + * Kwaku Otchere * ospinto@hotmail.com - * + * + * AFTERMARKET HACKER + * ================== + * Josh Sherman + * josh@crowdsavings.com + * * Thanks to Andrew Hewitt (rudebwoy@hotmail.com) for the idea and suggestion - * + * * All the credit goes to ColdFusion's brilliant cfdump tag * Hope the next version of PHP can implement this or have something similar * I love PHP, but var_dump BLOWS!!! @@ -32,22 +37,22 @@ * example: * new dBug ( $myVariable ); * - * - * if the optional "forceType" string is given, the variable supplied to the - * function is forced to have that forceType type. + * + * if the optional "forceType" string is given, the variable supplied to the + * function is forced to have that forceType type. * example: new dBug( $myVariable , "array" ); - * will force $myVariable to be treated and dumped as an array type, + * will force $myVariable to be treated and dumped as an array type, * even though it might originally have been a string type, etc. * * NOTE! * ============== * forceType is REQUIRED for dumping an xml string or xml file * new dBug ( $strXml, "xml" ); - * + * \*********************************************************************************************************************/ class dBug { - + var $xmlDepth=array(); var $xmlCData; var $xmlSData; @@ -59,7 +64,7 @@ class dBug { var $bInitialized = false; var $bCollapsed = false; var $arrHistory = array(); - + //constructor function dBug($var,$forceType="",$bCollapsed=false) { //include js and css scripts @@ -81,45 +86,45 @@ class dBug { //possible 'included' functions $arrInclude = array("include","include_once","require","require_once"); - + //check for any included/required files. if found, get array of the last included file (they contain the right line numbers) for($i=count($arrBacktrace)-1; $i>=0; $i--) { $arrCurrent = $arrBacktrace[$i]; - if(array_key_exists("function", $arrCurrent) && + if(array_key_exists("function", $arrCurrent) && (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) continue; $arrFile = $arrCurrent; - + break; } - + if(isset($arrFile)) { $arrLines = file($arrFile["file"]); $code = $arrLines[($arrFile["line"]-1)]; - + //find call to dBug class preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); - + return $arrMatches[1]; } return ""; } - + //create the main table header function makeTableHeader($type,$header,$colspan=2) { if(!$this->bInitialized) { $header = $this->getVariableName() . " (" . $header . ")"; $this->bInitialized = true; } - $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; - + $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; + echo ""; } - + //create the table row header function makeTDHeader($type,$header) { $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; @@ -127,12 +132,12 @@ class dBug { \n"; } - + //error function error($type) { $error="Error: Variable cannot be a"; @@ -166,35 +171,35 @@ class dBug { break; } } - + //if variable is a NULL type function varIsNULL() { echo "NULL"; } - + //if variable is a boolean type function varIsBoolean($var) { $var=($var==1) ? "TRUE" : "FALSE"; echo $var; } - + //if variable is an array type function varIsArray($var) { $var_ser = serialize($var); array_push($this->arrHistory, $var_ser); - + $this->makeTableHeader("array","array"); if(is_array($var)) { foreach($var as $key=>$value) { $this->makeTDHeader("array",$key); - + //check for recursion if(is_array($value)) { $var_ser = serialize($value); if(in_array($var_ser, $this->arrHistory, TRUE)) $value = "*RECURSION*"; } - + if(in_array(gettype($value),$this->arrType)) $this->checkType($value); else { @@ -208,20 +213,20 @@ class dBug { array_pop($this->arrHistory); echo "
".$header."
".$header." "; } - + //close table row function closeTDRow() { return "
"; } - + //if variable is an object type function varIsObject($var) { $var_ser = serialize($var); array_push($this->arrHistory, $var_ser); $this->makeTableHeader("object","object"); - + if(is_object($var)) { $arrObjVars=get_object_vars($var); foreach($arrObjVars as $key=>$value) { $value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value; $this->makeTDHeader("object",$key); - + //check for recursion if(is_object($value)||is_array($value)) { $var_ser = serialize($value); @@ -280,7 +285,7 @@ class dBug { $db = "pg"; if($db == "sybase-db" || $db == "sybase-ct") $db = "sybase"; - $arrFields = array("name","type","flags"); + $arrFields = array("name","type","flags"); $numrows=call_user_func($db."_num_rows",$var); $numfields=call_user_func($db."_num_fields",$var); $this->makeTableHeader("resource",$db." result",$numfields+1); @@ -304,7 +309,7 @@ class dBug { for($i=0;$i<$numrows;$i++) { $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); echo "\n"; - echo "".($i+1).""; + echo "".($i+1).""; for($k=0;$k<$numfields;$k++) { $tempField=$field[$k]->name; $fieldrow=$row[($field[$k]->name)]; @@ -317,7 +322,7 @@ class dBug { if($numrows>0) call_user_func($db."_data_seek",$var,0); } - + //if variable is an image/gd resource type function varIsGDResource($var) { $this->makeTableHeader("resource","gd",2); @@ -329,26 +334,26 @@ class dBug { echo imagecolorstotal($var).$this->closeTDRow(); echo ""; } - + //if variable is an xml type function varIsXml($var) { $this->varIsXmlResource($var); } - + //if variable is an xml resource type function varIsXmlResource($var) { $xml_parser=xml_parser_create(); - xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); - xml_set_element_handler($xml_parser,array(&$this,"xmlStartElement"),array(&$this,"xmlEndElement")); + xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); + xml_set_element_handler($xml_parser,array(&$this,"xmlStartElement"),array(&$this,"xmlEndElement")); xml_set_character_data_handler($xml_parser,array(&$this,"xmlCharacterData")); - xml_set_default_handler($xml_parser,array(&$this,"xmlDefaultHandler")); - + xml_set_default_handler($xml_parser,array(&$this,"xmlDefaultHandler")); + $this->makeTableHeader("xml","xml document",2); $this->makeTDHeader("xml","xmlRoot"); - + //attempt to open xml file $bFile=(!($fp=@fopen($var,"r"))) ? false : true; - + //read xml file if($bFile) { while($data=str_replace("\n","",fread($fp,4096))) @@ -363,20 +368,20 @@ class dBug { $data=$var; $this->xmlParse($xml_parser,$data,1); } - + echo $this->closeTDRow()."\n"; - + } - + //parse xml function xmlParse($xml_parser,$data,$bFinal) { - if (!xml_parse($xml_parser,$data,$bFinal)) { - die(sprintf("XML error: %s at line %d\n", - xml_error_string(xml_get_error_code($xml_parser)), - xml_get_current_line_number($xml_parser))); + if (!xml_parse($xml_parser,$data,$bFinal)) { + die(sprintf("XML error: %s at line %d\n", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); } } - + //xml: inititiated when a start tag is encountered function xmlStartElement($parser,$name,$attribs) { $this->xmlAttrib[$this->xmlCount]=$attribs; @@ -391,8 +396,8 @@ class dBug { $this->xmlSData[$this->xmlCount].='echo " ";'; $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; $this->xmlCount++; - } - + } + //xml: initiated when an end tag is encountered function xmlEndElement($parser,$name) { for($i=0;$i<$this->xmlCount;$i++) { @@ -409,8 +414,8 @@ class dBug { echo $this->closeTDRow(); echo ""; $this->xmlCount=0; - } - + } + //xml: initiated when text between tags is encountered function xmlCharacterData($parser,$data) { $count=$this->xmlCount-1; @@ -418,8 +423,8 @@ class dBug { $this->xmlCData[$count].=$data; else $this->xmlCData[$count]=$data; - } - + } + //xml: initiated when a comment or other miscellaneous texts is encountered function xmlDefaultHandler($parser,$data) { //strip '' off comments @@ -439,7 +444,7 @@ class dBug { var target = (document.all) ? source.parentElement.cells[1] : source.parentNode.lastChild; dBug_toggleTarget(target,dBug_toggleSource(source)); } - + function dBug_toggleSource(source) { if (source.style.fontStyle=='italic') { source.style.fontStyle='normal'; @@ -451,11 +456,11 @@ class dBug { return 'closed'; } } - + function dBug_toggleTarget(target,switchToState) { target.style.display = (switchToState=='open') ? '' : 'none'; } - + function dBug_toggleTable(source) { var switchToState=dBug_toggleSource(source); if(document.all) { @@ -476,48 +481,54 @@ class dBug { } } - +