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_Cms_PageController
  • Mage_Adminhtml_Model_System_Config_Source_Cms_Wysiwyg_Enabled
  • Mage_Cms_Block_Block
  • Mage_Cms_Block_Page
  • Mage_Cms_Block_Widget_Block
  • Mage_Cms_Block_Widget_Page_Link
  • Mage_Cms_Controller_Router
  • Mage_Cms_Helper_Data
  • Mage_Cms_Helper_Page
  • Mage_Cms_Helper_Wysiwyg_Images
  • Mage_Cms_IndexController
  • Mage_Cms_Model_Block
  • Mage_Cms_Model_Mysql4_Block
  • Mage_Cms_Model_Mysql4_Block_Collection
  • Mage_Cms_Model_Mysql4_Page
  • Mage_Cms_Model_Mysql4_Page_Collection
  • Mage_Cms_Model_Mysql4_Page_Service
  • Mage_Cms_Model_Observer
  • Mage_Cms_Model_Page
  • Mage_Cms_Model_Resource_Block
  • Mage_Cms_Model_Resource_Block_Collection
  • Mage_Cms_Model_Resource_Page
  • Mage_Cms_Model_Resource_Page_Collection
  • Mage_Cms_Model_Resource_Page_Service
  • Mage_Cms_Model_Template_Filter
  • Mage_Cms_Model_Wysiwyg_Config
  • Mage_Cms_Model_Wysiwyg_Images_Storage
  • Mage_Cms_Model_Wysiwyg_Images_Storage_Collection
  • Mage_Cms_PageController
  • 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:  * Cms manage pages controller
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Cms
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Adminhtml_Cms_PageController extends Mage_Adminhtml_Controller_Action
 36: {
 37: 
 38:     /**
 39:      * Init actions
 40:      *
 41:      * @return Mage_Adminhtml_Cms_PageController
 42:      */
 43:     protected function _initAction()
 44:     {
 45:         // load layout, set active menu and breadcrumbs
 46:         $this->loadLayout()
 47:             ->_setActiveMenu('cms/page')
 48:             ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
 49:             ->_addBreadcrumb(Mage::helper('cms')->__('Manage Pages'), Mage::helper('cms')->__('Manage Pages'))
 50:         ;
 51:         return $this;
 52:     }
 53: 
 54:     /**
 55:      * Index action
 56:      */
 57:     public function indexAction()
 58:     {
 59:         $this->_title($this->__('CMS'))
 60:              ->_title($this->__('Pages'))
 61:              ->_title($this->__('Manage Content'));
 62: 
 63:         $this->_initAction();
 64:         $this->renderLayout();
 65:     }
 66: 
 67:     /**
 68:      * Create new CMS page
 69:      */
 70:     public function newAction()
 71:     {
 72:         // the same form is used to create and edit
 73:         $this->_forward('edit');
 74:     }
 75: 
 76:     /**
 77:      * Edit CMS page
 78:      */
 79:     public function editAction()
 80:     {
 81:         $this->_title($this->__('CMS'))
 82:              ->_title($this->__('Pages'))
 83:              ->_title($this->__('Manage Content'));
 84: 
 85:         // 1. Get ID and create model
 86:         $id = $this->getRequest()->getParam('page_id');
 87:         $model = Mage::getModel('cms/page');
 88: 
 89:         // 2. Initial checking
 90:         if ($id) {
 91:             $model->load($id);
 92:             if (! $model->getId()) {
 93:                 Mage::getSingleton('adminhtml/session')->addError(
 94:                     Mage::helper('cms')->__('This page no longer exists.'));
 95:                 $this->_redirect('*/*/');
 96:                 return;
 97:             }
 98:         }
 99: 
100:         $this->_title($model->getId() ? $model->getTitle() : $this->__('New Page'));
101: 
102:         // 3. Set entered data if was error when we do save
103:         $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
104:         if (! empty($data)) {
105:             $model->setData($data);
106:         }
107: 
108:         // 4. Register model to use later in blocks
109:         Mage::register('cms_page', $model);
110: 
111:         // 5. Build edit form
112:         $this->_initAction()
113:             ->_addBreadcrumb(
114:                 $id ? Mage::helper('cms')->__('Edit Page')
115:                     : Mage::helper('cms')->__('New Page'),
116:                 $id ? Mage::helper('cms')->__('Edit Page')
117:                     : Mage::helper('cms')->__('New Page'));
118: 
119:         $this->renderLayout();
120:     }
121: 
122:     /**
123:      * Save action
124:      */
125:     public function saveAction()
126:     {
127:         // check if data sent
128:         if ($data = $this->getRequest()->getPost()) {
129:             $data = $this->_filterPostData($data);
130:             //init model and set data
131:             $model = Mage::getModel('cms/page');
132: 
133:             if ($id = $this->getRequest()->getParam('page_id')) {
134:                 $model->load($id);
135:             }
136: 
137:             $model->setData($data);
138: 
139:             Mage::dispatchEvent('cms_page_prepare_save', array('page' => $model, 'request' => $this->getRequest()));
140: 
141:             //validating
142:             if (!$this->_validatePostData($data)) {
143:                 $this->_redirect('*/*/edit', array('page_id' => $model->getId(), '_current' => true));
144:                 return;
145:             }
146: 
147:             // try to save it
148:             try {
149:                 // save the data
150:                 $model->save();
151: 
152:                 // display success message
153:                 Mage::getSingleton('adminhtml/session')->addSuccess(
154:                     Mage::helper('cms')->__('The page has been saved.'));
155:                 // clear previously saved data from session
156:                 Mage::getSingleton('adminhtml/session')->setFormData(false);
157:                 // check if 'Save and Continue'
158:                 if ($this->getRequest()->getParam('back')) {
159:                     $this->_redirect('*/*/edit', array('page_id' => $model->getId(), '_current'=>true));
160:                     return;
161:                 }
162:                 // go to grid
163:                 $this->_redirect('*/*/');
164:                 return;
165: 
166:             } catch (Mage_Core_Exception $e) {
167:                 $this->_getSession()->addError($e->getMessage());
168:             }
169:             catch (Exception $e) {
170:                 $this->_getSession()->addException($e,
171:                     Mage::helper('cms')->__('An error occurred while saving the page.'));
172:             }
173: 
174:             $this->_getSession()->setFormData($data);
175:             $this->_redirect('*/*/edit', array('page_id' => $this->getRequest()->getParam('page_id')));
176:             return;
177:         }
178:         $this->_redirect('*/*/');
179:     }
180: 
181:     /**
182:      * Delete action
183:      */
184:     public function deleteAction()
185:     {
186:         // check if we know what should be deleted
187:         if ($id = $this->getRequest()->getParam('page_id')) {
188:             $title = "";
189:             try {
190:                 // init model and delete
191:                 $model = Mage::getModel('cms/page');
192:                 $model->load($id);
193:                 $title = $model->getTitle();
194:                 $model->delete();
195:                 // display success message
196:                 Mage::getSingleton('adminhtml/session')->addSuccess(
197:                     Mage::helper('cms')->__('The page has been deleted.'));
198:                 // go to grid
199:                 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'success'));
200:                 $this->_redirect('*/*/');
201:                 return;
202: 
203:             } catch (Exception $e) {
204:                 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'fail'));
205:                 // display error message
206:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
207:                 // go back to edit form
208:                 $this->_redirect('*/*/edit', array('page_id' => $id));
209:                 return;
210:             }
211:         }
212:         // display error message
213:         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a page to delete.'));
214:         // go to grid
215:         $this->_redirect('*/*/');
216:     }
217: 
218:     /**
219:      * Check the permission to run it
220:      *
221:      * @return boolean
222:      */
223:     protected function _isAllowed()
224:     {
225:         switch ($this->getRequest()->getActionName()) {
226:             case 'new':
227:             case 'save':
228:                 return Mage::getSingleton('admin/session')->isAllowed('cms/page/save');
229:                 break;
230:             case 'delete':
231:                 return Mage::getSingleton('admin/session')->isAllowed('cms/page/delete');
232:                 break;
233:             default:
234:                 return Mage::getSingleton('admin/session')->isAllowed('cms/page');
235:                 break;
236:         }
237:     }
238: 
239:     /**
240:      * Filtering posted data. Converting localized data if needed
241:      *
242:      * @param array
243:      * @return array
244:      */
245:     protected function _filterPostData($data)
246:     {
247:         $data = $this->_filterDates($data, array('custom_theme_from', 'custom_theme_to'));
248:         return $data;
249:     }
250: 
251:     /**
252:      * Validate post data
253:      *
254:      * @param array $data
255:      * @return bool     Return FALSE if someone item is invalid
256:      */
257:     protected function _validatePostData($data)
258:     {
259:         $errorNo = true;
260:         if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) {
261:             /** @var $validatorCustomLayout Mage_Adminhtml_Model_LayoutUpdate_Validator */
262:             $validatorCustomLayout = Mage::getModel('adminhtml/layoutUpdate_validator');
263:             if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) {
264:                 $errorNo = false;
265:             }
266:             if (!empty($data['custom_layout_update_xml'])
267:             && !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])) {
268:                 $errorNo = false;
269:             }
270:             foreach ($validatorCustomLayout->getMessages() as $message) {
271:                 $this->_getSession()->addError($message);
272:             }
273:         }
274:         return $errorNo;
275:     }
276: }
277: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0