-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin_debug.php
More file actions
executable file
·505 lines (407 loc) · 12.5 KB
/
plugin_debug.php
File metadata and controls
executable file
·505 lines (407 loc) · 12.5 KB
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
<?php
/*
This file is part of Mkframework.
Mkframework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License.
Mkframework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* plugin_gestionuser classe de gestion user
* @author Mika
* @link http://mkf.mkdevs.com/
*/
class plugin_debug{
private $iStartMicrotime;
private $sHtml;
private static $tSpy;
private static $tTime;
private static $tTimeById;
public static $enabled=0;
public function __construct($sMicrotime){
if(!self::$enabled){ return; }
$this->iStartMicrotime=self::microtime($sMicrotime);
$iEndTime=self::microtime();
self::$tTime[]=array('End',$iEndTime);
$iDiff=($iEndTime-$this->iStartMicrotime);
$this->add('Time',sprintf('%0.3f',$iDiff).'s');
$this->addComplexTimes('times',self::$tTime);
$this->addComplex('$_GET',print_r($_GET,1));
if(isset($_POST)){
$this->addComplex('$_POST',print_r($_POST,1));
}
if(isset($_SESSION)){
$this->addComplex('$_SESSION',print_r($_SESSION,1));
}
if(isset($_SERVER)){
$this->addComplex('$_SERVER',print_r($_SERVER,1));
}
$oRequest=_root::getRequest();
$this->add('Module',$oRequest->getModule());
$this->add('Action',$oRequest->getAction());
$oFileLog=new _file(_root::getConfigVar('path.log','data/log/').date('Y-m-d').'_log.csv');
if($oFileLog->exist()){
$oFileLog->load();
$sContentLog=$oFileLog->getContent();
$this->addFileLog('File log',$sContentLog);
}
$sVarIniConfig=_root::getConfigVar('model.ini.var','db');
$tClassSgbd=_root::getConfigVar($sVarIniConfig);
$this->addComplexIni('Connexions',array($sVarIniConfig=>$tClassSgbd));
$tConfigSection=array(
'path' ,
'cache' ,
'language',
'auth',
'acl',
'navigation',
'urlrewriting',
'security',
'log',
'check',
'path',
'model',
);
$tConfig=array();
foreach($tConfigSection as $sSection){
$tConfig[$sSection]=_root::getConfigVar($sSection);
}
$this->addComplexIni('Config',$tConfig);
if(self::$tSpy){
$this->addComplexSpy('Spy variables',self::$tSpy);
}
$tSessionSpy=self::getListSessionSpy();
if($tSessionSpy){
$this->addComplexSpy('Spy Session variables',$tSessionSpy);
}
$this->addAcl();
}
/** ajoute dans la barre de debug l'affichage d'une variable (tableau,objet..)
* @access public
* @return void
* @param string $uLabel nom de la variable a afficher
* @param mixte $uVar la variable a afficher dans la barre
*/
public static function addSpy($uLabel,$uVar){
if(!self::$enabled){ return; }
self::$tSpy[][$uLabel]=$uVar;
}
public static function getIpHash(){
return sha1($_SERVER['REMOTE_ADDR']);
}
public static function getSessionSpyVarFilename(){
$sIP=self::getIpHash();
return _root::getConfigVar('path.log','data/log/').'spyVar'.$sIP;
}
public static function addSessionSpy($uLabel,$uVar){
if(!self::$enabled){ return; }
$sFilename=self::getSessionSpyVarFilename();
$tSpy=array();
if(file_exists($sFilename)){
$tSpy=unserialize(file_get_contents( $sFilename ));
}
$tSpy[][$uLabel]=$uVar;
file_put_contents($sFilename, serialize($tSpy));
}
public static function getListSessionSpy(){
$sFilename=self::getSessionSpyVarFilename();
$tSpy=array();
if(file_exists($sFilename)){
$tSpy=unserialize(file_get_contents( $sFilename ));
}
file_put_contents($sFilename, null);
return $tSpy;
}
public static function getListSpy(){
return self::$tSpy;
}
/** ajoute un chrono
* @access public
* @return void
* @param string $uLabel nom du chrono
*/
public static function addChrono($uLabel){
if(!self::$enabled){ return; }
$iTime=self::microtime();
self::$tTime[]=array($uLabel,$iTime);
}
/** demarre un chrono (pour chronometre le temps d'un point A a un point B)
* @access public
* @return void
* @param string $uLabel nom du chrono
*/
public static function startChrono($uLabel){
if(!self::$enabled){ return; }
$iTime=self::microtime();
self::$tTimeById[$uLabel]['start']=$iTime;
}
/** arrete le chrono de l'id passe (pour chronometre le temps d'un point A a un point B)
* @access public
* @return void
* @param string $uLabel nom du chrono (qui doit etre le meme que le chrono demarre)
*/
public static function stopChrono($uLabel){
if(!self::$enabled){ return; }
$iTime=self::microtime();
self::$tTimeById[$uLabel]['end']=$iTime;
}
public function display(){
echo '<script>
var activePopup=\'\';
function openPopupDebug(id){
if(id!=activePopup){
closePopup();
}
var a=getById(id);
if(!a){
}else if(a.style.display=="none"){
a.style.display="block";
activePopup=id;
}else if(a.style.display=="block"){
a.style.display="none";
activePopup=id;
}
}
function closePopup(){
if(activePopup){
var b=getById(activePopup);
if(b){
b.style.display="none";
}
}
}
function showHideDebugBar(){
var a=getById(\'debugBar\');
if(a){
btnName="Masquer";
if(a.style.display==\'none\'){
a.style.display=\'block\';
var b=getById(\'debugBtn\');
if(b){
b.style.width=\'100%\';
}
}else{
a.style.display=\'none\';
var b=getById(\'debugBtn\');
if(b){
b.style.width=\'auto\';
}
btnName=">>";
}
var c=getById(\'btnHidebar\');
if(c){
c.value=btnName;
}
}
}
</script>';
echo '<div id="debugBtn" ';
echo 'style="position:fixed;border:2px solid #444;background:#ddd;bottom:0px;left:0px;width:100%">';
echo '<div style="float:left"><input id="btnHidebar" type="button" value="Masquer" onclick="showHideDebugBar()"/></div>';
echo '<div id="debugBar" style="width:100%">';
echo $this->sHtml;
echo '</div>';
echo '</div>';
}
private function addComplex($key,$value){
$this->addHtml('<input type="button" value="'.$key.'" onclick="openPopupDebug(\'popupDebug'.$key.'\')" />');
$this->addSep();
$this->addPopupPrintr($key,$value);
}
private function addComplexTimes($key,$value){
$this->addHtml('<input type="button" value="'.$key.'" onclick="openPopupDebug(\'popupDebug'.$key.'\')" />');
$this->addSep();
$value=$this->parseTime($value);
$this->addPopup($key,$value);
}
private function addComplexIni($key,$value){
$this->addHtml('<input type="button" value="'.$key.'" onclick="openPopupDebug(\'popupDebug'.$key.'\')" />');
$this->addSep();
$value=$this->parseIni($value);
$this->addPopup($key,$value);
}
private function addComplexSpy($key,$value){
$this->addHtml('<input type="button" value="'.$key.'" onclick="openPopupDebug(\'popupDebug'.$key.'\')" />');
$this->addSep();
$sValue=$this->parseSpy($value);
$this->addPopup($key,$sValue);
}
private function addFileLog($key,$value){
$this->addHtml('<input type="button" value="'.$key.'" onclick="openPopupDebug(\'popupDebug'.$key.'\')" />');
$this->addSep();
$value=$this->parseLog($value);
$this->addPopup($key,$value);
}
private function add($key,$value){
$this->addHtml('<strong>'.$key.'</strong>:<span style="padding:2px 4px;background:#fff">'.$value.'</span>');
$this->addSep();
}
private function addPopupPrintr($key,$value){
$this->addHtml(
'<div id="popupDebug'.$key.'"
style="display:none;position:absolute;left:0px;bottom:20px;border:2px solid gray;background:white">
<p style="text-align:right;background:#ccc;margin:0px;"><a href="#" onclick="closePopup()">Fermer</a></p>
<div style="height:350px;width:400px;overflow:auto;padding:10px;">
<pre>'.customHtmlentities(print_r($value,1)).'</pre>
</div>
</div>');
}
private function addPopup($key,$value,$width=800){
$this->addHtml(
'<div id="popupDebug'.$key.'"
style="display:none;position:absolute;left:0px;bottom:20px;border:2px solid gray;background:white">
<p style="text-align:right;background:#ccc;margin:0px;"><a href="#" onclick="closePopup()">Fermer</a></p>
<div style="height:350px;width:'.$width.'px;overflow:auto;padding:10px;">
'.$value.'
</div>
</div>');
}
private function addAcl(){
$this->addHtml('<input type="button" value="Permissions" onclick="openPopupDebug(\'popupDebugACL\')" />');
$this->addSep();
$sHtml='<div style="position:absolute">';
$sHtml.='<table style="background:white;border-collapse:collapse">
<tr>
<th style="border:1px solid gray;">Action</th>
<th style="border:1px solid gray;">Component</th>
</tr>';
$tab=_root::getConfigVar('tAskCan');
if($tab and is_array($tab)):
foreach($tab as $tVal):
$sHtml.='<tr>
<td style="border:1px solid gray;';
if($tVal[2]){
$sHtml.='color:green;';
}else{
$sHtml.='color:red';
}
$sHtml.='">'.$tVal[0].'</td>
<td style="border:1px solid gray;';
if($tVal[2]){
$sHtml.='color:green;';
}else{
$sHtml.='color:red';
}
$sHtml.='">'.$tVal[1].'</td>
</tr>';
endforeach;
endif;
$sHtml.='</table>';
$this->addPopup('ACL', $sHtml,300);
}
private function addSep(){
$this->addHtml(' ');
}
private function addHtml($sHtml){
$this->sHtml.=$sHtml;
}
private function parseLog($value){
$sep=' | ';
$tLine=explode("\n",$value);
$sHtml=null;
$iMax=count($tLine)-1;
for($i=$iMax;$i>0;$i--){
$sLine=$tLine[$i];
$tCase=explode(';',$sLine,4);
$sDate=null;
if(isset($tCase[0])){
$sDate=$tCase[0];
}
$sTime=null;
if(isset($tCase[1])){
$sTime=$tCase[1];
}
$sType=null;
if(isset($tCase[2])){
$sType=$tCase[2];
}
$sLog=null;
if(isset($tCase[3])){
$sLog=$tCase[3];
}
if($sDate==null){
continue;
}
$sHtml.='<p style="margin:0px">';
$sHtml.='<span >'.$sDate.'</span> ';
$sHtml.='<span style="font-weight:bold">'.$sTime.'</span>';
$sHtml.=$sep;
$sHtml.='<span style="color:';
if($sType=='info'){ $sHtml.='gray';}
elseif($sType=='log'){ $sHtml.='darkblue';}
$sHtml.='">'.$sType.'</span>';
$sHtml.=$sep;
if(substr($sLog,0,3)=='sql'){
$sHtml.='<span style="color:darkblue"><strong>SQL</strong> '.substr($sLog,3).'</span>';
}else{
$sHtml.=$sLog;
}
$sHtml.='</p>';
if(preg_match('/module a appeler/',$sLog)){
$sHtml.='<p> </p>';
}
}
return $sHtml;
}
private function parseSpy($tValue){
$sHtml=null;
foreach($tValue as $tDetail){
foreach($tDetail as $ref => $value){
$sHtml.='<h2 style="border-bottom:1px solid black">'.$ref.'</h2>';
$sHtml.='<p><pre>'.customHtmlentities(print_r($value,1)).'</pre></p>';
}
}
return $sHtml;
}
private function parseIni($tValue){
$sHtml=null;
foreach($tValue as $sSection => $tDetail){
$sHtml.='<h2 style="border-bottom:1px solid black">'.$sSection.'</h2>';
foreach($tDetail as $sKey => $sValue){
$sHtml.='<p style="margin:0px;margin-left:10px;">';
$sHtml.='<strong>'.$sKey.'</strong> = <span style="color:darkgreen"> '.$sValue.'</span>';
$sHtml.='</p>';
}
}
return $sHtml;
}
private function parseTime($tValue){
$sHtml=null;
$iPreviousTime=$this->iStartMicrotime;
$sPreviousStep='Start';
foreach($tValue as $tDetail){
list($sLabel,$iTime)=$tDetail;
$iDelta=($iTime-$iPreviousTime);
$sHtml.='<p><strong>'.$sPreviousStep.' >> '.$sLabel.'</strong> : '.sprintf('%0.3f',$iDelta).'s</p>';
$iPreviousTime=$iTime;
$sPreviousStep=$sLabel;
}
$sHtml.='<p style="border-top:1px solid gray">';
$sHtml.='<strong>Total</strong> '.sprintf('%0.3f',($iTime-$this->iStartMicrotime)).'s';
$sHtml.='</p>';
if(self::$tTimeById){
$sHtml.='<p> </p>';
foreach(self::$tTimeById as $sLabel => $tValue){
if(isset($tValue['end']) and isset($tValue['start'])){
$iDelta=($tValue['end']-$tValue['start']);
$sHtml.='<p><strong>'.$sLabel.' </strong> : '.sprintf('%0.3f',$iDelta).'s</p>';
}else{
$sHtml.='<p><strong>'.$sLabel.' </strong> : <span style="color:red">';
$sHtml.=' Erreur il manque startChrono ou stopChrono</span></p>';
}
}
}
return $sHtml;
}
public static function microtime($sMicrotime=null){
return microtime(true);
}
}
if(_root::getConfigVar('site.mode')=='dev'){
plugin_debug::$enabled=1;
}