Index: t3lib/class.t3lib_div.php =================================================================== --- t3lib/class.t3lib_div.php (revision 8735) +++ t3lib/class.t3lib_div.php (working copy) @@ -3533,6 +3533,8 @@ * *************************/ + /* Deprecated since 4.5, use t3lib_utility_Debug */ + /** * Returns a string with a list of ascii-values for the first $characters characters in $string * Usage: 0 @@ -3540,13 +3542,11 @@ * @param string String to show ASCII value for * @param integer Number of characters to show * @return string The string with ASCII values in separated by a space char. + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::debug_ordvalue instead */ - public static function debug_ordvalue($string,$characters=100) { - if(strlen($string) < $characters) $characters = strlen($string); - for ($i=0; $i<$characters; $i++) { - $valuestring.=' '.ord(substr($string,$i,1)); - } - return trim($valuestring); + public static function debug_ordvalue($string, $characters = 100) { + self::logDeprecatedFunction(); + return t3lib_utility_Debug::debug_ordvalue($string, $characters); } /** @@ -3557,49 +3557,11 @@ * * @param mixed Array to view * @return string HTML output + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::view_array instead */ - public static function view_array($array_in) { - if (is_array($array_in)) { - $result=' - '; - if (count($array_in) == 0) { - $result.= ''; - } else { - foreach ($array_in as $key => $val) { - $result.= ' - - - '; - } - } - $result.= '
EMPTY!
'.htmlspecialchars((string)$key).''; - if (is_array($val)) { - $result.=self::view_array($val); - } elseif (is_object($val)) { - $string = ''; - if (method_exists($val, '__toString')) { - $string .= get_class($val) . ': ' . (string) $val; - } else { - $string .= print_r($val, TRUE); - } - $result .= ''.nl2br(htmlspecialchars($string)).'
'; - } else { - if (gettype($val) == 'object') { - $string = 'Unknown object'; - } else { - $string = (string)$val; - } - $result.= ''.nl2br(htmlspecialchars($string)).'
'; - } - $result.= '
'; - } else { - $result = ' - - - -
'.nl2br(htmlspecialchars((string)$array_in)).'
'; // Output it as a string. - } - return $result; + public static function view_array($array_in) { + self::logDeprecatedFunction(); + return t3lib_utility_Debug::view_array($array_in); } /** @@ -3609,9 +3571,11 @@ * @param mixed Array to print visually (in a table). * @return void * @see view_array() + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::print_array instead */ - public static function print_array($array_in) { - echo self::view_array($array_in); + public static function print_array($array_in) { + self::logDeprecatedFunction(); + t3lib_utility_Debug::print_array($array_in); } /** @@ -3625,122 +3589,22 @@ * @param string The header. * @param string Group for the debug console * @return void + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::debug instead */ - public static function debug($var = '', $header = '', $group = 'Debug') { - // buffer the output of debug if no buffering started before - if (ob_get_level()==0) { - ob_start(); - } - $debug = ''; - - if ($header) { - $debug .= ' - - - - - - - -
' . - htmlspecialchars((string) $header) . - '
'; - } - - if (is_array($var)) { - $debug .= self::view_array($var); - } elseif (is_object($var)) { - $debug .= '|Object:
';
-			$debug .= print_r($var, TRUE);
-			$debug .=  '
|
'; - } elseif ((string) $var !== '') { - $debug .= '|' . htmlspecialchars((string)$var) . '|'; - } else { - $debug .= '| debug |'; - } - - if ($header) { - $debug .= ' -
'; - } - - 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('\"', '\/', '\<', '
', ''), - $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; - } + public static function debug($var = '', $header = '', $group = 'Debug') { + self::logDeprecatedFunction(); + t3lib_utility_Debug::debug($var, $header, $group); } /** * Displays the "path" of the function call stack in a string, using debug_backtrace * * @return string + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::debug_trail instead */ - public static function debug_trail() { - $trail = debug_backtrace(); - $trail = array_reverse($trail); - array_pop($trail); - - $path = array(); - foreach($trail as $dat) { - $path[] = $dat['class'].$dat['type'].$dat['function'].'#'.$dat['line']; - } - - return implode(' // ',$path); + public static function debug_trail() { + self::logDeprecatedFunction(); + return t3lib_utility_Debug::debug_trail(); } /** @@ -3750,46 +3614,11 @@ * @param string Table header * @param boolean If TRUE, will return content instead of echo'ing out. * @return void Outputs to browser. + * @deprecated since TYPO3 4.5 - Use t3lib_utility_Debug::debugRows instead */ - public static function debugRows($rows,$header='',$returnHTML=FALSE) { - if (is_array($rows)) { - reset($rows); - $firstEl = current($rows); - if (is_array($firstEl)) { - $headerColumns = array_keys($firstEl); - $tRows = array(); - - // Header: - $tRows[] = ''.htmlspecialchars($header).''; - $tCells = array(); - foreach($headerColumns as $key) { - $tCells[] = ' - '.htmlspecialchars($key).''; - } - $tRows[] = ' - '.implode('',$tCells).' - '; - - // Rows: - foreach($rows as $singleRow) { - $tCells = array(); - foreach($headerColumns as $key) { - $tCells[] = ' - '.(is_array($singleRow[$key]) ? self::debugRows($singleRow[$key],'',TRUE) : htmlspecialchars($singleRow[$key])).''; - } - $tRows[] = ' - '.implode('',$tCells).' - '; - } - - $table = ' - '.implode('',$tRows).' -
'; - if ($returnHTML) return $table; else echo $table; - } else debug('Empty array of rows',$header); - } else { - debug('No array of rows',$header); - } + public static function debugRows($rows, $header = '', $returnHTML = FALSE) { + self::logDeprecatedFunction(); + t3lib_utility_Debug::debugRows($rows, $header, $returnHTML); } @@ -3799,26 +3628,6 @@ - - - - - - - - - - - - - - - - - - - - /************************* * * SYSTEM INFORMATION Index: t3lib/core_autoload.php =================================================================== --- t3lib/core_autoload.php (revision 8735) +++ t3lib/core_autoload.php (working copy) @@ -133,6 +133,7 @@ 't3lib_utility_client' => PATH_t3lib . 'utility/class.t3lib_utility_client.php', 't3lib_utility_http' => PATH_t3lib . 'utility/class.t3lib_utility_http.php', 't3lib_utility_mail' => PATH_t3lib . 'utility/class.t3lib_utility_mail.php', + 't3lib_utility_debug' => PATH_t3lib . 'utility/class.t3lib_utility_debug.php', 't3lib_spritemanager' => PATH_t3lib . 'class.t3lib_spritemanager.php', 't3lib_spritemanager_spritegenerator' => PATH_t3lib . 'spritemanager/class.t3lib_spritemanager_spritegenerator.php', 't3lib_spritemanager_spriteicongenerator' => PATH_t3lib . 'interfaces/interface.t3lib_spritemanager_spriteicongenerator.php', Index: t3lib/utility/class.t3lib_utility_debug.php =================================================================== --- t3lib/utility/class.t3lib_utility_debug.php (revision 0) +++ t3lib/utility/class.t3lib_utility_debug.php (revision 0) @@ -0,0 +1,303 @@ + + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * A copy is found in the textfile GPL.txt and important notices to the license + * from the author is found in LICENSE.txt distributed with these scripts. + * + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +/** + * Class to handle debug + * + * $Id: $ + * + * + * @author Steffen Kamper + * @package TYPO3 + * @subpackage t3lib + */ +class t3lib_utility_Debug { + + /** + * Template for debug output + * + * @var string + */ + const DEBUG_TABLE_TEMPLATE = ' + + + + + + + +
%s
+ %s +
+ '; + + + public static function debug($var = '', $header = '', $group = 'Debug') { + // buffer the output of debug if no buffering started before + if (ob_get_level() == 0) { + ob_start(); + } + $debug = ''; + + if (is_array($var)) { + $debug .= self::view_array($var); + } elseif (is_object($var)) { + $debug .= '|Object:
';
+			$debug .= print_r($var, TRUE);
+			$debug .= '
|
'; + } elseif ((string) $var !== '') { + $debug .= '|' . htmlspecialchars((string) $var) . '|'; + } else { + $debug .= '| debug |'; + } + + if ($header) { + $debug = sprintf(self::DEBUG_TABLE_TEMPLATE, htmlspecialchars((string) $header), $debug); + } + + 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 ( + '\"', '\/', '\<', '
', '' + ), $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 t3lib_div::wrapJS($script); + } else { + echo $debug; + } + } + + /** + * Displays the "path" of the function call stack in a string, using debug_backtrace + * + * @return string + */ + public static function debug_trail() { + $trail = debug_backtrace(); + $trail = array_reverse($trail); + array_pop($trail); + + $path = array (); + foreach ($trail as $dat) { + $path[] = $dat['class'] . $dat['type'] . $dat['function'] . '#' . $dat['line']; + } + + return implode(' // ', $path); + } + + /** + * Displays an array as rows in a table. Useful to debug output like an array of database records. + * + * @param mixed Array of arrays with similar keys + * @param string Table header + * @param boolean If TRUE, will return content instead of echo'ing out. + * @return void Outputs to browser. + */ + public static function debugRows($rows, $header = '', $returnHTML = FALSE) { + if (is_array($rows)) { + reset($rows); + $firstEl = current($rows); + if (is_array($firstEl)) { + $headerColumns = array_keys($firstEl); + $tRows = array (); + + // Header: + $tRows[] = '' . + htmlspecialchars($header) . ''; + $tCells = array (); + foreach ($headerColumns as $key) { + $tCells[] = ' + ' . htmlspecialchars($key) . ''; + } + $tRows[] = ' + ' . implode('', $tCells) . ' + '; + + // Rows: + foreach ($rows as $singleRow) { + $tCells = array (); + foreach ($headerColumns as $key) { + $tCells[] = ' + ' . + (is_array($singleRow[$key]) ? self::debugRows($singleRow[$key], '', TRUE) : htmlspecialchars($singleRow[$key])) . + ''; + } + $tRows[] = ' + ' . implode('', $tCells) . ' + '; + } + + $table = ' + ' . implode('', $tRows) . ' +
'; + if ($returnHTML) + return $table; + else + echo $table; + } else + debug('Empty array of rows', $header); + } else { + debug('No array of rows', $header); + } + } + + public static function debug_ordvalue($string, $characters = 100) { + if (strlen($string) < $characters) + $characters = strlen($string); + for ($i = 0; $i < $characters; $i++) { + $valuestring .= ' ' . ord(substr($string, $i, 1)); + } + return trim($valuestring); + } + + /** + * Returns HTML-code, which is a visual representation of a multidimensional array + * use t3lib_div::print_array() in order to print an array + * Returns false if $array_in is not an array + * Usage: 31 + * + * @param mixed Array to view + * @return string HTML output + */ + public static function view_array($array_in) { + if (is_array($array_in)) { + $result = ' + '; + if (count($array_in) == 0) { + $result .= ''; + } else { + foreach ($array_in as $key => $val) { + $result .= ' + + + '; + } + } + $result .= '
EMPTY!
' . htmlspecialchars((string) $key) . ''; + if (is_array($val)) { + $result .= self::view_array($val); + } elseif (is_object($val)) { + $string = ''; + if (method_exists($val, '__toString')) { + $string .= get_class($val) . ': ' . (string) $val; + } else { + $string .= print_r($val, TRUE); + } + $result .= '' . + nl2br(htmlspecialchars($string)) . + '
'; + } else { + if (gettype($val) == 'object') { + $string = 'Unknown object'; + } else { + $string = (string) $val; + } + $result .= '' . + nl2br(htmlspecialchars($string)) . + '
'; + } + $result .= '
'; + } else { + $result = ' + + + +
' . + nl2br(htmlspecialchars((string) $array_in)) . + '
'; // Output it as a string. + } + return $result; + } + + /** + * Prints an array + * Usage: 6 + * + * @param mixed Array to print visually (in a table). + * @return void + * @see view_array() + */ + public static function print_array($array_in) { + echo self::view_array($array_in); + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/utility/class.t3lib_utility_debug.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/utility/class.t3lib_utility_debug.php']); +} +?> \ No newline at end of file