Completed
Push — master ( 77243d...dac2cf )
by Jacob
02:14
created

display.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
4
5
 Title : HTML Output for Php Quick Profiler
6
 Author : Created by Ryan Campbell
7
 URL : http://particletree.com/features/php-quick-profiler/
8
9
 Last Updated : April 22, 2009
10
11
 Description : This is a horribly ugly function used to output
12
 the PQP HTML. This is great because it will just work in your project,
13
 but it is hard to maintain and read. See the README file for how to use
14
 the Smarty file we provided with PQP.
15
16
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
17
18
function displayPqp($output, $config) {
0 ignored issues
show
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
	
20
$css = file_get_contents(__DIR__ . '/css/pQp.css');
21
		
22
echo <<<JAVASCRIPT
23
<!-- JavaScript -->
24
<script type="text/javascript">
25
	var PQP_DETAILS = true;
26
	var PQP_HEIGHT = "short";
27
	
28
	function changeTab(tab) {
29
		var pQp = document.getElementById('pQp');
30
		hideAllTabs();
31
		addClassName(pQp, tab, true);
32
	}
33
	
34
	function hideAllTabs() {
35
		var pQp = document.getElementById('pQp');
36
		removeClassName(pQp, 'console');
37
		removeClassName(pQp, 'speed');
38
		removeClassName(pQp, 'queries');
39
		removeClassName(pQp, 'memory');
40
		removeClassName(pQp, 'files');
41
	}
42
	
43
	function toggleDetails(){
44
		var container = document.getElementById('pqp-container');
45
		
46
		if(PQP_DETAILS){
47
			addClassName(container, 'hideDetails', true);
48
			PQP_DETAILS = false;
49
		}
50
		else{
51
			removeClassName(container, 'hideDetails');
52
			PQP_DETAILS = true;
53
		}
54
	}
55
	function toggleHeight(){
56
		var container = document.getElementById('pqp-container');
57
		
58
		if(PQP_HEIGHT == "short"){
59
			addClassName(container, 'tallDetails', true);
60
			PQP_HEIGHT = "tall";
61
		}
62
		else{
63
			removeClassName(container, 'tallDetails');
64
			PQP_HEIGHT = "short";
65
		}
66
	}
67
	
68
  setTimeout(function(){document.getElementById("pqp-container").style.display = "block"}, 10);
69
	
70
	//http://www.bigbold.com/snippets/posts/show/2630
71
	function addClassName(objElement, strClass, blnMayAlreadyExist){
72
	   if ( objElement.className ){
73
	      var arrList = objElement.className.split(' ');
74
	      if ( blnMayAlreadyExist ){
75
	         var strClassUpper = strClass.toUpperCase();
76
	         for ( var i = 0; i < arrList.length; i++ ){
77
	            if ( arrList[i].toUpperCase() == strClassUpper ){
78
	               arrList.splice(i, 1);
79
	               i--;
80
	             }
81
	           }
82
	      }
83
	      arrList[arrList.length] = strClass;
84
	      objElement.className = arrList.join(' ');
85
	   }
86
	   else{  
87
	      objElement.className = strClass;
88
	      }
89
	}
90
91
	//http://www.bigbold.com/snippets/posts/show/2630
92
	function removeClassName(objElement, strClass){
93
	   if ( objElement.className ){
94
	      var arrList = objElement.className.split(' ');
95
	      var strClassUpper = strClass.toUpperCase();
96
	      for ( var i = 0; i < arrList.length; i++ ){
97
	         if ( arrList[i].toUpperCase() == strClassUpper ){
98
	            arrList.splice(i, 1);
99
	            i--;
100
	         }
101
	      }
102
	      objElement.className = arrList.join(' ');
103
	   }
104
	}
105
106
	//http://ejohn.org/projects/flexible-javascript-events/
107
	function addEvent( obj, type, fn ) {
108
	  if ( obj.attachEvent ) {
109
	    obj["e"+type+fn] = fn;
110
	    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
111
	    obj.attachEvent( "on"+type, obj[type+fn] );
112
	  } 
113
	  else{
114
	    obj.addEventListener( type, fn, false );	
115
	  }
116
	}
117
</script>
118
JAVASCRIPT;
119
120
echo <<<STYLESHEETS
121
<style type="text/css">
122
$css
123
</style>
124
STYLESHEETS;
125
126
echo '<div id="pqp-container" class="pQp" style="display:none">';
127
128
$logCount = count($output['logs']['console']['messages']);
129
$fileCount = count($output['files']);
130
$memoryUsed = $output['memoryTotals']['used'];
131
$queryCount = $output['queryTotals']['count'];
132
$speedTotal = $output['speedTotals']['total'];
133
134
echo <<<PQPTABS
135
<div id="pQp" class="console">
136
<table id="pqp-metrics" cellspacing="0">
137
<tr>
138
	<td class="green" onclick="changeTab('console');">
139
		<var>$logCount</var>
140
		<h4>Console</h4>
141
	</td>
142
	<td class="blue" onclick="changeTab('speed');">
143
		<var>$speedTotal</var>
144
		<h4>Load Time</h4>
145
	</td>
146
	<td class="purple" onclick="changeTab('queries');">
147
		<var>$queryCount Queries</var>
148
		<h4>Database</h4>
149
	</td>
150
	<td class="orange" onclick="changeTab('memory');">
151
		<var>$memoryUsed</var>
152
		<h4>Memory Used</h4>
153
	</td>
154
	<td class="red" onclick="changeTab('files');">
155
		<var>{$fileCount} Files</var>
156
		<h4>Included</h4>
157
	</td>
158
</tr>
159
</table>
160
PQPTABS;
161
162
echo '<div id="pqp-console" class="pqp-box">';
163
164
if($logCount ==  0) {
165
	echo '<h3>This panel has no log items.</h3>';
166
}
167
else {
168
  $console = $output['logs']['console'];
169
	echo '<table class="side" cellspacing="0">
170
		<tr>
171
			<td class="alt1"><var>'.$console['totals']['log'].'</var><h4>Logs</h4></td>
172
			<td class="alt2"><var>'.$console['totals']['error'].'</var> <h4>Errors</h4></td>
173
		</tr>
174
		<tr>
175
			<td class="alt3"><var>'.$console['totals']['memory'].'</var> <h4>Memory</h4></td>
176
			<td class="alt4"><var>'.$console['totals']['speed'].'</var> <h4>Speed</h4></td>
177
		</tr>
178
		</table>
179
		<table class="main" cellspacing="0">';
180
		
181
		$class = '';
182
		foreach($output['logs']['console']['messages'] as $log) {
183
			echo '<tr class="log-'.$log['type'].'">
184
				<td class="type">'.$log['type'].'</td>
185
				<td class="'.$class.'">';
186
			if($log['type'] == 'log') {
187
				echo '<div><pre>'.$log['data'].'</pre></div>';
188
			}
189
			elseif($log['type'] == 'memory') {
190
				echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['data_type'].'</em>: '.$log['name'].' </div>';
191
			}
192
			elseif($log['type'] == 'speed') {
193
				echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>';
194
			}
195
			elseif($log['type'] == 'error') {
196
				echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>';
197
			}
198
		
199
			echo '</td></tr>';
200
			if($class == '') $class = 'alt';
201
			else $class = '';
202
		}
203
			
204
		echo '</table>';
205
}
206
207
echo '</div>';
208
209
echo '<div id="pqp-speed" class="pqp-box">';
210
211
if($output['logs']['speedCount'] ==  0) {
212
	echo '<h3>This panel has no log items.</h3>';
213
}
214
else {
215
	echo '<table class="side" cellspacing="0">
216
		  <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr>
217
		  <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr>
218
		 </table>
219
		<table class="main" cellspacing="0">';
220
		
221
		$class = '';
222
		foreach($output['logs']['console'] as $log) {
223
			if($log['type'] == 'speed') {
224
				echo '<tr class="log-'.$log['type'].'">
225
				<td class="'.$class.'">';
226
				echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>';
227
				echo '</td></tr>';
228
				if($class == '') $class = 'alt';
229
				else $class = '';
230
			}
231
		}
232
			
233
		echo '</table>';
234
}
235
236
echo '</div>';
237
238
echo '<div id="pqp-queries" class="pqp-box">';
239
240
if($output['queryTotals']['count'] ==  0) {
241
	echo '<h3>This panel has no log items.</h3>';
242
}
243
else {
244
	echo '<table class="side" cellspacing="0">
245
		  <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr>
246
		  <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr>
247
		  <tr><td><var>0</var> <h4>Duplicates</h4></td></tr>
248
		 </table>
249
		<table class="main" cellspacing="0">';
250
		
251
		$class = '';
252
		foreach($output['queries'] as $query) {
253
			echo '<tr>
254
				<td class="'.$class.'">'.$query['sql'];
255
			if($query['explain']) {
256
					echo '<em>
257
						Possible keys: <b>'.$query['explain']['possible_keys'].'</b> &middot; 
258
						Key Used: <b>'.$query['explain']['key'].'</b> &middot; 
259
						Type: <b>'.$query['explain']['type'].'</b> &middot; 
260
						Rows: <b>'.$query['explain']['rows'].'</b> &middot; 
261
						Speed: <b>'.$query['time'].'</b>
262
					</em>';
263
			}
264
			echo '</td></tr>';
265
			if($class == '') $class = 'alt';
266
			else $class = '';
267
		}
268
			
269
		echo '</table>';
270
}
271
272
echo '</div>';
273
274
echo '<div id="pqp-memory" class="pqp-box">';
275
276
if($output['logs']['memoryCount'] ==  0) {
277
	echo '<h3>This panel has no log items.</h3>';
278
}
279
else {
280
	echo '<table class="side" cellspacing="0">
281
		  <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr>
282
		  <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr>
283
		 </table>
284
		<table class="main" cellspacing="0">';
285
		
286
		$class = '';
287
		foreach($output['logs']['console'] as $log) {
288
			if($log['type'] == 'memory') {
289
				echo '<tr class="log-'.$log['type'].'">';
290
				echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>';
291
				echo '</tr>';
292
				if($class == '') $class = 'alt';
293
				else $class = '';
294
			}
295
		}
296
			
297
		echo '</table>';
298
}
299
300
echo '</div>';
301
302
echo '<div id="pqp-files" class="pqp-box">';
303
304
if($output['fileTotals']['count'] ==  0) {
305
	echo '<h3>This panel has no log items.</h3>';
306
}
307
else {
308
	echo '<table class="side" cellspacing="0">
309
		  	<tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr>
310
			<tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr>
311
			<tr><td><var>'.$output['fileTotals']['largest'].'</var> <h4>Largest</h4></td></tr>
312
		 </table>
313
		<table class="main" cellspacing="0">';
314
		
315
		$class ='';
316
		foreach($output['files'] as $file) {
317
			echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>';
318
			if($class == '') $class = 'alt';
319
			else $class = '';
320
		}
321
			
322
		echo '</table>';
323
}
324
325
echo '</div>';
326
327
echo <<<FOOTER
328
	<table id="pqp-footer" cellspacing="0">
329
		<tr>
330
			<td class="credit">
331
				<a href="http://particletree.com" target="_blank">
332
				<strong>PHP</strong> 
333
				<b class="green">Q</b><b class="blue">u</b><b class="purple">i</b><b class="orange">c</b><b class="red">k</b>
334
				Profiler</a></td>
335
			<td class="actions">
336
				<a href="#" onclick="toggleDetails();return false">Details</a>
337
				<a class="heightToggle" href="#" onclick="toggleHeight();return false">Height</a>
338
			</td>
339
		</tr>
340
	</table>
341
FOOTER;
342
		
343
echo '</div></div>';
344
345
}
346
347
?>
348