1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Tracy;
9:
10: use Tracy;
11:
12:
13: 14: 15: 16: 17:
18: class Bar
19: {
20:
21: public $info = array();
22:
23:
24: private $panels = array();
25:
26:
27: 28: 29: 30: 31: 32:
33: public function addPanel(IBarPanel $panel, $id = NULL)
34: {
35: if ($id === NULL) {
36: $c = 0;
37: do {
38: $id = get_class($panel) . ($c++ ? "-$c" : '');
39: } while (isset($this->panels[$id]));
40: }
41: $this->panels[$id] = $panel;
42: return $this;
43: }
44:
45:
46: 47: 48: 49: 50:
51: public function getPanel($id)
52: {
53: return isset($this->panels[$id]) ? $this->panels[$id] : NULL;
54: }
55:
56:
57: 58: 59: 60:
61: public function render()
62: {
63: $obLevel = ob_get_level();
64: $panels = array();
65: foreach ($this->panels as $id => $panel) {
66: $idHtml = preg_replace('#[^a-z0-9]+#i', '-', $id);
67: try {
68: $tab = (string) $panel->getTab();
69: $panelHtml = $tab ? (string) $panel->getPanel() : NULL;
70: if ($tab && $panel instanceof \Nette\Diagnostics\IBarPanel) {
71: $panelHtml = preg_replace('~(["\'.\s#])nette-(debug|inner|collapsed|toggle|toggle-collapsed)(["\'\s])~', '$1tracy-$2$3', $panelHtml);
72: $panelHtml = str_replace('tracy-toggle-collapsed', 'tracy-toggle tracy-collapsed', $panelHtml);
73: }
74: $panels[] = array('id' => $idHtml, 'tab' => $tab, 'panel' => $panelHtml);
75:
76: } catch (\Throwable $e) {
77: } catch (\Exception $e) {
78: }
79: if (isset($e)) {
80: $panels[] = array(
81: 'id' => "error-$idHtml",
82: 'tab' => "Error in $id",
83: 'panel' => '<h1>Error: ' . $id . '</h1><div class="tracy-inner">'
84: . nl2br(htmlSpecialChars($e, ENT_IGNORE, 'UTF-8')) . '</div>',
85: );
86: while (ob_get_level() > $obLevel) {
87: ob_end_clean();
88: }
89: }
90: }
91:
92: @session_start();
93: $session = & $_SESSION['__NF']['debuggerbar'];
94: if (preg_match('#^Location:#im', implode("\n", headers_list()))) {
95: $session[] = $panels;
96: return;
97: }
98:
99: foreach (array_reverse((array) $session) as $reqId => $oldpanels) {
100: $panels[] = array(
101: 'tab' => '<span title="Previous request before redirect">previous</span>',
102: 'panel' => NULL,
103: 'previous' => TRUE,
104: );
105: foreach ($oldpanels as $panel) {
106: $panel['id'] .= '-' . $reqId;
107: $panels[] = $panel;
108: }
109: }
110: $session = NULL;
111:
112: $info = array_filter($this->info);
113: require __DIR__ . '/templates/bar.phtml';
114: }
115:
116: }
117: