- // buffer the output of debug if no buffering started before
- if (ob_get_level() == 0) {
- ob_start();
- }
- $debug = '';
-
- if ($header) {
- $debug .= '
- <table class="typo3-debug" border="0" cellpadding="0" cellspacing="0" bgcolor="white" style="border:0px; margin-top:3px; margin-bottom:3px;">
- <tr>
- <td style="background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;">' .
- htmlspecialchars((string) $header) .
- '</td>
- </tr>
- <tr>
- <td>';
- }
-
- if (is_array($var)) {
- $debug .= self::view_array($var);
- } elseif (is_object($var)) {
- $debug .= '<strong>|Object:<pre>';
- $debug .= print_r($var, TRUE);
- $debug .= '</pre>|</strong>';
- } elseif ((string) $var !== '') {
- $debug .= '<strong>|' . htmlspecialchars((string) $var) . '|</strong>';
- } else {
- $debug .= '<strong>| debug |</strong>';
- }
-
- if ($header) {
- $debug .= '
- </td>
- </tr>
- </table>';
- }
-
- if (TYPO3_MODE === 'BE') {
- $group = htmlspecialchars($group);
-
- if ($header !== '') {
- $tabHeader = htmlspecialchars($header);
- } else {
- $tabHeader = 'Debug';
- }
-
- if (is_object($var)) {
- $debug = str_replace(
- array('"', '/', '<', "\n", "\r"),
- array('\"', '\/', '\<', '<br />', ''),
- $debug
- );
- } else {
- $debug = str_replace(
- array('"', '/', '<', "\n", "\r"),
- array('\"', '\/', '\<', '', ''),
- $debug
- );
- }
-
- $script = '
- (function debug() {
- var debugMessage = "' . $debug . '";
- var header = "' . $tabHeader . '";
- var group = "' . $group . '";
-
- if (typeof Ext !== "object" && (top && typeof top.Ext !== "object")) {
- document.write(debugMessage);
- return;
- }
-
- if (top && typeof Ext !== "object") {
- Ext = top.Ext;
- }
-
- Ext.onReady(function() {
- var TYPO3ViewportInstance = null;
-
- if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
- TYPO3ViewportInstance = top.TYPO3.Backend;
- } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
- TYPO3ViewportInstance = TYPO3.Backend;
- }
-
- if (TYPO3ViewportInstance !== null) {
- TYPO3ViewportInstance.DebugConsole.addTab(debugMessage, header, group);
- } else {
- document.write(debugMessage);
- }
- });
- })();
- ';
- echo self::wrapJS($script);
- } else {
- echo $debug;
- }