phpDocumentor PHPShopClass
[ class tree: PHPShopClass ] [ all elements ]

Source for file debug.class.php

Documentation is available at debug.class.php

  1. <?php
  2. /**
  3.  * Отладочная панель
  4.  * Включение в config.ini параметр my[debug]=true
  5.  * <code>
  6.  * // example:
  7.  * timer('start','Моя отладка');
  8.  * debug($_POST,'Моя отладка');
  9.  * timer('end','Моя отладка');
  10.  * </code>
  11.  * @author PHPShop Software
  12.  * @version 1.0
  13.  * @package PHPShopClass
  14.  */
  15. class PHPShopDebug {
  16.     var $value;
  17.     var $tollbar_height_closed=150;
  18.     var $tollbar_height_opened=500;
  19.     /**
  20.      * @var string фон отладочной панели для вывода информации
  21.      */
  22.     var $backgroundcolor='black';
  23.     /**
  24.      * @var string цвет текста в отладчной панели
  25.      */
  26.     var $textcolor='green';
  27.     /**
  28.      * @var string цвет панели
  29.      */
  30.     var $tabcolor='green';
  31.     /**
  32.      * @var string цвет заголовков панели
  33.      */
  34.     var $texttabcolor='white';
  35.  
  36.     function add($value,$desc=false{
  37.         $this->value[$desc]=$value;
  38.     }
  39.  
  40.     function timeon($desc=false{
  41.         // Включаем таймер
  42.         $time=explode(' 'microtime());
  43.         $this->start_time[$desc]=$time[1]+$time[0];
  44.     }
  45.  
  46.     function timeoff($desc=false{
  47.         // Выключаем таймер
  48.         $time=explode(' 'microtime());
  49.         $seconds=($time[1]+$time[0]-$this->start_time[$desc]);
  50.         $this->seconds[$desc]=substr($seconds,0,6);
  51.     }
  52.  
  53.     function disp($name,$content{
  54.         ob_start();
  55.         print_r($name);
  56.         $disp=$content.': '.ob_get_clean();
  57.         echo  '<pre>'.strip_tags($disp).'</pre>';
  58.     }
  59.  
  60.     function log({
  61.         $disp='';
  62.         $base=$GLOBALS['SysValue']['base']['errorlog']['errorlog_log'];
  63.  
  64.         if(!empty($base)) {
  65.             $PHPShopOrm new PHPShopOrm($base);
  66.             $data $PHPShopOrm->select(array('*'),$where,array('order'=>'id DESC'),array('limit'=>100));
  67.  
  68.             if(is_array($data))
  69.                 foreach($data as $val$disp.=PHPShopDate::dataV($val['date']).' '.$val['error'].'</br>';
  70.         }
  71.         else $disp='Модуль Error Log не установлен';
  72.  
  73.         echo $disp;
  74.  
  75.     }
  76.  
  77.     function compile({
  78.         
  79.         if(!empty($_GET['debug'])) {
  80.             $height=$this->tollbar_height_closed."px";
  81.             $height2=($this->tollbar_height_closed-20)."px";
  82.         }
  83.         else {
  84.             $height="25px";
  85.             $height2="0px";
  86.         }
  87.         echo '
  88.            <script>
  89.            function debug_toolbar(toolbar,height){
  90.            height = toolbar.style.height;
  91.            if(height == "'.($this->tollbar_height_closed-20).'px") {
  92.            document.getElementById("debug-kit-toolbar").style.height="500px";
  93.            toolbar.style.height="500px";
  94.            }
  95.              else {
  96.              toolbar.style.height = "'.($this->tollbar_height_closed-20).'px";
  97.              document.getElementById("debug-kit-toolbar").style.height="'.$this->tollbar_height_closed.'px";
  98.              }
  99.            }
  100.            </script>
  101.            <style>
  102.  
  103.            #debug-kit-toolbar {
  104.            position: fixed;
  105.            top: 0px;
  106.            right:0px;
  107.            width: 100%;
  108.            height: '.$height.';
  109.            overflow: visible;
  110.            z-index:10000;
  111.            font-family: helvetica, arial, sans-serif;
  112.            }
  113.            
  114.            #debug-kit-nav{
  115.            background-color: '.$this->tabcolor.';
  116.  
  117.            color: '.$this->textcolor.';
  118.            width: 380px;
  119.            padding: 3px;
  120.            }
  121.  
  122.            #debug-kit-nav a{
  123.            color: '.$this->texttabcolor.';
  124.            font-size: 12px;
  125.            }
  126.  
  127.            #debug-kit-display {
  128.            background-color: '.$this->backgroundcolor.';
  129.            overflow: auto;
  130.            color: '.$this->textcolor.';
  131.            border: 0px;
  132.            border-style: inset;
  133.            height: '.$height2.';
  134.            font-size: 11px;
  135.            text-align: left;
  136.            }
  137.  
  138.            </style>
  139.            <div title="Развернуть" id="debug-kit-toolbar" align="right">
  140.            <div id="debug-kit-nav">
  141.            <IMG border=0 alt="" src="/phpshop/lib/icon/debug.png" width=16 height=16 alt="Отладчик Вкл" align="absmiddle" hspace="5">
  142.            <a href="?debug=session">Session</a> |
  143.            <a href="?debug=sysvalue">SysValue</a> |
  144.            <a href="?debug=request">Request</a> | 
  145.            <a href="?debug=timer">Timer</a> |
  146.            <a href="?debug=variables">Variables</a> |
  147.            <a href="?debug=values">Values</a> |
  148.            <a href="?exit">Exit</a></div>
  149.            <div id="debug-kit-display" onclick="debug_toolbar(this)">';
  150.  
  151.         if(!empty($_GET['debug']))
  152.         switch($_GET['debug']{
  153.             case "session":
  154.                 $this->disp($_SESSION,"_SESSION");
  155.                 break;
  156.             case "sysvalue":
  157.                 $SysValue=$GLOBALS['SysValue'];
  158.                 $SysValue['connect']='******';
  159.                 $SysValue['other']='******';
  160.                 $this->disp($SysValue,"GLOBALS['SysValue']");
  161.                 break;
  162.             case "request":
  163.                 $this->disp($GLOBALS['SysValue']['nav'],"GLOBALS['SysValue']['nav']");
  164.                 break;
  165.             case "log":
  166.                 $this->log();
  167.                 break;
  168.             case "variables":
  169.                 $this->disp($GLOBALS['SysValue']['other'],"GLOBALS['SysValue']['other']");
  170.                 break;
  171.             case "values":
  172.                 $this->disp($this->value,"Values");
  173.                 break;
  174.             case "timer":
  175.                 $this->disp($this->seconds,"Timer");
  176.                 break;
  177.         }
  178.  
  179.         echo '</div></div>';
  180.     }
  181. }
  182.  
  183. /**
  184.  * Отладка персональных данных
  185.  * @global obj $PHPShopDebug
  186.  * @param mixed $value перемнная для отладки
  187.  * @param string $desc оисание переменной
  188.  */
  189. function debug($value,$desc=false{
  190.     global $PHPShopDebug;
  191.     $PHPShopDebug->add($value,$desc);
  192. }
  193.  
  194. /**
  195.  * Замер времени выполнения
  196.  * @global obj $PHPShopDebug
  197.  * @param string $option переключатель вкл.выкл [start|end]
  198.  * @param string $desc описание таймера
  199.  */
  200. function timer($option='start',$desc=false{
  201.     global $PHPShopDebug;
  202.  
  203.     if($option == 'start'$PHPShopDebug->timeon($desc);
  204.     else $PHPShopDebug->timeoff($desc);
  205. }
  206.  
  207. ?>

Documentation generated on Mon, 25 Jun 2012 15:09:42 +0400 by phpDocumentor 1.4.3