PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dnejedly/eaparts
PHP | 126 lines | 53 code | 15 blank | 58 comment | 7 complexity | 1f351b246b6c179ec0f68c6a3321b0be 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@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_Page
  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. * Page layout helper
  28. *
  29. * @category Mage
  30. * @package Mage_Page
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Page_Helper_Layout extends Mage_Core_Helper_Abstract
  34. {
  35. /**
  36. * Apply page layout handle
  37. *
  38. * @param string $pageLayout
  39. * @return Mage_Page_Helper_Layout
  40. */
  41. public function applyHandle($pageLayout)
  42. {
  43. $pageLayout = $this->_getConfig()->getPageLayout($pageLayout);
  44. if (!$pageLayout) {
  45. return $this;
  46. }
  47. $this->getLayout()
  48. ->getUpdate()
  49. ->addHandle($pageLayout->getLayoutHandle());
  50. return $this;
  51. }
  52. /**
  53. * Apply page layout template
  54. * (for old design packages)
  55. *
  56. * @param string $pageLayout
  57. * @return Mage_Page_Helper_Layout
  58. */
  59. public function applyTemplate($pageLayout = null)
  60. {
  61. if ($pageLayout === null) {
  62. $pageLayout = $this->getCurrentPageLayout();
  63. } else {
  64. $pageLayout = $this->_getConfig()->getPageLayout($pageLayout);
  65. }
  66. if (!$pageLayout) {
  67. return $this;
  68. }
  69. if ($this->getLayout()->getBlock('root') &&
  70. !$this->getLayout()->getBlock('root')->getIsHandle()) {
  71. // If not applied handle
  72. $this->getLayout()
  73. ->getBlock('root')
  74. ->setTemplate($pageLayout->getTemplate());
  75. }
  76. return $this;
  77. }
  78. /**
  79. * Retrieve current applied page layout
  80. *
  81. * @return Varien_Object|boolean
  82. */
  83. public function getCurrentPageLayout()
  84. {
  85. if ($this->getLayout()->getBlock('root') &&
  86. $this->getLayout()->getBlock('root')->getLayoutCode()) {
  87. return $this->_getConfig()->getPageLayout($this->getLayout()->getBlock('root')->getLayoutCode());
  88. }
  89. // All loaded handles
  90. $handles = $this->getLayout()->getUpdate()->getHandles();
  91. // Handles used in page layouts
  92. $pageLayoutHandles = $this->_getConfig()->getPageLayoutHandles();
  93. // Applied page layout handles
  94. $appliedHandles = array_intersect($handles, $pageLayoutHandles);
  95. if (empty($appliedHandles)) {
  96. return false;
  97. }
  98. $currentHandle = array_pop($appliedHandles);
  99. $layoutCode = array_search($currentHandle, $pageLayoutHandles, true);
  100. return $this->_getConfig()->getPageLayout($layoutCode);
  101. }
  102. /**
  103. * Retrieve page config
  104. *
  105. * @return Mage_Page_Model_Config
  106. */
  107. protected function _getConfig()
  108. {
  109. return Mage::getSingleton('page/config');
  110. }
  111. }