BxProfilerTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. if ((int)phpversion() < 5)
  13. require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/inc/fb4.php');
  14. else
  15. require_once(BX_DIRECTORY_PATH_MODULES . 'boonex/profiler/inc/fb5.php');
  16. class BxProfilerTemplate extends BxDolModuleTemplate {
  17. var $_isAjaxOutput = false;
  18. /**
  19. * Constructor
  20. */
  21. function BxProfilerTemplate(&$oConfig) {
  22. $oDb = null;
  23. parent::BxDolModuleTemplate($oConfig, $oDb);
  24. $this->_isAjaxOutput = $this->_isAjaxRequest();
  25. }
  26. function plank($sTitle, $sContent = '') {
  27. if ($this->_isAjaxOutput) {
  28. if ($sContent && is_array($sContent))
  29. fb($sContent, $sTitle, FIREPHP_TABLE);
  30. else
  31. fb($sTitle . $sContent);
  32. return '';
  33. }
  34. if ($sContent)
  35. $sContent = '<div class="bx_profiler_switch" onclick="bx_profiler_switch(this)">+</div><div class="bx_profiler_content">'.$sContent.'</div>';
  36. return '<div class="bx_profiler_plank"><span class="bx_profiler_plank_title">' . $sTitle . '</span>' . $sContent . '</div>';
  37. }
  38. function nameValue ($sName, $sVal) {
  39. return $this->_isAjaxOutput ? "{$sName}{$sVal} | " : "<u>$sName</u><b>$sVal</b>";
  40. }
  41. function table ($a, $sHighlight = '') {
  42. if ($this->_isAjaxOutput) {
  43. $table = array();
  44. foreach ($a as $r) {
  45. if (!$table)
  46. $table[] = array_keys($r);
  47. $rr = array_values($r);
  48. if (false !== strpos($rr[0], '&#160;'))
  49. $rr[0] = str_replace('&#160;', '-', $rr[0]);
  50. $table[] = $rr;
  51. }
  52. return $table;
  53. }
  54. $sId = md5(time() . rand());
  55. $s = '<table id="'.$sId.'" class="bx_profiler_table">';
  56. $th = '';
  57. foreach ($a as $r) {
  58. if (!$th) {
  59. foreach ($r as $k => $v)
  60. $th .= "<th>$k</th>";
  61. $s .= "<thead><tr>$th</tr></thead><tbody>";
  62. }
  63. $s .= '<tr>';
  64. foreach ($r as $k => $v)
  65. {
  66. $sClass = '';
  67. if ($sHighlight && $k == $sHighlight)
  68. $sClass = ' class="highlight" ';
  69. $s .= "<td $sClass>".htmlspecialchars_adv($v)."</td>";
  70. }
  71. $s .= '</tr>';
  72. }
  73. $s .= '</tbody></table>';
  74. $s .= '<script type="text/javascript">$(document).ready(function(){ $(\'#'.$sId.'\').tablesorter(); });</script>';
  75. return $s;
  76. }
  77. function _isAjaxRequest () {
  78. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
  79. return true;
  80. if (isset($_GET['bx_profiler_ajax_request']))
  81. return true;
  82. if (preg_match('/popup\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  83. return true;
  84. if (preg_match('/subscription\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  85. return true;
  86. if (preg_match('/vote\.php/', bx_html_attribute($_SERVER['PHP_SELF'])))
  87. return true;
  88. if (!empty($_GET['r']) && preg_match('/^poll\//', $_GET['r']))
  89. return true;
  90. if (preg_match('/pageBuilder\.php/', bx_html_attribute($_SERVER['PHP_SELF'])) && $_REQUEST['action'] == 'load')
  91. return true;
  92. return false;
  93. }
  94. }
  95. /** @} */