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