/var/www-protected/php-debug.com/www/PHP/Debug/Renderer/HTML/Div.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
<?php
 
/**
 * Class of the HTML_Div renderer
 * 
 * Idea from the debug system of the symfony PHP framework 
 * @see http://www.symfony-project.org
 * @author Fabien Potencier
 * @author François Zaninotto
 * 
 * @author  Vernet Loïc
 * 
 * @version CVS: $Id: Div.php,v 1.3 2008/10/05 14:41:37 c0il Exp $
 */
 
require_once 'PHP/Debug/Renderer/HTML/DivConfig.php';
 
 
/**
 * A floating div renderer for PHP_Debug
 *
 * Returns a floating based representation of the debug infos in XHTML sctrict
 * format
 *
 * @package PHP_Debug
 * @category PHP
 * @author Loïc Vernet <qrf_coil at yahoo dot fr>
 * @since V2.1.0 - 30 march 2007
 * 
 * @package PHP_Debug
 * @filesource
 */
 
class PHP_Debug_Renderer_HTML_Div extends PHP_Debug_Renderer_Common
{    
    // debug types for Vars & Config
    protected static $settingsType = array(
        PHP_DebugLine::TYPE_ENV,
    );
 
    // debug types for Log & Message tab
    protected static $msgTypes = array(
        PHP_DebugLine::TYPE_STD,
        PHP_DebugLine::TYPE_PAGEACTION,
        PHP_DebugLine::TYPE_APPERROR,
        PHP_DebugLine::TYPE_CREDITS,
        PHP_DebugLine::TYPE_DUMP,
        PHP_DebugLine::TYPE_WATCH,
        PHP_DebugLine::TYPE_PHPERROR
    );
 
    // debug types for Database tab
    protected static $databaseTypes = array(
        PHP_DebugLine::TYPE_QUERY,
        PHP_DebugLine::TYPE_QUERYREL,
        PHP_DebugLine::TYPE_SQLPARSE,
    );
 
    /**
     * Debug_Renderer_HTML_Div class constructor
     * 
     * @since V2.1.0 - 3 apr 2007
     */
    function __construct($DebugObject, $options)
    {
        $this->DebugObject = $DebugObject;
        $this->defaultOptions = PHP_Debug_Renderer_HTML_DivConfig::singleton()->getConfig();
        $this->setOptions($options);
        
        if ($this->options['HTML_DIV_disable_credits'] == false) {
            $this->DebugObject->addDebugFirst($this->options['HTML_DIV_credits'], 
                PHP_DebugLine::TYPE_CREDITS);
        }
 
        // Add execution time
        $this->DebugObject->addProcessPerf();
    }
 
    /**
     * This is the function to display the debug informations
     *
     * @since V2.0.0 - 07 Apr 2006
     * @see PHP_Debug::Render()
     */
    public function display()
    {
        $buffer = '';
 
        // Header        
        $buffer .= $this->displayHeader();
 
        // Infos
        $debugInfos = $this->DebugObject->getDebugBuffer(); 
             
        // Vars & config
        $buffer .= $this->showVarsAndConfig($debugInfos);
 
        // Logs & msg
        $buffer .= $this->showLogsAndMsg($debugInfos);
 
        // Database
        $buffer .= $this->showDatabaseInfos($debugInfos);
 
        // W3C Validation
        $buffer .= $this->showW3cValidation($debugInfos);
 
        // Process time
        $buffer .= $this->showProcessTime($debugInfos);
        
        // Footer
        $buffer .= $this->displayFooter();
        
        return $buffer;        
    }
 
    /**
     * Show W3C validator tab
     * 
     * @author COil
     * @since V2.1.1 - 23 apr 2007
     */
    protected function showW3cValidation()
    {
        return str_replace(
            array(
                '{$imagesPath}',
            ),
            array(
                $this->options['HTML_DIV_images_path']
            ),
            $this->options['HTML_DIV_sfWebDebugW3CDetails']
        );
    }
 
