PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/include/includes/func/debug.php

https://bitbucket.org/GeCk0/ilchshop
PHP | 202 lines | 134 code | 13 blank | 55 comment | 25 complexity | a32b7aecc2a9674f750438d89134615d MD5 | raw file
  1. <?php
  2. /**
  3. * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL)
  4. * @copyright (C) 2000-2010 ilch.de
  5. * @version $Id$
  6. */
  7. defined('main') or die('no direct access');
  8. /**
  9. * eine funktion für var_dump und <pre>print_r()</pre> zu vereinen
  10. *
  11. * @return formatierte Ausgabe eines Arrays oder Objectes
  12. * @author gecko
  13. */
  14. function dump($src) {
  15. if (is_array($src)) {
  16. echo "<pre>----------\n";
  17. print_r($src);
  18. echo "----------</pre>";
  19. } elseif (is_object($src)) {
  20. echo "<pre>==========\n";
  21. var_dump($src);
  22. echo "==========</pre>";
  23. } else {
  24. echo "=========&gt; ";
  25. var_dump($src);
  26. echo " &lt;=========";
  27. }
  28. }
  29. if (DEBUG) {
  30. $ILCH_DEBUG_OUTPUT = '';
  31. /**
  32. * debug_nice_filename()
  33. * macht den Dateinamen kürzer und lesbarer (auf ilch Ordner Struktur bezogen)
  34. *
  35. * @param string $filename kompletten Dateinamen
  36. * @return string gekürzten Dateinamen
  37. */
  38. function debug_nice_filename($filename) {
  39. return str_replace(dirname($_SERVER['SCRIPT_FILENAME']) . '/', '', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
  40. }
  41. /**
  42. * debug()
  43. * Einfach Debugfunktion, mit Zeitausgabe
  44. *
  45. * @param mixed $d Gibt an was fürs Debugging ausgegeben werden soll, wenn leer wird der Datename + Zeilennummer angegeben
  46. * @param boolean $time Gibt an ob die Zeit mit ausgegeben
  47. */
  48. function debug($d = '', $time = true) {
  49. global $ILCH_DEBUG_OUTPUT;
  50. if ($time) {
  51. $time = round(microtime(true) - SCRIPT_START_TIME, 5) . ': ';
  52. } else {
  53. $time = '';
  54. }
  55. if (empty($d)) {
  56. // Filename + Linenumber ( + time);
  57. $array = debug_backtrace();
  58. $filename = debug_nice_filename($array[0]['file']);
  59. $ILCH_DEBUG_OUTPUT .= '<div>' . $time . $filename . ' - Line: ' . $array[0]['line'] . '</div>';
  60. } elseif (is_array($d) or is_object($d)) {
  61. // if (DEVELOPER_MODE) {
  62. // $d = manipulate_debug_output($d);
  63. // }
  64. $ILCH_DEBUG_OUTPUT .= '<div style="white-space:pre">' . $time . var_export($d, true) . '</div>';
  65. } else {
  66. if (is_bool($d)) {
  67. $d = 'Bool: ' . ($d ? 'true' : 'false');
  68. }
  69. $ILCH_DEBUG_OUTPUT .= '<div>' . $time . $d . '</div>';
  70. }
  71. }
  72. /**
  73. * Funktion parst den backtrace output und kann seine ausgabe verändern
  74. *
  75. * @return array
  76. * @author annemarie`
  77. **/
  78. function manipulate_debug_output($d)
  79. {
  80. foreach ($d as $key => $rvalue) {
  81. if (!isset($rvalue['query'])) {
  82. return $d;
  83. }
  84. $q = $rvalue['query'];
  85. if (!empty($q)) {
  86. if (preg_match('/(SELECT){1}/i',$q,$match)) {
  87. $new_query = link_querys($q, $key);
  88. $d[$key]['query'] = $new_query;
  89. $_SESSION['debug_backtrace']['SELECT'][$key] = $q;
  90. }
  91. }
  92. }
  93. return $d;
  94. }
  95. /**
  96. * soll später einen mysql query verlinken um seine ergebnisse angezeigt zu bekommen
  97. *
  98. * @return string
  99. * @author annemarie
  100. **/
  101. function link_querys($old_query, $key = NULL, $function = NULL, $href = 'javascript:FUNCTION;')
  102. {
  103. if ((preg_match('/(javascript:)(FUNCTION)(;)/i',$href, $match) AND !is_NULL($function)) OR preg_match('/(javascript:)(FUNCTION)(;)/i',$href, $match)) {
  104. $href = $match[1] . 'alert(' . $key . ')' . $match[3];
  105. }
  106. $new_query = '';
  107. $new_query = '<a href="';
  108. $new_query .= $href;
  109. $new_query .= '" title="Query ausf&uuml;hren">QUERY #'.$key.' ' . $old_query;
  110. $new_query .= '</a>';
  111. return $new_query;
  112. }
  113. /**
  114. * debug_bt()
  115. * from php.net
  116. * Gibt ein formatiertes debug_backtrace als String zurück
  117. * @return string
  118. */
  119. function debug_bt() {
  120. if (!function_exists('debug_backtrace')) {
  121. return 'function debug_backtrace does not exists' . "\r\n";
  122. }
  123. $r = 'Debug backtrace:' . "\r\n";
  124. $i = 0;
  125. foreach (debug_backtrace() as $t) {
  126. $i++;
  127. if ($i == 1) {
  128. continue;
  129. }
  130. $r .= "\t" . '@ ';
  131. if (isset($t[ 'file' ])) {
  132. $r .= debug_nice_filename($t[ 'file' ]) . ':' . $t[ 'line' ];
  133. } else {
  134. $r .= '<PHP inner-code>';
  135. }
  136. $r .= ' -- ';
  137. if (isset($t[ 'class' ])) {
  138. $r .= $t[ 'class' ] . $t[ 'type' ];
  139. }
  140. $r .= $t[ 'function' ];
  141. if (isset($t[ 'args' ]) && sizeof($t[ 'args' ]) > 0) {
  142. // $r .= '('.implode(',', $t['args']).')';
  143. $r .= '(...)';
  144. } else {
  145. $r .= '()';
  146. }
  147. $r .= "\r\n";
  148. }
  149. return $r;
  150. }
  151. /**
  152. * debug_out()
  153. * Gibt gespeicherte Debugmeldungen aus
  154. */
  155. function debug_out() {
  156. global $ILCH_DEBUG_OUTPUT, $ILCH_DEBUG_DB_QUERIES, $ILCH_DEBUG_DB_COUNT_QUERIES;
  157. debug('Scriptlaufzeit: ' . round(microtime(true) - SCRIPT_START_TIME, 5) . ' secs');
  158. debug('anzahl sql querys: ' . $ILCH_DEBUG_DB_COUNT_QUERIES);
  159. debug($ILCH_DEBUG_DB_QUERIES);
  160. ?>
  161. <script type="text/javascript">
  162. function toggleDebugDiv() {
  163. var div = document.getElementById('debugDiv');
  164. if (div.style.display == 'none') {
  165. div.style.display = 'block';
  166. } else {
  167. div.style.display = 'none';
  168. }
  169. }
  170. </script>
  171. <style type="text/css">
  172. #debugButton {position:absolute; top:0px; left:0px; display:block; width:50px; height:20px; line-height:20px; vertical-align:middle; border: 1px solid black; background: #ff9;}
  173. #debugDiv {position: absolute; top:30px; left:50px; overflow: scroll; width:90%; height: 90%; background-color:#FFFFFF; border:1px solid grey; color: #000000; z-index: 1000;}
  174. #debugDiv div {border-bottom: 1px dashed black; text-align: left;}
  175. </style>
  176. <div id="debugButton"><a href="javascript:toggleDebugDiv();">Debug</a></div>
  177. <div id="debugDiv" style="display: none;">
  178. <?php echo $ILCH_DEBUG_OUTPUT; ?>
  179. </div>
  180. <?php
  181. }
  182. } else {
  183. function debug($d = '', $time = true) {}
  184. function debug_bt() {
  185. }
  186. function debug_out() {
  187. }
  188. }
  189. ?>