Version Notes
Tested with Magento 1.4.2.
Download this release
Release Info
Developer | Magento Core Team |
Extension | Layout_Undelete |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
app/code/local/Alanstormdotcom/Unremove/Model/Observer.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
Copyright (c) 2011 Alan Storm
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in
|
13 |
+
all copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
+
THE SOFTWARE.
|
22 |
+
*/
|
23 |
+
class Alanstormdotcom_Unremove_Model_Observer
|
24 |
+
{
|
25 |
+
const ROOTNODE = 'root';
|
26 |
+
public function unremoveUpdate($observer)
|
27 |
+
{
|
28 |
+
$layout = $observer->getLayout();
|
29 |
+
$update = $observer->getLayout()->getUpdate();
|
30 |
+
$original_updates = $update->asArray();
|
31 |
+
$update->resetUpdates();
|
32 |
+
foreach($original_updates as $s_xml_update)
|
33 |
+
{
|
34 |
+
$s_xml_update = $this->_processUnremoveNodes($s_xml_update);
|
35 |
+
$update->addUpdate($s_xml_update);
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
protected function _processUnremoveNodes($string)
|
40 |
+
{
|
41 |
+
$o_xml_update = $this->_getSimplexmlFromFragment($string);
|
42 |
+
$to_unremove = $this->_getUnremoveNames($o_xml_update);
|
43 |
+
$nodes = $o_xml_update->xpath('//remove');
|
44 |
+
foreach($nodes as $node)
|
45 |
+
{
|
46 |
+
if(in_array($node['name'], $to_unremove))
|
47 |
+
{
|
48 |
+
unset($node['name']);
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
$s_xml = '';
|
53 |
+
foreach($o_xml_update->children() as $node)
|
54 |
+
{
|
55 |
+
$s_xml .= $node->asXml();
|
56 |
+
}
|
57 |
+
return $s_xml;
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function _getUnremoveNames($xml)
|
62 |
+
{
|
63 |
+
$nodes = $xml->xpath('//x-unremove');
|
64 |
+
$unremove = array();
|
65 |
+
foreach($nodes as $node)
|
66 |
+
{
|
67 |
+
$unremove[] = (string) $node['name'];
|
68 |
+
}
|
69 |
+
return $unremove;
|
70 |
+
}
|
71 |
+
|
72 |
+
protected function _getSimplexmlFromFragment($fragment)
|
73 |
+
{
|
74 |
+
return simplexml_load_string('<'.self::ROOTNODE.'>'.$fragment.'</'.self::ROOTNODE.'>');
|
75 |
+
}
|
76 |
+
}
|
app/code/local/Alanstormdotcom/Unremove/etc/config.xml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
Copyright (c) 2011 Alan Storm
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in
|
13 |
+
all copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
+
THE SOFTWARE.
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Alanstormdotcom_Unremove>
|
26 |
+
<version>1.0.0</version>
|
27 |
+
</Alanstormdotcom_Unremove>
|
28 |
+
</modules>
|
29 |
+
<global>
|
30 |
+
<models>
|
31 |
+
<alanstormdotcomunremove>
|
32 |
+
<class>
|
33 |
+
Alanstormdotcom_Unremove_Model
|
34 |
+
</class>
|
35 |
+
</alanstormdotcomunremove>
|
36 |
+
</models>
|
37 |
+
|
38 |
+
<events>
|
39 |
+
<controller_action_layout_generate_xml_before>
|
40 |
+
<observers>
|
41 |
+
<alanstormdotcom_unremoveblock_observer>
|
42 |
+
<type>singleton</type>
|
43 |
+
<class>alanstormdotcomunremove/observer</class>
|
44 |
+
<method>unremoveUpdate</method>
|
45 |
+
</alanstormdotcom_unremoveblock_observer>
|
46 |
+
</observers>
|
47 |
+
</controller_action_layout_generate_xml_before>
|
48 |
+
</events>
|
49 |
+
|
50 |
+
</global>
|
51 |
+
</config>
|
app/etc/modules/Alanstormdotcom_Unremove.xml
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?><config><modules><Alanstormdotcom_Unremove><active>true</active><codePool>local</codePool></Alanstormdotcom_Unremove></modules></config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Layout_Undelete</name>
|
4 |
+
<version>1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>MIT License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Allows you to use "x-undelete" in local.xml to undo a block removal.</summary>
|
10 |
+
<description>Allows you to use "x-undelete" in local.xml to undo a block removal.</description>
|
11 |
+
<notes>Tested with Magento 1.4.2.</notes>
|
12 |
+
<authors><author><name>Alan Storm</name><user>auto-converted</user><email>astorm@alanstorm.com</email></author></authors>
|
13 |
+
<date>2011-01-01</date>
|
14 |
+
<time>03:14:00</time>
|
15 |
+
<contents><target name="magelocal"><dir name="Alanstormdotcom"><dir name="Unremove"><dir name="etc"><file name="config.xml" hash="428920683aa902dab106a3610ead1738"/></dir><dir name="Model"><file name="Observer.php" hash="3428d1a7f1a942eb6e7761355e7e38b7"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Alanstormdotcom_Unremove.xml" hash="0de8ee6e3514ee1c25976140005528b1"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies/>
|
18 |
+
</package>
|