Version Notes
Version 0.1.2 First stable release
Download this release
Release Info
Developer | Magento Core Team |
Extension | Magentix_LayoutAnalyzer |
Version | 0.1.2 |
Comparing to | |
See all releases |
Version 0.1.2
- app/code/community/Magentix/LayoutAnalyzer/Block/Analyzer.php +227 -0
- app/code/community/Magentix/LayoutAnalyzer/Helper/Data.php +5 -0
- app/code/community/Magentix/LayoutAnalyzer/Model/Analyzer.php +91 -0
- app/code/community/Magentix/LayoutAnalyzer/Model/Observer.php +39 -0
- app/code/community/Magentix/LayoutAnalyzer/controllers/IndexController.php +82 -0
- app/code/community/Magentix/LayoutAnalyzer/etc/config.xml +63 -0
- app/code/community/Magentix/LayoutAnalyzer/etc/system.xml +27 -0
- app/etc/modules/Magentix_LayoutAnalyzer.xml +9 -0
- package.xml +18 -0
app/code/community/Magentix/LayoutAnalyzer/Block/Analyzer.php
ADDED
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Magentix_LayoutAnalyzer_Block_Analyzer extends Mage_Core_Block_Text {
|
4 |
+
|
5 |
+
public function getLayoutListe($nodes,$t=0,$s=0) {
|
6 |
+
$colors = array('#900','#009','#060','#c60','#909','#c06');
|
7 |
+
$html = '<ul class="layout-liste">';
|
8 |
+
foreach ($nodes as $k => $v) {
|
9 |
+
if(is_string($k)) {
|
10 |
+
$html .= '<li style="color:'.(isset($colors[$t]) ? $colors[$t] : '#000').'">';
|
11 |
+
$type = (explode(' ',$k));
|
12 |
+
preg_match('#(name)="(.*)"#sU',$k,$name);
|
13 |
+
if(is_array($v) && count($v)) {
|
14 |
+
if($s == 1 && $t == 1 && isset($name[2])) {
|
15 |
+
$html .= '<span'.(!$t ? ' class="first"' : '').'><a href="javascript:void(0);" style="color:'.$colors[$t].'" onclick="javascript:layoutSearch(\''.$name[2].'|'.$type[0].'\',this)">'.$k.'</a></span>'.$this->getLayoutListe($v,$t+1);
|
16 |
+
} else {
|
17 |
+
$html .= '<span'.(!$t ? ' class="first"' : '').'>'.$k.'</span>'.$this->getLayoutListe($v,$t+1);
|
18 |
+
}
|
19 |
+
} else {
|
20 |
+
if($s == 1 && $t == 1 && isset($name[2])) {
|
21 |
+
$html .= '<a href="javascript:void(0);" style="color:'.$colors[$t].'" onclick="javascript:layoutSearch(\''.$name[2].'|'.$type[0].'\',this)">'.$k.(is_string($v) ? ' '.$v : '').'</a>';
|
22 |
+
} else {
|
23 |
+
$html .= $k.(is_string($v) ? ' '.$v : '');
|
24 |
+
}
|
25 |
+
}
|
26 |
+
$html .= '</li>';
|
27 |
+
} else {
|
28 |
+
$html .= '<li class="layout-liste-box">'.$this->getLayoutListe($v,$t,1).'</li>';
|
29 |
+
}
|
30 |
+
}
|
31 |
+
return $html .= '</ul>';
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getScript() {
|
35 |
+
return '<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
|
36 |
+
<script type="text/javascript">
|
37 |
+
//<![CDATA[
|
38 |
+
function layoutSearch(blockname,el) {
|
39 |
+
var links = $(\'layout-list-content\').select(\'a\');
|
40 |
+
for(i=0;i<links.length;i++) { links[i].style.background = \'none\'; }
|
41 |
+
|
42 |
+
var parameters = { name: blockname };
|
43 |
+
var files_data = $(\'layout-files-data\');
|
44 |
+
if(files_data) { files_data.update(\'Loading...\'); }
|
45 |
+
new Ajax.Request(\''.Mage::getUrl('layoutanalyzer/index/search/').'\', {
|
46 |
+
method: \'post\',
|
47 |
+
onSuccess: function(transport) {
|
48 |
+
if(transport.status == 200) {
|
49 |
+
var data = transport.responseText;
|
50 |
+
if(files_data) {
|
51 |
+
files_data.update(data);
|
52 |
+
getAllFiles(data,blockname);
|
53 |
+
}
|
54 |
+
if(el) { el.style.background = \'#ff0\'; }
|
55 |
+
}
|
56 |
+
},
|
57 |
+
parameters: parameters
|
58 |
+
});
|
59 |
+
void(0);
|
60 |
+
}
|
61 |
+
|
62 |
+
function layoutGetFile(dfile,highlight,type) {
|
63 |
+
var parameters = { file: dfile };
|
64 |
+
if(highlight) { parameters[\'highlight\'] = highlight; }
|
65 |
+
if(type) { parameters[\'type\'] = type; }
|
66 |
+
var file_content = $(\'layout-file-content\');
|
67 |
+
if(file_content) { file_content.update(\'Loading...\'); }
|
68 |
+
|
69 |
+
new Ajax.Request(\''.Mage::getUrl('layoutanalyzer/index/openfile/').'\', {
|
70 |
+
method: \'post\',
|
71 |
+
onSuccess: function(transport){
|
72 |
+
if(transport.status == 200) {
|
73 |
+
var data = transport.responseText;
|
74 |
+
if(file_content) {
|
75 |
+
file_content.update(data);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
},
|
79 |
+
parameters: parameters
|
80 |
+
});
|
81 |
+
void(0);
|
82 |
+
}
|
83 |
+
|
84 |
+
function getAllFiles(data,blockname) {
|
85 |
+
if(!data) { data = \'\'; }
|
86 |
+
if(!blockname) { blockname = \'\'; }
|
87 |
+
var parameters = { files: data };
|
88 |
+
parameters[\'name\'] = blockname;
|
89 |
+
|
90 |
+
var file_content = $(\'layout-file-content\');
|
91 |
+
if(file_content) { file_content.update(\'Loading...\'); }
|
92 |
+
|
93 |
+
new Ajax.Request(\''.Mage::getUrl('layoutanalyzer/index/getallfiles/').'\', {
|
94 |
+
method: \'post\',
|
95 |
+
onSuccess: function(transport){
|
96 |
+
if(transport.status == 200) {
|
97 |
+
var data = transport.responseText;
|
98 |
+
if(file_content) {
|
99 |
+
file_content.update(data);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
},
|
103 |
+
parameters: parameters
|
104 |
+
});
|
105 |
+
void(0);
|
106 |
+
}
|
107 |
+
|
108 |
+
function layoutAction() {
|
109 |
+
var layout_content = $(\'layout-content\');
|
110 |
+
var layout_objects = $$(\'object\');
|
111 |
+
if(layout_content) {
|
112 |
+
if(layout_content.style.display == \'none\') {
|
113 |
+
layout_content.show();
|
114 |
+
if(layout_objects) {
|
115 |
+
for(i=0;i<layout_objects.length;i++) { layout_objects[i].hide(); }
|
116 |
+
}
|
117 |
+
} else {
|
118 |
+
layout_content.hide();
|
119 |
+
if(layout_objects) {
|
120 |
+
for(i=0;i<layout_objects.length;i++) { layout_objects[i].show(); }
|
121 |
+
}
|
122 |
+
}
|
123 |
+
}
|
124 |
+
void(0);
|
125 |
+
}
|
126 |
+
|
127 |
+
function colorsyntaxe() {
|
128 |
+
prettyPrint();
|
129 |
+
var pre = $$(\'pre.prettyprint\')[0];
|
130 |
+
pre.className = \'window\';
|
131 |
+
}
|
132 |
+
//]]>
|
133 |
+
</script>
|
134 |
+
';
|
135 |
+
}
|
136 |
+
|
137 |
+
public function getStyle() {
|
138 |
+
return '<style type="text/css">
|
139 |
+
.layout-wrapper{position:absolute;top:0;left:0;right:0;text-align:left;font:11px Arial, Helvetica, sans-serif;border-bottom:3px solid #ccc;border-top:3px solid #ccc;background:#496778;z-index:1000;min-width:900px}
|
140 |
+
.layout-wrapper a{text-decoration:none}
|
141 |
+
.layout-wrapper .handles a{color:#1979A3}
|
142 |
+
.layout-wrapper .layout-liste li a{text-decoration:underline}
|
143 |
+
.layout-wrapper .layout-get-file{margin-left:5px;text-decoration:underline}
|
144 |
+
.layout-liste{margin:0;padding:0}
|
145 |
+
.layout-liste li{padding:3px 0 3px 15px;margin:0;list-style-type:none}
|
146 |
+
.layout-liste li.first{border:0}
|
147 |
+
.layout-liste li span.first{font-weight:bold}
|
148 |
+
.layout-liste li.layout-liste-box{background:#fff;border:1px solid #ccc;margin:2px 0 2px 0}
|
149 |
+
.layout-liste li.layout-liste-box .layout-liste-box{border:0;margin:0;padding:0}
|
150 |
+
.layout-box{width:50%;float:left}
|
151 |
+
.layout-box .window{overflow:auto;margin:0 10px;border:1px solid #ccc;height:350px;background:#efefef;padding:5px}
|
152 |
+
.layout-box .window-full{margin:0 10px 0;border:1px solid #ccc;background:#efefef;padding:5px}
|
153 |
+
.layout-box .module-author{margin:10px;border:1px solid #ccc;padding:5px;text-align:right;border:0;color:#efefef}
|
154 |
+
.layout-box .module-author a{color:#fff;font-size:11px}
|
155 |
+
.layout-action{padding:3px;color:#fff;display:block;background:#405C6C}
|
156 |
+
.layout-action:hover{background:#000}
|
157 |
+
.layout-title{margin:20px 10px 0 10px;background:#618499;color:#fff;font-size:16px;padding:3px 10px;font-weight:bold}
|
158 |
+
.layout-title a{color:#C7E8FF}
|
159 |
+
.layout-title a.clean{font-size:11px;margin-left:10px;font-weight:normal;float:right}
|
160 |
+
.layout-highlight{background:#FFFF00}
|
161 |
+
.layout-file-path{background:#ccc;margin-bottom:5px;padding:2px}
|
162 |
+
#layout-files-data{margin:0 10px;font-size:12px;color:#C7E8FF;background:#618499;padding:0 5px}
|
163 |
+
#layout-file-content a{color:#000}
|
164 |
+
#layout-file-content a.use{color:#900}
|
165 |
+
#layout-file-content strong{color:#900;display:block;margin-top:3px}
|
166 |
+
.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}
|
167 |
+
.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}
|
168 |
+
</style>';
|
169 |
+
}
|
170 |
+
|
171 |
+
public function getAnalyzer() {
|
172 |
+
if(!($this->getXml() && $this->getNodesArray())) return '';
|
173 |
+
|
174 |
+
$_handles = '';
|
175 |
+
$_files = '';
|
176 |
+
|
177 |
+
$xml = $this->getXml();
|
178 |
+
$nodes = $this->getNodesArray();
|
179 |
+
$handles = $this->getHandles();
|
180 |
+
$files = Mage::getModel('layoutanalyzer/analyzer')->getFileNames();
|
181 |
+
sort($files);
|
182 |
+
|
183 |
+
foreach($handles as $h) {
|
184 |
+
$_handles .= '<strong>'.$h.'</strong><br />';
|
185 |
+
$usefiles = Mage::getModel('layoutanalyzer/analyzer')->getUseFiles($files,array($h));
|
186 |
+
foreach($usefiles as $f) {
|
187 |
+
$_handles .= '<a href="javascript:void(0);" onclick="javascript:layoutGetFile(\''.addslashes($f).'\',\''.$h.'\',\'h\')">'.$f.'</a><br />';
|
188 |
+
}
|
189 |
+
$_handles .= '<br />';
|
190 |
+
}
|
191 |
+
|
192 |
+
foreach($files as $f) {
|
193 |
+
$filename = substr($f,strrpos($f,DS)+1);
|
194 |
+
$_files .= '<strong>'.$filename.'</strong> <a href="javascript:void(0);" onclick="javascript:layoutGetFile(\''.addslashes($f).'\')">'.$f.'</a><br />';
|
195 |
+
}
|
196 |
+
|
197 |
+
return '<div class="layout-wrapper"><a href="javascript:layoutAction()" class="layout-action">Layout Analyzer : '.Mage::helper('core/url')->getCurrentUrl().'</a><div id="layout-content" style="display:none">'.$this->getStyle().$this->getScript().
|
198 |
+
'<div class="layout-box">
|
199 |
+
<h2 class="layout-title">'.Mage::helper('layoutanalyzer')->__('Generated Layout').' <a href="'.Mage::getUrl('layoutanalyzer/index/cache/').'" class="clean">'.Mage::helper('layoutanalyzer')->__('Clean Cache and Refresh').'</a></h2>
|
200 |
+
<pre class="prettyprint window">'.htmlentities($xml).'</pre>
|
201 |
+
<script type="text/javascript">colorsyntaxe();</script>
|
202 |
+
</div>
|
203 |
+
<div class="layout-box">
|
204 |
+
<h2 class="layout-title">'.Mage::helper('layoutanalyzer')->__('Organized Layout').' <span id="layout-files-data">'.Mage::helper('layoutanalyzer')->__('Select block for search').'</span></h2>
|
205 |
+
<div class="window" id="layout-list-content">'.$this->getLayoutListe($nodes).'</div>
|
206 |
+
</div>
|
207 |
+
<div class="layout-box">
|
208 |
+
<h2 class="layout-title">'.Mage::helper('layoutanalyzer')->__('Layout Files').' <a href="javascript:getAllFiles()" class="clean">'.Mage::helper('layoutanalyzer')->__('Files').'</a></h2>
|
209 |
+
<div class="window" id="layout-file-content">'.$_files.'</div>
|
210 |
+
</div>
|
211 |
+
<div class="layout-box">
|
212 |
+
<h2 class="layout-title">'.Mage::helper('layoutanalyzer')->__('Handles').'</h2>
|
213 |
+
<div class="window handles">'.$_handles.'</div>
|
214 |
+
</div>
|
215 |
+
<div class="layout-box" style="width:100%"><div class="module-author">Layout Analyzer 0.1.2 - Magento '.Mage::getVersion().' - By Magentix - <a href="http://www.magentix.fr" target="_blank">http://www.magentix.fr</a> - <a href="http://www.magentix.fr/contact/" target="_blank">'.Mage::helper('layoutanalyzer')->__('Report All Bugs').'</a></div></div>
|
216 |
+
</div>
|
217 |
+
<div style="clear:both"></div>
|
218 |
+
</div>';
|
219 |
+
}
|
220 |
+
|
221 |
+
protected function _toHtml() {
|
222 |
+
$this->setCacheLifetime(null);
|
223 |
+
$this->addText($this->getAnalyzer());
|
224 |
+
return parent::_toHtml();
|
225 |
+
}
|
226 |
+
|
227 |
+
}
|
app/code/community/Magentix/LayoutAnalyzer/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Magentix_LayoutAnalyzer_Helper_Data extends Mage_Core_Helper_Abstract {
|
4 |
+
|
5 |
+
}
|
app/code/community/Magentix/LayoutAnalyzer/Model/Analyzer.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Magentix_LayoutAnalyzer_Model_Analyzer {
|
4 |
+
|
5 |
+
public function xmlToArray($nodes) {
|
6 |
+
$layout = array();
|
7 |
+
foreach ($nodes->children() as $node) {
|
8 |
+
$key = trim($node->getName().' : '.$this->extractAttributes($node));
|
9 |
+
|
10 |
+
if(!array_key_exists($key, $layout)) {
|
11 |
+
$layout[$key] = array();
|
12 |
+
}
|
13 |
+
|
14 |
+
if($child = $this->xmlToArray($node)) {
|
15 |
+
if(is_array($layout[$key])) $layout[$key][] = $child;
|
16 |
+
} else {
|
17 |
+
if(strlen(trim((string)$node[0]))) {
|
18 |
+
$layout[$key] = trim((string)$node[0]);
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
}
|
23 |
+
return $layout;
|
24 |
+
}
|
25 |
+
|
26 |
+
public function extractAttributes($node) {
|
27 |
+
$attributes = '';
|
28 |
+
foreach($node->attributes() as $a => $b) {
|
29 |
+
$attributes .= $a.'="'.$b.'" ';
|
30 |
+
}
|
31 |
+
return trim($attributes);
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getFileNames() {
|
35 |
+
$design = Mage::getSingleton('core/design_package');
|
36 |
+
|
37 |
+
$updatesRoot = Mage::app()->getConfig()->getNode($design->getArea().'/layout/updates');
|
38 |
+
|
39 |
+
$updateFiles = array();
|
40 |
+
foreach ($updatesRoot->children() as $updateNode) {
|
41 |
+
if ($updateNode->file) {
|
42 |
+
$module = $updateNode->getAttribute('module');
|
43 |
+
if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, Mage::app()->getStore()->getId())) {
|
44 |
+
continue;
|
45 |
+
}
|
46 |
+
$updateFiles[] = (string)$updateNode->file;
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
$filenames = array();
|
51 |
+
|
52 |
+
foreach ($updateFiles as $file) {
|
53 |
+
$filename = $design->getLayoutFilename($file, array(
|
54 |
+
'_area' => $design->getArea(),
|
55 |
+
'_package' => $design->getPackageName(),
|
56 |
+
'_theme' => $design->getTheme('layout')
|
57 |
+
));
|
58 |
+
if (!is_readable($filename)) {
|
59 |
+
continue;
|
60 |
+
}
|
61 |
+
|
62 |
+
$filenames[] = $filename;
|
63 |
+
}
|
64 |
+
return $filenames;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getUseFiles($files,$handles=array()) {
|
68 |
+
$useFiles = array();
|
69 |
+
foreach($files as $f) {
|
70 |
+
$content = file_get_contents($f);
|
71 |
+
foreach($handles as $h) {
|
72 |
+
if(preg_match('/<'.$h.'(.*?)>/',$content)) {
|
73 |
+
$useFiles[] = $f;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
}
|
77 |
+
return $useFiles;
|
78 |
+
}
|
79 |
+
|
80 |
+
public function searchFilesByNode($files,$name,$node) {
|
81 |
+
$_files = array();
|
82 |
+
foreach($files as $f) {
|
83 |
+
$content = file_get_contents($f);
|
84 |
+
if(preg_match('/<'.$node.'(.*)name="'.$name.'"/',$content)) {
|
85 |
+
$_files[] = $f;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
return $_files;
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
app/code/community/Magentix/LayoutAnalyzer/Model/Observer.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Magentix_LayoutAnalyzer_Model_Observer {
|
4 |
+
|
5 |
+
public function addBlock($observer) {
|
6 |
+
if(!Mage::getStoreConfigFlag('dev/layoutanalyzer/active')) return $this;
|
7 |
+
|
8 |
+
$layout = $observer->getLayout();
|
9 |
+
|
10 |
+
$bodyEnd = $layout->getXpath("//block[@name='before_body_end']");
|
11 |
+
|
12 |
+
if (!$bodyEnd) return $this;
|
13 |
+
|
14 |
+
$block = $bodyEnd[0]->addChild('block');
|
15 |
+
$block->addAttribute('type', 'layoutanalyzer/analyzer');
|
16 |
+
$block->addAttribute('name', 'layout_analyzer');
|
17 |
+
$block->addAttribute('as', 'layout_analyzer');
|
18 |
+
}
|
19 |
+
|
20 |
+
public function setAnalyzer($observer) {
|
21 |
+
if(!Mage::getStoreConfigFlag('dev/layoutanalyzer/active')) return $this;
|
22 |
+
|
23 |
+
$layout = $observer->getLayout();
|
24 |
+
$update = $layout->getUpdate();
|
25 |
+
|
26 |
+
$xml = $update->asString();
|
27 |
+
$handles = $update->getHandles();
|
28 |
+
$nodes = Mage::getModel('layoutanalyzer/analyzer')->xmlToArray(simplexml_load_string('<layout>'.$xml.'</layout>'));
|
29 |
+
|
30 |
+
$analyzerBlock = $layout->getBlock('layout_analyzer');
|
31 |
+
|
32 |
+
if($xml && $nodes && $analyzerBlock) {
|
33 |
+
$analyzerBlock->setXml($xml);
|
34 |
+
$analyzerBlock->setNodesArray($nodes);
|
35 |
+
$analyzerBlock->setHandles($handles);
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
app/code/community/Magentix/LayoutAnalyzer/controllers/IndexController.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Magentix_LayoutAnalyzer_IndexController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
public function preDispatch() {
|
6 |
+
parent::preDispatch();
|
7 |
+
|
8 |
+
if(!Mage::getStoreConfigFlag('dev/layoutanalyzer/active')) {
|
9 |
+
$this->norouteAction();
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
public function cacheAction() {
|
14 |
+
Mage::app()->cleanCache();
|
15 |
+
$this->_redirectReferer();
|
16 |
+
}
|
17 |
+
|
18 |
+
public function searchAction() {
|
19 |
+
$search = $this->getRequest()->getPost('name', false);
|
20 |
+
|
21 |
+
$_files = Mage::helper('layoutanalyzer')->__('Appears in : ');
|
22 |
+
|
23 |
+
if($search) {
|
24 |
+
list($name,$node) = explode('|',$search);
|
25 |
+
$analyzer = Mage::getModel('layoutanalyzer/analyzer');
|
26 |
+
$files = $analyzer->getFileNames();
|
27 |
+
$appearFiles = $analyzer->searchFilesByNode($files,$name,$node);
|
28 |
+
|
29 |
+
if(count($appearFiles)) {
|
30 |
+
foreach($appearFiles as $b) {
|
31 |
+
$filename = substr($b,strrpos($b,DS)+1);
|
32 |
+
$_files .= '<a href="javascript:layoutGetFile(\''.addslashes($b).'\',\''.$search.'\',\'b\')" class="layout-get-file">'.$filename.'</a> ';
|
33 |
+
}
|
34 |
+
} else {
|
35 |
+
$_files = Mage::helper('layoutanalyzer')->__('Not found in files, updated from backend');
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
echo $_files;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function openfileAction() {
|
43 |
+
$file = $this->getRequest()->getPost('file', false);
|
44 |
+
$name = $this->getRequest()->getPost('highlight', false);
|
45 |
+
$type = $this->getRequest()->getPost('type', false);
|
46 |
+
|
47 |
+
$_content = '';
|
48 |
+
|
49 |
+
if($file) {
|
50 |
+
$_content = htmlentities(file_get_contents($file));
|
51 |
+
if($name && $type) {
|
52 |
+
switch($type) {
|
53 |
+
case 'h':
|
54 |
+
$_content = preg_replace('/<(.?)'.$name.'>/','<span class="layout-highlight"><$1'.$name.'></span>',$_content);
|
55 |
+
break;
|
56 |
+
default:
|
57 |
+
list($name,$node) = explode('|',$name);
|
58 |
+
$_content = preg_replace('/<'.$node.'(.*?)"'.$name.'"(.*?)>/','<span class="layout-highlight"><'.$node.'$1"'.$name.'"$2></span>',$_content);
|
59 |
+
break;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
echo '<div class="layout-file-path">'.$file.'</div><pre class="prettyprint">'.$_content.'</pre><script type="text/javascript">prettyPrint();</script>';
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getallfilesAction() {
|
68 |
+
$search = $this->getRequest()->getPost('files', false);
|
69 |
+
$name = $this->getRequest()->getPost('name', false);
|
70 |
+
|
71 |
+
$_files = '';
|
72 |
+
$files = Mage::getModel('layoutanalyzer/analyzer')->getFileNames();
|
73 |
+
|
74 |
+
foreach($files as $f) {
|
75 |
+
$filename = substr($f,strrpos($f,DS)+1);
|
76 |
+
$_files .= '<strong'.(preg_match('/'.$filename.'/',$search) ? ' class="layout-highlight"' : '').'>'.$filename.'</strong> <a href="javascript:void(0);" onclick="javascript:layoutGetFile(\''.addslashes($f).'\',\''.$name.'\',\'b\')">'.$f.'</a><br />';
|
77 |
+
}
|
78 |
+
|
79 |
+
echo $_files;
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
app/code/community/Magentix/LayoutAnalyzer/etc/config.xml
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Magentix_LayoutAnalyzer>
|
5 |
+
<version>0.1.2</version>
|
6 |
+
</Magentix_LayoutAnalyzer>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<layoutanalyzer>
|
11 |
+
<class>Magentix_LayoutAnalyzer_Model</class>
|
12 |
+
</layoutanalyzer>
|
13 |
+
</models>
|
14 |
+
<blocks>
|
15 |
+
<layoutanalyzer>
|
16 |
+
<class>Magentix_LayoutAnalyzer_Block</class>
|
17 |
+
</layoutanalyzer>
|
18 |
+
</blocks>
|
19 |
+
<helpers>
|
20 |
+
<layoutanalyzer>
|
21 |
+
<class>Magentix_LayoutAnalyzer_Helper</class>
|
22 |
+
</layoutanalyzer>
|
23 |
+
</helpers>
|
24 |
+
</global>
|
25 |
+
<frontend>
|
26 |
+
<routers>
|
27 |
+
<layoutanalyzer>
|
28 |
+
<use>standard</use>
|
29 |
+
<args>
|
30 |
+
<module>Magentix_LayoutAnalyzer</module>
|
31 |
+
<frontName>layoutanalyzer</frontName>
|
32 |
+
</args>
|
33 |
+
</layoutanalyzer>
|
34 |
+
</routers>
|
35 |
+
<events>
|
36 |
+
<controller_action_layout_generate_blocks_before>
|
37 |
+
<observers>
|
38 |
+
<add_analyzer>
|
39 |
+
<type>singleton</type>
|
40 |
+
<class>layoutanalyzer/observer</class>
|
41 |
+
<method>addBlock</method>
|
42 |
+
</add_analyzer>
|
43 |
+
</observers>
|
44 |
+
</controller_action_layout_generate_blocks_before>
|
45 |
+
<controller_action_layout_generate_blocks_after>
|
46 |
+
<observers>
|
47 |
+
<set_analyzer>
|
48 |
+
<type>singleton</type>
|
49 |
+
<class>layoutanalyzer/observer</class>
|
50 |
+
<method>setAnalyzer</method>
|
51 |
+
</set_analyzer>
|
52 |
+
</observers>
|
53 |
+
</controller_action_layout_generate_blocks_after>
|
54 |
+
</events>
|
55 |
+
</frontend>
|
56 |
+
<default>
|
57 |
+
<dev>
|
58 |
+
<layoutanalyzer>
|
59 |
+
<active>0</active>
|
60 |
+
</layoutanalyzer>
|
61 |
+
</dev>
|
62 |
+
</default>
|
63 |
+
</config>
|
app/code/community/Magentix/LayoutAnalyzer/etc/system.xml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<sections>
|
3 |
+
<dev>
|
4 |
+
<groups>
|
5 |
+
<layoutanalyzer translate="label">
|
6 |
+
<label>Layouts Analyzer</label>
|
7 |
+
<frontend_type>text</frontend_type>
|
8 |
+
<sort_order>110</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<fields>
|
13 |
+
<active translate="label">
|
14 |
+
<label>Enable Analyzer</label>
|
15 |
+
<frontend_type>select</frontend_type>
|
16 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
17 |
+
<sort_order>10</sort_order>
|
18 |
+
<show_in_default>1</show_in_default>
|
19 |
+
<show_in_website>1</show_in_website>
|
20 |
+
<show_in_store>1</show_in_store>
|
21 |
+
</active>
|
22 |
+
</fields>
|
23 |
+
</layoutanalyzer>
|
24 |
+
</groups>
|
25 |
+
</dev>
|
26 |
+
</sections>
|
27 |
+
</config>
|
app/etc/modules/Magentix_LayoutAnalyzer.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Magentix_LayoutAnalyzer>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Magentix_LayoutAnalyzer>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Magentix_LayoutAnalyzer</name>
|
4 |
+
<version>0.1.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>Analyzing all layout generated for a page</summary>
|
10 |
+
<description>This extension allows to precisely analyze the xml file layouts. Search in layouts files the blocks and handles reported.</description>
|
11 |
+
<notes>Version 0.1.2 First stable release</notes>
|
12 |
+
<authors><author><name>Matthieu Vion</name><user>auto-converted</user><email>contact@magentix.fr</email></author></authors>
|
13 |
+
<date>2010-07-26</date>
|
14 |
+
<time>20:09:16</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Magentix"><dir name="LayoutAnalyzer"><dir name="Block"><file name="Analyzer.php" hash="d71709c225c744deebda1bfeedecd5c9"/></dir><dir name="controllers"><file name="IndexController.php" hash="82fb18d785d3daef0181bf9022071e9e"/></dir><dir name="etc"><file name="config.xml" hash="526e7c0ceb4076fe3eafb2ae9f0a74b8"/><file name="system.xml" hash="f85931bec927f9cfe6442dd704c53282"/></dir><dir name="Helper"><file name="Data.php" hash="9836946169d48d3208de3906e430420e"/></dir><dir name="Model"><file name="Analyzer.php" hash="cd1f79ba93670a3cbf49c357f355a07c"/><file name="Observer.php" hash="4bc4d6e4f9e2fb104264eeac24594511"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magentix_LayoutAnalyzer.xml" hash="4d9da56efddc1c5bf4509fcb4ba2e8b0"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies/>
|
18 |
+
</package>
|