Version Notes
Initial release with correct dates.
Download this release
Release Info
Developer | Activo Extensions |
Extension | Activo_Xmlsitemap |
Version | 0.1.0 |
Comparing to | |
See all releases |
Version 0.1.0
- app/code/community/Activo/Xmlsitemap/Helper/Data.php +5 -0
- app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Catalog/Category.php +72 -0
- app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Catalog/Product.php +69 -0
- app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Cms/Page.php +50 -0
- app/code/community/Activo/Xmlsitemap/Model/Sitemap/Sitemap.php +84 -0
- app/code/community/Activo/Xmlsitemap/etc/config.xml +37 -0
- app/etc/modules/Activo_Xmlsitemap.xml +10 -0
- package.xml +18 -0
app/code/community/Activo/Xmlsitemap/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Activo_Xmlsitemap_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
5 |
+
|
app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Catalog/Category.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Activo_Xmlsitemap_Model_Sitemap_Resource_Catalog_Category extends Mage_Sitemap_Model_Resource_Catalog_Category
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Get category collection array
|
6 |
+
*
|
7 |
+
* @param unknown_type $storeId
|
8 |
+
* @return array
|
9 |
+
*/
|
10 |
+
public function getCollection($storeId)
|
11 |
+
{
|
12 |
+
$categories = array();
|
13 |
+
|
14 |
+
$store = Mage::app()->getStore($storeId);
|
15 |
+
/* @var $store Mage_Core_Model_Store */
|
16 |
+
|
17 |
+
if (!$store) {
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
|
21 |
+
$this->_select = $this->_getWriteAdapter()->select()
|
22 |
+
->from($this->getMainTable())
|
23 |
+
->where($this->getIdFieldName() . '=?', $store->getRootCategoryId());
|
24 |
+
$categoryRow = $this->_getWriteAdapter()->fetchRow($this->_select);
|
25 |
+
|
26 |
+
if (!$categoryRow) {
|
27 |
+
return false;
|
28 |
+
}
|
29 |
+
|
30 |
+
$urConditions = array(
|
31 |
+
'e.entity_id=ur.category_id',
|
32 |
+
$this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
|
33 |
+
'ur.product_id IS NULL',
|
34 |
+
$this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
|
35 |
+
);
|
36 |
+
$this->_select = $this->_getWriteAdapter()->select()
|
37 |
+
->from(array('e' => $this->getMainTable()), array($this->getIdFieldName(), 'created_at', 'updated_at'))
|
38 |
+
->joinLeft(
|
39 |
+
array('ur' => $this->getTable('core/url_rewrite')),
|
40 |
+
join(' AND ', $urConditions),
|
41 |
+
array('url'=>'request_path')
|
42 |
+
)
|
43 |
+
->where('e.path LIKE ?', $categoryRow['path'] . '/%');
|
44 |
+
|
45 |
+
$this->_addFilter($storeId, 'is_active', 1);
|
46 |
+
|
47 |
+
$query = $this->_getWriteAdapter()->query($this->_select);
|
48 |
+
while ($row = $query->fetch()) {
|
49 |
+
$category = $this->_prepareCategory($row);
|
50 |
+
$categories[$category->getId()] = $category;
|
51 |
+
}
|
52 |
+
|
53 |
+
return $categories;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Prepare category
|
58 |
+
*
|
59 |
+
* @param array $categoryRow
|
60 |
+
* @return Varien_Object
|
61 |
+
*/
|
62 |
+
protected function _prepareCategory(array $categoryRow)
|
63 |
+
{
|
64 |
+
$category = new Varien_Object();
|
65 |
+
$category->setId($categoryRow[$this->getIdFieldName()]);
|
66 |
+
$categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId();
|
67 |
+
$category->setUrl($categoryUrl);
|
68 |
+
$category->setCreatedAt($categoryRow['created_at']);
|
69 |
+
$category->setUpdatedAt($categoryRow['updated_at']);
|
70 |
+
return $category;
|
71 |
+
}
|
72 |
+
}
|
app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Catalog/Product.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Activo_Xmlsitemap_Model_Sitemap_Resource_Catalog_Product extends Mage_Sitemap_Model_Resource_Catalog_Product
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Get category collection array
|
6 |
+
*
|
7 |
+
* @param unknown_type $storeId
|
8 |
+
* @return array
|
9 |
+
*/
|
10 |
+
public function getCollection($storeId)
|
11 |
+
{
|
12 |
+
$products = array();
|
13 |
+
|
14 |
+
$store = Mage::app()->getStore($storeId);
|
15 |
+
/* @var $store Mage_Core_Model_Store */
|
16 |
+
|
17 |
+
if (!$store) {
|
18 |
+
return false;
|
19 |
+
}
|
20 |
+
|
21 |
+
$urCondions = array(
|
22 |
+
'e.entity_id=ur.product_id',
|
23 |
+
'ur.category_id IS NULL',
|
24 |
+
$this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
|
25 |
+
$this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
|
26 |
+
);
|
27 |
+
$this->_select = $this->_getWriteAdapter()->select()
|
28 |
+
->from(array('e' => $this->getMainTable()), array($this->getIdFieldName(), 'created_at', 'updated_at'))
|
29 |
+
->join(
|
30 |
+
array('w' => $this->getTable('catalog/product_website')),
|
31 |
+
'e.entity_id=w.product_id',
|
32 |
+
array()
|
33 |
+
)
|
34 |
+
->where('w.website_id=?', $store->getWebsiteId())
|
35 |
+
->joinLeft(
|
36 |
+
array('ur' => $this->getTable('core/url_rewrite')),
|
37 |
+
join(' AND ', $urCondions),
|
38 |
+
array('url' => 'request_path')
|
39 |
+
);
|
40 |
+
|
41 |
+
$this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in');
|
42 |
+
$this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in');
|
43 |
+
|
44 |
+
$query = $this->_getWriteAdapter()->query($this->_select);
|
45 |
+
while ($row = $query->fetch()) {
|
46 |
+
$product = $this->_prepareProduct($row);
|
47 |
+
$products[$product->getId()] = $product;
|
48 |
+
}
|
49 |
+
|
50 |
+
return $products;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Prepare product
|
55 |
+
*
|
56 |
+
* @param array $productRow
|
57 |
+
* @return Varien_Object
|
58 |
+
*/
|
59 |
+
protected function _prepareProduct(array $productRow)
|
60 |
+
{
|
61 |
+
$product = new Varien_Object();
|
62 |
+
$product->setId($productRow[$this->getIdFieldName()]);
|
63 |
+
$productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId();
|
64 |
+
$product->setUrl($productUrl);
|
65 |
+
$product->setCreatedAt($productRow['created_at']);
|
66 |
+
$product->setUpdatedAt($productRow['updated_at']);
|
67 |
+
return $product;
|
68 |
+
}
|
69 |
+
}
|
app/code/community/Activo/Xmlsitemap/Model/Sitemap/Resource/Cms/Page.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Activo_Xmlsitemap_Model_Sitemap_Resource_Cms_Page extends Mage_Sitemap_Model_Resource_Cms_Page
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Retrieve cms page collection array
|
6 |
+
*
|
7 |
+
* @param unknown_type $storeId
|
8 |
+
* @return array
|
9 |
+
*/
|
10 |
+
public function getCollection($storeId)
|
11 |
+
{
|
12 |
+
$pages = array();
|
13 |
+
|
14 |
+
$select = $this->_getWriteAdapter()->select()
|
15 |
+
->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'identifier AS url', 'creation_time', 'update_time'))
|
16 |
+
->join(
|
17 |
+
array('store_table' => $this->getTable('cms/page_store')),
|
18 |
+
'main_table.page_id=store_table.page_id',
|
19 |
+
array()
|
20 |
+
)
|
21 |
+
->where('main_table.is_active=1')
|
22 |
+
->where('store_table.store_id IN(?)', array(0, $storeId));
|
23 |
+
$query = $this->_getWriteAdapter()->query($select);
|
24 |
+
while ($row = $query->fetch()) {
|
25 |
+
if ($row['url'] == Mage_Cms_Model_Page::NOROUTE_PAGE_ID) {
|
26 |
+
continue;
|
27 |
+
}
|
28 |
+
$page = $this->_prepareObject($row);
|
29 |
+
$pages[$page->getId()] = $page;
|
30 |
+
}
|
31 |
+
|
32 |
+
return $pages;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Prepare page object
|
37 |
+
*
|
38 |
+
* @param array $data
|
39 |
+
* @return Varien_Object
|
40 |
+
*/
|
41 |
+
protected function _prepareObject(array $data)
|
42 |
+
{
|
43 |
+
$object = new Varien_Object();
|
44 |
+
$object->setId($data[$this->getIdFieldName()]);
|
45 |
+
$object->setUrl($data['url']);
|
46 |
+
$object->setCreatedAt($data['creation_time']);
|
47 |
+
$object->setUpdatedAt($data['update_time']);
|
48 |
+
return $object;
|
49 |
+
}
|
50 |
+
}
|
app/code/community/Activo/Xmlsitemap/Model/Sitemap/Sitemap.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Activo_Xmlsitemap_Model_Sitemap_Sitemap extends Mage_Sitemap_Model_Sitemap
|
3 |
+
{
|
4 |
+
public function generateXml()
|
5 |
+
{
|
6 |
+
$io = new Varien_Io_File();
|
7 |
+
$io->setAllowCreateFolders(true);
|
8 |
+
$io->open(array('path' => $this->getPath()));
|
9 |
+
|
10 |
+
if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
|
11 |
+
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
|
12 |
+
}
|
13 |
+
|
14 |
+
$io->streamOpen($this->getSitemapFilename());
|
15 |
+
|
16 |
+
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
|
17 |
+
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
|
18 |
+
|
19 |
+
$storeId = $this->getStoreId();
|
20 |
+
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
|
21 |
+
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Generate categories sitemap
|
25 |
+
*/
|
26 |
+
$changefreq = (string)Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
|
27 |
+
$priority = (string)Mage::getStoreConfig('sitemap/category/priority', $storeId);
|
28 |
+
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
|
29 |
+
foreach ($collection as $item) {
|
30 |
+
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
|
31 |
+
htmlspecialchars($baseUrl . $item->getUrl()),
|
32 |
+
date('Y-m-d', strtotime($item->getUpdatedAt()!=null ? $item->getUpdatedAt() : $item->getCreatedAt()) ),
|
33 |
+
$changefreq,
|
34 |
+
$priority
|
35 |
+
);
|
36 |
+
$io->streamWrite($xml);
|
37 |
+
}
|
38 |
+
unset($collection);
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Generate products sitemap
|
42 |
+
*/
|
43 |
+
$changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
|
44 |
+
$priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
|
45 |
+
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
|
46 |
+
foreach ($collection as $item) {
|
47 |
+
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
|
48 |
+
htmlspecialchars($baseUrl . $item->getUrl()),
|
49 |
+
date('Y-m-d', strtotime($item->getUpdatedAt()!=null ? $item->getUpdatedAt() : $item->getCreatedAt()) ),
|
50 |
+
$changefreq,
|
51 |
+
$priority
|
52 |
+
);
|
53 |
+
$io->streamWrite($xml);
|
54 |
+
}
|
55 |
+
unset($collection);
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Generate cms pages sitemap
|
59 |
+
*/
|
60 |
+
$changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
|
61 |
+
$priority = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
|
62 |
+
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
|
63 |
+
foreach ($collection as $item) {
|
64 |
+
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
|
65 |
+
htmlspecialchars($baseUrl . $item->getUrl()),
|
66 |
+
date('Y-m-d', strtotime($item->getUpdatedAt()!=null ? $item->getUpdatedAt() : $item->getCreatedAt()) ),
|
67 |
+
$changefreq,
|
68 |
+
$priority
|
69 |
+
);
|
70 |
+
$io->streamWrite($xml);
|
71 |
+
}
|
72 |
+
unset($collection);
|
73 |
+
|
74 |
+
$io->streamWrite('</urlset>');
|
75 |
+
$io->streamClose();
|
76 |
+
|
77 |
+
$this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
|
78 |
+
$this->save();
|
79 |
+
|
80 |
+
return $this;
|
81 |
+
}
|
82 |
+
|
83 |
+
}
|
84 |
+
|
app/code/community/Activo/Xmlsitemap/etc/config.xml
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Activo_Xmlsitemap>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Activo_Xmlsitemap>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<helpers>
|
10 |
+
<xmlsitemap>
|
11 |
+
<class>Activo_Xmlsitemap_Helper</class>
|
12 |
+
</xmlsitemap>
|
13 |
+
</helpers>
|
14 |
+
<models>
|
15 |
+
<xmlsitemap>
|
16 |
+
<class>Activo_Xmlsitemap_Model</class>
|
17 |
+
<resourceModel>xmlsitemap_resource</resourceModel>
|
18 |
+
</xmlsitemap>
|
19 |
+
<sitemap>
|
20 |
+
<rewrite>
|
21 |
+
<sitemap>Activo_Xmlsitemap_Model_Sitemap_Sitemap</sitemap>
|
22 |
+
</rewrite>
|
23 |
+
</sitemap>
|
24 |
+
<sitemap_resource>
|
25 |
+
<rewrite>
|
26 |
+
<catalog_product>Activo_Xmlsitemap_Model_Sitemap_Resource_Catalog_Product</catalog_product>
|
27 |
+
</rewrite>
|
28 |
+
<rewrite>
|
29 |
+
<catalog_category>Activo_Xmlsitemap_Model_Sitemap_Resource_Catalog_Category</catalog_category>
|
30 |
+
</rewrite>
|
31 |
+
<rewrite>
|
32 |
+
<cms_page>Activo_Xmlsitemap_Model_Sitemap_Resource_Cms_Page</cms_page>
|
33 |
+
</rewrite>
|
34 |
+
</sitemap_resource>
|
35 |
+
</models>
|
36 |
+
</global>
|
37 |
+
</config>
|
app/etc/modules/Activo_Xmlsitemap.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Activo_Xmlsitemap>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</Activo_Xmlsitemap>
|
9 |
+
</modules>
|
10 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Activo_Xmlsitemap</name>
|
4 |
+
<version>0.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://extensions.activo.com/license_professional">Commercial</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Updates core Google Sitemap XML generator to use the correct <lastmod> dates. This makes the whole XML Sitemap more usable by search engines.</summary>
|
10 |
+
<description>Updates core Google Sitemap XML generator to use the correct <lastmod> dates. This makes the whole XML Sitemap more usable by search engines.</description>
|
11 |
+
<notes>Initial release with correct <lastmod> dates.</notes>
|
12 |
+
<authors><author><name>Activo Extensions</name><user>activo</user><email>extensions@activo.com</email></author></authors>
|
13 |
+
<date>2013-01-06</date>
|
14 |
+
<time>07:18:46</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Activo"><dir name="Xmlsitemap"><dir><dir name="Helper"><file name="Data.php" hash="7e9a738bbd9ee44ae6b4231b9f625a41"/></dir><dir name="Model"><dir name="Sitemap"><dir name="Resource"><dir name="Catalog"><file name="Category.php" hash="41b7efe21c8a8be7a3b08218a49d7a79"/><file name="Product.php" hash="9da077cb52bc186c11076b9464958b94"/></dir><dir name="Cms"><file name="Page.php" hash="333c87e0ba89c95e18ac90c931371c71"/></dir></dir><file name="Sitemap.php" hash="0a2f094cbe15056326ef530d695acec6"/></dir></dir><dir name="etc"><file name="config.xml" hash="681af8b0a6d79c2a626e0dcd4e602d92"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Activo_Xmlsitemap.xml" hash="c4b0fec6721e50db1c4664b51be42a34"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|