00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_SitemapController extends Mage_Adminhtml_Controller_Action
00035 {
00036
00037
00038
00039
00040
00041 protected function _initAction()
00042 {
00043
00044 $this->loadLayout()
00045 ->_setActiveMenu('catalog/system_sitemap')
00046 ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog'))
00047 ->_addBreadcrumb(Mage::helper('sitemap')->__('Google Sitemap'), Mage::helper('sitemap')->__('Google Sitemap'))
00048 ;
00049 return $this;
00050 }
00051
00052
00053
00054
00055 public function indexAction()
00056 {
00057 $this->_initAction()
00058 ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap'))
00059 ->renderLayout();
00060 }
00061
00062
00063
00064
00065 public function newAction()
00066 {
00067
00068 $this->_forward('edit');
00069 }
00070
00071
00072
00073
00074 public function editAction()
00075 {
00076
00077 $id = $this->getRequest()->getParam('sitemap_id');
00078 $model = Mage::getModel('sitemap/sitemap');
00079
00080
00081 if ($id) {
00082 $model->load($id);
00083 if (! $model->getId()) {
00084 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('sitemap')->__('This sitemap no longer exists'));
00085 $this->_redirect('*/*/');
00086 return;
00087 }
00088 }
00089
00090
00091 $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
00092 if (! empty($data)) {
00093 $model->setData($data);
00094 }
00095
00096
00097 Mage::register('sitemap_sitemap', $model);
00098
00099
00100 $this->_initAction()
00101 ->_addBreadcrumb($id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'), $id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'))
00102 ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap_edit'))
00103 ->renderLayout();
00104 }
00105
00106
00107
00108
00109 public function saveAction()
00110 {
00111
00112 if ($data = $this->getRequest()->getPost()) {
00113
00114 $model = Mage::getModel('sitemap/sitemap');
00115
00116 if ($this->getRequest()->getParam('sitemap_id')) {
00117 $model ->load($this->getRequest()->getParam('sitemap_id'));
00118
00119 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
00120 unlink($model->getPreparedFilename());
00121 }
00122 }
00123
00124
00125 $model->setData($data);
00126
00127
00128 try {
00129
00130 $model->save();
00131
00132 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sitemap')->__('Sitemap was successfully saved'));
00133
00134 Mage::getSingleton('adminhtml/session')->setFormData(false);
00135
00136
00137 if ($this->getRequest()->getParam('back')) {
00138 $this->_redirect('*/*/edit', array('sitemap_id' => $model->getId()));
00139 return;
00140 }
00141
00142 if ($this->getRequest()->getParam('generate')) {
00143 $this->getRequest()->setParam('sitemap_id', $model->getId());
00144 $this->_forward('generate');
00145 return;
00146 }
00147 $this->_redirect('*/*/');
00148 return;
00149
00150 } catch (Exception $e) {
00151
00152 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00153
00154 Mage::getSingleton('adminhtml/session')->setFormData($data);
00155
00156 $this->_redirect('*/*/edit', array('sitemap_id' => $this->getRequest()->getParam('sitemap_id')));
00157 return;
00158 }
00159 }
00160 $this->_redirect('*/*/');
00161
00162 }
00163
00164
00165
00166
00167 public function deleteAction()
00168 {
00169
00170 if ($id = $this->getRequest()->getParam('sitemap_id')) {
00171 try {
00172
00173 $model = Mage::getModel('sitemap/sitemap');
00174 $model->setId($id);
00175
00176
00177
00178 $model->load($id);
00179
00180 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
00181 unlink($model->getPreparedFilename());
00182 }
00183 $model->delete();
00184
00185 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sitemap')->__('Sitemap was successfully deleted'));
00186
00187 $this->_redirect('*/*/');
00188 return;
00189
00190 } catch (Exception $e) {
00191
00192 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00193
00194 $this->_redirect('*/*/edit', array('sitemap_id' => $id));
00195 return;
00196 }
00197 }
00198
00199 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('sitemap')->__('Unable to find a sitemap to delete'));
00200
00201 $this->_redirect('*/*/');
00202 }
00203
00204
00205
00206
00207 public function generateAction()
00208 {
00209
00210 $id = $this->getRequest()->getParam('sitemap_id');
00211 $sitemap = Mage::getModel('sitemap/sitemap');
00212
00213 $sitemap->load($id);
00214
00215 if ($sitemap->getId()) {
00216 try {
00217 $sitemap->generateXml();
00218
00219 $this->_getSession()->addSuccess(Mage::helper('sitemap')->__('Sitemap "%s" has been successfully generated', $sitemap->getSitemapFilename()));
00220 }
00221 catch (Mage_Core_Exception $e) {
00222 $this->_getSession()->addError($e->getMessage());
00223 }
00224 catch (Exception $e) {
00225 $this->_getSession()->addException($e, Mage::helper('sitemap')->__('Unable to generate a sitemap'));
00226 }
00227 }
00228 else {
00229 $this->_getSession()->addError(Mage::helper('sitemap')->__('Unable to find a sitemap to generate'));
00230 }
00231
00232
00233 $this->_redirect('*/*/');
00234 }
00235
00236
00237
00238
00239
00240
00241 protected function _isAllowed()
00242 {
00243 return Mage::getSingleton('admin/session')->isAllowed('catalog/sitemap');
00244 }
00245 }