PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Cms/Helper/Page.php

https://bitbucket.org/ttphong2612/billigastamplar-new.se
PHP | 180 lines | 93 code | 22 blank | 65 comment | 20 complexity | 9dbd6afbf7f7fc1020ab6bf2e5308de1 MD5 | raw file
  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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Cms
  23. * @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * CMS Page Helper
  28. *
  29. * @category Mage
  30. * @package Mage_Cms
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Cms_Helper_Page extends Mage_Core_Helper_Abstract
  34. {
  35. const XML_PATH_NO_ROUTE_PAGE = 'web/default/cms_no_route';
  36. const XML_PATH_NO_COOKIES_PAGE = 'web/default/cms_no_cookies';
  37. const XML_PATH_HOME_PAGE = 'web/default/cms_home_page';
  38. /**
  39. * Renders CMS page on front end
  40. *
  41. * Call from controller action
  42. *
  43. * @param Mage_Core_Controller_Front_Action $action
  44. * @param integer $pageId
  45. * @return boolean
  46. */
  47. public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId = null)
  48. {
  49. return $this->_renderPage($action, $pageId);
  50. }
  51. /**
  52. * Renders CMS page
  53. *
  54. * @param Mage_Core_Controller_Front_Action $action
  55. * @param integer $pageId
  56. * @param bool $renderLayout
  57. * @return boolean
  58. */
  59. protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
  60. {
  61. $page = Mage::getSingleton('cms/page');
  62. if (!is_null($pageId) && $pageId!==$page->getId()) {
  63. $delimeterPosition = strrpos($pageId, '|');
  64. if ($delimeterPosition) {
  65. $pageId = substr($pageId, 0, $delimeterPosition);
  66. }
  67. $page->setStoreId(Mage::app()->getStore()->getId());
  68. if (!$page->load($pageId)) {
  69. return false;
  70. }
  71. }
  72. if (!$page->getId()) {
  73. return false;
  74. }
  75. $inRange = Mage::app()->getLocale()
  76. ->isStoreDateInInterval(null, $page->getCustomThemeFrom(), $page->getCustomThemeTo());
  77. if ($page->getCustomTheme()) {
  78. if ($inRange) {
  79. list($package, $theme) = explode('/', $page->getCustomTheme());
  80. Mage::getSingleton('core/design_package')
  81. ->setPackageName($package)
  82. ->setTheme($theme);
  83. }
  84. }
  85. $action->getLayout()->getUpdate()
  86. ->addHandle('default')
  87. ->addHandle('cms_page');
  88. $action->addActionLayoutHandles();
  89. if ($page->getRootTemplate()) {
  90. $handle = ($page->getCustomRootTemplate()
  91. && $page->getCustomRootTemplate() != 'empty'
  92. && $inRange) ? $page->getCustomRootTemplate() : $page->getRootTemplate();
  93. $action->getLayout()->helper('page/layout')->applyHandle($handle);
  94. }
  95. Mage::dispatchEvent('cms_page_render', array('page' => $page, 'controller_action' => $action));
  96. $action->loadLayoutUpdates();
  97. $layoutUpdate = ($page->getCustomLayoutUpdateXml() && $inRange)
  98. ? $page->getCustomLayoutUpdateXml() : $page->getLayoutUpdateXml();
  99. $action->getLayout()->getUpdate()->addUpdate($layoutUpdate);
  100. $action->generateLayoutXml()->generateLayoutBlocks();
  101. $contentHeadingBlock = $action->getLayout()->getBlock('page_content_heading');
  102. if ($contentHeadingBlock) {
  103. $contentHeading = $this->escapeHtml($page->getContentHeading());
  104. $contentHeadingBlock->setContentHeading($contentHeading);
  105. }
  106. if ($page->getRootTemplate()) {
  107. $action->getLayout()->helper('page/layout')
  108. ->applyTemplate($page->getRootTemplate());
  109. }
  110. /* @TODO: Move catalog and checkout storage types to appropriate modules */
  111. $messageBlock = $action->getLayout()->getMessagesBlock();
  112. foreach (array('catalog/session', 'checkout/session', 'customer/session') as $storageType) {
  113. $storage = Mage::getSingleton($storageType);
  114. if ($storage) {
  115. $messageBlock->addStorageType($storageType);
  116. $messageBlock->addMessages($storage->getMessages(true));
  117. }
  118. }
  119. if ($renderLayout) {
  120. $action->renderLayout();
  121. }
  122. return true;
  123. }
  124. /**
  125. * Renders CMS Page with more flexibility then original renderPage function.
  126. * Allows to use also backend action as first parameter.
  127. * Also takes third parameter which allows not run renderLayout method.
  128. *
  129. * @param Mage_Core_Controller_Varien_Action $action
  130. * @param $pageId
  131. * @param $renderLayout
  132. * @return bool
  133. */
  134. public function renderPageExtended(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
  135. {
  136. return $this->_renderPage($action, $pageId, $renderLayout);
  137. }
  138. /**
  139. * Retrieve page direct URL
  140. *
  141. * @param string $pageId
  142. * @return string
  143. */
  144. public function getPageUrl($pageId = null)
  145. {
  146. $page = Mage::getModel('cms/page');
  147. if (!is_null($pageId) && $pageId !== $page->getId()) {
  148. $page->setStoreId(Mage::app()->getStore()->getId());
  149. if (!$page->load($pageId)) {
  150. return null;
  151. }
  152. }
  153. if (!$page->getId()) {
  154. return null;
  155. }
  156. return Mage::getUrl(null, array('_direct' => $page->getIdentifier()));
  157. }
  158. }