00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Model_System_Config_Source_Admin_Page
00036 {
00037 protected $_url;
00038
00039 public function toOptionArray()
00040 {
00041 $options = array();
00042 $menu = $this->_buildMenuArray();
00043
00044 $this->_createOptions($options, $menu);
00045
00046 return $options;
00047 }
00048
00049 protected function _createOptions(&$optionArray, $menuNode)
00050 {
00051 foreach ($menuNode as $menu) {
00052
00053 if (!empty($menu['url'])) {
00054 $optionArray[] = array(
00055 'label' => str_repeat(' ', ($menu['level'] * 4)) . $menu['label'],
00056 'value' => $menu['path'],
00057 );
00058
00059 if (isset($menu['children'])) {
00060 $this->_createOptions($optionArray, $menu['children']);
00061 }
00062 }
00063 else {
00064 $children = array();
00065 $this->_createOptions($children, $menu['children']);
00066
00067 $optionArray[] = array(
00068 'label' => str_repeat(' ', ($menu['level'] * 4)) . $menu['label'],
00069 'value' => $children,
00070 );
00071 }
00072 }
00073 }
00074
00075 protected function _getUrlModel()
00076 {
00077 if (is_null($this->_url)) {
00078 $this->_url = Mage::getModel('adminhtml/url');
00079 }
00080 return $this->_url;
00081 }
00082
00083 protected function _buildMenuArray(Varien_Simplexml_Element $parent=null, $path='', $level=0)
00084 {
00085 if (is_null($parent)) {
00086 $parent = Mage::getConfig()->getNode('adminhtml/menu');
00087 }
00088
00089 $parentArr = array();
00090 $sortOrder = 0;
00091 foreach ($parent->children() as $childName=>$child) {
00092
00093 if ($child->depends && !$this->_checkDepends($child->depends)) {
00094 continue;
00095 }
00096
00097 $menuArr = array();
00098 $menuArr['label'] = $this->_getHelperValue($child);
00099
00100 $menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;
00101
00102 if ($child->action) {
00103 $menuArr['url'] = (string)$child->action;
00104 } else {
00105 $menuArr['url'] = '';
00106 }
00107
00108 $menuArr['level'] = $level;
00109 $menuArr['path'] = $path . $childName;
00110
00111 if ($child->children) {
00112 $menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
00113 }
00114 $parentArr[$childName] = $menuArr;
00115
00116 $sortOrder++;
00117 }
00118
00119 uasort($parentArr, array($this, '_sortMenu'));
00120
00121 while (list($key, $value) = each($parentArr)) {
00122 $last = $key;
00123 }
00124 if (isset($last)) {
00125 $parentArr[$last]['last'] = true;
00126 }
00127
00128 return $parentArr;
00129 }
00130
00131 protected function _sortMenu($a, $b)
00132 {
00133 return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
00134 }
00135
00136 protected function _checkDepends(Varien_Simplexml_Element $depends)
00137 {
00138 if ($depends->module) {
00139 $modulesConfig = Mage::getConfig()->getNode('modules');
00140 foreach ($depends->module as $module) {
00141 if (!$modulesConfig->$module || !$modulesConfig->$module->is('active')) {
00142 return false;
00143 }
00144 }
00145 }
00146
00147 return true;
00148 }
00149
00150 protected function _getHelperValue(Varien_Simplexml_Element $child)
00151 {
00152 $helperName = 'adminhtml';
00153 $titleNodeName = 'title';
00154 $childAttributes = $child->attributes();
00155 if (isset($childAttributes['module'])) {
00156 $helperName = (string)$childAttributes['module'];
00157 }
00158
00159 $titleNodeName = 'title';
00160
00161 return Mage::helper($helperName)->__((string)$child->$titleNodeName);
00162 }
00163 }