    /**
     * Add the debug informations of the W3C validation process 
     * 
     * @author Vernet Loïc
     * @since 2.1.0 - 23 avr. 2007
     */
    protected function addW3CErrorInfos($res, $key)
    {
        $title = ucwords($key);  
        $type = 'sfW3C'. $title;
        $errorCpt = 1;
        $results = str_replace(
          '{$title}', 
          $title, 
          $this->options['HTML_DIV_sfWebDebugW3CTableHeader']
        );
 
        foreach ($res->$key as $error) {
            $id = $errorCpt. ($error->messageid ? ' ('. $error->messageid. ')' : '');
            $results .= str_replace(
                array(
                    '{$type}', 
                    '{$cpt}', 
                    '{$line}', 
                    '{$col}', 
                    '{$message}',
                    '{$source}',
                ),
                array(
                    $type,
                    $id,
                    $error->line,
                    $error->col,
                    $error->message,
                    '&nbsp',
                ),
                $this->options['HTML_DIV_sfWebDebugW3CErrorRow']
            );                        
            $errorCpt++;        
        }
        $results .= '</table>';
        
        return $results;
    }
 
    /**
     * Shows vars & config
     * 
     * @param array debug row
     * 
     * @author COil
     * @since V2.1.0 - 30 march 2007
     */
    protected function showDatabaseInfos($debugInfos)
    {
        $idx = 1;
        $buffer = '';
 
        foreach ($debugInfos as $debugInfo) {
            $properties = $debugInfo->getProperties();
            if (in_array($properties['type'], self::$databaseTypes)) {                
                $buffer.= '<li>['. $this->processExecTime($properties). '] '. 
                    $this->processDebugInfo($properties) .'</li>'. CR;
            }
        }
 
        return str_replace(
            array('{$buffer}'),
            array($buffer ? $buffer : '<li>No database debug available</li>'),
            $this->options['HTML_DIV_sfWebDebugDatabaseDetails']
        );
    }
 
    /**
     * Shows vars & config
     * 
     * @author COil
     * @since V2.1.0 - 30 march 2007
     */
    protected function showLogsAndMsg($debugInfos)
    {
        $idx = 1;
        $buffer = '';
 
        foreach($debugInfos as $debugInfo) {
            $properties = $debugInfo->getProperties();
            if (in_array($properties['type'], self::$msgTypes)) {
            
                // Error level of debug information
                $level = $this->getLogInfoLevel($properties);   
                $infoImg = $this->getImageInfo($level);
            
                $buffer .= '<tr class=\'sfWebDebugLogLine '. $this->getDebugLevelClass($level). '\'>
                    <td class="sfWebDebugLogNumber"># '. $idx. '</td>
                    <td class="sfWebDebugLogType">
                        <img src="'. $this->options['HTML_DIV_images_path']. '/'. $infoImg .'" alt="" />&nbsp;'. $this->processType($properties).
                    '</td>
                    <td class="sfWebDebugLogFile">'. $this->processFile($properties). '</td>
                    <td class="sfWebDebugLogLine">'. $this->processLine($properties). '</td>
                    <td class="sfWebDebugLogClass">'. $this->processClass($properties). '</td>
                    <td class="sfWebDebugLogFunction">'. $this->processFunction($properties). '</td>
                    <td class="sfWebDebugLogTime">'. $this->processExecTime($properties). '</td>
                    <td class="sfWebDebugLogMessage">'. $this->processDebugInfo($properties). '</td>
                </tr>'. CR;
                $idx++;
            }
        }
 
        return str_replace(
            array(
                '{$buffer}',
                '{$imagesPath}',
            ),
            array(
                $buffer,
                $this->options['HTML_DIV_images_path']
            ),
            $this->options['HTML_DIV_sfWebDebugLog']
        );
    }
 
    /**
     * Get the log level of the debug info
     * 
     * @author COil
     * @since V2.1.0 - 2 avr. 2007
     * 
     * @param array debug row
     */
    protected function getLogInfoLevel($properties)
    {
        $level = PHP_DebugLine::INFO_LEVEL;
 
        switch ($properties['type']) {
            case PHP_DebugLine::TYPE_PAGEACTION:
            case PHP_DebugLine::TYPE_CREDITS:
            case PHP_DebugLine::TYPE_DUMP:
            case PHP_DebugLine::TYPE_WATCH:
            break;
 
            case PHP_DebugLine::TYPE_APPERROR:
                $level = PHP_DebugLine::ERROR_LEVEL;
            break;
 
            case PHP_DebugLine::TYPE_PHPERROR:
                $level = $this->getPhpErrorLevel($properties);
            break;
        }
        
        return $level;        
    }
 
