Buscape_Sitemap - Version 0.1.0

Version Notes

Buscapé Sitemap é compatível com Magento Enterprise Edition 1.7.0.0 ou superior, Professional Edition 1.9.0.0 ou superior, e Magento Community Edition 1.3.3.0 ou superior.

Download this release

Release Info

Developer Magento Core Team
Extension Buscape_Sitemap
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Buscape/Sitemap/Block/Admin/Edit.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
22
+ {
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+
27
+ $this->_blockGroup = 'buscapemap';
28
+ $this->_mode = 'edit';
29
+ $this->_controller = 'admin';
30
+
31
+ if( $this->getRequest()->getParam($this->_objectId) ) {
32
+ $sitemap = Mage::getModel('buscapemap/sitemap')
33
+ ->load($this->getRequest()->getParam($this->_objectId));
34
+
35
+ Mage::register('frozen_sitemap', $sitemap);
36
+ }
37
+ }
38
+
39
+ public function getHeaderText()
40
+ {
41
+ return Mage::helper('buscapemap')->__("Edit Sitemap'%s'", $this->htmlEscape(Mage::registry('frozen_sitemap')->getName()));
42
+ }
43
+ }
app/code/community/Buscape/Sitemap/Block/Admin/Edit/Form.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
15
+ *
16
+ * @category Buscape
17
+ * @package Buscape_Sitemap
18
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ class Buscape_Sitemap_Block_Admin_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
22
+ {
23
+
24
+ protected function _prepareForm() {
25
+ $form = new Varien_Data_Form();
26
+
27
+ $fieldset = $form->addFieldset('edit_sitemap', array('legend' => Mage::helper('buscapemap')->__('Sitemap Details')));
28
+
29
+ $data = Mage::registry('frozen_sitemap')->getData();
30
+
31
+ $fieldset->addField('sitemap_id', 'hidden', array(
32
+ 'name' => 'sitemap_id',
33
+ 'value' => $data["sitemap_id"]
34
+ ));
35
+
36
+ $fieldset->addField('filename', 'text', array(
37
+ 'name' => 'filename',
38
+ 'title' => Mage::helper('buscapemap')->__('Filename'),
39
+ 'label' => Mage::helper('buscapemap')->__('Filename'),
40
+ 'maxlength' => '250',
41
+ 'required' => true,
42
+ ));
43
+
44
+ $fieldset->addField('path', 'text', array(
45
+ 'name' => 'path',
46
+ 'title' => Mage::helper('buscapemap')->__('Path'),
47
+ 'label' => Mage::helper('buscapemap')->__('Path'),
48
+ 'maxlength' => '250',
49
+ 'required' => true,
50
+ ));
51
+
52
+ $store_array = array("" => "Choose an option");
53
+
54
+ $stores = Mage::app()->getStores();
55
+ foreach ($stores as $store) {
56
+ $store_array[$store->getId()] = $store->getName();
57
+ }
58
+
59
+ $fieldset->addField('store_id', 'select', array(
60
+ 'name' => 'store_id',
61
+ 'title' => Mage::helper('buscapemap')->__('Store ID'),
62
+ 'label' => Mage::helper('buscapemap')->__('Store ID'),
63
+ 'required' => true,
64
+ ))->setValues($store_array);
65
+
66
+ $site_model = array(
67
+ "" => "Choose an option",
68
+ "buscape" => "Buscapé",
69
+ "quebarato" => "Que Barato",
70
+ "bondfaro" => "Bondfaro"
71
+ );
72
+
73
+ $fieldset->addField('site_model', 'select', array(
74
+ 'name' => 'site_model',
75
+ 'title' => Mage::helper('buscapemap')->__('Modelo de XML'),
76
+ 'label' => Mage::helper('buscapemap')->__('Modelo de XML'),
77
+ 'required' => true,
78
+ ))->setValues($site_model);
79
+
80
+ $form->setMethod('post');
81
+ $form->setUseContainer(true);
82
+ $form->setId('edit_form');
83
+ $form->setAction($this->getUrl('*/*/save'));
84
+ $form->setValues(Mage::registry('frozen_sitemap')->getData());
85
+
86
+ $this->setForm($form);
87
+ }
88
+
89
+ }
app/code/community/Buscape/Sitemap/Block/Admin/Grid/Renderer/Link.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_Grid_Renderer_Link extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
22
+ {
23
+
24
+ /**
25
+ * Prepare link to display in grid
26
+ *
27
+ * @param Varien_Object $row
28
+ * @return string
29
+ */
30
+ public function render(Varien_Object $row)
31
+ {
32
+ $fileName = preg_replace('/^\//', '', $row->getPath() . $row->getFilename());
33
+
34
+ $url = $this->htmlEscape(Mage::app()->getStore($row->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . $fileName);
35
+
36
+ if (file_exists(BP . DS . $fileName)) {
37
+ return sprintf('<a href="%1$s" target="_blank">%1$s</a>', $url);
38
+ }
39
+ return $url;
40
+ }
41
+
42
+ }
app/code/community/Buscape/Sitemap/Block/Admin/Main.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_Main extends Mage_Adminhtml_Block_Widget_Grid_Container
22
+ {
23
+
24
+ public function __construct()
25
+ {
26
+ parent::__construct();
27
+
28
+ $this->_headerText = Mage::helper('buscapemap')->__('Sitemap(s) BuscaPé');
29
+
30
+ $this->_blockGroup = 'buscapemap';
31
+
32
+ $this->_controller = 'admin_main';
33
+
34
+ $this->_addButton('add', array(
35
+ 'label' => Mage::helper('buscapemap')->__('Adicionar Sitemap BuscaPé / Bondfaro'),
36
+ 'onclick' => "setLocation('{$this->getUrl('*/*/express', array('type' => 'buscape'))}')",
37
+ 'class' => 'add'
38
+ ));
39
+ }
40
+ }
app/code/community/Buscape/Sitemap/Block/Admin/Main/Grid.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_Main_Grid extends Mage_Adminhtml_Block_Widget_Grid
22
+ {
23
+
24
+ public function __construct()
25
+ {
26
+ parent::__construct();
27
+ $this->setFilterVisibility(false);
28
+ $this->setPagerVisibility(false);
29
+ $this->setUseAjax(false);
30
+ $this->setId('buscapemapGrid');
31
+ $this->_controller = 'buscapemap';
32
+ }
33
+
34
+ protected function _prepareCollection()
35
+ {
36
+ $model = Mage::getModel('buscapemap/sitemap');
37
+
38
+ $collection = $model->getCollection();
39
+
40
+ $this->setCollection($collection);
41
+
42
+ return parent::_prepareCollection();
43
+ }
44
+
45
+
46
+
47
+ protected function _prepareColumns()
48
+ {
49
+
50
+ $this->addColumn('sitemap_id', array(
51
+ 'header' => Mage::helper('buscapemap')->__('ID'),
52
+ 'align' => 'right',
53
+ 'width' => '50px',
54
+ 'filter_index' => 'sitemap_id',
55
+ 'index' => 'sitemap_id',
56
+ ));
57
+
58
+ $this->addColumn('filename', array(
59
+ 'header' => Mage::helper('buscapemap')->__('Nome do Arquivo'),
60
+ 'align' => 'left',
61
+ 'width' => '150px',
62
+ 'filter_index' => 'filename',
63
+ 'index' => 'filename',
64
+ 'type' => 'text',
65
+ 'truncate' => 50,
66
+ 'escape' => true,
67
+ ));
68
+
69
+ $this->addColumn('path', array(
70
+ 'header' => Mage::helper('buscapemap')->__('Caminho'),
71
+ 'align' => 'left',
72
+ 'width' => '150px',
73
+ 'filter_index' => 'path',
74
+ 'index' => 'path',
75
+ 'type' => 'text',
76
+ 'truncate' => 50,
77
+ 'escape' => true,
78
+ ));
79
+
80
+ $this->addColumn('link', array(
81
+ 'header' => Mage::helper('buscapemap')->__('Link'),
82
+ 'align' => 'left',
83
+ 'width' => '150px',
84
+ 'filter_index' => 'link',
85
+ 'index' => 'link',
86
+ //'type' => 'input',
87
+ 'truncate' => 50,
88
+ 'escape' => true,
89
+ 'renderer' => 'buscapemap/admin_grid_renderer_link'
90
+ ));
91
+
92
+ $this->addColumn('site_model', array(
93
+ 'header' => Mage::helper('buscapemap')->__('Tipo'),
94
+ 'align' => 'left',
95
+ 'width' => '150px',
96
+ 'filter_index' => 'site_model',
97
+ 'index' => 'site_model',
98
+ 'type' => 'text',
99
+ 'truncate' => 50,
100
+ 'escape' => true,
101
+ ));
102
+
103
+ $this->addColumn('last_time_created', array(
104
+ 'header' => Mage::helper('buscapemap')->__('Última data de criação'),
105
+ 'align' => 'left',
106
+ 'width' => '150px',
107
+ 'filter_index' => 'dt.last_time_created',
108
+ 'index' => 'last_time_created',
109
+ 'type' => 'datetime',
110
+ 'truncate' => 50,
111
+ 'escape' => true,
112
+ ));
113
+
114
+ $this->addColumn('action',
115
+ array(
116
+ 'header' => Mage::helper('buscapemap')->__('Ação'),
117
+ 'width' => '150px',
118
+ 'type' => 'action',
119
+ 'getter' => 'getSitemapId',
120
+ 'actions' => array(
121
+ #array(
122
+ # 'caption' => Mage::helper('buscapemap')->__('Editar'),
123
+ # 'url' => array(
124
+ # 'base'=>'*/*/edit'
125
+ # ),
126
+ # 'field' => 'id'
127
+ #),
128
+ array(
129
+ 'caption' => Mage::helper('buscapemap')->__('Apagar'),
130
+ 'url' => array(
131
+ 'base'=>'*/*/delete'
132
+ ),
133
+ 'field' => 'id'
134
+ ),
135
+ array(
136
+ 'caption' => Mage::helper('buscapemap')->__('Atualizar XML'),
137
+ 'url' => array(
138
+ 'base'=>'*/*/generate'
139
+ ),
140
+ 'field' => 'id'
141
+ )
142
+ ),
143
+ 'filter' => false,
144
+ 'sortable' => false
145
+ ));
146
+
147
+ return parent::_prepareColumns();
148
+ }
149
+ }
app/code/community/Buscape/Sitemap/Block/Admin/New.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_New extends Mage_Adminhtml_Block_Widget_Form_Container
22
+ {
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+
27
+ $this->_blockGroup = 'buscapemap';
28
+ $this->_mode = 'new';
29
+ $this->_controller = 'admin';
30
+ }
31
+
32
+ public function getHeaderText()
33
+ {
34
+ return Mage::helper('buscapemap')->__('Add New Sitemap BuscaPé');
35
+ }
36
+ }
app/code/community/Buscape/Sitemap/Block/Admin/New/Form.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Block_Admin_New_Form extends Mage_Adminhtml_Block_Widget_Form
22
+ {
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form();
26
+
27
+ $fieldset = $form->addFieldset('new_sitemap', array('legend' => Mage::helper('buscapemap')->__('Sitemap Details')));
28
+
29
+ $fieldset->addField('filename', 'text', array(
30
+ 'name' => 'filename',
31
+ 'title' => Mage::helper('buscapemap')->__('Filename'),
32
+ 'label' => Mage::helper('buscapemap')->__('Filename'),
33
+ 'maxlength' => '250',
34
+ 'note' => Mage::helper('adminhtml')->__('exemplo: sitemap.xml'),
35
+ 'required' => true,
36
+ ));
37
+
38
+ $fieldset->addField('path', 'text', array(
39
+ 'name' => 'path',
40
+ 'title' => Mage::helper('buscapemap')->__('Path'),
41
+ 'label' => Mage::helper('buscapemap')->__('Path'),
42
+ 'maxlength' => '250',
43
+ 'note' => Mage::helper('adminhtml')->__('examplo: sitemap/'),
44
+ 'required' => true,
45
+ ));
46
+
47
+ $store_array = array("" => "Choose an option" );
48
+
49
+ $stores = Mage::app()->getStores();
50
+
51
+ foreach( $stores as $store )
52
+ {
53
+ $store_array[$store->getId()] = $store->getName();
54
+ }
55
+
56
+ $fieldset->addField('store_id', 'select', array(
57
+ 'name' => 'store_id',
58
+ 'title' => Mage::helper('buscapemap')->__('Store ID'),
59
+ 'label' => Mage::helper('buscapemap')->__('Store ID'),
60
+ 'required' => true,
61
+ ))->setValues($store_array);
62
+
63
+ $site_model = array(
64
+ "" => "Choose an option",
65
+ "buscape" => "Buscapé",
66
+ "quebarato" => "QueBarato",
67
+ "bondfaro" => "Bondfaro" );
68
+
69
+ $fieldset->addField('site_model', 'select', array(
70
+ 'name' => 'site_model',
71
+ 'title' => Mage::helper('buscapemap')->__('Modelo de XML'),
72
+ 'label' => Mage::helper('buscapemap')->__('Modelo de XML'),
73
+ 'required' => true,
74
+ ))->setValues($site_model);
75
+
76
+ $form->setMethod('post');
77
+
78
+ $form->setUseContainer(true);
79
+
80
+ $form->setId('edit_form');
81
+
82
+ $form->setAction($this->getUrl('*/*/post'));
83
+
84
+ $this->setForm($form);
85
+ }
86
+ }
app/code/community/Buscape/Sitemap/Helper/Data.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Helper_Data extends Mage_Core_Helper_Abstract
22
+ {
23
+ }
app/code/community/Buscape/Sitemap/Model/Config.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Model_Config extends Varien_Object
22
+ {
23
+ const XML_PATH = 'web/buscapemap/';
24
+
25
+ const XML_PATH_ACTIVE = 'web/buscapemap/active';
26
+
27
+ const XML_PATH_ACCOUNT = 'web/buscapemap/account';
28
+
29
+ protected $_config = array();
30
+
31
+ public function getConfigData($key, $storeId = null)
32
+ {
33
+ if (!isset($this->_config[$key][$storeId])) {
34
+ $value = Mage::getStoreConfig(self::XML_PATH . $key, $storeId);
35
+ $this->_config[$key][$storeId] = $value;
36
+ }
37
+ return $this->_config[$key][$storeId];
38
+ }
39
+
40
+ public function getAccount($store = null)
41
+ {
42
+ if (!$this->hasData('buscapemap_account')) {
43
+ $this->setData('buscapemap_account', $this->getConfigData('account', $store));
44
+ }
45
+
46
+ return $this->getData('buscapemap_account');
47
+ }
48
+ }
app/code/community/Buscape/Sitemap/Model/Mysql4/Sitemap.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Model_Mysql4_Sitemap extends Mage_Core_Model_Mysql4_Abstract
22
+ {
23
+ protected function _construct()
24
+ {
25
+ $this->_init('buscapemap/sitemap', 'sitemap_id');
26
+ }
27
+ }
app/code/community/Buscape/Sitemap/Model/Mysql4/Sitemap/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Model_Mysql4_Sitemap_Collection extends Varien_Data_Collection_Db
22
+ {
23
+ protected $_sitemapTable;
24
+
25
+ public function __construct()
26
+ {
27
+ $resources = Mage::getSingleton('core/resource');
28
+ parent::__construct($resources->getConnection('buscapemap_read'));
29
+
30
+ $this->_sitemapTable = $resources->getTableName('buscapemap/sitemap');
31
+
32
+ $this->_select->from(
33
+ array('sitemap' => $this->_sitemapTable),
34
+ array('*')
35
+ );
36
+
37
+ $this->setItemObjectClass(Mage::getConfig()->getModelClassName('buscapemap/sitemap'));
38
+ }
39
+ }
app/code/community/Buscape/Sitemap/Model/Observer.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Model_Observer
22
+ {
23
+
24
+ }
app/code/community/Buscape/Sitemap/Model/Sitemap.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_Model_Sitemap extends Mage_Sitemap_Model_Sitemap
22
+ {
23
+
24
+ protected function _construct()
25
+ {
26
+ $this->_init('buscapemap/sitemap');
27
+ }
28
+
29
+ protected function _getConfig()
30
+ {
31
+ return Mage::getModel('buscapemap/config');
32
+ }
33
+
34
+ protected function _beforeSave()
35
+ {
36
+ $io = new Varien_Io_File();
37
+
38
+ $realPath = $io->getCleanPath(Mage::getBaseDir() . '/' . $this->getData('path'));
39
+
40
+ $io->setAllowCreateFolders(true);
41
+
42
+ $io->open(array('path' => $this->getData('path')));
43
+
44
+ /**
45
+ * Check path is allow
46
+ */
47
+ if (!$io->allowedPath($realPath, Mage::getBaseDir())) {
48
+ Mage::throwException(Mage::helper('buscapemap')->__('Please define correct path'));
49
+ }
50
+
51
+ /**
52
+ * Check exists and writeable path
53
+ */
54
+ if (!$io->fileExists($realPath, false)) {
55
+ Mage::throwException(Mage::helper('buscapemap')->__('Please create the specified folder "%s" before saving the sitemap.', Mage::helper('core')->htmlEscape($this->getSitemapPath())));
56
+ }
57
+
58
+ if (!$io->isWriteable($realPath)) {
59
+ Mage::throwException(Mage::helper('buscapemap')->__('Please make sure that "%s" is writable by web-server.', $this->getSitemapPath()));
60
+ }
61
+
62
+ /**
63
+ * Check allow filename
64
+ */
65
+ if (!preg_match('#^[a-zA-Z0-9_\.]+$#', $this->getFilename())) {
66
+ Mage::throwException(Mage::helper('buscapemap')->__('Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in the filename. No spaces or other characters are allowed.'));
67
+ }
68
+
69
+ if (!preg_match('#\.xml$#', $this->getFilename())) {
70
+ $this->setSitemapFilename($this->getFilename() . '.xml');
71
+ } else {
72
+ $this->setSitemapFilename($this->getFilename());
73
+ }
74
+
75
+ $this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', Mage::getBaseDir()), '', $realPath), '/') . '/');
76
+
77
+ $this->setLink($this->getPrepareLink());
78
+
79
+ return parent::_beforeSave();
80
+ }
81
+
82
+ /**
83
+ * Return full link of xml file
84
+ *
85
+ * @return string
86
+ */
87
+ public function getPrepareLink()
88
+ {
89
+ $baseUrl = Mage::app()->getStore($this->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
90
+
91
+ return $baseUrl . $this->getData('path') . $this->getFilename();
92
+ }
93
+
94
+ public function _generateXml($data)
95
+ {
96
+ switch($data['site_model']) {
97
+ case 'buscape':
98
+
99
+ if(is_null($this->_getConfig()->getAccount())) {
100
+ throw new Exception('Necessário incluir Código da Central de Négócios nas configurações.');
101
+ return;
102
+ }
103
+
104
+ $this->xmlBuscape();
105
+ break;
106
+ case 'quebarato':
107
+ $this->xmlQuebarato();
108
+ break;
109
+ default:
110
+ Mage::getSingleton('adminhtml/session')->addNotice("Tipo do XML não definido.");
111
+ return;
112
+ break;
113
+ }
114
+
115
+ return $this;
116
+ }
117
+
118
+ public function xmlBuscape()
119
+ {
120
+ $io = new Varien_Io_File();
121
+
122
+ $io->setAllowCreateFolders(true);
123
+
124
+ $io->open(array('path' => $this->getData('path')));
125
+
126
+ if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
127
+ Mage::throwException(Mage::helper('buscapemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
128
+ }
129
+
130
+ if($io->fileExists($this->getSitemapFilename()))
131
+ {
132
+ $io->rm($this->getSitemapFilename());
133
+ }
134
+
135
+ $io->streamOpen($this->getSitemapFilename());
136
+
137
+ $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>');
138
+
139
+ $io->streamWrite("\n<sitemap>\n");
140
+
141
+ $storeId = $this->getStoreId();
142
+
143
+ $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
144
+
145
+ /**
146
+ * Generate products sitemap
147
+ */
148
+ $collection = Mage::getModel('catalog/product')
149
+ ->setStoreId($storeId)
150
+ ->getCollection();
151
+
152
+ foreach($collection as $item) {
153
+
154
+ $product = Mage::getModel("catalog/product")->load($item->getId());
155
+
156
+ $template = <<<EOT
157
+ <produto>
158
+ <descricao>%s</descricao>
159
+ <preco>%s</preco>
160
+ <id_produto>%s</id_produto>
161
+ <codigo_barra>%s</codigo_barra>
162
+ <link_prod>%s</link_prod>
163
+ <imagem>%s</imagem>
164
+ <categ>%s</categ>
165
+ <estoque>%s</estoque>
166
+ <id_filial>%s</id_filial>
167
+ </produto>
168
+ EOT;
169
+
170
+ try {
171
+
172
+ $category_filter = Mage::getModel('catalog/category')
173
+ ->getCollection()
174
+ ->addFieldToFilter('entity_id', array('in' => implode(",", $product->getCategoryIds())))
175
+ ->getFirstItem();
176
+
177
+ $category = Mage::getModel('catalog/category')->load($category_filter->getId());
178
+
179
+ $category_name = str_replace('"', '', $category->getName());
180
+
181
+ $category_name = str_replace('\'', '', $category_name);
182
+
183
+ $xml .= sprintf($template,
184
+ str_replace("&", " ", $product->getName()),
185
+ str_replace(".", ",", Mage::helper('checkout')->convertPrice($product->getPrice(), false)),
186
+ $product->getId(),
187
+ $product->getSku(),
188
+ $product->getProductUrl(),
189
+ $product->getImageUrl(),
190
+ $category_name,
191
+ intval($product->getStockItem()->getQty()),
192
+ $this->_getConfig()->getAccount()
193
+ );
194
+
195
+ $xml .= "\n";
196
+
197
+ $io->streamWrite($xml);
198
+
199
+ } catch(Exception $e) {
200
+
201
+ continue;
202
+ }
203
+ }
204
+
205
+ unset($collection);
206
+
207
+ $io->streamWrite("</sitemap>");
208
+
209
+ $io->streamClose();
210
+
211
+ $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
212
+
213
+ $this->save();
214
+ }
215
+
216
+ public function xmlQuebarato()
217
+ {
218
+ $io = new Varien_Io_File();
219
+
220
+ $io->setAllowCreateFolders(true);
221
+
222
+ $io->open(array('path' => $this->getData('path')));
223
+
224
+ if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
225
+ Mage::throwException(Mage::helper('buscapemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
226
+ }
227
+
228
+ if($io->fileExists($this->getSitemapFilename()))
229
+ {
230
+ $io->rm($this->getSitemapFilename());
231
+ }
232
+
233
+ $io->streamOpen($this->getSitemapFilename());
234
+
235
+ $io->streamWrite("<ad:Ads xmlns:ad='http://www.quebarato.com.br/Ads' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.quebarato.com.br/Ads http://www.quebarato.com.br/Ad.xsd'>");
236
+
237
+ $storeId = $this->getStoreId();
238
+
239
+ $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
240
+
241
+ /**
242
+ * Generate products sitemap
243
+ */
244
+ $collection = Mage::getModel('catalog/product')
245
+ ->setStoreId($storeId)
246
+ ->getCollection();
247
+
248
+ foreach($collection as $item) {
249
+
250
+ $product = Mage::getModel("catalog/product")->load($item->getId());
251
+
252
+ $template = <<<EOT
253
+ <ad:Ad>
254
+ <ad:Details>
255
+ <ad:Title>%s</ad:Title>
256
+ <ad:Description><![CDATA[
257
+ %s
258
+ ]]>
259
+ </ad:Description>
260
+ <ad:ItemCondition value='novo' />
261
+ <ad:Price currency='%s' value='%s'/>
262
+ </ad:Details>
263
+ <ad:Address xsi:type='ad:'>
264
+ <ad:zip>%s</ad:zip>
265
+ </ad:Address>
266
+ <ad:Category value='%s' />
267
+ <ad:Pictures>
268
+ <ad:PictureURI>%s</ad:PictureURI>
269
+ </ad:Pictures>
270
+ </ad:Ad>
271
+ EOT;
272
+
273
+ try {
274
+
275
+ $xml .= sprintf($template,
276
+ str_replace("&", " ", $product->getName()),
277
+ str_replace("&", " ", $product->getDescription()),
278
+ Mage::app()->getBaseCurrencyCode(),
279
+ str_replace(".", ",", Mage::helper('checkout')->convertPrice($product->getPrice(), false)),
280
+ 'valor zip',
281
+ 'categoria',
282
+ $product->getImageUrl()
283
+ );
284
+
285
+ $xml .= "\n";
286
+
287
+ $io->streamWrite($xml);
288
+
289
+ } catch(Exception $e) {
290
+
291
+ continue;
292
+ }
293
+ }
294
+
295
+ unset($collection);
296
+
297
+ $io->streamWrite("</ad:Ads>");
298
+
299
+ $io->streamClose();
300
+
301
+ $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
302
+
303
+ $this->save();
304
+ }
305
+ }
app/code/community/Buscape/Sitemap/controllers/AdminController.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Buscape_Sitemap_AdminController extends Mage_Adminhtml_Controller_Action
22
+ {
23
+
24
+ public function indexAction()
25
+ {
26
+ $this->loadLayout()
27
+ ->_addContent($this->getLayout()->createBlock('buscapemap/admin_main'))
28
+ ->renderLayout();
29
+ }
30
+
31
+ public function deleteAction()
32
+ {
33
+ $sitemapId = $this->getRequest()->getParam('id', false);
34
+
35
+ try {
36
+
37
+ $buscapemap = Mage::getModel('buscapemap/sitemap')->load($sitemapId);
38
+
39
+ $d_buscapemap = $buscapemap->getData();
40
+
41
+ $io = new Varien_Io_File();
42
+
43
+ $io->open(array('path' => $d_buscapemap["path"]));
44
+
45
+ if( $io->fileExists( $d_buscapemap["filename"] ) )
46
+ {
47
+ $io->rm($d_buscapemap["filename"]);
48
+ }
49
+
50
+ $io->close();
51
+
52
+ Mage::getModel('buscapemap/sitemap')->setId($sitemapId)->delete();
53
+
54
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('buscapemap')->__('Sitemap deletado com sucesso.'));
55
+
56
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
57
+
58
+ } catch (Exception $e) {
59
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
60
+ }
61
+
62
+ $this->_redirectReferer();
63
+ }
64
+
65
+ public function newAction()
66
+ {
67
+ $this->loadLayout()
68
+ ->_addContent($this->getLayout()->createBlock('buscapemap/admin_new'))
69
+ ->renderLayout();
70
+ }
71
+
72
+ public function expressAction()
73
+ {
74
+ $type = $this->getRequest()->getParam('type', false);
75
+
76
+ if(!$type) {
77
+
78
+ Mage::getSingleton('adminhtml/session')->addNotice("Tipo do Sitemap não definido.");
79
+
80
+ return;
81
+ }
82
+
83
+ $validate = Mage::getModel('buscapemap/sitemap')
84
+ ->getCollection();
85
+
86
+ $validate->addFilter('filename', "{$type}.xml");
87
+
88
+ if(count($validate) > 0) {
89
+
90
+ switch($type) {
91
+ case 'buscape':
92
+ Mage::getSingleton('adminhtml/session')->addNotice("Sitemap do BuscaPé / Bondfaro já foi criado.");
93
+ break;
94
+ case 'quebarato':
95
+ Mage::getSingleton('adminhtml/session')->addNotice("Sitemap do QueBarato! já foi criado.");
96
+ break;
97
+ default:
98
+ Mage::getSingleton('adminhtml/session')->addNotice("Sitemap já foi criado.");
99
+ break;
100
+ }
101
+
102
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
103
+
104
+ return;
105
+ }
106
+
107
+ $data = array();
108
+
109
+ $data['filename'] = "{$type}.xml";
110
+
111
+ $data['path'] = 'sitemap/';
112
+
113
+ $data['store_id'] = Mage::app()->getStore()->getStoreId();
114
+
115
+ $data['site_model'] = "{$type}";
116
+
117
+ $data["last_time_created"] = date("Y-m-d H:i:s");
118
+
119
+ $sitemap = Mage::getModel('buscapemap/sitemap')->setData($data);
120
+
121
+ try {
122
+
123
+ $sitemap->save();
124
+
125
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('buscapemap')->__('Sitemap foi alterado com sucesso.'));
126
+
127
+ $sitemap->_generateXml($data);
128
+
129
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
130
+
131
+ } catch (Exception $e) {
132
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
133
+ }
134
+
135
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
136
+ }
137
+
138
+ public function postAction()
139
+ {
140
+ if ($data = $this->getRequest()->getPost()) {
141
+
142
+ if(strlen($data["path"]) <= 1) {
143
+
144
+ Mage::getSingleton('adminhtml/session')->addError('Nome do caminho inválido: '.$data["path"].', tente sitemap/');
145
+ } else {
146
+
147
+ $data["link"] = "/";
148
+
149
+ $data["last_time_created"] = date("Y-m-d H:i:s");
150
+
151
+ $sitemap = Mage::getModel('buscapemap/sitemap')->setData($data);
152
+
153
+ try {
154
+
155
+ $sitemap->save();
156
+
157
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('buscapemap')->__('Sitemap foi alterado com sucesso.'));
158
+
159
+ $sitemap->_generateXml($data);
160
+
161
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
162
+
163
+ } catch (Exception $e){
164
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
165
+ }
166
+ }
167
+ }
168
+
169
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
170
+ }
171
+
172
+ public function editAction()
173
+ {
174
+ $this->loadLayout();
175
+
176
+ $this->_addContent($this->getLayout()->createBlock('buscapemap/admin_edit'));
177
+
178
+ $this->renderLayout();
179
+ }
180
+
181
+ public function saveAction()
182
+ {
183
+ $sitemapId = $this->getRequest()->getParam('sitemap_id', false);
184
+
185
+ $buscapemap = Mage::getModel('buscapemap/sitemap')->load($sitemapId);
186
+
187
+ $d_buscapemap = $buscapemap->getData();
188
+
189
+ $io = new Varien_Io_File();
190
+
191
+ $io->open(array('path' => $d_buscapemap["path"]));
192
+
193
+ if( $io->fileExists( $d_buscapemap["filename"] ) ) {
194
+
195
+ $io->rm($d_buscapemap["filename"]);
196
+ }
197
+
198
+ $io->close();
199
+
200
+ if($data = $this->getRequest()->getPost()) {
201
+
202
+ $sitemap = Mage::getModel('buscapemap/sitemap')->load($sitemapId)->addData($data);
203
+
204
+ try {
205
+
206
+ $sitemap->setId($sitemapId)->save();
207
+
208
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('buscapemap')->__('Site'));
209
+
210
+ $sitemap->_generateXml($data);
211
+
212
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
213
+
214
+ } catch (Exception $e) {
215
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
216
+ }
217
+ }
218
+
219
+ $this->_redirectReferer();
220
+ }
221
+
222
+ public function generateAction()
223
+ {
224
+
225
+ $sitemapId = $this->getRequest()->getParam('id', false);
226
+
227
+ $sitemap = Mage::getModel('buscapemap/sitemap')->load($sitemapId);
228
+
229
+ $data = $sitemap->getData();
230
+
231
+ $data["last_time_created"] = date("Y-m-d H:i:s");
232
+
233
+ $sitemap->setData($data);
234
+
235
+ $sitemap->save();
236
+
237
+ $sitemap->_generateXml($data);
238
+
239
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('buscapemap')->__('Sitemap foi gerado com sucesso.'));
240
+
241
+ $this->getResponse()->setRedirect($this->getUrl('*/*/'));
242
+ }
243
+ }
app/code/community/Buscape/Sitemap/etc/config.xml ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
15
+ *
16
+ * @category Buscape
17
+ * @package Buscape_Sitemap
18
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ -->
22
+ <config>
23
+ <modules>
24
+ <Buscape_Sitemap>
25
+ <version>0.1.0</version>
26
+ </Buscape_Sitemap>
27
+ </modules>
28
+ <global>
29
+ <models>
30
+ <buscapemap>
31
+ <class>Buscape_Sitemap_Model</class>
32
+ <resourceModel>buscapemap_mysql4</resourceModel>
33
+ </buscapemap>
34
+ <buscapemap_mysql4>
35
+ <class>Buscape_Sitemap_Model_Mysql4</class>
36
+ <entities>
37
+ <sitemap>
38
+ <table>buscape_sitemap</table>
39
+ </sitemap>
40
+ </entities>
41
+ </buscapemap_mysql4>
42
+ </models>
43
+ <blocks>
44
+ <buscapemap>
45
+ <class>Buscape_Sitemap_Block</class>
46
+ </buscapemap>
47
+ </blocks>
48
+ <helpers>
49
+ <buscapemap>
50
+ <class>Buscape_Sitemap_Helper</class>
51
+ </buscapemap>
52
+ </helpers>
53
+ <resources>
54
+ <buscapemap_setup>
55
+ <setup>
56
+ <module>Buscape_Sitemap</module>
57
+ </setup>
58
+ <connection>
59
+ <use>core_setup</use>
60
+ </connection>
61
+ </buscapemap_setup>
62
+ <buscapemap_write>
63
+ <connection>
64
+ <use>core_write</use>
65
+ </connection>
66
+ </buscapemap_write>
67
+ <buscapemap_read>
68
+ <connection>
69
+ <use>core_read</use>
70
+ </connection>
71
+ </buscapemap_read>
72
+ </resources>
73
+ </global>
74
+ <adminhtml>
75
+ <menu>
76
+ <catalog>
77
+ <children>
78
+ <buscapemap translate="title">
79
+ <title>Buscapé Sitemap(s)</title>
80
+ <sort_order>9999</sort_order>
81
+ <action>buscapemap/admin</action>
82
+ </buscapemap>
83
+ </children>
84
+ </catalog>
85
+ </menu>
86
+ </adminhtml>
87
+ <frontend>
88
+ <routers>
89
+ <Buscape_Sitemap>
90
+ <use>standard</use>
91
+ <args>
92
+ <module>Buscape_Sitemap</module>
93
+ <frontName>buscapemap</frontName>
94
+ </args>
95
+ </Buscape_Sitemap>
96
+ </routers>
97
+ </frontend>
98
+ </config>
app/code/community/Buscape/Sitemap/etc/system.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
15
+ *
16
+ * @category Buscape
17
+ * @package Buscape_Sitemap
18
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ -->
22
+ <config>
23
+ <sections>
24
+ <web translate="label">
25
+ <groups>
26
+ <buscapemap translate="label">
27
+ <label>BuscaPé Sitemap</label>
28
+ <sort_order>0</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ <fields>
33
+ <active translate="label">
34
+ <label>Habilitado</label>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_yesno</source_model>
37
+ <sort_order>1</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </active>
42
+ <account translate="label">
43
+ <label>Conta</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>20</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment><![CDATA[Identificador na Central de Negócios BuscaPé]]></comment>
50
+ </account>
51
+ </fields>
52
+ </buscapemap>
53
+ </groups>
54
+ </web>
55
+ </sections>
56
+ </config>
app/code/community/Buscape/Sitemap/sql/buscapemap_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
14
+ *
15
+ * @category Buscape
16
+ * @package Buscape_Sitemap
17
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ $installer = $this;
22
+
23
+ $installer->startSetup();
24
+
25
+ $installer->run("
26
+ CREATE TABLE IF NOT EXISTS {$this->getTable('buscape_sitemap')} (
27
+ `sitemap_id` int(10) unsigned NOT NULL auto_increment,
28
+ `filename` varchar(250) NOT NULL default '',
29
+ `path` varchar(250) default NULL,
30
+ `link` varchar(250) default NULL,
31
+ `store_id` smallint(5) unsigned NULL,
32
+ `site_model` varchar(250) default NULL,
33
+ `last_time_created` datetime default NULL,
34
+ PRIMARY KEY (`sitemap_id`)
35
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
+ ");
37
+
38
+ $installer->endSetup();
app/etc/modules/Buscape_Sitemap.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to suporte.developer@buscape-inc.com so we can send you a copy immediately.
15
+ *
16
+ * @category Buscape
17
+ * @package Buscape_Sitemap
18
+ * @copyright Copyright (c) 2010 Buscapé Company (http://www.buscapecompany.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ -->
22
+ <config>
23
+ <modules>
24
+ <Buscape_Sitemap>
25
+ <active>true</active>
26
+ <codePool>community</codePool>
27
+ </Buscape_Sitemap>
28
+ </modules>
29
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Buscape_Sitemap</name>
4
+ <version>0.1.0</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>Extens&#xE3;o Buscap&#xE9; Sitemap para Magento</summary>
10
+ <description>Permite que voc&#xEA; crie sitemap para utilizar na central de neg&#xF3;cios, inclu&#xED;ndo seus produtos e servi&#xE7;os em ofertas no Buscap&#xE9;.com e Bondfaro.com</description>
11
+ <notes>Buscap&#xE9; Sitemap &#xE9; compat&#xED;vel com Magento Enterprise Edition 1.7.0.0 ou superior, Professional Edition 1.9.0.0 ou superior, e Magento Community Edition 1.3.3.0 ou superior.</notes>
12
+ <authors><author><name>BuscaP&#xE9; Developer</name><user>auto-converted</user><email>suporte.developer@buscape-inc.com</email></author></authors>
13
+ <date>2011-12-09</date>
14
+ <time>16:59:09</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Buscape_Sitemap.xml" hash="e49a3a6d37df6cd56928f2ba4d517559"/></dir></target><target name="magecommunity"><dir name="Buscape"><dir name="Sitemap"><dir name="Block"><dir name="Admin"><dir name="Edit"><file name="Form.php" hash="4eabebc5239ba40ef9d7ed01b87338de"/></dir><dir name="Grid"><dir name="Renderer"><file name="Link.php" hash="c3fc7d89a673e8eba245240eeca1eba0"/></dir></dir><dir name="Main"><file name="Grid.php" hash="a1708e4296c4963f920d4218b7009e0e"/></dir><dir name="New"><file name="Form.php" hash="98e92a67cd4fbd3d7a4e65704f542f2e"/></dir><file name="Edit.php" hash="fe15ceb6569bcdcd99a08d53599aaca9"/><file name="Main.php" hash="a6c4688b7cbe3a5d2fd18733e9f1a56e"/><file name="New.php" hash="74afbf19d3a6bdb83cf345de916a0242"/></dir></dir><dir name="Helper"><file name="Data.php" hash="fe038765e31661ba27cf8784a1559d6b"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Sitemap"><file name="Collection.php" hash="28c00c86c4fe5aa87325643a5255b32a"/></dir><file name="Sitemap.php" hash="c78328a3a52da29e242b00822935a615"/></dir><file name="Config.php" hash="4386e1c98918d5a114b7a9d31afea296"/><file name="Observer.php" hash="ff2c01550acf78584d6ab56bfbf9b579"/><file name="Sitemap.php" hash="1314baba6101a134f4444ed703b8d5ae"/></dir><dir name="controllers"><file name="AdminController.php" hash="d644112cd5b8b16fed00c253c94eeeaf"/></dir><dir name="etc"><file name="config.xml" hash="cb89da9627439ea4fc2cb9e55f11b31c"/><file name="system.xml" hash="11d6d0609d435447bf1f2c5229f78158"/></dir><dir name="sql"><dir name="buscapemap_setup"><file name="mysql4-install-0.1.0.php" hash="915a5dc3b7a2ba4d5c634db00780303c"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>