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_Config extends Varien_Simplexml_Config
36: {
37:
38: 39: 40: 41: 42:
43: protected $_sections;
44:
45: 46: 47: 48: 49:
50: protected $_tabs;
51:
52: 53: 54: 55: 56: 57: 58: 59:
60: public function getSections($sectionCode=null, $websiteCode=null, $storeCode=null)
61: {
62: if (empty($this->_sections)) {
63: $this->_initSectionsAndTabs();
64: }
65:
66: return $this->_sections;
67: }
68:
69: 70: 71: 72: 73:
74: public function getTabs()
75: {
76: if (empty($this->_tabs)) {
77: $this->_initSectionsAndTabs();
78: }
79:
80: return $this->_tabs;
81: }
82:
83: 84: 85: 86: 87:
88: protected function _initSectionsAndTabs()
89: {
90: $config = Mage::getConfig()->loadModulesConfiguration('system.xml')
91: ->applyExtends();
92:
93: Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));
94: $this->_sections = $config->getNode('sections');
95: $this->_tabs = $config->getNode('tabs');
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105:
106: public function getSection($sectionCode=null, $websiteCode=null, $storeCode=null)
107: {
108: if ($sectionCode){
109: return $this->getSections()->$sectionCode;
110: } elseif ($websiteCode) {
111: return $this->getSections()->$websiteCode;
112: } elseif ($storeCode) {
113: return $this->getSections()->$storeCode;
114: }
115: }
116:
117: 118: 119: 120: 121: 122: 123: 124: 125:
126: public function hasChildren ($node, $websiteCode=null, $storeCode=null, $isField=false)
127: {
128: $showTab = false;
129: if ($storeCode) {
130: if (isset($node->show_in_store)) {
131: if ((int)$node->show_in_store) {
132: $showTab=true;
133: }
134: }
135: } elseif ($websiteCode) {
136: if (isset($node->show_in_website)) {
137: if ((int)$node->show_in_website) {
138: $showTab=true;
139: }
140: }
141: } elseif (isset($node->show_in_default)) {
142: if ((int)$node->show_in_default) {
143: $showTab=true;
144: }
145: }
146: if ($showTab) {
147: if (isset($node->groups)) {
148: foreach ($node->groups->children() as $children){
149: if ($this->hasChildren ($children, $websiteCode, $storeCode)) {
150: return true;
151: }
152:
153: }
154: }elseif (isset($node->fields)) {
155:
156: foreach ($node->fields->children() as $children){
157: if ($this->hasChildren ($children, $websiteCode, $storeCode, true)) {
158: return true;
159: }
160: }
161: } else {
162: return true;
163: }
164: }
165: return false;
166: }
167:
168: 169: 170: 171: 172: 173: 174: 175:
176: function getAttributeModule($sectionNode = null, $groupNode = null, $fieldNode = null)
177: {
178: $moduleName = 'adminhtml';
179: if (is_object($sectionNode) && method_exists($sectionNode, 'attributes')) {
180: $sectionAttributes = $sectionNode->attributes();
181: $moduleName = isset($sectionAttributes['module']) ? (string)$sectionAttributes['module'] : $moduleName;
182: }
183: if (is_object($groupNode) && method_exists($groupNode, 'attributes')) {
184: $groupAttributes = $groupNode->attributes();
185: $moduleName = isset($groupAttributes['module']) ? (string)$groupAttributes['module'] : $moduleName;
186: }
187: if (is_object($fieldNode) && method_exists($fieldNode, 'attributes')) {
188: $fieldAttributes = $fieldNode->attributes();
189: $moduleName = isset($fieldAttributes['module']) ? (string)$fieldAttributes['module'] : $moduleName;
190: }
191:
192: return $moduleName;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: public function getSystemConfigNodeLabel($sectionName, $groupName = null, $fieldName = null)
204: {
205: $sectionName = trim($sectionName, '/');
206: $path = '//sections/' . $sectionName;
207: $groupNode = $fieldNode = null;
208: $sectionNode = $this->_sections->xpath($path);
209: if (!empty($groupName)) {
210: $path .= '/groups/' . trim($groupName, '/');
211: $groupNode = $this->_sections->xpath($path);
212: }
213: if (!empty($fieldName)) {
214: if (!empty($groupName)) {
215: $path .= '/fields/' . trim($fieldName, '/');
216: $fieldNode = $this->_sections->xpath($path);
217: }
218: else {
219: Mage::throwException(Mage::helper('adminhtml')->__('The group node name must be specified with field node name.'));
220: }
221: }
222: $moduleName = $this->getAttributeModule($sectionNode, $groupNode, $fieldNode);
223: $systemNode = $this->_sections->xpath($path);
224: foreach ($systemNode as $node) {
225: return Mage::helper($moduleName)->__((string)$node->label);
226: }
227: return '';
228: }
229:
230: 231: 232: 233: 234:
235: public function getEncryptedNodeEntriesPaths($explodePathToEntities = false)
236: {
237: $paths = array();
238: $configSections = $this->getSections();
239: if ($configSections) {
240: foreach ($configSections->xpath('//sections/*/groups/*/fields/*/backend_model') as $node) {
241: if ('adminhtml/system_config_backend_encrypted' === (string)$node) {
242: $section = $node->getParent()->getParent()->getParent()->getParent()->getParent()->getName();
243: $group = $node->getParent()->getParent()->getParent()->getName();
244: $field = $node->getParent()->getName();
245: if ($explodePathToEntities) {
246: $paths[] = array('section' => $section, 'group' => $group, 'field' => $field);
247: }
248: else {
249: $paths[] = $section . '/' . $group . '/' . $field;
250: }
251: }
252: }
253: }
254: return $paths;
255: }
256: }
257: