BxProfilerTemplate.php 3.5 KB

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