Completed
Push — master ( 1e3fad...c58c9b )
by Jacob
04:36 queued 01:34
created

display.php (1 issue)

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

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...