Skip to content

Commit 9480286

Browse files
authored
Merge pull request #3 from BurdaPraha/feature-templates
Feature templates
2 parents 551d010 + 8ab4cc2 commit 9480286

File tree

3 files changed

+105
-23
lines changed

3 files changed

+105
-23
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace TracyPanel;
4+
5+
use Tracy\IBarPanel;
6+
7+
class TemplatesPanel implements IBarPanel
8+
{
9+
/** @var string */
10+
private $title = "Templates";
11+
12+
/** @var string */
13+
private $icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADWSURBVDjLlZNNCsIwEEZzKW/jyoVbD+Aip/AGgmvRldCKNxDBv4LSfSG7kBZix37BQGiapA48ZpjMvIZAGRExwDmnESw7MMvsHnMFTdOQUsqjrmtXsggKEEVReCDseZc/HbOgoCxLDytwUEFBVVUe/fjNDguEEFGSAiml4Xq+DdZJAV78sM1oOpnT/fI0oEYPZ0lBtjuaBWSttcHtRQWvx9sMrlcb7+HQwxlmojfI9ycziGyj34sK3AV8zd7KFSYFCCwO1aMFsQgK8DO1bRsFM0HBP9i9L2ONMKHNZV7xAAAAAElFTkSuQmCC";
14+
15+
/**
16+
* @return array
17+
*/
18+
private function getLog()
19+
{
20+
return isset($_SESSION['_tracy']['templates_log']) ? $_SESSION['_tracy']['templates_log'] : array();
21+
}
22+
23+
/**
24+
* Renders HTML code for custom tab.
25+
* @return string
26+
*/
27+
public function getTab()
28+
{
29+
return "<span title=''><img src='{$this->icon}'> {$this->title} (" . sizeof($this->getLog()) . ")</span>";
30+
}
31+
32+
/**
33+
* Renders HTML code for custom panel.
34+
* @return string
35+
*/
36+
public function getPanel()
37+
{
38+
$output = "<h1>{$this->title}</h1>
39+
<div class='tracy-inner tracy-InfoPanel'>
40+
<table>
41+
<thead>
42+
<tr>
43+
<th>template name</th>
44+
</tr>
45+
</thead>
46+
<tbody>";
47+
48+
$total = sizeof($this->getLog());
49+
foreach ($this->getLog() as $key => $tpl)
50+
{
51+
$output.="
52+
<tr>
53+
<td style='font-weight: normal'>{$tpl}</td>
54+
</tr>";
55+
}
56+
57+
$output.="
58+
</tbody>
59+
<tfoot>
60+
<tr>
61+
<td colspan='2'><strong>Total: {$total} files</strong></td>
62+
</tr>
63+
</tfoot>
64+
</table>
65+
</div>";
66+
67+
return $output;
68+
}
69+
}

src/TracyPanel/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function __construct()
1414
Debugger::getBar()
1515
->addPanel(new \TracyPanel\SystemPanel())
1616
->addPanel(new \TracyPanel\SqlPanel())
17+
->addPanel(new \TracyPanel\TemplatesPanel())
1718
->addPanel(new \TracyPanel\VariablePanel())
1819
;
1920
}

vqmod/xml/tracy.xml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,17 @@
55
<vqmver required="true">2.6.0</vqmver>
66
<author>Michal Landsman</author>
77

8-
<file path="system/startup.php">
9-
<operation info="bring tracy">
10-
<search position="before">
11-
<![CDATA[function library($class) {]]>
8+
<file path="system/engine/loader.php">
9+
<operation info="log templates">
10+
<search position="after">
11+
<![CDATA[$output = $template->render($route . '.tpl');]]>
1212
</search>
1313
<add>
1414
<![CDATA[
15-
if(defined('DEV') && true == DEV) {
16-
17-
Tracy\Debugger::enable(Tracy\Debugger::DEVELOPMENT, DIR_LOGS);
18-
Tracy\Debugger::$strictMode = TRUE;
19-
20-
if(defined('DEV_EMAIL')) {
21-
Tracy\Debugger::$email = DEV_EMAIL;
22-
}
23-
24-
// register opencart panels
25-
$panels = new TracyPanel\Plugin();
26-
27-
} else {
28-
29-
Tracy\Debugger::enable(Tracy\Debugger::DETECT, DIR_LOGS);
30-
31-
}
32-
]]>
15+
$_SESSION['_tracy']['templates_log'][] = $route;
16+
// todo: think about this for future - some javascript tooltips
17+
// $output = '<span data-type="suggestions" data-template="'.$route.'" >' . $output . '</span>';
18+
]]>
3319
</add>
3420
</operation>
3521
</file>
@@ -61,7 +47,7 @@
6147
</operation>
6248
<operation info="switch database vs session order init">
6349
<search position="before">
64-
<![CDATA[// Database]]>
50+
<![CDATA[// Loader]]>
6551
</search>
6652
<add>
6753
<![CDATA[
@@ -73,6 +59,32 @@
7359
}
7460
7561
$registry->set('session', $session);
62+
63+
// clear last session about Tracy
64+
if(isset($_SESSION['_tracy']['templates_log'])) {
65+
unset($_SESSION['_tracy']['templates_log']);
66+
}
67+
]]>
68+
</add>
69+
</operation>
70+
<operation info="bring tracy">
71+
<search position="after">
72+
<![CDATA[$session = new Session();]]>
73+
</search>
74+
<add>
75+
<![CDATA[
76+
if(defined('DEV') && true == DEV) {
77+
78+
Tracy\Debugger::enable(Tracy\Debugger::DEVELOPMENT, DIR_LOGS);
79+
Tracy\Debugger::$strictMode = TRUE;
80+
81+
if(defined('DEV_EMAIL')) {
82+
Tracy\Debugger::$email = DEV_EMAIL;
83+
}
84+
85+
// register opencart panels
86+
$panels = new TracyPanel\Plugin();
87+
}
7688
]]>
7789
</add>
7890
</operation>

0 commit comments

Comments
 (0)