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_Adminhtml
 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:  * Google sitemap controller
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Sitemap
 33:  */
 34: class Mage_Adminhtml_SitemapController extends  Mage_Adminhtml_Controller_Action
 35: {
 36:     /**
 37:      * Init actions
 38:      *
 39:      * @return Mage_Adminhtml_SitemapController
 40:      */
 41:     protected function _initAction()
 42:     {
 43:         // load layout, set active menu and breadcrumbs
 44:         $this->loadLayout()
 45:             ->_setActiveMenu('catalog/system_sitemap')
 46:             ->_addBreadcrumb(
 47:                 Mage::helper('catalog')->__('Catalog'),
 48:                 Mage::helper('catalog')->__('Catalog'))
 49:             ->_addBreadcrumb(
 50:                 Mage::helper('sitemap')->__('Google Sitemap'),
 51:                 Mage::helper('sitemap')->__('Google Sitemap'))
 52:         ;
 53:         return $this;
 54:     }
 55: 
 56:     /**
 57:      * Index action
 58:      */
 59:     public function indexAction()
 60:     {
 61:         $this->_title($this->__('Catalog'))->_title($this->__('Google Sitemaps'));
 62: 
 63:         $this->_initAction()
 64:             ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap'))
 65:             ->renderLayout();
 66:     }
 67: 
 68:     /**
 69:      * Create new sitemap
 70:      */
 71:     public function newAction()
 72:     {
 73:         // the same form is used to create and edit
 74:         $this->_forward('edit');
 75:     }
 76: 
 77:     /**
 78:      * Edit sitemap
 79:      */
 80:     public function editAction()
 81:     {
 82:         $this->_title($this->__('Catalog'))->_title($this->__('Google Sitemaps'));
 83: 
 84:         // 1. Get ID and create model
 85:         $id = $this->getRequest()->getParam('sitemap_id');
 86:         $model = Mage::getModel('sitemap/sitemap');
 87: 
 88:         // 2. Initial checking
 89:         if ($id) {
 90:             $model->load($id);
 91:             if (! $model->getId()) {
 92:                 Mage::getSingleton('adminhtml/session')->addError(
 93:                     Mage::helper('sitemap')->__('This sitemap no longer exists.'));
 94:                 $this->_redirect('*/*/');
 95:                 return;
 96:             }
 97:         }
 98: 
 99:         $this->_title($model->getId() ? $model->getSitemapFilename() : $this->__('New Sitemap'));
100: 
101:         // 3. Set entered data if was error when we do save
102:         $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
103:         if (! empty($data)) {
104:             $model->setData($data);
105:         }
106: 
107:         // 4. Register model to use later in blocks
108:         Mage::register('sitemap_sitemap', $model);
109: 
110:         // 5. Build edit form
111:         $this->_initAction()
112:             ->_addBreadcrumb(
113:                 $id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'),
114:                 $id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'))
115:             ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap_edit'))
116:             ->renderLayout();
117:     }
118: 
119:     /**
120:      * Save action
121:      */
122:     public function saveAction()
123:     {
124:         // check if data sent
125:         if ($data = $this->getRequest()->getPost()) {
126:             // init model and set data
127:             $model = Mage::getModel('sitemap/sitemap');
128: 
129:             //validate path to generate
130:             if (!empty($data['sitemap_filename']) && !empty($data['sitemap_path'])) {
131:                 $path = rtrim($data['sitemap_path'], '\\/')
132:                       . DS . $data['sitemap_filename'];
133:                 /** @var $validator Mage_Core_Model_File_Validator_AvailablePath */
134:                 $validator = Mage::getModel('core/file_validator_availablePath');
135:                 /** @var $helper Mage_Adminhtml_Helper_Catalog */
136:                 $helper = Mage::helper('adminhtml/catalog');
137:                 $validator->setPaths($helper->getSitemapValidPaths());
138:                 if (!$validator->isValid($path)) {
139:                     foreach ($validator->getMessages() as $message) {
140:                         Mage::getSingleton('adminhtml/session')->addError($message);
141:                     }
142:                     // save data in session
143:                     Mage::getSingleton('adminhtml/session')->setFormData($data);
144:                     // redirect to edit form
145:                     $this->_redirect('*/*/edit', array(
146:                         'sitemap_id' => $this->getRequest()->getParam('sitemap_id')));
147:                     return;
148:                 }
149:             }
150: 
151:             if ($this->getRequest()->getParam('sitemap_id')) {
152:                 $model ->load($this->getRequest()->getParam('sitemap_id'));
153: 
154:                 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
155:                     unlink($model->getPreparedFilename());
156:                 }
157:             }
158: 
159:             $model->setData($data);
160: 
161:             // try to save it
162:             try {
163:                 // save the data
164:                 $model->save();
165:                 // display success message
166:                 Mage::getSingleton('adminhtml/session')->addSuccess(
167:                     Mage::helper('sitemap')->__('The sitemap has been saved.'));
168:                 // clear previously saved data from session
169:                 Mage::getSingleton('adminhtml/session')->setFormData(false);
170: 
171:                 // check if 'Save and Continue'
172:                 if ($this->getRequest()->getParam('back')) {
173:                     $this->_redirect('*/*/edit', array('sitemap_id' => $model->getId()));
174:                     return;
175:                 }
176:                 // go to grid or forward to generate action
177:                 if ($this->getRequest()->getParam('generate')) {
178:                     $this->getRequest()->setParam('sitemap_id', $model->getId());
179:                     $this->_forward('generate');
180:                     return;
181:                 }
182:                 $this->_redirect('*/*/');
183:                 return;
184: 
185:             } catch (Exception $e) {
186:                 // display error message
187:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
188:                 // save data in session
189:                 Mage::getSingleton('adminhtml/session')->setFormData($data);
190:                 // redirect to edit form
191:                 $this->_redirect('*/*/edit', array(
192:                     'sitemap_id' => $this->getRequest()->getParam('sitemap_id')));
193:                 return;
194:             }
195:         }
196:         $this->_redirect('*/*/');
197: 
198:     }
199: 
200:     /**
201:      * Delete action
202:      */
203:     public function deleteAction()
204:     {
205:         // check if we know what should be deleted
206:         if ($id = $this->getRequest()->getParam('sitemap_id')) {
207:             try {
208:                 // init model and delete
209:                 $model = Mage::getModel('sitemap/sitemap');
210:                 $model->setId($id);
211:                 // init and load sitemap model
212: 
213:                 /* @var $sitemap Mage_Sitemap_Model_Sitemap */
214:                 $model->load($id);
215:                 // delete file
216:                 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
217:                     unlink($model->getPreparedFilename());
218:                 }
219:                 $model->delete();
220:                 // display success message
221:                 Mage::getSingleton('adminhtml/session')->addSuccess(
222:                     Mage::helper('sitemap')->__('The sitemap has been deleted.'));
223:                 // go to grid
224:                 $this->_redirect('*/*/');
225:                 return;
226: 
227:             } catch (Exception $e) {
228:                 // display error message
229:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
230:                 // go back to edit form
231:                 $this->_redirect('*/*/edit', array('sitemap_id' => $id));
232:                 return;
233:             }
234:         }
235:         // display error message
236:         Mage::getSingleton('adminhtml/session')->addError(
237:             Mage::helper('sitemap')->__('Unable to find a sitemap to delete.'));
238:         // go to grid
239:         $this->_redirect('*/*/');
240:     }
241: 
242:     /**
243:      * Generate sitemap
244:      */
245:     public function generateAction()
246:     {
247:         // init and load sitemap model
248:         $id = $this->getRequest()->getParam('sitemap_id');
249:         $sitemap = Mage::getModel('sitemap/sitemap');
250:         /* @var $sitemap Mage_Sitemap_Model_Sitemap */
251:         $sitemap->load($id);
252:         // if sitemap record exists
253:         if ($sitemap->getId()) {
254:             try {
255:                 $sitemap->generateXml();
256: 
257:                 $this->_getSession()->addSuccess(
258:                     Mage::helper('sitemap')->__('The sitemap "%s" has been generated.', $sitemap->getSitemapFilename()));
259:             }
260:             catch (Mage_Core_Exception $e) {
261:                 $this->_getSession()->addError($e->getMessage());
262:             }
263:             catch (Exception $e) {
264:                 $this->_getSession()->addException($e,
265:                     Mage::helper('sitemap')->__('Unable to generate the sitemap.'));
266:             }
267:         } else {
268:             $this->_getSession()->addError(
269:                 Mage::helper('sitemap')->__('Unable to find a sitemap to generate.'));
270:         }
271: 
272:         // go to grid
273:         $this->_redirect('*/*/');
274:     }
275: 
276:     /**
277:      * Check the permission to run it
278:      *
279:      * @return boolean
280:      */
281:     protected function _isAllowed()
282:     {
283:         return Mage::getSingleton('admin/session')->isAllowed('catalog/sitemap');
284:     }
285: }
286: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0