public static function debug($vars, $parts = null) { static $include_stuff_puked; if (!self::$unique_debug_id) { self::$unique_debug_id = time() - rand(1, 10000); } else { self::$unique_debug_id++; } $id = md5(self::$unique_debug_id); $part = is_array($parts) ? $parts[1] : null; $hash = is_array($parts) && isset($parts[2]) ? $parts[2] : '#'; $color = is_array($parts) && isset($parts[3]) ? $parts[3] : 'red'; if ($hash[0] == '/') { unset($parts[0]); unset($parts[1]); $src = preg_replace('#/+#', '/', implode('.', $parts)); $hash = '<img src="' . $src . '" border="0" title="' . $part . '"/>'; } $what = $part ? $part : 'ALL'; if (is_array($parts) && isset($parts[4])) { $what = $parts[4]; if ($what[0] == '$') { $what = substr($what, 1); if (isset($vars[$what])) { $what = $vars[$what]; } } } $ret = ' <a class="debugger" href="javascript:" onclick="smekta_show_debug(\'content_' . $id . '\')" id="hash_' . $id . '" style="color:' . $color . '" title="' . $what . '">' . $hash . '</a>'; $ret .= ' <div style="display:none; font-size:10px; font-family: Courier" title="' . $what . '" id="content_' . $id . '">'; if ($part && isset($vars[$part])) { $ret .= '<pre style="font-size:12px; font-family: Courier">' . print_r($vars[$part], 1) . '</pre>'; } else { foreach ($vars as $k => $v) { $ret .= '<p><b>{' . $k . '}</b> '; $ret .= gettype($v); if (is_array($v)) { $ret .= ' [count=' . count($v) . ']'; } if (is_string($v)) { $ret .= ' [len=' . strlen($v) . ']'; } if (is_bool($v)) { $ret .= ' [value=' . ($v ? 'TRUE' : 'FALSE') . ']'; } if (is_numeric($v)) { $ret .= ' [value=' . $v . ']'; } $ret .= '</p>'; } } $ret .= '<hr size="1">'; if (!$part || !isset($vars[$part])) { $ret .= '<p><b>{debug.variable}</b> = full {variable} contents</p>'; } $ret .= '<b>{loop:xxx} additional variables:</b><ul><li><b>{__loop__}</b> = key in array</li>'; $ret .= '<li><b>{__index__}</b> = incremental index starting from 1</li>'; $ret .= '<li><b>{__count__<i>variable</i>}</b> = number of items in array <i>variable</i></li></ul>'; $ret .= ' </div>'; if (!$include_stuff_puked) { $ret .= ' <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script type="text/javascript"> function smekta_show_debug(div_id) { document.getElementById(div_id).style.display = "block"; $("#" + div_id).dialog({ width : 800, height : 500 }); } function smekta_load_jquery_ui() { if (typeof $.ui == "undefined") { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"; document.getElementsByTagName("head")[0].appendChild(script); } } function smekta_load_jquery() { if (typeof $ == "undefined") { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"; script.onload = smekta_load_jquery_ui; document.getElementsByTagName("head")[0].appendChild(script); } else { smekta_load_jquery_ui(); } } smekta_load_jquery(); </script>'; } $include_stuff_puked = true; return $ret; }