1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Cms_Helper_Page extends Mage_Core_Helper_Abstract
36: {
37: const XML_PATH_NO_ROUTE_PAGE = 'web/default/cms_no_route';
38: const XML_PATH_NO_COOKIES_PAGE = 'web/default/cms_no_cookies';
39: const XML_PATH_HOME_PAGE = 'web/default/cms_home_page';
40:
41: 42: 43: 44: 45: 46: 47: 48: 49:
50: public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId = null)
51: {
52: return $this->_renderPage($action, $pageId);
53: }
54:
55: 56: 57: 58: 59: 60: 61: 62:
63: protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
64: {
65:
66: $page = Mage::getSingleton('cms/page');
67: if (!is_null($pageId) && $pageId!==$page->getId()) {
68: $delimeterPosition = strrpos($pageId, '|');
69: if ($delimeterPosition) {
70: $pageId = substr($pageId, 0, $delimeterPosition);
71: }
72:
73: $page->setStoreId(Mage::app()->getStore()->getId());
74: if (!$page->load($pageId)) {
75: return false;
76: }
77: }
78:
79: if (!$page->getId()) {
80: return false;
81: }
82:
83: $inRange = Mage::app()->getLocale()
84: ->isStoreDateInInterval(null, $page->getCustomThemeFrom(), $page->getCustomThemeTo());
85:
86: if ($page->getCustomTheme()) {
87: if ($inRange) {
88: list($package, $theme) = explode('/', $page->getCustomTheme());
89: Mage::getSingleton('core/design_package')
90: ->setPackageName($package)
91: ->setTheme($theme);
92: }
93: }
94:
95: $action->getLayout()->getUpdate()
96: ->addHandle('default')
97: ->addHandle('cms_page');
98:
99: $action->addActionLayoutHandles();
100: if ($page->getRootTemplate()) {
101: $handle = ($page->getCustomRootTemplate()
102: && $page->getCustomRootTemplate() != 'empty'
103: && $inRange) ? $page->getCustomRootTemplate() : $page->getRootTemplate();
104: $action->getLayout()->helper('page/layout')->applyHandle($handle);
105: }
106:
107: Mage::dispatchEvent('cms_page_render', array('page' => $page, 'controller_action' => $action));
108:
109: $action->loadLayoutUpdates();
110: $layoutUpdate = ($page->getCustomLayoutUpdateXml() && $inRange)
111: ? $page->getCustomLayoutUpdateXml() : $page->getLayoutUpdateXml();
112: $action->getLayout()->getUpdate()->addUpdate($layoutUpdate);
113: $action->generateLayoutXml()->generateLayoutBlocks();
114:
115: $contentHeadingBlock = $action->getLayout()->getBlock('page_content_heading');
116: if ($contentHeadingBlock) {
117: $contentHeading = $this->escapeHtml($page->getContentHeading());
118: $contentHeadingBlock->setContentHeading($contentHeading);
119: }
120:
121: if ($page->getRootTemplate()) {
122: $action->getLayout()->helper('page/layout')
123: ->applyTemplate($page->getRootTemplate());
124: }
125:
126:
127: $messageBlock = $action->getLayout()->getMessagesBlock();
128: foreach (array('catalog/session', 'checkout/session', 'customer/session') as $storageType) {
129: $storage = Mage::getSingleton($storageType);
130: if ($storage) {
131: $messageBlock->addStorageType($storageType);
132: $messageBlock->addMessages($storage->getMessages(true));
133: }
134: }
135:
136: if ($renderLayout) {
137: $action->renderLayout();
138: }
139:
140: return true;
141: }
142:
143: 144: 145: 146: 147: 148: 149: 150: 151: 152:
153: public function renderPageExtended(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
154: {
155: return $this->_renderPage($action, $pageId, $renderLayout);
156: }
157:
158: 159: 160: 161: 162: 163:
164: public function getPageUrl($pageId = null)
165: {
166: $page = Mage::getModel('cms/page');
167: if (!is_null($pageId) && $pageId !== $page->getId()) {
168: $page->setStoreId(Mage::app()->getStore()->getId());
169: if (!$page->load($pageId)) {
170: return null;
171: }
172: }
173:
174: if (!$page->getId()) {
175: return null;
176: }
177:
178: return Mage::getUrl(null, array('_direct' => $page->getIdentifier()));
179: }
180: }
181: