View source
<?php
if (!defined('DIR_SEP')) {
define('DIR_SEP', DIRECTORY_SEPARATOR);
}
if (!defined('PATH_SEPARATOR')) {
define('PATH_SEPARATOR', OS_WINDOWS ? ';' : ':');
}
if (!defined('KRUMO_DIR')) {
define('KRUMO_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
if (!defined('KRUMO_TRUNCATE_LENGTH')) {
define('KRUMO_TRUNCATE_LENGTH', 50);
}
class krumo {
static function version() {
return '0.2a';
}
static function backtrace() {
if (!krumo::_debug()) {
return false;
}
return krumo::dump(debug_backtrace());
}
static function classes() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently declared classes.
</div>
<?php
return krumo::dump(get_declared_classes());
}
static function interfaces() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently declared interfaces.
</div>
<?php
return krumo::dump(get_declared_interfaces());
}
static function includes() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently included (or required) files.
</div>
<?php
return krumo::dump(get_included_files());
}
static function functions() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently declared functions.
</div>
<?php
return krumo::dump(get_defined_functions());
}
static function defines() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently declared constants (defines).
</div>
<?php
return krumo::dump(get_defined_constants());
}
static function extensions() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all currently loaded PHP extensions.
</div>
<?php
return krumo::dump(get_loaded_extensions());
}
static function headers() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all HTTP request headers.
</div>
<?php
return krumo::dump(getAllHeaders());
}
static function phpini() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of the configuration settings read from <code><b><?php
echo get_cfg_var('cfg_file_path');
?></b></code>.
</div>
<?php
return krumo::dump(parse_ini_file(get_cfg_var('cfg_file_path'), true));
}
static function conf() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all your configuration settings.
</div>
<?php
return krumo::dump(ini_get_all());
}
static function path() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of the specified directories under your <code><b>include_path</b></code> option.
</div>
<?php
return krumo::dump(explode(PATH_SEPARATOR, ini_get('include_path')));
}
static function request() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_REQUEST</b></code> array.
</div>
<?php
return krumo::dump($_REQUEST);
}
static function get() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_GET</b></code> array.
</div>
<?php
return krumo::dump($_GET);
}
static function post() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_POST</b></code> array.
</div>
<?php
return krumo::dump($_POST);
}
static function server() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_SERVER</b></code> array.
</div>
<?php
return krumo::dump($_SERVER);
}
static function cookie() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_COOKIE</b></code> array.
</div>
<?php
return krumo::dump($_COOKIE);
}
static function env() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_ENV</b></code> array.
</div>
<?php
return krumo::dump($_ENV);
}
static function session() {
if (!krumo::_debug()) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_SESSION</b></code> array.
</div>
<?php
return krumo::dump($_SESSION);
}
static function ini($ini_file) {
if (!krumo::_debug()) {
return false;
}
if (!($_ = @parse_ini_file($ini_file, 1))) {
return false;
}
?>
<div class="krumo-title">
This is a list of all the values from the <code><b><?php
echo realpath($ini_file) ? realpath($ini_file) : $ini_file;
?></b></code> INI file.
</div>
<?php
return krumo::dump($_);
}
static function dump($data) {
if (!krumo::_debug()) {
return false;
}
if (func_num_args() > 1) {
$_ = func_get_args();
foreach ($_ as $d) {
krumo::dump($d);
}
return;
}
krumo::_css();
$_ = array_reverse(debug_backtrace());
while ($d = array_pop($_)) {
if (strpos(@$d['file'], 'devel') === FALSE && strpos(@$d['file'], 'krumo') === FALSE && @$d['class'] != 'krumo') {
break;
}
}
?>
<div class="krumo-root" dir="ltr">
<ul class="krumo-node krumo-first">
<?php
echo krumo::_dump($data);
?>
<li class="krumo-footnote">
<div class="krumo-version" style="white-space:nowrap;">
<h6>Krumo version <?php
echo krumo::version();
?></h6> | <a
href="http://krumo.sourceforge.net"
target="_blank">http://krumo.sourceforge.net</a>
</div>
<?php
if (@$d['file']) {
?>
<span class="krumo-call" style="white-space:nowrap;">
Called from <code><?php
echo $d['file'];
?></code>,
line <code><?php
echo $d['line'];
?></code></span>
<?php
}
?>
</li>
</ul>
</div>
<?php
$_recursion_marker = krumo::_marker();
if ($hive =& krumo::_hive($dummy)) {
foreach ($hive as $i => $bee) {
if (is_object($bee)) {
unset($hive[$i]->{$_recursion_marker});
}
elseif (is_array($bee)) {
unset($hive[$i][$_recursion_marker]);
}
}
}
if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
unset($GLOBALS[krumo::_marker()]);
}
}
static function _css() {
static $_css = false;
if ($_css) {
return true;
}
$css = '';
$skin = variable_get('devel_krumo_skin', 'orange');
$_ = KRUMO_DIR . "skins/{$skin}/skin.css";
if ($fp = @fopen($_, 'r', 1)) {
$css = fread($fp, filesize($_));
fclose($fp);
}
if (!$css && $skin != 'default') {
$skin = 'default';
$_ = KRUMO_DIR . "skins/default/skin.css";
$css = join('', @file($_));
}
if ($_css = $css != '') {
$css_url = base_path() . drupal_get_path('module', 'devel') . "/krumo/skins/{$skin}/";
$css = preg_replace('~%url%~Uis', $css_url, $css);
?>
<!-- Using Krumo Skin: <?php
echo preg_replace('~^' . preg_quote(realpath(KRUMO_DIR) . DIRECTORY_SEPARATOR) . '~Uis', '', realpath($_));
?> -->
<style type="text/css">
<!--/**/
<?php
echo $css;
?>
/**/-->
</style>
<?php
?>
<script type="text/javascript">
<!--//
<?php
echo join(file(KRUMO_DIR . "krumo.js"));
?>
//-->
</script>
<?php
}
return $_css;
}
static function enable() {
return true === krumo::_debug(true);
}
static function disable() {
return false === krumo::_debug(false);
}
static function _debug($state = null) {
static $_ = true;
if (isset($state)) {
$_ = (bool) $state;
}
return $_;
}
static function _dump(&$data, $name = '...') {
if (is_object($data)) {
return krumo::_object($data, $name);
}
if (is_array($data)) {
if (version_compare(PHP_VERSION, "5", "<")) {
if (!isset($GLOBALS[krumo::_marker()])) {
$GLOBALS[krumo::_marker()] = array();
}
if (!is_array($GLOBALS[krumo::_marker()])) {
$GLOBALS[krumo::_marker()] = (array) $GLOBALS[krumo::_marker()];
}
if (!empty($GLOBALS[krumo::_marker()])) {
$d = array_shift($GLOBALS[krumo::_marker()]);
if (is_array($d)) {
$data = $d;
}
}
}
return krumo::_array($data, $name);
}
if (is_resource($data)) {
return krumo::_resource($data, $name);
}
if (is_string($data)) {
return krumo::_string($data, $name);
}
if (is_float($data)) {
return krumo::_float($data, $name);
}
if (is_integer($data)) {
return krumo::_integer($data, $name);
}
if (is_bool($data)) {
return krumo::_boolean($data, $name);
}
if (is_null($data)) {
return krumo::_null($name);
}
}
static function _null($name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type krumo-null">NULL</em>)
</div>
</li>
<?php
}
static function _marker() {
static $_recursion_marker;
if (!isset($_recursion_marker)) {
$_recursion_marker = uniqid('krumo');
}
return $_recursion_marker;
}
static function &_hive(&$bee) {
static $_ = array();
if (!is_null($bee)) {
$_recursion_marker = krumo::_marker();
is_object($bee) ? @$bee->{$_recursion_marker}++ : @$bee[$_recursion_marker]++;
$_[0][] =& $bee;
}
return $_[0];
}
static function _vars(&$data) {
$_is_object = is_object($data);
$_recursion_marker = krumo::_marker();
$_r = $_is_object ? @$data->{$_recursion_marker} : @$data[$_recursion_marker];
$_r = (int) $_r;
if ($_r > 0) {
return krumo::_recursion();
}
krumo::_hive($data);
?>
<div class="krumo-nest" style="display:none;">
<ul class="krumo-node">
<?php
$keys = $_is_object ? array_keys(get_object_vars($data)) : array_keys($data);
foreach ($keys as $k) {
if ($k === $_recursion_marker) {
continue;
}
if ($_is_object) {
$v =& $data->{$k};
}
else {
$v =& $data[$k];
}
if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
$GLOBALS[krumo::_marker()][] =& $v;
}
krumo::_dump($v, $k);
}
?>
</ul>
</div>
<?php
}
static function _recursion() {
?>
<div class="krumo-nest" style="display:none;">
<ul class="krumo-node">
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<a class="krumo-name"><big>∞</big></a>
(<em class="krumo-type">Recursion</em>)
</div>
</li>
</ul>
</div>
<?php
}
static function _array(&$data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element<?php
echo count($data) > 0 ? ' krumo-expand' : '';
?>"
<?php
if (count($data) > 0) {
?> onClick="krumo.toggle(this);"<?php
}
?>
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Array, <strong class="krumo-array-length"><?php
echo count($data) == 1 ? "1 element" : count($data) . " elements";
?></strong></em>)
<?php
if (is_callable($data)) {
$_ = array_values($data);
?>
<span class="krumo-callback"> |
(<em class="krumo-type">Callback</em>)
<strong class="krumo-string"><?php
echo htmlSpecialChars($_[0]);
?>::<?php
echo htmlSpecialChars($_[1]);
?>();</strong></span>
<?php
}
?>
</div>
<?php
if (count($data)) {
krumo::_vars($data);
}
?>
</li>
<?php
}
static function _object(&$data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element<?php
echo count($data) > 0 ? ' krumo-expand' : '';
?>"
<?php
if (count($data) > 0) {
?> onClick="krumo.toggle(this);"<?php
}
?>
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Object</em>)
<strong class="krumo-class"><?php
echo get_class($data);
?></strong>
</div>
<?php
if (count($data)) {
krumo::_vars($data);
}
?>
</li>
<?php
}
static function _resource($data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Resource</em>)
<strong class="krumo-resource"><?php
echo get_resource_type($data);
?></strong>
</div>
</li>
<?php
}
static function _boolean($data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Boolean</em>)
<strong class="krumo-boolean"><?php
echo $data ? 'TRUE' : 'FALSE';
?></strong>
</div>
</li>
<?php
}
static function _integer($data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Integer</em>)
<strong class="krumo-integer"><?php
echo $data;
?></strong>
</div>
</li>
<?php
}
static function _float($data, $name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">Float</em>)
<strong class="krumo-float"><?php
echo $data;
?></strong>
</div>
</li>
<?php
}
static function _string($data, $name) {
$_extra = false;
$_ = $data;
if (strLen($data) > KRUMO_TRUNCATE_LENGTH) {
$_ = substr($data, 0, KRUMO_TRUNCATE_LENGTH - 3) . '...';
$_extra = true;
}
?>
<li class="krumo-child">
<div class="krumo-element<?php
echo $_extra ? ' krumo-expand' : '';
?>"
<?php
if ($_extra) {
?> onClick="krumo.toggle(this);"<?php
}
?>
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<?php
?>
<a class="krumo-name"><?php
echo htmlSpecialChars($name);
?></a>
(<em class="krumo-type">String,
<strong class="krumo-string-length"><?php
echo strlen($data);
?> characters</strong> </em>)
<strong class="krumo-string"><?php
echo htmlSpecialChars($_);
?></strong>
<?php
if (is_callable($data)) {
?>
<span class="krumo-callback"> |
(<em class="krumo-type">Callback</em>)
<strong class="krumo-string"><?php
echo htmlSpecialChars($_);
?>();</strong></span>
<?php
}
?>
</div>
<?php
if ($_extra) {
?>
<div class="krumo-nest" style="display:none;">
<ul class="krumo-node">
<li class="krumo-child">
<div class="krumo-preview"><?php
echo htmlSpecialChars($data);
?></div>
</li>
</ul>
</div>
<?php
}
?>
</li>
<?php
}
}
function krumo() {
$_ = func_get_args();
return call_user_func_array(array(
'krumo',
'dump',
), $_);
}