/admin/helpers/html/debug.php

https://github.com/elkuku/EasyCreator · PHP · 138 lines · 87 code · 26 blank · 25 comment · 10 complexity · b097511327e2f82be25dded8fbbb40b9 MD5 · raw file

  1. <?php defined('_JEXEC') || die('=;)');
  2. /**
  3. * @package EasyCreator
  4. * @subpackage Helpers.HTML
  5. * @author Nikolai Plath (elkuku)
  6. * @author Created on 16-May-2012
  7. * @license GNU/GPL, see JROOT/LICENSE.php
  8. */
  9. /**
  10. * HTML debug class.
  11. *
  12. * @package EasyCreator
  13. */
  14. abstract class EcrHtmlDebug
  15. {
  16. /**
  17. * Draws a debug console "window".
  18. *
  19. * @static
  20. * @return string
  21. */
  22. public static function logConsole()
  23. {
  24. JFactory::getDocument()->addScriptDeclaration(
  25. "window.addEvent('domready', function() {
  26. document.id('ecrDebugBoxConsole').makeResizable({
  27. modifiers: {x: false, y: 'height'},
  28. limit: {y: [1, 600]},
  29. invert: true,
  30. handle: 'pollStatusGrip'
  31. });
  32. });");
  33. ecrStylesheet('logconsole');
  34. $html = array();
  35. $html[] = '<div id="ecrDebugBoxConsole">';
  36. $html[] = ' <div id="pollStatusGrip">&uArr;&dArr;</div>';
  37. $html[] = ' <div id="pollStatus">idle</div>';
  38. $html[] = ' <div class="debugTitle">'.jgettext('Log console').'</div>';
  39. $html[] = ' <div id="ecrDebugBox"></div>';
  40. $html[] = '</div>';
  41. return implode(NL, $html);
  42. }
  43. /**
  44. * @static
  45. *
  46. * @param null $trace
  47. *
  48. * @return string
  49. */
  50. public static function printTrace($trace = null)
  51. {
  52. if(false == function_exists('debug_backtrace'))
  53. return '';
  54. if( ! $trace)
  55. $trace = debug_backtrace();
  56. $traces = array();
  57. $traces['Debug trace'] = debug_backtrace();
  58. if($trace)
  59. $traces['Exception trace'] = $trace;
  60. $linkFormat = ini_get('xdebug.file_link_format');
  61. foreach($traces as $traceType => $trace)
  62. {
  63. $s = '';
  64. $s = '<h2>'.$traceType.'</h2>';
  65. $s .= '<table border="1">';
  66. $s .= '<tr>';
  67. $s .= '<th>#</th><th>Function</th><th>File</th><th>Line</th><th>Args</th>';
  68. $s .= '</tr>';
  69. for($i = count($trace) - 1; $i >= 0; --$i)
  70. {
  71. $link = '&nbsp;';
  72. if(isset($trace[$i]['file']))
  73. {
  74. $link = str_replace(JPATH_ROOT, 'JROOT', $trace[$i]['file']);
  75. if($linkFormat)
  76. {
  77. $href = $linkFormat;
  78. $href = str_replace('%f', $trace[$i]['file'], $href);
  79. if(isset($trace[$i]['line']))
  80. {
  81. $href = str_replace('%l', $trace[$i]['line'], $href);
  82. }
  83. $link = '<a href="'.$href.'">'.$link.'</a>';
  84. }
  85. }
  86. $s .= '<tr>';
  87. $s .= '<td align="right"><tt>'.$i.'</tt></td>';
  88. $s .= '<td>';
  89. $s .= (isset($trace[$i]['class'])) ? $trace[$i]['class'] : '';
  90. $s .= (isset($trace[$i]['type'])) ? $trace[$i]['type'] : '';
  91. $s .= (isset($trace[$i]['function'])) ? $trace[$i]['function'] : '';
  92. $s .= '</td>';
  93. $s .= '<td>'.$link.'</td>';
  94. $s .= (isset($trace[$i]['line']))
  95. ? '<td align="right"><tt>'.$trace[$i]['line'].'</tt></td>'
  96. : '<td>&nbsp;</td>';
  97. $s .= '<td>';
  98. if(isset($trace[$i]['args']))
  99. {
  100. foreach($trace[$i]['args'] as $arg)
  101. {
  102. $s .= str_replace(JPATH_ROOT.DS, '', $arg).BR;
  103. }
  104. }
  105. $s .= '</td>';
  106. $s .= '</tr>';
  107. }
  108. $s .= '</table>';
  109. echo $s;
  110. }
  111. }
  112. }