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_Adminhtml_Model_System_Config_Source_Admin_Page
36: {
37: protected $_url;
38:
39: public function toOptionArray()
40: {
41: $options = array();
42: $menu = $this->_buildMenuArray();
43:
44: $this->_createOptions($options, $menu);
45:
46: return $options;
47: }
48:
49: protected function _createOptions(&$optionArray, $menuNode)
50: {
51: $nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
52:
53: foreach ($menuNode as $menu) {
54:
55: if (!empty($menu['url'])) {
56: $optionArray[] = array(
57: 'label' => str_repeat($nonEscapableNbspChar, ($menu['level'] * 4)) . $menu['label'],
58: 'value' => $menu['path'],
59: );
60:
61: if (isset($menu['children'])) {
62: $this->_createOptions($optionArray, $menu['children']);
63: }
64: }
65: else {
66: $children = array();
67:
68: if(isset($menu['children'])) {
69: $this->_createOptions($children, $menu['children']);
70: }
71:
72: $optionArray[] = array(
73: 'label' => str_repeat($nonEscapableNbspChar, ($menu['level'] * 4)) . $menu['label'],
74: 'value' => $children,
75: );
76: }
77: }
78: }
79:
80: protected function _getUrlModel()
81: {
82: if (is_null($this->_url)) {
83: $this->_url = Mage::getModel('adminhtml/url');
84: }
85: return $this->_url;
86: }
87:
88: protected function (Varien_Simplexml_Element $parent=null, $path='', $level=0)
89: {
90: if (is_null($parent)) {
91: $parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu');
92: }
93:
94: $parentArr = array();
95: $sortOrder = 0;
96: foreach ($parent->children() as $childName=>$child) {
97: if ((1 == $child->disabled)
98: || ($child->depends && !$this->_checkDepends($child->depends))
99: ) {
100: continue;
101: }
102:
103: $menuArr = array();
104: $menuArr['label'] = $this->_getHelperValue($child);
105:
106: $menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;
107:
108: if ($child->action) {
109: $menuArr['url'] = (string)$child->action;
110: } else {
111: $menuArr['url'] = '';
112: }
113:
114: $menuArr['level'] = $level;
115: $menuArr['path'] = $path . $childName;
116:
117: if ($child->children) {
118: $menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
119: }
120: $parentArr[$childName] = $menuArr;
121:
122: $sortOrder++;
123: }
124:
125: uasort($parentArr, array($this, '_sortMenu'));
126:
127: while (list($key, $value) = each($parentArr)) {
128: $last = $key;
129: }
130: if (isset($last)) {
131: $parentArr[$last]['last'] = true;
132: }
133:
134: return $parentArr;
135: }
136:
137: protected function ($a, $b)
138: {
139: return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
140: }
141:
142: protected function _checkDepends(Varien_Simplexml_Element $depends)
143: {
144: if ($depends->module) {
145: $modulesConfig = Mage::getConfig()->getNode('modules');
146: foreach ($depends->module as $module) {
147: if (!$modulesConfig->$module || !$modulesConfig->$module->is('active')) {
148: return false;
149: }
150: }
151: }
152:
153: return true;
154: }
155:
156: protected function _getHelperValue(Varien_Simplexml_Element $child)
157: {
158: $helperName = 'adminhtml';
159: $titleNodeName = 'title';
160: $childAttributes = $child->attributes();
161: if (isset($childAttributes['module'])) {
162: $helperName = (string)$childAttributes['module'];
163: }
164:
165: $titleNodeName = 'title';
166:
167: return Mage::helper($helperName)->__((string)$child->$titleNodeName);
168: }
169: }
170: