Aoe_TemplateHints - Version 0.0.2

Version Notes

Initial upload to Magento Connect

Download this release

Release Info

Developer Magento Core Team
Extension Aoe_TemplateHints
Version 0.0.2
Comparing to
See all releases


Version 0.0.2

app/code/local/Aoe/TemplateHints/Model/Observer.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Template hints
5
+ *
6
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
7
+ */
8
+ class Aoe_TemplateHints_Model_Observer {
9
+
10
+ protected $showHints;
11
+
12
+
13
+
14
+ /**
15
+ * Check if hints should be displayed
16
+ *
17
+ * @return bool
18
+ */
19
+ public function showHints() {
20
+ if (is_null($this->showHints)) {
21
+ $this->showHints = false;
22
+ if (Mage::helper('core')->isDevAllowed()) {
23
+ if (Mage::getModel('core/cookie')->get('ath') || Mage::getSingleton('core/app')->getRequest()->get('ath')) {
24
+ $this->showHints = true;
25
+ }
26
+ }
27
+ }
28
+ return $this->showHints;
29
+ }
30
+
31
+
32
+
33
+ /**
34
+ * Event core_block_abstract_to_html_after
35
+ *
36
+ * @param Varien_Event_Observer $params
37
+ * @return void
38
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
39
+ * @since 2011-01-24
40
+ */
41
+ public function core_block_abstract_to_html_after(Varien_Event_Observer $params) {
42
+
43
+ if (!$this->showHints()) {
44
+ return;
45
+ }
46
+
47
+ $block = $params->getBlock(); /* @var $block Mage_Core_Block_Abstract */
48
+ $transport = $params->getTransport();
49
+
50
+ $info = array();
51
+
52
+ $moduleName = $block->getModuleName();
53
+
54
+ $info['MODULE'] = $moduleName;
55
+ $info['PATH'] = $this->getBlockPath($block);
56
+
57
+ if ($block instanceof Mage_Cms_Block_Block) {
58
+ $info['CMS-BLOCK-ID'] = $block->getBlockId();
59
+ }
60
+
61
+ if ($block instanceof Mage_Cms_Block_Page) {
62
+ $info['CMS-PAGE-ID'] = $block->getPage()->getIdentifier();
63
+ }
64
+
65
+ $templateFile = $block->getTemplateFile();
66
+ if ($templateFile) {
67
+ $info['TEMPLATE'] = $templateFile;
68
+ }
69
+
70
+ $color = Mage::getStoreConfig('dev/debug/border_color_notcached'); // not cached
71
+ $cacheInfo = $this->getCacheInfo($block);
72
+ if ($cacheInfo) {
73
+ $info['CACHE'] = $cacheInfo;
74
+ $color = Mage::getStoreConfig('dev/debug/border_color_cached'); // cached
75
+ } elseif ($this->isWithinCachedBlock($block)) {
76
+ $color = Mage::getStoreConfig('dev/debug/border_color_cached_inherit'); // not cached, but within cached
77
+ }
78
+
79
+ $title = array();
80
+ foreach ($info as $key => $value) {
81
+ $title[] = "$key: $value";
82
+ }
83
+ $title = implode(' // ', $title);
84
+
85
+ // wrap info around block output
86
+ $html = $transport->getHtml();
87
+ $html = '<div class="tpl-hint" title="'.$title.'" style="border: 1px dotted '.$color.'; margin:2px; padding:2px; overflow: hidden;">' . $html . '</div>';
88
+ $transport->setHtml($html);
89
+ }
90
+
91
+
92
+
93
+ /**
94
+ * Check if a block is within another one that is cached
95
+ *
96
+ * @param Mage_Core_Block_Abstract $block
97
+ * @return bool
98
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
99
+ * @since 2011-01-24
100
+ */
101
+ protected function isWithinCachedBlock(Mage_Core_Block_Abstract $block) {
102
+ $step = $block;
103
+ while ($step instanceof Mage_Core_Block_Abstract) {
104
+ if (!is_null($step->getCacheLifetime())) {
105
+ return true;
106
+ }
107
+ $step = $step->getParentBlock();
108
+ }
109
+ return false;
110
+ }
111
+
112
+
113
+
114
+ /**
115
+ * Get path information of a block
116
+ *
117
+ * @param Mage_Core_Block_Abstract $block
118
+ * @return string
119
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
120
+ * @since 2011-01-24
121
+ */
122
+ protected function getBlockPath(Mage_Core_Block_Abstract $block) {
123
+ $blockPath = '';
124
+ $step = $block;
125
+ $aliasName = '';
126
+ while ($step instanceof Mage_Core_Block_Abstract) {
127
+ $aliasNamePart = $step->getNameInLayout();
128
+ $alias = $step->getBlockAlias();
129
+ if ($aliasNamePart != $alias) {
130
+ $aliasNamePart = 'name: '.$aliasNamePart;
131
+ if ($alias) {
132
+ $aliasNamePart .= ' /alias: '. $alias ;
133
+ }
134
+ } else {
135
+ $aliasNamePart = 'alias/name: '.$aliasNamePart;
136
+ }
137
+ $blockPath .= (!empty($blockPath) ? ' <- ' : '') . get_class($step) . ' ('.$aliasNamePart.') ';
138
+ $step = $step->getParentBlock();
139
+ }
140
+ return $blockPath;
141
+ }
142
+
143
+
144
+
145
+ /**
146
+ * Get cache information of a block
147
+ *
148
+ * @param Mage_Core_Block_Abstract $block
149
+ * @return string
150
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
151
+ * @since 2011-01-24
152
+ */
153
+ protected function getCacheInfo(Mage_Core_Block_Abstract $block) {
154
+ $cacheLifeTime = $block->getCacheLifetime();
155
+ $cacheInfo = '';
156
+ if (!is_null($cacheLifeTime)) {
157
+ $cacheLifeTime = (intval($cacheLifeTime) == 0) ? 'forever' : intval($cacheLifeTime) . ' sec';
158
+ $cacheInfo = 'Lifetime: ' . $cacheLifeTime .', ';
159
+ $cacheInfo .= 'Key:' . $block->getCacheKey() . ', ';
160
+ $cacheInfo .= 'Tags: ' . implode(',', $block->getCacheTags()) . '';
161
+ }
162
+ return $cacheInfo;
163
+ }
164
+
165
+ }
app/code/local/Aoe/TemplateHints/etc/config.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Template hints
5
+ *
6
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
7
+ * @author André Herrn <info@andre-herrn.de> (Thanks, for making border colors configurable)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Aoe_TemplateHints>
13
+ <version>0.0.2</version>
14
+ </Aoe_TemplateHints>
15
+ </modules>
16
+ <global>
17
+ <models>
18
+ <aoe_templatehints>
19
+ <class>Aoe_TemplateHints_Model</class>
20
+ </aoe_templatehints>
21
+ </models>
22
+ <events>
23
+ <core_block_abstract_to_html_after>
24
+ <observers>
25
+ <core_block_abstract_to_html_after>
26
+ <type>singleton</type>
27
+ <class>Aoe_TemplateHints_Model_Observer</class>
28
+ <method>core_block_abstract_to_html_after</method>
29
+ </core_block_abstract_to_html_after>
30
+ </observers>
31
+ </core_block_abstract_to_html_after>
32
+ </events>
33
+ </global>
34
+ <default>
35
+ <dev>
36
+ <debug>
37
+ <border_color_notcached>red</border_color_notcached>
38
+ <border_color_cached>green</border_color_cached>
39
+ <border_color_cached_inherit>orange</border_color_cached_inherit>
40
+ </debug>
41
+ </dev>
42
+ </default>
43
+ </config>
app/code/local/Aoe/TemplateHints/etc/system.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Template hints
5
+ *
6
+ * @author Fabrizio Branca <fabrizio.branca@aoemedia.de>
7
+ * @author André Herrn <info@andre-herrn.de> (Thanks, for making border colors configurable)
8
+ */
9
+ -->
10
+ <config>
11
+ <sections>
12
+ <dev>
13
+ <groups>
14
+ <debug>
15
+ <fields>
16
+ <border_color_notcached translate="label">
17
+ <label>Color not cached</label>
18
+ <comment><![CDATA[Border color of blocks which are not cached (W3C-colorname or hex value)]]></comment>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>100</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ </border_color_notcached>
25
+ <border_color_cached translate="label">
26
+ <label>Color cached</label>
27
+ <comment><![CDATA[Border color of blocks which are cached (W3C-colorname or hex value)]]></comment>
28
+ <frontend_type>text</frontend_type>
29
+ <sort_order>110</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </border_color_cached>
34
+ <border_color_cached_inherit translate="label">
35
+ <label>Color cached inherit</label>
36
+ <comment><![CDATA[Border color of blocks which are cached implicitly because they consist to a parent block which is cached (W3C-colorname or hex value)]]></comment>
37
+ <frontend_type>text</frontend_type>
38
+ <sort_order>120</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </border_color_cached_inherit>
43
+ </fields>
44
+ </debug>
45
+ </groups>
46
+ </dev>
47
+ </sections>
48
+ </config>
app/etc/modules/Aoe_TemplateHints.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Aoe_TemplateHints>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Aoe_TemplateHints>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Aoe_TemplateHints</name>
4
+ <version>0.0.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Advanced Template Hints</summary>
10
+ <description>The Aoe_TemplateHints module offers advanced template hints including all blocks (not only those extending Mage_Core_Block_Template) and adding plenty of useful information that will help you while developing and debugging your Magento store.</description>
11
+ <notes>Initial upload to Magento Connect</notes>
12
+ <authors><author><name>Fabrizio Branca</name><user>auto-converted</user><email>magento@fabrizio-branca.de</email></author></authors>
13
+ <date>2011-09-13</date>
14
+ <time>18:56:06</time>
15
+ <contents><target name="magelocal"><dir name="Aoe"><dir name="TemplateHints"><dir name="Model"><file name="Observer.php" hash="9883a919f2f9e0a52e8bd97200d4a2b3"/></dir><dir name="etc"><file name="config.xml" hash="1a611a9be3131f55520608f442b5a9eb"/><file name="system.xml" hash="ccf17e6c0480c6c61e4321bb31de17ad"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aoe_TemplateHints.xml" hash="e1affeb23aa842346ef64114120efe25"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>