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
00035 class Mage_Adminhtml_Cms_PageController extends Mage_Adminhtml_Controller_Action
00036 {
00037
00038
00039
00040
00041
00042
00043 protected function _initAction()
00044 {
00045
00046 $this->loadLayout()
00047 ->_setActiveMenu('cms/page')
00048 ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
00049 ->_addBreadcrumb(Mage::helper('cms')->__('Manage Pages'), Mage::helper('cms')->__('Manage Pages'))
00050 ;
00051 return $this;
00052 }
00053
00054
00055
00056
00057 public function indexAction()
00058 {
00059 $this->_initAction()
00060 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_page'))
00061 ->renderLayout();
00062 }
00063
00064
00065
00066
00067 public function newAction()
00068 {
00069
00070 $this->_forward('edit');
00071 }
00072
00073
00074
00075
00076 public function editAction()
00077 {
00078
00079 $id = $this->getRequest()->getParam('page_id');
00080 $model = Mage::getModel('cms/page');
00081
00082
00083 if ($id) {
00084 $model->load($id);
00085 if (! $model->getId()) {
00086 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This page no longer exists'));
00087 $this->_redirect('*/*/');
00088 return;
00089 }
00090 }
00091
00092
00093 $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
00094 if (! empty($data)) {
00095 $model->setData($data);
00096 }
00097
00098
00099 Mage::register('cms_page', $model);
00100
00101
00102 $this->_initAction()
00103 ->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Page') : Mage::helper('cms')->__('New Page'), $id ? Mage::helper('cms')->__('Edit Page') : Mage::helper('cms')->__('New Page'))
00104 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_page_edit')->setData('action', $this->getUrl('*/cms_page/save')))
00105 ->_addLeft($this->getLayout()->createBlock('adminhtml/cms_page_edit_tabs'));
00106
00107 if (Mage::app()->getConfig()->getModuleConfig('Mage_GoogleOptimizer')->is('active', true)
00108 && Mage::helper('googleoptimizer')->isOptimizerActiveForCms()) {
00109 $this->_addJs($this->getLayout()->createBlock('googleoptimizer/js')->setTemplate('googleoptimizer/js.phtml'));
00110 }
00111 $this->renderLayout();
00112 }
00113
00114
00115
00116
00117 public function saveAction()
00118 {
00119
00120 if ($data = $this->getRequest()->getPost()) {
00121
00122 $model = Mage::getModel('cms/page');
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 $model->setData($data);
00135
00136 Mage::dispatchEvent('cms_page_prepare_save', array('page' => $model, 'request' => $this->getRequest()));
00137
00138
00139 try {
00140
00141 $model->save();
00142
00143
00144 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Page was successfully saved'));
00145
00146 Mage::getSingleton('adminhtml/session')->setFormData(false);
00147
00148 if ($this->getRequest()->getParam('back')) {
00149 $this->_redirect('*/*/edit', array('page_id' => $model->getId()));
00150 return;
00151 }
00152
00153 $this->_redirect('*/*/');
00154 return;
00155
00156 } catch (Exception $e) {
00157
00158 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00159
00160 Mage::getSingleton('adminhtml/session')->setFormData($data);
00161
00162 $this->_redirect('*/*/edit', array('page_id' => $this->getRequest()->getParam('page_id')));
00163 return;
00164 }
00165 }
00166 $this->_redirect('*/*/');
00167 }
00168
00169
00170
00171
00172 public function deleteAction()
00173 {
00174
00175 if ($id = $this->getRequest()->getParam('page_id')) {
00176 $title = "";
00177 try {
00178
00179 $model = Mage::getModel('cms/page');
00180 $model->load($id);
00181 $title = $model->getTitle();
00182 $model->delete();
00183
00184 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Page was successfully deleted'));
00185
00186 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'success'));
00187 $this->_redirect('*/*/');
00188 return;
00189
00190 } catch (Exception $e) {
00191 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'fail'));
00192
00193 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00194
00195 $this->_redirect('*/*/edit', array('page_id' => $id));
00196 return;
00197 }
00198 }
00199
00200 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a page to delete'));
00201
00202 $this->_redirect('*/*/');
00203 }
00204
00205
00206
00207
00208
00209
00210 protected function _isAllowed()
00211 {
00212 return Mage::getSingleton('admin/session')->isAllowed('cms/page');
00213 }
00214 }