public static function renderHTML($struct, $key = 'root', $vis = 2, $expand = 1000, $st = true, $bktrc = null) { // track max key width (8px/char) self::$keyWidth = max(self::$keyWidth, strlen($key) * self::$chrWidth); $inject = ''; if (self::$initial) { $inject = self::$css . self::$js; self::$initial = false; } $buf = ''; if ($st) { $dump_id = 'dump-' . rand(100, 999); $where = $bktrc !== null ? "<div class=\"file-line\">{$bktrc->file} (line {$bktrc->line})</div>" : ''; $buf .= "{$inject}<pre class=\"dump_r\" id=\"{$dump_id}\">{$where}<ul>"; } $s =& $struct; $disp = htmlspecialchars($s->disp); // add jumps to referenced objects if (!empty($s->hash)) { $disp = "<a name=\"{$s->hash}\">{$disp}</a>"; } else { if ($s->type == 'ref') { $disp = "<a href=\"#{$s->ref->hash}\">{$disp}</a>"; } } $len = !is_null($s->length) ? "<div class=\"len\">{$s->length}</div>" : ''; $sub = !is_null($s->subtype) ? "<div class=\"sub\">{$s->subtype}</div>" : ''; $excol = !empty($s->children) ? '<div class="excol"></div>' : ''; $exp_state = $excol ? $expand > 0 ? ' expanded' : ' collapsed' : ''; $empty = $s->empty ? ' empty' : ''; $numeric = $s->numeric ? ' numeric' : ''; $subtype = $s->subtype ? " {$s->subtype}" : ''; $privprot = $vis === 1 ? ' protected' : ($vis === 0 ? ' private' : ''); $depthlim = $s->depthlim ? ' depthlim' : ''; $classes = $s->classes ? ' ' . implode(' ', $s->classes) : ''; $buf .= "<li class=\"{$s->type}{$subtype}{$numeric}{$empty}{$privprot}{$classes}{$depthlim}{$exp_state}\">{$excol}<div class=\"lbl\"><div class=\"key\">{$key}</div><div class=\"val\">{$disp}</div><div class=\"typ\">({$s->type})</div>{$sub}{$len}</div>"; if ($s->children) { $buf .= '<ul>'; foreach ($s->children as $k => $s2) { $buf .= self::renderHTML($s2, $k, $s->childvis[$k], $expand - 1, false); } $buf .= '</ul>'; } $buf .= '</li>'; if ($st) { $buf .= "</ul><style>#{$dump_id} .key {min-width: " . self::$keyWidth . 'px;}</style></pre>'; self::$keyWidth = 0; // reset } return $buf; }