Skip to content

Commit

Permalink
Merge pull request #3 from BurdaPraha/feature-templates
Browse files Browse the repository at this point in the history
Feature templates
  • Loading branch information
landsman authored Jun 7, 2017
2 parents 551d010 + 8ab4cc2 commit 9480286
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 23 deletions.
69 changes: 69 additions & 0 deletions src/TracyPanel/Panel/TemplatesPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace TracyPanel;

use Tracy\IBarPanel;

class TemplatesPanel implements IBarPanel
{
/** @var string */
private $title = "Templates";

/** @var string */
private $icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADWSURBVDjLlZNNCsIwEEZzKW/jyoVbD+Aip/AGgmvRldCKNxDBv4LSfSG7kBZix37BQGiapA48ZpjMvIZAGRExwDmnESw7MMvsHnMFTdOQUsqjrmtXsggKEEVReCDseZc/HbOgoCxLDytwUEFBVVUe/fjNDguEEFGSAiml4Xq+DdZJAV78sM1oOpnT/fI0oEYPZ0lBtjuaBWSttcHtRQWvx9sMrlcb7+HQwxlmojfI9ycziGyj34sK3AV8zd7KFSYFCCwO1aMFsQgK8DO1bRsFM0HBP9i9L2ONMKHNZV7xAAAAAElFTkSuQmCC";

/**
* @return array
*/
private function getLog()
{
return isset($_SESSION['_tracy']['templates_log']) ? $_SESSION['_tracy']['templates_log'] : array();
}

/**
* Renders HTML code for custom tab.
* @return string
*/
public function getTab()
{
return "<span title=''><img src='{$this->icon}'> {$this->title} (" . sizeof($this->getLog()) . ")</span>";
}

/**
* Renders HTML code for custom panel.
* @return string
*/
public function getPanel()
{
$output = "<h1>{$this->title}</h1>
<div class='tracy-inner tracy-InfoPanel'>
<table>
<thead>
<tr>
<th>template name</th>
</tr>
</thead>
<tbody>";

$total = sizeof($this->getLog());
foreach ($this->getLog() as $key => $tpl)
{
$output.="
<tr>
<td style='font-weight: normal'>{$tpl}</td>
</tr>";
}

$output.="
</tbody>
<tfoot>
<tr>
<td colspan='2'><strong>Total: {$total} files</strong></td>
</tr>
</tfoot>
</table>
</div>";

return $output;
}
}
1 change: 1 addition & 0 deletions src/TracyPanel/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct()
Debugger::getBar()
->addPanel(new \TracyPanel\SystemPanel())
->addPanel(new \TracyPanel\SqlPanel())
->addPanel(new \TracyPanel\TemplatesPanel())
->addPanel(new \TracyPanel\VariablePanel())
;
}
Expand Down
58 changes: 35 additions & 23 deletions vqmod/xml/tracy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,17 @@
<vqmver required="true">2.6.0</vqmver>
<author>Michal Landsman</author>

<file path="system/startup.php">
<operation info="bring tracy">
<search position="before">
<![CDATA[function library($class) {]]>
<file path="system/engine/loader.php">
<operation info="log templates">
<search position="after">
<![CDATA[$output = $template->render($route . '.tpl');]]>
</search>
<add>
<![CDATA[
if(defined('DEV') && true == DEV) {
Tracy\Debugger::enable(Tracy\Debugger::DEVELOPMENT, DIR_LOGS);
Tracy\Debugger::$strictMode = TRUE;
if(defined('DEV_EMAIL')) {
Tracy\Debugger::$email = DEV_EMAIL;
}
// register opencart panels
$panels = new TracyPanel\Plugin();
} else {
Tracy\Debugger::enable(Tracy\Debugger::DETECT, DIR_LOGS);
}
]]>
$_SESSION['_tracy']['templates_log'][] = $route;
// todo: think about this for future - some javascript tooltips
// $output = '<span data-type="suggestions" data-template="'.$route.'" >' . $output . '</span>';
]]>
</add>
</operation>
</file>
Expand Down Expand Up @@ -61,7 +47,7 @@
</operation>
<operation info="switch database vs session order init">
<search position="before">
<![CDATA[// Database]]>
<![CDATA[// Loader]]>
</search>
<add>
<![CDATA[
Expand All @@ -73,6 +59,32 @@
}
$registry->set('session', $session);
// clear last session about Tracy
if(isset($_SESSION['_tracy']['templates_log'])) {
unset($_SESSION['_tracy']['templates_log']);
}
]]>
</add>
</operation>
<operation info="bring tracy">
<search position="after">
<![CDATA[$session = new Session();]]>
</search>
<add>
<![CDATA[
if(defined('DEV') && true == DEV) {
Tracy\Debugger::enable(Tracy\Debugger::DEVELOPMENT, DIR_LOGS);
Tracy\Debugger::$strictMode = TRUE;
if(defined('DEV_EMAIL')) {
Tracy\Debugger::$email = DEV_EMAIL;
}
// register opencart panels
$panels = new TracyPanel\Plugin();
}
]]>
</add>
</operation>
Expand Down

0 comments on commit 9480286

Please sign in to comment.