jacobemerick /
pqp
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
|
|||
| 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']); |
||
| 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 | echo '<table class="side" cellspacing="0"> |
||
| 169 | <tr> |
||
| 170 | <td class="alt1"><var>'.$output['logs']['logCount'].'</var><h4>Logs</h4></td> |
||
| 171 | <td class="alt2"><var>'.$output['logs']['errorCount'].'</var> <h4>Errors</h4></td> |
||
| 172 | </tr> |
||
| 173 | <tr> |
||
| 174 | <td class="alt3"><var>'.$output['logs']['memoryCount'].'</var> <h4>Memory</h4></td> |
||
| 175 | <td class="alt4"><var>'.$output['logs']['speedCount'].'</var> <h4>Speed</h4></td> |
||
| 176 | </tr> |
||
| 177 | </table> |
||
| 178 | <table class="main" cellspacing="0">'; |
||
| 179 | |||
| 180 | $class = ''; |
||
| 181 | foreach($output['logs']['console'] as $log) { |
||
| 182 | echo '<tr class="log-'.$log['type'].'"> |
||
| 183 | <td class="type">'.$log['type'].'</td> |
||
| 184 | <td class="'.$class.'">'; |
||
| 185 | if($log['type'] == 'log') { |
||
| 186 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
||
| 187 | } |
||
| 188 | elseif($log['type'] == 'memory') { |
||
| 189 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['dataType'].'</em>: '.$log['name'].' </div>'; |
||
| 190 | } |
||
| 191 | elseif($log['type'] == 'speed') { |
||
| 192 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
||
| 193 | } |
||
| 194 | elseif($log['type'] == 'error') { |
||
| 195 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
||
| 196 | } |
||
| 197 | |||
| 198 | echo '</td></tr>'; |
||
| 199 | if($class == '') $class = 'alt'; |
||
| 200 | else $class = ''; |
||
| 201 | } |
||
| 202 | |||
| 203 | echo '</table>'; |
||
| 204 | } |
||
| 205 | |||
| 206 | echo '</div>'; |
||
| 207 | |||
| 208 | echo '<div id="pqp-speed" class="pqp-box">'; |
||
| 209 | |||
| 210 | if($output['logs']['speedCount'] == 0) { |
||
| 211 | echo '<h3>This panel has no log items.</h3>'; |
||
| 212 | } |
||
| 213 | else { |
||
| 214 | echo '<table class="side" cellspacing="0"> |
||
| 215 | <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr> |
||
| 216 | <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr> |
||
| 217 | </table> |
||
| 218 | <table class="main" cellspacing="0">'; |
||
| 219 | |||
| 220 | $class = ''; |
||
| 221 | foreach($output['logs']['console'] as $log) { |
||
| 222 | if($log['type'] == 'speed') { |
||
| 223 | echo '<tr class="log-'.$log['type'].'"> |
||
| 224 | <td class="'.$class.'">'; |
||
| 225 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
||
| 226 | echo '</td></tr>'; |
||
| 227 | if($class == '') $class = 'alt'; |
||
| 228 | else $class = ''; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | echo '</table>'; |
||
| 233 | } |
||
| 234 | |||
| 235 | echo '</div>'; |
||
| 236 | |||
| 237 | echo '<div id="pqp-queries" class="pqp-box">'; |
||
| 238 | |||
| 239 | if($output['queryTotals']['count'] == 0) { |
||
| 240 | echo '<h3>This panel has no log items.</h3>'; |
||
| 241 | } |
||
| 242 | else { |
||
| 243 | echo '<table class="side" cellspacing="0"> |
||
| 244 | <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr> |
||
| 245 | <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr> |
||
| 246 | <tr><td><var>0</var> <h4>Duplicates</h4></td></tr> |
||
| 247 | </table> |
||
| 248 | <table class="main" cellspacing="0">'; |
||
| 249 | |||
| 250 | $class = ''; |
||
| 251 | foreach($output['queries'] as $query) { |
||
| 252 | echo '<tr> |
||
| 253 | <td class="'.$class.'">'.$query['sql']; |
||
| 254 | if($query['explain']) { |
||
| 255 | echo '<em> |
||
| 256 | Possible keys: <b>'.$query['explain']['possible_keys'].'</b> · |
||
| 257 | Key Used: <b>'.$query['explain']['key'].'</b> · |
||
| 258 | Type: <b>'.$query['explain']['type'].'</b> · |
||
| 259 | Rows: <b>'.$query['explain']['rows'].'</b> · |
||
| 260 | Speed: <b>'.$query['time'].'</b> |
||
| 261 | </em>'; |
||
| 262 | } |
||
| 263 | echo '</td></tr>'; |
||
| 264 | if($class == '') $class = 'alt'; |
||
| 265 | else $class = ''; |
||
| 266 | } |
||
| 267 | |||
| 268 | echo '</table>'; |
||
| 269 | } |
||
| 270 | |||
| 271 | echo '</div>'; |
||
| 272 | |||
| 273 | echo '<div id="pqp-memory" class="pqp-box">'; |
||
| 274 | |||
| 275 | if($output['logs']['memoryCount'] == 0) { |
||
| 276 | echo '<h3>This panel has no log items.</h3>'; |
||
| 277 | } |
||
| 278 | else { |
||
| 279 | echo '<table class="side" cellspacing="0"> |
||
| 280 | <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr> |
||
| 281 | <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr> |
||
| 282 | </table> |
||
| 283 | <table class="main" cellspacing="0">'; |
||
| 284 | |||
| 285 | $class = ''; |
||
| 286 | foreach($output['logs']['console'] as $log) { |
||
| 287 | if($log['type'] == 'memory') { |
||
| 288 | echo '<tr class="log-'.$log['type'].'">'; |
||
| 289 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>'; |
||
| 290 | echo '</tr>'; |
||
| 291 | if($class == '') $class = 'alt'; |
||
| 292 | else $class = ''; |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | echo '</table>'; |
||
| 297 | } |
||
| 298 | |||
| 299 | echo '</div>'; |
||
| 300 | |||
| 301 | echo '<div id="pqp-files" class="pqp-box">'; |
||
| 302 | |||
| 303 | if($output['fileTotals']['count'] == 0) { |
||
| 304 | echo '<h3>This panel has no log items.</h3>'; |
||
| 305 | } |
||
| 306 | else { |
||
| 307 | echo '<table class="side" cellspacing="0"> |
||
| 308 | <tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr> |
||
| 309 | <tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr> |
||
| 310 | <tr><td><var>'.$output['fileTotals']['largest'].'</var> <h4>Largest</h4></td></tr> |
||
| 311 | </table> |
||
| 312 | <table class="main" cellspacing="0">'; |
||
| 313 | |||
| 314 | $class =''; |
||
| 315 | foreach($output['files'] as $file) { |
||
| 316 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
||
| 317 | if($class == '') $class = 'alt'; |
||
| 318 | else $class = ''; |
||
| 319 | } |
||
| 320 | |||
| 321 | echo '</table>'; |
||
| 322 | } |
||
| 323 | |||
| 324 | echo '</div>'; |
||
| 325 | |||
| 326 | echo <<<FOOTER |
||
| 327 | <table id="pqp-footer" cellspacing="0"> |
||
| 328 | <tr> |
||
| 329 | <td class="credit"> |
||
| 330 | <a href="http://particletree.com" target="_blank"> |
||
| 331 | <strong>PHP</strong> |
||
| 332 | <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> |
||
| 333 | Profiler</a></td> |
||
| 334 | <td class="actions"> |
||
| 335 | <a href="#" onclick="toggleDetails();return false">Details</a> |
||
| 336 | <a class="heightToggle" href="#" onclick="toggleHeight();return false">Height</a> |
||
| 337 | </td> |
||
| 338 | </tr> |
||
| 339 | </table> |
||
| 340 | FOOTER; |
||
| 341 | |||
| 342 | echo '</div></div>'; |
||
| 343 | |||
| 344 | } |
||
| 345 | |||
| 346 | ?> |
||
| 347 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.