PageRenderTime 28ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php

https://bitbucket.org/acidel/buykoala
PHP | 168 lines | 107 code | 30 blank | 31 comment | 17 complexity | f20245da11576f35464d5f213c321ca1 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_Adminhtml
  23. * @copyright Copyright (c) 2011 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. * Admin system config sturtup page
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Model_System_Config_Source_Admin_Page
  34. {
  35. protected $_url;
  36. public function toOptionArray()
  37. {
  38. $options = array();
  39. $menu = $this->_buildMenuArray();
  40. $this->_createOptions($options, $menu);
  41. return $options;
  42. }
  43. protected function _createOptions(&$optionArray, $menuNode)
  44. {
  45. $nonEscapableNbspChar = html_entity_decode('&#160;', ENT_NOQUOTES, 'UTF-8');
  46. foreach ($menuNode as $menu) {
  47. if (!empty($menu['url'])) {
  48. $optionArray[] = array(
  49. 'label' => str_repeat($nonEscapableNbspChar, ($menu['level'] * 4)) . $menu['label'],
  50. 'value' => $menu['path'],
  51. );
  52. if (isset($menu['children'])) {
  53. $this->_createOptions($optionArray, $menu['children']);
  54. }
  55. }
  56. else {
  57. $children = array();
  58. if(isset($menu['children'])) {
  59. $this->_createOptions($children, $menu['children']);
  60. }
  61. $optionArray[] = array(
  62. 'label' => str_repeat($nonEscapableNbspChar, ($menu['level'] * 4)) . $menu['label'],
  63. 'value' => $children,
  64. );
  65. }
  66. }
  67. }
  68. protected function _getUrlModel()
  69. {
  70. if (is_null($this->_url)) {
  71. $this->_url = Mage::getModel('adminhtml/url');
  72. }
  73. return $this->_url;
  74. }
  75. protected function _buildMenuArray(Varien_Simplexml_Element $parent=null, $path='', $level=0)
  76. {
  77. if (is_null($parent)) {
  78. $parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu');
  79. }
  80. $parentArr = array();
  81. $sortOrder = 0;
  82. foreach ($parent->children() as $childName=>$child) {
  83. if ($child->depends && !$this->_checkDepends($child->depends)) {
  84. continue;
  85. }
  86. $menuArr = array();
  87. $menuArr['label'] = $this->_getHelperValue($child);
  88. $menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;
  89. if ($child->action) {
  90. $menuArr['url'] = (string)$child->action;
  91. } else {
  92. $menuArr['url'] = '';
  93. }
  94. $menuArr['level'] = $level;
  95. $menuArr['path'] = $path . $childName;
  96. if ($child->children) {
  97. $menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
  98. }
  99. $parentArr[$childName] = $menuArr;
  100. $sortOrder++;
  101. }
  102. uasort($parentArr, array($this, '_sortMenu'));
  103. while (list($key, $value) = each($parentArr)) {
  104. $last = $key;
  105. }
  106. if (isset($last)) {
  107. $parentArr[$last]['last'] = true;
  108. }
  109. return $parentArr;
  110. }
  111. protected function _sortMenu($a, $b)
  112. {
  113. return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
  114. }
  115. protected function _checkDepends(Varien_Simplexml_Element $depends)
  116. {
  117. if ($depends->module) {
  118. $modulesConfig = Mage::getConfig()->getNode('modules');
  119. foreach ($depends->module as $module) {
  120. if (!$modulesConfig->$module || !$modulesConfig->$module->is('active')) {
  121. return false;
  122. }
  123. }
  124. }
  125. return true;
  126. }
  127. protected function _getHelperValue(Varien_Simplexml_Element $child)
  128. {
  129. $helperName = 'adminhtml';
  130. $titleNodeName = 'title';
  131. $childAttributes = $child->attributes();
  132. if (isset($childAttributes['module'])) {
  133. $helperName = (string)$childAttributes['module'];
  134. }
  135. $titleNodeName = 'title';
  136. return Mage::helper($helperName)->__((string)$child->$titleNodeName);
  137. }
  138. }