    /**
     * Return the global error level corresponding to the related php error
     * level
     * 
     * @param array debug row
     * 
     * @author COil
     * @since 2.1.0 - 3 apr 2007
     */
    protected function getPhpErrorLevel($properties)
    {
        $infos = $properties['info'];
 
        switch ($infos[0]) {
            case E_ERROR:
            case E_PARSE:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
            case E_USER_ERROR:
                return PHP_DebugLine::ERROR_LEVEL;
            break;                
            
            case E_WARNING:
            case E_CORE_WARNING:
            case E_NOTICE:
            case E_COMPILE_WARNING:
            case E_USER_WARNING:
            case E_USER_NOTICE:
            case E_ALL:
            case E_STRICT:
            case E_RECOVERABLE_ERROR:
                return PHP_DebugLine::WARNING_LEVEL;
            break;                
 
            default:
                return PHP_DebugLine::ERROR_LEVEL;
            break;                
        }
    }
 
    /**
     * Get the image info for the current debug type
     * 
     * @author COil
     * @since V2.1.0 - 2 avp 2007
     */
    protected function getDebugLevelClass($debug_level)
    {
        return $this->options['HTML_DIV_debug_level_classes'][$debug_level];
    }
 
    /**
     * Get the image info for the current debug type
     * 
     * @author COil
     * @since V2.1.0 - 2 avp 2007
     */
    protected function getImageInfo($debug_level)
    {
        $info = $this->options['HTML_DIV_image_info'];
        $warning = $this->options['HTML_DIV_image_warning'];
        $error   = $this->options['HTML_DIV_image_error'];
 
        switch ($debug_level) {
            case PHP_DebugLine::INFO_LEVEL:
                $level = $info;
            break;
 
            case PHP_DebugLine::WARNING_LEVEL:
                $level = $warning;
            break;
 
            case PHP_DebugLine::ERROR_LEVEL:
                $level = $error;
            break;
        }
        
        return $level;
    }
 
    /**
     * Shows vars & config
     * 
     * @author COil
     * @since V2.1.0 - 30 march 2007
     */
    protected function showVarsAndConfig($debugInfos)
    {
        return str_replace(
            array(
                '{$sfWebDebugRequest}',
                '{$sfWebDebugResponse}',
                '{$sfWebDebugSettings}',
                '{$sfWebDebugConstants}',
                '{$sfWebDebugGlobals}',
                '{$sfWebDebugPhp}',
                '{$sfWebDebugFiles}',
                '{$imagesPath}',
            ),
            array(
                $this->showSuperArray(PHP_Debug::GLOBAL_REQUEST),
                $this->showSuperArray(PHP_Debug::GLOBAL_COOKIE),
                $this->showArray($this->settingsAsArray($debugInfos), 'Settings'),
                $this->showArray(get_defined_constants(true)),
                $this->showArray($this->globalsAsArray(), 'Globals'),
                $this->showArray($this->phpInfoAsArray(), 'PHP Infos'),
                $this->showTemplates(),
                $this->options['HTML_DIV_images_path'],
            ),
            $this->options['HTML_DIV_sfWebDebugConfig']
        );
    }
 
    /**
     * Return all settings of application
     * 
     * @author COil
     * @since V2.1.0 - 2 apr 2007
     */
    public function settingsAsArray($debugInfos)
    {
        $settings = array();
        foreach($debugInfos as $debugInfo) {
            $infos = $debugInfo->getProperties();
            if (in_array($infos['type'], self::$settingsType)) {
                $settings[] = $infos['info']; 
            }
        }    
    
        return $settings;
    }
 
   /**
    * Returns PHP globals variables as a sorted array.
    *
    * @return array PHP globals
    * @since V2.1.0 - 2 apr 2007
    */
    public static function globalsAsArray()
    {
        $values = array();
        foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name) {
 
            if (!isset($GLOBALS['_'.strtoupper($name)])) {
                continue;
            }
    
            $values[$name] = array();
            foreach ($GLOBALS['_'. strtoupper($name)] as $key => $value) {
                $values[$name][$key] = $value;
            }
            ksort($values[$name]);
        }   
 
        ksort($values);
 
