BxProfilerTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Profiler Profiler
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModuleTemplate');
  12. require_once(BX_DIRECTORY_PATH_PLUGINS . "firephp/fb.php");
  13. define('FIREPHP_TABLE', FirePHP::TABLE);
  14. class BxProfilerTemplate extends BxDolModuleTemplate {
  15. protected $_isAjaxOutput = false;
  16. function __construct(&$oConfig) {
  17. $oDb = null;
  18. parent::__construct($oConfig, $oDb);
  19. $this->_isAjaxOutput = $this->_isAjaxRequest();
  20. }
  21. function plank($sTitle, $sContent = '') {
  22. if ($this->_isAjaxOutput) {
  23. if ($sContent && is_array($sContent))
  24. fb($sContent, $sTitle, FIREPHP_TABLE);
  25. else
  26. fb($sTitle . $sContent);
  27. return '';
  28. }
  29. if ($sContent)
  30. $sContent = '<div class="bx_profiler_switch" onclick="bx_profiler_switch(this)">+</div><div class="bx_profiler_content">'.$sContent.'</div>';
  31. return '<div class="bx_profiler_plank"><span class="bx_profiler_plank_title">' . $sTitle . '</span>' . $sContent . '</div>';
  32. }
  33. function nameValue ($sName, $sVal) {
  34. return $this->_isAjaxOutput ? "{$sName}{$sVal} | " : "<u>$sName</u><b>$sVal</b>";
  35. }
  36. function table ($a, $sHighlight = '') {
  37. if ($this->_isAjaxOutput) {
  38. $table = array();
  39. foreach ($a as $r) {
  40. if (!$table)
  41. $table[] = array_keys($r);
  42. $rr = array_values($r);
  43. if (false !== strpos($rr[0], '&#160;'))
  44. $rr[0] = str_replace('&#160;', '-', $rr[0]);
  45. $table[] = $rr;
  46. }
  47. return $table;
  48. }
  49. $sId = md5(time() . rand());
  50. $s = '<table id="'.$sId.'" class="bx_profiler_table">';
  51. $th = '';
  52. foreach ($a as $r) {
  53. if (!$th) {
  54. foreach ($r as $k => $v)
  55. $th .= "<th>$k</th>";
  56. $s .= "<thead><tr>$th</tr></thead><tbody>";
  57. }
  58. $s .= '<tr>';
  59. foreach ($r as $k => $v)
  60. {
  61. $sClass = '';
  62. if ($sHighlight && $k == $sHighlight)
  63. $sClass = ' class="highlight" ';
  64. $s .= "<td $sClass>".htmlspecialchars_adv($v)."</td>";
  65. }
  66. $s .= '</tr>';
  67. }
  68. $s .= '</tbody></table>';
  69. $s .= '<script type="text/javascript">$(document).ready(function(){ $(\'#'.$sId.'\').tablesorter(); });</script>';
  70. return $s;
  71. }
  72. function _isAjaxRequest () {
  73. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
  74. return true;
  75. if (isset($_GET['bx_profiler_ajax_request']))
  76. return true;
  77. if (preg_match('/vote\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  78. return true;
  79. if (preg_match('/image_transcoder\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  80. return true;
  81. if (preg_match('/storage\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  82. return true;
  83. if (preg_match('/storage_uploader\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  84. return true;
  85. if (preg_match('/searchKeywordContent\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  86. return true;
  87. if (preg_match('/menu\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  88. return true;
  89. return false;
  90. }
  91. }
  92. /** @} */