Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Adminhtml_Block_Sitemap
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Action
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Link
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Time
  • Mage_Adminhtml_SitemapController
  • Mage_Sitemap_Helper_Data
  • Mage_Sitemap_Model_Mysql4_Catalog_Category
  • Mage_Sitemap_Model_Mysql4_Catalog_Product
  • Mage_Sitemap_Model_Mysql4_Cms_Page
  • Mage_Sitemap_Model_Mysql4_Sitemap
  • Mage_Sitemap_Model_Mysql4_Sitemap_Collection
  • Mage_Sitemap_Model_Observer
  • Mage_Sitemap_Model_Resource_Catalog_Category
  • Mage_Sitemap_Model_Resource_Catalog_Product
  • Mage_Sitemap_Model_Resource_Cms_Page
  • Mage_Sitemap_Model_Resource_Sitemap
  • Mage_Sitemap_Model_Resource_Sitemap_Collection
  • Mage_Sitemap_Model_Sitemap
  • Overview
  • Package
  • Class
  • Tree
  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 license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Sitemap
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Sitemap model
 30:  *
 31:  * @method Mage_Sitemap_Model_Resource_Sitemap _getResource()
 32:  * @method Mage_Sitemap_Model_Resource_Sitemap getResource()
 33:  * @method string getSitemapType()
 34:  * @method Mage_Sitemap_Model_Sitemap setSitemapType(string $value)
 35:  * @method string getSitemapFilename()
 36:  * @method Mage_Sitemap_Model_Sitemap setSitemapFilename(string $value)
 37:  * @method string getSitemapPath()
 38:  * @method Mage_Sitemap_Model_Sitemap setSitemapPath(string $value)
 39:  * @method string getSitemapTime()
 40:  * @method Mage_Sitemap_Model_Sitemap setSitemapTime(string $value)
 41:  * @method int getStoreId()
 42:  * @method Mage_Sitemap_Model_Sitemap setStoreId(int $value)
 43:  *
 44:  * @category    Mage
 45:  * @package     Mage_Sitemap
 46:  * @author      Magento Core Team <core@magentocommerce.com>
 47:  */
 48: class Mage_Sitemap_Model_Sitemap extends Mage_Core_Model_Abstract
 49: {
 50:     /**
 51:      * Real file path
 52:      *
 53:      * @var string
 54:      */
 55:     protected $_filePath;
 56: 
 57:     /**
 58:      * Init model
 59:      */
 60:     protected function _construct()
 61:     {
 62:         $this->_init('sitemap/sitemap');
 63:     }
 64: 
 65:     protected function _beforeSave()
 66:     {
 67:         $io = new Varien_Io_File();
 68:         $realPath = $io->getCleanPath(Mage::getBaseDir() . '/' . $this->getSitemapPath());
 69: 
 70:         /**
 71:          * Check path is allow
 72:          */
 73:         if (!$io->allowedPath($realPath, Mage::getBaseDir())) {
 74:             Mage::throwException(Mage::helper('sitemap')->__('Please define correct path'));
 75:         }
 76:         /**
 77:          * Check exists and writeable path
 78:          */
 79:         if (!$io->fileExists($realPath, false)) {
 80:             Mage::throwException(Mage::helper('sitemap')->__('Please create the specified folder "%s" before saving the sitemap.', Mage::helper('core')->htmlEscape($this->getSitemapPath())));
 81:         }
 82: 
 83:         if (!$io->isWriteable($realPath)) {
 84:             Mage::throwException(Mage::helper('sitemap')->__('Please make sure that "%s" is writable by web-server.', $this->getSitemapPath()));
 85:         }
 86:         /**
 87:          * Check allow filename
 88:          */
 89:         if (!preg_match('#^[a-zA-Z0-9_\.]+$#', $this->getSitemapFilename())) {
 90:             Mage::throwException(Mage::helper('sitemap')->__('Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in the filename. No spaces or other characters are allowed.'));
 91:         }
 92:         if (!preg_match('#\.xml$#', $this->getSitemapFilename())) {
 93:             $this->setSitemapFilename($this->getSitemapFilename() . '.xml');
 94:         }
 95: 
 96:         $this->setSitemapPath(rtrim(str_replace(str_replace('\\', '/', Mage::getBaseDir()), '', $realPath), '/') . '/');
 97: 
 98:         return parent::_beforeSave();
 99:     }
100: 
101:     /**
102:      * Return real file path
103:      *
104:      * @return string
105:      */
106:     protected function getPath()
107:     {
108:         if (is_null($this->_filePath)) {
109:             $this->_filePath = str_replace('//', '/', Mage::getBaseDir() .
110:                 $this->getSitemapPath());
111:         }
112:         return $this->_filePath;
113:     }
114: 
115:     /**
116:      * Return full file name with path
117:      *
118:      * @return string
119:      */
120:     public function getPreparedFilename()
121:     {
122:         return $this->getPath() . $this->getSitemapFilename();
123:     }
124: 
125:     /**
126:      * Generate XML file
127:      *
128:      * @return Mage_Sitemap_Model_Sitemap
129:      */
130:     public function generateXml()
131:     {
132:         $io = new Varien_Io_File();
133:         $io->setAllowCreateFolders(true);
134:         $io->open(array('path' => $this->getPath()));
135: 
136:         if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
137:             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()));
138:         }
139: 
140:         $io->streamOpen($this->getSitemapFilename());
141: 
142:         $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
143:         $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
144: 
145:         $storeId = $this->getStoreId();
146:         $date    = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
147:         $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
148: 
149:         /**
150:          * Generate categories sitemap
151:          */
152:         $changefreq = (string)Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
153:         $priority   = (string)Mage::getStoreConfig('sitemap/category/priority', $storeId);
154:         $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
155:         foreach ($collection as $item) {
156:             $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
157:                 htmlspecialchars($baseUrl . $item->getUrl()),
158:                 $date,
159:                 $changefreq,
160:                 $priority
161:             );
162:             $io->streamWrite($xml);
163:         }
164:         unset($collection);
165: 
166:         /**
167:          * Generate products sitemap
168:          */
169:         $changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
170:         $priority   = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
171:         $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
172:         foreach ($collection as $item) {
173:             $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
174:                 htmlspecialchars($baseUrl . $item->getUrl()),
175:                 $date,
176:                 $changefreq,
177:                 $priority
178:             );
179:             $io->streamWrite($xml);
180:         }
181:         unset($collection);
182: 
183:         /**
184:          * Generate cms pages sitemap
185:          */
186:         $changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
187:         $priority   = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
188:         $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
189:         foreach ($collection as $item) {
190:             $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
191:                 htmlspecialchars($baseUrl . $item->getUrl()),
192:                 $date,
193:                 $changefreq,
194:                 $priority
195:             );
196:             $io->streamWrite($xml);
197:         }
198:         unset($collection);
199: 
200:         $io->streamWrite('</urlset>');
201:         $io->streamClose();
202: 
203:         $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
204:         $this->save();
205: 
206:         return $this;
207:     }
208: }
209: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0