        return $values;
    }
 
    /**
     * Returns PHP information as an array.
     * 
     * @return  array An array of php information
     * @since V2.1.0 - 2 apr 2007
     */
    public static function phpInfoAsArray()
    {
        $values = array(
            'php'        => phpversion(),
            'os'         => php_uname(),
            'extensions' => get_loaded_extensions(),
        );
 
        // assign extension version if available
        if ($values['extensions']) {
            foreach ($values['extensions'] as $lkey => $extension) {
                $values['extensions'][$lkey] = phpversion($extension) ? $extension. 
                    ' ('. phpversion($extension). ')' : $extension;
            }
        }
 
        return $values;
    }
 
    /**
     * Add the process time information to the debug information
     * 
     * @since V2.0.0 - 18 Apr 2006
     */ 
    protected function showProcessTime($debugInfos)
    {
        // Lang
        $txtExecutionTime = 'Global execution time ';
        $txtPHP           = 'PHP';
        $txtSQL           = 'SQL';              
        $txtSECOND        = 's';
        $txtOneQry        = ' query';
        $txtMultQry       = ' queries';
        $queryCount       = $this->DebugObject->getQueryCount();
        $txtQuery         = $queryCount > 1 ? $txtMultQry : $txtOneQry;
        $buffer           = '';
 
        // Performance Debug
        $processTime = $this->DebugObject->getProcessTime();
        $sqlTime    = $this->DebugObject->getQueryTime();
        $phpTime    = $processTime - $sqlTime;
    
        $sqlPercent = round(($sqlTime / $processTime) * 100, 2);                              
        $phpPercent = round(($phpTime / $processTime) * 100, 2);
 
        $processTime = $processTime*1000;
        $sqlTime    = $sqlTime*1000;
        $phpTime    = $phpTime*1000;
        
        if ($debugInfos) {
            $buffer .= '
            <tr>
                <th>message</th>
                <th>time (ms)</th>
                <th>percent</th>
            </tr>'. CR;
 
            foreach($debugInfos as $debugInfo) {
                $properties = $debugInfo->getProperties();
                if ($properties['startTime'] && $properties['endTime']) {
 
                    $localPercent = round((($properties['endTime'] - 
                        $properties['startTime'])*1000 / $processTime) * 100, 2);
                    $buffer .= '
                    <tr>
                        <td class="sfWebDebugLogMessagePerf">'. $this->ProcessDebugInfo($properties). '</td>
                        <td style="text-align: right">'. $this->ProcessExecTime($properties). '</td>
                        <td style="text-align: right">'. $localPercent. '%</td>
                    </tr>'. CR;
                }
            }
        }
 
        return str_replace(
            array(
                '{$txtExecutionTime}',
                '{$processTime}',
                '{$txtPHP}',
                '{$phpTime}',
                '{$phpPercent}',
                '{$txtSQL}',
                '{$sqlTime}',
                '{$sqlPercent}',
                '{$queryCount}',
                '{$txtQuery}',
                '{$buffer}'
                
            ),
            array(
                $txtExecutionTime,
                $processTime,
                $txtPHP,
                $phpTime,
                $phpPercent,
                $txtSQL,
                $sqlTime,
                $sqlPercent,
                $queryCount,
                $txtQuery,
                $buffer
            ),
            $this->options['HTML_DIV_sfWebDebugTimeDetails']       
        );
    }
 
    /**
     * Default render function for HTML_Div renderer
     *
     * @since V2.0.0 - 11 Apr 2006
     * @see Renderer
     */
    public function render()
    {
        return $this->display();
    }
 
    /**
     * Displays the header of the PHP_Debug object
     *
     * @since V2.0.0 - 08 Apr 2006
     * @see PHP_Debug
     */
    protected function displayHeader()
    {
        return str_replace(
            array(
                '{$nb_queries}', 
                '{$exec_time}',
                '{$imagesPath}',
                '{$phpDebugVersion}'
            ),
            array(
                $this->DebugObject->getQueryCount(), 
                $this->DebugObject->getProcessTime() * 1000,
                $this->options['HTML_DIV_images_path'],
                PHP_Debug::PEAR_RELEASE
            ),        
            $this->options['HTML_DIV_header']);  
    }        
 
    /**
     * Diplays the footer of the PHP_Debug object
     *
     * @since V2.0.0 - 08 Apr 2006
     * @see PHP_Debug
     */
    protected function displayFooter()
    {
        return $this->options['HTML_DIV_footer'];
    }        
    
    /**
     * process display of the execution time of debug information  
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the main debug info
     * @since V2.0.0 - 28 Apr 2006
     */ 
    protected function processExecTime($properties)
    {   
        // Lang
        $txtPHP = 'PHP';
        $txtSQL = 'SQL';
        $txtSECOND = 's';
 
        if (!empty($properties['endTime'])) {
 
            $time = round(PHP_Debug::getElapsedTime(
                $properties['startTime'], 
                $properties['endTime']
            ) * 1000);
 
            $buffer = $this->span($time > 1 ? $time. ' ms' : '&lt; 1 ms', 'time');
 
        } else {
            $buffer = '&nbsp;';
        }
 
        return $buffer; 
    }
    
    /**
     * process display of the main information of debug 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the main debug info
     * @since V2.0.0 - 28 Apr 2006
     */ 
    protected function processDebugInfo($properties)
    {   
        $buffer = '';
 
        switch($properties['type']) {
 
            // Case for each of the debug lines types
            // 1 : Standard
            case PHP_DebugLine::TYPE_STD:
                $buffer .= $this->span($properties['info'], 'std');
                break;
            
            // 2 : Query
            case PHP_DebugLine::TYPE_QUERY:
                $buffer .= preg_replace('/\b(SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES)\b/', 
                    '<span class="sfWebDebugLogInfo">\\1</span>', 
                    $properties['info']);
                break;
 
            // 3 : Query related
            case PHP_DebugLine::TYPE_QUERYREL:
                $buffer .= $this->span($properties['info'], 'query');
                break;
                
            // 4 : Environment
            case PHP_DebugLine::TYPE_ENV:
                $buffer .= $this->showSuperArray($properties['info']);
                break;
 
            // 6 : User app error
            case PHP_DebugLine::TYPE_APPERROR:
                $buffer .= $this->span('/!\\ User error : '. 
                    $properties['info']. ' /!\\', 'app-error');
                break;
                
            // 7
            case PHP_DebugLine::TYPE_CREDITS:
                $buffer .= $this->span($properties['info'], 'credits');            
                break;
 
            // 9
            case PHP_DebugLine::TYPE_DUMP:
                $buffer .= $this->showDump($properties);
                break;
 
            // 10
            case PHP_DebugLine::TYPE_PROCESSPERF:
                $buffer .= $this->showProcessTime();
                break;
 
            // 12 : Main Page Action
            case PHP_DebugLine::TYPE_PAGEACTION;
                $buffer .= $this->span('[Action : '. 
                    $properties['info']. ']', 'pageaction');
                break;
 
            // 14 : SQL parse 
            case PHP_DebugLine::TYPE_SQLPARSE:
                $buffer .= $properties['info'];
                break;
 
            // 15 : Watches
            case PHP_DebugLine::TYPE_WATCH:
                $infos = $properties['info'];
                $buffer .= 'Variable '. $this->span($infos[0], 'watch').
                           ' changed from value '. 
                            $this->span($infos[1], 'watch-val'). ' ('. gettype($infos[1]). 
                            ') to value '. $this->span($infos[2], 'watch-val'). 
                            ' ('. gettype($infos[2]). ')';
                break;
 
            // 16 : PHP errors
            case PHP_DebugLine::TYPE_PHPERROR:                
                $buffer .= $this->showError($properties['info']);
                break;
 
            default:
                $buffer .= '<b>Default('. $properties['type'].
                           ')</b>: TO IMPLEMENT OR TO CORRECT : &gt;'. 
                           $properties['info']. '&lt;';
                break;
        }
 
        return $buffer;
    }
 
    /**
     * Return a string with applying a span style on it
     * 
     * @param string $info String to apply the style
     * @param string $class CSS style to apply to the string
     * @return string Formatted string with style applied
     * @since V2.0.0 - 05 May 2006
     */ 
    protected function span($info, $class)
    {   
        return '<span class="'. $class .'">'. $info .'</span>'; 
    }
 
    /**
     * process display of the type of the debug information 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the debug type
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function processType($properties)
    {   
        $buffer = PHP_DebugLine::$debugLineLabels[$properties['type']];
        return $buffer;
    }
 
    /**
     * process display of Class 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the class
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function processClass($properties)
    {
        $buffer = '';
 
        switch ($properties['type'])
        {
            case PHP_DebugLine::TYPE_STD:
            case PHP_DebugLine::TYPE_QUERY:
            case PHP_DebugLine::TYPE_QUERYREL:
            case PHP_DebugLine::TYPE_APPERROR:             
            case PHP_DebugLine::TYPE_PAGEACTION:
            case PHP_DebugLine::TYPE_PHPERROR:
            case PHP_DebugLine::TYPE_SQLPARSE:
            case PHP_DebugLine::TYPE_WATCH:
            case PHP_DebugLine::TYPE_DUMP:
                        
                if (!empty($properties['class'])) {
                    $buffer .= $properties['class'];
                } else {
                    $buffer .= '&nbsp;';
                }
 
                break;
                        
            case PHP_DebugLine::TYPE_CREDITS: 
            case PHP_DebugLine::TYPE_SEARCH:
            case PHP_DebugLine::TYPE_PROCESSPERF:
            case PHP_DebugLine::TYPE_TEMPLATES:
            case PHP_DebugLine::TYPE_ENV:
 
                $buffer .= '&nbsp;';
 
                break;
        
            default:
                break;
        }
        
        return $buffer;
    }
 
    /**
     * process display of function 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the function
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function processFunction($properties)
    {
        $buffer = '';
 
        switch ($properties['type'])
        {
            case PHP_DebugLine::TYPE_STD:
            case PHP_DebugLine::TYPE_QUERY:
            case PHP_DebugLine::TYPE_QUERYREL:
            case PHP_DebugLine::TYPE_APPERROR:             
            case PHP_DebugLine::TYPE_PAGEACTION:
            case PHP_DebugLine::TYPE_PHPERROR:
            case PHP_DebugLine::TYPE_SQLPARSE:
            case PHP_DebugLine::TYPE_WATCH:
            case PHP_DebugLine::TYPE_DUMP:
                        
                if (!empty($properties['function'])) {                    
                    if ($properties['function'] != 'unknown') { 
                        $buffer .= $properties['function']. '()';
                    } else {
                        $buffer .= '&nbsp;';
                }
                } else {
                    $buffer .= '&nbsp;';
                }
 
                break;
                        
            case PHP_DebugLine::TYPE_CREDITS: 
            case PHP_DebugLine::TYPE_SEARCH:
            case PHP_DebugLine::TYPE_PROCESSPERF:
            case PHP_DebugLine::TYPE_TEMPLATES:
            case PHP_DebugLine::TYPE_ENV:
 
                $buffer .= '&nbsp;';
                break;
        
            default:
                break;
        }
        
        return $buffer;
    }
 
 
    /**
     * process display of line number 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the line number
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function processLine($properties)
    {
        $buffer = '';
 
        switch ($properties['type'])
        {
            case PHP_DebugLine::TYPE_STD:
            case PHP_DebugLine::TYPE_QUERY:
            case PHP_DebugLine::TYPE_QUERYREL:
            case PHP_DebugLine::TYPE_APPERROR:             
            case PHP_DebugLine::TYPE_PAGEACTION:
            case PHP_DebugLine::TYPE_PHPERROR:
            case PHP_DebugLine::TYPE_SQLPARSE:
            case PHP_DebugLine::TYPE_WATCH:
            case PHP_DebugLine::TYPE_DUMP:
                        
                if (!empty($properties['line'])) {
                    $buffer.= '<span class="line">'. 
                        $properties['line']. '</span>';
                } else {
                    $buffer.= '&nbsp;';
                }        
 
                break;
                        
            case PHP_DebugLine::TYPE_CREDITS: 
            case PHP_DebugLine::TYPE_SEARCH:
            case PHP_DebugLine::TYPE_PROCESSPERF:
            case PHP_DebugLine::TYPE_TEMPLATES:
            case PHP_DebugLine::TYPE_ENV:
 
                $buffer.= '&nbsp;';
 
                break;
        
            default:
                break;
        }
        
        return $buffer;
    }
 
    /**
     * process display of file name 
     * 
     * @param array $properties Properties of the debug line
     * @return string Formatted string containing the file
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function processFile($properties)
    {
        $buffer = '';
 
        switch ($properties['type'])
        {
            case PHP_DebugLine::TYPE_STD:
            case PHP_DebugLine::TYPE_QUERY:
            case PHP_DebugLine::TYPE_QUERYREL:
            case PHP_DebugLine::TYPE_APPERROR:             
            case PHP_DebugLine::TYPE_PAGEACTION:
            case PHP_DebugLine::TYPE_PHPERROR:
            case PHP_DebugLine::TYPE_SQLPARSE:
            case PHP_DebugLine::TYPE_WATCH:
            case PHP_DebugLine::TYPE_DUMP:
 
                if (!empty($properties['file'])) {
                    if (!empty($this->options['HTML_DIV_view_source_script_path']) && 
                        !empty($this->options['HTML_DIV_view_source_script_name'])) {
                        $buffer .= '<a href="'. 
                                $this->options['HTML_DIV_view_source_script_path'].
                                '/'. 
                                $this->options['HTML_DIV_view_source_script_name'].  
                                '?file='. urlencode($properties['file']);
 
                        $buffer .= '">'. basename($properties['file']). '</a>'; 
 
                    } else {
                        $buffer .= basename($properties['file']);                        
                    }
                } else {
                    $buffer .=  '&nbsp;';
                }        
        
                break;
                        
            case PHP_DebugLine::TYPE_CREDITS: 
            case PHP_DebugLine::TYPE_SEARCH:
            case PHP_DebugLine::TYPE_PROCESSPERF:
            case PHP_DebugLine::TYPE_TEMPLATES:
            case PHP_DebugLine::TYPE_ENV:
 
                $buffer .=  '&nbsp;';
 
                break;
        
            default:
                break;
        }
        
        return $buffer;
    }
 
    /**
     * Dump of a variable
     * 
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function showDump($properties)
    {
        $buffer = '';
 
        // Check display with a <pre> design
        if (is_array($properties['info'][1])) {
            $preDisplay = true;                      
        } elseif (is_object($properties['info'][1])) {
            $preDisplay = true;                      
        } else {
            $preDisplay = false;                      
        }
 
        // Check var name
        if (empty($properties['info'][0])) {
            if (is_array($properties['info'][1])) {
                $varName = 'Array';
            } elseif (is_object($properties['info'][1])) {
                $varName = get_class($properties['info'][1]);
            } else {
                $varName = 'Variable';                              
            }
        } else {
            $varName = $properties['info'][0];
        }
        
        // Output
        if ($properties['type'] != PHP_DebugLine::TYPE_ENV) { 
            $title = 'dump of \'';
        } 
        
        $title .= $varName. '\' ('.  gettype($properties['info'][1]) .') : ';
        
        $buffer .= $this->span($title , 'dump-title');
        
        if ($preDisplay == true){
            $buffer .= '<pre>';                   
            $buffer .= PHP_Debug::dumpVar(
                $properties['info'][1], 
                '', 
                false, 
                PHP_Debug::DUMP_STR);
        } else {
            $buffer .= $this->span(
                PHP_Debug::dumpVar(
                    $properties['info'][1], 
                    '', 
                    false, 
                    PHP_Debug::DUMP_STR
                ), 'dump-val');
        }
 
        if ($preDisplay == true) {
            $buffer .= '</pre>';                  
        }
 
        return $buffer;
    }
 
    /**
     * Get the templates info
     * 
     * @since V2.0.0 - 26 Apr 2006
     */ 
    protected function showTemplates()
    {
        $txtMainFile = 'MAIN File';
        $idx = 1;
        $buffer = '<br />';
 
        foreach($this->DebugObject->getRequiredFiles() as $lvalue) {
            
            $isToDisplay = true;
 
            if ($this->options['HTML_DIV_view_source_excluded_template']) {            
                foreach ($this->options['HTML_DIV_view_source_excluded_template'] as $template) {                
                    if (stristr($lvalue, $template)) {
                        $isToDisplay = false;
                    }
                }
            }
 
            if ($isToDisplay == true) {
 
                $buffer .= '<div class="source">';
                $buffer .= $this->span($this->truncate($lvalue), 'files');
                $buffer .= ' <a href="'. 
                             $this->options['HTML_DIV_view_source_script_path'].
                             '/'. $this->options['HTML_DIV_view_source_script_name'].  
                             '?file='. urlencode($lvalue). '">View source</a> ';
                    
                // main file    
                if ($idx == 1) {
                    $buffer .= $this->span('&laquo; '. $txtMainFile, 'main-file');
                }                       
                $idx++;
                $buffer .= '</div><br />'. CR;
            }            
        }        
 
        $buffer .= '<br />'. CR;
        return $buffer; 
    }
    
    
    /**
     * Truncate/replace a pattern from the file path
     * 
     * @param string full file path
     * 
     * @author COil
     * @since V2.1.0 - 3 apr 2007
     * 
     * @see 
     * - HTML_DIV_remove_templates_pattern
     * - HTML_DIV_templates_pattern
     */
    protected function truncate($file)
    {
        if ($this->options['HTML_DIV_remove_templates_pattern'] && 
            $this->options['HTML_DIV_templates_pattern']) {
            return strtr($file, $this->options['HTML_DIV_templates_pattern']);
        } 
 
        return $file;
    }
    
    /**
     * Process an error info
     * 
     * @param array $info Array containing information about the error
     * 
     * @since V2.0.0 - 25 Apr 2006
     * @see PHP_DebugLine::TYPE_PHPERROR
     */ 
    protected function showError($infos)    
    {
        $buffer = '';
        $infos[1] = str_replace("'", '"', $infos[1]);
        $infos[1] = str_replace(
            'href="function.', 
            ' href="http://www.php.net/'. 
            $this->options['lang']. '/', $infos[1]);
 
        switch ($infos[0])
        {
            case E_WARNING:
                $errorlevel = 'PHP WARNING : ';
                $buffer .= '<span class="pd-php-warning"> /!\\ '. 
                    $errorlevel. $infos[1] . ' /!\\ </span>';                
                break;
 
            case E_NOTICE:
                $errorlevel = 'PHP notice : ';
                $buffer .= '<span class="pd-php-notice">'. 
                    $errorlevel. $infos[1] . '</span>';
                break;
 
            case E_USER_ERROR:
                $errorlevel = 'PHP User error : ';
                $buffer .= '<span class="pd-php-user-error"> /!\\ '. 
                    $errorlevel. $infos[1] . ' /!\\ </span>';
                break;
 
            case E_STRICT:
                
                $errorlevel = 'PHP STRICT error : ';
                $buffer .= '<span class="pd-php-user-error"> /!\\ '. 
                    $errorlevel. $infos[1] . ' /!\\ </span>';
                break;
 
            default:
                $errorlevel = 'PHP errorlevel = '. $infos[0]. ' : ';
                $buffer .= $errorlevel. 
                    ' is not implemented in PHP_Debug ('. __FILE__. ','. __LINE__. ')';
                break;
        }
        
        return $buffer;
    }
 
    /**
     * Show a super array
     * 
     * @param string $SuperArrayType Type of super en array to add
     * @since V2.0.0 - 07 Apr 2006
     */ 
    protected function showSuperArray($SuperArrayType)    
    {
        // Lang
        $txtVariable   = 'Var';
        $txtNoVariable = 'NO VARIABLE';
        $NoVariable    = ' -- '. $txtNoVariable. ' -- ';
        $SuperArray    = null;
        $buffer        = '';
 
        $ArrayTitle = PHP_Debug::$globalEnvConstantsCorresp[$SuperArrayType];
        $SuperArray = $GLOBALS[$ArrayTitle];
        $Title = $ArrayTitle. ' '. $txtVariable;
        $SectionBasetitle = '<b>'. $Title. '('. count($SuperArray). ') :';
 
        if (count($SuperArray)) {
            $buffer .= $SectionBasetitle. '</b>';
            $buffer .= '<pre>'. 
                PHP_Debug::dumpVar(
                    $SuperArray, 
                    $ArrayTitle, 
                    false, 
                    PHP_Debug::DUMP_STR
                    ). '</pre>';
        } else {
            $buffer .= $SectionBasetitle. $NoVariable. '</b>';
        }
        
        return $buffer;
    }
 
    /**
     * Displays an array.
     * 
     * @param string $SuperArrayType Type of super en array to add
     * @since V2.0.0 - 07 Apr 2006
     */ 
    protected function showArray($array, $name)    
    {
        // Lang
        $txtNoVariable = 'NO VARIABLE';
        $NoVariable    = ' -- '. $txtNoVariable. ' -- ';
        $buffer        = '';
        $SectionBasetitle = '<b>'. $name. '('. count($array). ') :';
 
        if (count($array)) {
            $buffer .= $SectionBasetitle. '</b>';
            $buffer .= '<pre>'. PHP_Debug::dumpVar(
                $array, 
                $name, 
                false, 
                PHP_Debug::DUMP_STR). '</pre>';
        } else {
            $buffer .= $SectionBasetitle. $NoVariable. '</b>';
        }
        
        return $buffer;
    }
}