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_Admin_Model_Config extends Varien_Simplexml_Config
36: {
37: 38: 39: 40: 41:
42: protected $_adminhtmlConfig;
43:
44: 45: 46:
47: public function __construct()
48: {
49: parent::__construct();
50: $this->setCacheId('adminhtml_acl_menu_config');
51:
52:
53: $adminhtmlConfig = Mage::app()->loadCache($this->getCacheId());
54: if ($adminhtmlConfig) {
55: $this->_adminhtmlConfig = new Varien_Simplexml_Config($adminhtmlConfig);
56: } else {
57: $adminhtmlConfig = new Varien_Simplexml_Config;
58: $adminhtmlConfig->loadString('<?xml version="1.0"?><config></config>');
59: Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig);
60: $this->_adminhtmlConfig = $adminhtmlConfig;
61:
62: 63: 64: 65:
66: $aclConfig = Mage::getConfig()->getNode('adminhtml/acl');
67: if ($aclConfig) {
68: $adminhtmlConfig->getNode()->extendChild($aclConfig, true);
69: }
70: $menuConfig = Mage::getConfig()->getNode('adminhtml/menu');
71: if ($menuConfig) {
72: $adminhtmlConfig->getNode()->extendChild($menuConfig, true);
73: }
74:
75: if (Mage::app()->useCache('config')) {
76: Mage::app()->saveCache($adminhtmlConfig->getXmlString(), $this->getCacheId(),
77: array(Mage_Core_Model_Config::CACHE_TAG));
78: }
79: }
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89:
90: public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource = null, $parentName = null)
91: {
92: if (is_null($resource)) {
93: $resource = $this->getAdminhtmlConfig()->getNode("acl/resources");
94: $resourceName = null;
95: } else {
96: $resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName();
97: $acl->add(Mage::getModel('admin/acl_resource', $resourceName), $parentName);
98: }
99:
100: if (isset($resource->all)) {
101: $acl->add(Mage::getModel('admin/acl_resource', 'all'), null);
102: }
103:
104: if (isset($resource->admin)) {
105: $children = $resource->admin;
106: } elseif (isset($resource->children)){
107: $children = $resource->children->children();
108: }
109:
110:
111:
112: if (empty($children)) {
113: return $this;
114: }
115:
116: foreach ($children as $res) {
117: if (1 == $res->disabled) {
118: continue;
119: }
120: $this->loadAclResources($acl, $res, $resourceName);
121: }
122: return $this;
123: }
124:
125: 126: 127: 128: 129: 130:
131: public function getAclAssert($name = '')
132: {
133: $asserts = $this->getNode("admin/acl/asserts");
134: if ('' === $name) {
135: return $asserts;
136: }
137:
138: if (isset($asserts->$name)) {
139: return $asserts->$name;
140: }
141:
142: return false;
143: }
144:
145: 146: 147: 148: 149: 150:
151: public function getAclPrivilegeSet($name = '')
152: {
153: $sets = $this->getNode("admin/acl/privilegeSets");
154: if ('' === $name) {
155: return $sets;
156: }
157:
158: if (isset($sets->$name)) {
159: return $sets->$name;
160: }
161:
162: return false;
163: }
164:
165: 166: 167: 168: 169:
170: public function getAdminhtmlConfig()
171: {
172: return $this->_adminhtmlConfig;
173: }
174:
175: 176: 177: 178: 179: 180:
181: public function ($path)
182: {
183: $moduleName = 'adminhtml';
184: $menuNode = $this->getAdminhtmlConfig()->getNode('menu/' . str_replace('/', '/children/', trim($path, '/')));
185: if ($menuNode->getAttribute('module')) {
186: $moduleName = (string)$menuNode->getAttribute('module');
187: }
188: return Mage::helper($moduleName)->__((string)$menuNode->title);
189: }
190: }
191: