Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file lensdebug.class.php

Documentation is available at lensdebug.class.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2001, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: lensdebug.class.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  */
  10.  
  11.  /**
  12.  * Debug Variables - show debugging results in another window using javascript.
  13.  *
  14.  * The original saved into a file then displayed it in a window
  15.  * and was written by Alter Gr <alt-gr@gmx.de>.
  16.  *
  17.  * The new version by John Lim <jlim@natsoft.com.my>
  18.  * 1. writes directly to the debug window without using an intermediate file
  19.  * 2. supports all types, including objects, floats and booleans
  20.  * 3. cleans up strings with < correctly using htmlspecialchars()
  21.  * 4. added msg()
  22.  * 5. added recursion check in v2()
  23.  *
  24.  * Tested with IE 5.5 and Netscape 4.77 and 6.
  25.  *
  26.  * usage:
  27.  * $D = new LensDebug();
  28.  * $D->v($var1,"var1"); // display a variable and its type
  29.  * $D->msg('Show a text message');
  30.  *
  31.  * second parameter is optional
  32.  *
  33.  * Original (c) by DATABAY AG 2001 - ay@databay.de
  34.  * Other portions (c) 2001 by John Lim
  35.  *
  36.  * This is free software. Use at your own risk.
  37.  */
  38.  
  39. /**
  40.  * @package Zikula_Core
  41.  * @subpackage Zikula_Debug
  42.  */
  43. class LensDebug {
  44.     var $show = false;
  45.     var $depth = 0;
  46.     // destination of the results
  47.     // file - to a file named debug.html
  48.     // window - to the lens debug window
  49.     var $destination = "window";
  50.     // ------------------------------------------
  51.     // Format variable recursively based on type
  52.     function v2($V$Name ""$class false)
  53.     {
  54.         global $depth;
  55.  
  56.         if ($this->depth > 32{
  57.             return '<p>Recursive Depth Exceeded</p>';
  58.         }
  59.         $depth += 1;
  60.         $TYPE_COLOR "RED";
  61.         $NAME_COLOR "BLUE";
  62.         $VALUE_COLOR "BLACK";
  63.  
  64.         $D "";
  65.  
  66.         $Name htmlspecialchars($Name);
  67.  
  68.         $type gettype($V);
  69.         if (is_string($V)) {
  70.             $V htmlspecialchars($V);
  71.             $D "<FONT COLOR=$TYPE_COLOR><B>$type: </B></FONT>";
  72.             if ($Name != ""{
  73.                 $D .= "<FONT COLOR=$NAME_COLOR>$Name</FONT> = ";
  74.             }
  75.             $D .= "<FONT COLOR=$VALUE_COLOR>&quot;$V&quot;</FONT>";
  76.         else if (is_object($V)) {
  77.             $D .= $this->v2(get_object_vars($V)$Nameget_class($V));
  78.             $D substr($D0strlen($D)-4)// get rid of last BR
  79.         else if (is_array($V)) {
  80.             if ($class{
  81.                 $t "Class $class";
  82.             else {
  83.                 $t 'Array';
  84.             }
  85.  
  86.             $D "<FONT COLOR=$TYPE_COLOR><B>$t: </B></FONT>";
  87.  
  88.             if ($Name != ""{
  89.                 $D .= " (<FONT COLOR=$NAME_COLOR>$Name</FONT>) ";
  90.             }
  91.             $D .= "<FONT COLOR=$VALUE_COLOR><UL>";
  92.  
  93.             foreach($V as $key => $val{
  94.                 $D .= $this->v2($val$key);
  95.             }
  96.             // $D = substr($D,0,strlen($D)-4); // get rid of last BR
  97.             $D .= "</UL></FONT>";
  98.         else {
  99.             if ($V === null{
  100.                 $V 'null';
  101.             else if ($V === false{
  102.                 $V 'false';
  103.             else if ($V === true{
  104.                 $V 'true';
  105.             }
  106.  
  107.             $D "<FONT COLOR=$TYPE_COLOR><B>$type: </B></FONT>";
  108.             if ($Name != ""{
  109.                 $D .= "<FONT COLOR=$NAME_COLOR>$Name</FONT> = ";
  110.             }
  111.             $D .= "<FONT COLOR=$VALUE_COLOR>$V</FONT>";
  112.         }
  113.  
  114.         $D .= "<BR>";
  115.         $this->depth -= 1;
  116.         return($D);
  117.     }
  118.  
  119.     function _show()
  120.     {
  121.         if (!$this->show{
  122.             global $PHP_SELF;
  123.  
  124.             $file $PHP_SELF;
  125.             $D "<TABLE SIZE=100% CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD><HR SIZE=1></TD><TD WIDTH=1%><FONT FACE='Verdana,arial' SIZE=1>" date("d.m.Y""&nbsp;" date("H:i:s""</FONT></TD></TR></TABLE>";
  126.  
  127.             if ($this->destination == "window"{
  128.  
  129.                 ?>
  130.    <SCRIPT>
  131.    lensdebugw=window.open('',"DEBUGVAR","WIDTH=450,HEIGHT=500,scrollbars=yes,resizable=yes");
  132.    if (lensdebugw) {
  133.        lensdebugw.focus();
  134.        lensdebugw.document.write("<?php echo $D;
  135.  
  136.                 ?>"+'<b>'+window.location.href+'</b></p>');
  137.    }
  138.    </SCRIPT>
  139. <?php
  140.             else {
  141.                 $fh fopen('debug.htm''a');
  142.                 fwrite($fh$D);
  143.                 fclose($fh);
  144.             }
  145.             $this->show = true;
  146.         }
  147.     }
  148.     // ---------------------------------
  149.     // display message in debug window
  150.     function msg($D$encode true)
  151.     {
  152.         $this->_show();
  153.         if ($encode{
  154.             $D htmlspecialchars($D'<p>';
  155.         }
  156.         $D str_replace('\\''\\\\'$D);
  157.         $D str_replace('"''\"'$D);
  158.         $D str_replace("\r"' '$D);
  159.         $D str_replace("\n"' '$D);
  160.  
  161.         if ($this->destination == "window"{
  162.  
  163.             ?>
  164. <SCRIPT>
  165. if (lensdebugw) {
  166.     lensdebugw.document.write("<?php echo $D;
  167.  
  168.             ?>");
  169.     lensdebugw.scrollBy(0,100000);
  170. }
  171. </SCRIPT>
  172. <?php
  173.         else {
  174.             $fh fopen('debug.html''a');
  175.             fwrite($fh$D);
  176.             fclose($fh);
  177.         }
  178.     }
  179.     // ---------------------------------
  180.     // display variable in debug window
  181.     function v($V$Name "")
  182.     {
  183.         $this->_show();
  184.  
  185.         $D $this->v2($V$Name);
  186.         if (!is_object($Vand !is_array($V)) {
  187.             $D .= '<br>';
  188.         }
  189.         $this->msg($Dfalse);
  190.     }
  191. // LensDebug class
  192.  
  193. ?>

Documentation generated on Fri, 18 Jul 2008 21:47:34 +0200 by phpDocumentor 1.4.1