PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Model/Config.php

https://bitbucket.org/claudiu_marginean/magento-hg-mirror
PHP | 256 lines | 140 code | 24 blank | 92 comment | 28 complexity | 4342ded155b401cca9d9f52fcb413222 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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) 2010 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 configuration model
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Model_Config extends Varien_Simplexml_Config
  34. {
  35. /**
  36. * Enter description here...
  37. *
  38. * @var Varien_Simplexml_Element
  39. */
  40. protected $_sections;
  41. /**
  42. * Tabs
  43. *
  44. * @var Varien_Simplexml_Element
  45. */
  46. protected $_tabs;
  47. /**
  48. * Enter description here...
  49. *
  50. * @param string $sectionCode
  51. * @param string $websiteCode
  52. * @param string $storeCode
  53. * @return Varien_Simplexml_Element
  54. */
  55. public function getSections($sectionCode=null, $websiteCode=null, $storeCode=null)
  56. {
  57. if (empty($this->_sections)) {
  58. $this->_initSectionsAndTabs();
  59. }
  60. return $this->_sections;
  61. }
  62. /**
  63. * Retrive tabs
  64. *
  65. * @return Varien_Simplexml_Element
  66. */
  67. public function getTabs()
  68. {
  69. if (empty($this->_tabs)) {
  70. $this->_initSectionsAndTabs();
  71. }
  72. return $this->_tabs;
  73. }
  74. protected function _initSectionsAndTabs()
  75. {
  76. $mergeConfig = Mage::getModel('core/config_base');
  77. $config = Mage::getConfig()->loadModulesConfiguration('system.xml');
  78. $this->_sections = $config->getNode('sections');
  79. $this->_tabs = $config->getNode('tabs');
  80. }
  81. /**
  82. * Enter description here...
  83. *
  84. * @param string $sectionCode
  85. * @param string $websiteCode
  86. * @param string $storeCode
  87. * @return Varien_Simplexml_Element
  88. */
  89. public function getSection($sectionCode=null, $websiteCode=null, $storeCode=null)
  90. {
  91. if ($sectionCode){
  92. return $this->getSections()->$sectionCode;
  93. } elseif ($websiteCode) {
  94. return $this->getSections()->$websiteCode;
  95. } elseif ($storeCode) {
  96. return $this->getSections()->$storeCode;
  97. }
  98. }
  99. /**
  100. * Enter description here...
  101. *
  102. * @param Varien_Simplexml_Element $node
  103. * @param string $websiteCode
  104. * @param string $storeCode
  105. * @param boolean $isField
  106. * @return boolean
  107. */
  108. public function hasChildren ($node, $websiteCode=null, $storeCode=null, $isField=false)
  109. {
  110. $showTab = false;
  111. if ($storeCode) {
  112. if (isset($node->show_in_store)) {
  113. if ((int)$node->show_in_store) {
  114. $showTab=true;
  115. }
  116. }
  117. }elseif ($websiteCode) {
  118. if (isset($node->show_in_website)) {
  119. if ((int)$node->show_in_website) {
  120. $showTab=true;
  121. }
  122. }
  123. } elseif (isset($node->show_in_default)) {
  124. if ((int)$node->show_in_default) {
  125. $showTab=true;
  126. }
  127. }
  128. if ($showTab) {
  129. if (isset($node->groups)) {
  130. foreach ($node->groups->children() as $children){
  131. if ($this->hasChildren ($children, $websiteCode, $storeCode)) {
  132. return true;
  133. }
  134. }
  135. }elseif (isset($node->fields)) {
  136. foreach ($node->fields->children() as $children){
  137. if ($this->hasChildren ($children, $websiteCode, $storeCode, true)) {
  138. return true;
  139. }
  140. }
  141. } else {
  142. return true;
  143. }
  144. }
  145. return false;
  146. }
  147. /**
  148. * Get translate module name
  149. *
  150. * @param Varien_Simplexml_Element $sectionNode
  151. * @param Varien_Simplexml_Element $groupNode
  152. * @param Varien_Simplexml_Element $fieldNode
  153. * @return string
  154. */
  155. function getAttributeModule($sectionNode = null, $groupNode = null, $fieldNode = null)
  156. {
  157. $moduleName = 'adminhtml';
  158. if (is_object($sectionNode) && method_exists($sectionNode, 'attributes')) {
  159. $sectionAttributes = $sectionNode->attributes();
  160. $moduleName = isset($sectionAttributes['module']) ? (string)$sectionAttributes['module'] : $moduleName;
  161. }
  162. if (is_object($groupNode) && method_exists($groupNode, 'attributes')) {
  163. $groupAttributes = $groupNode->attributes();
  164. $moduleName = isset($groupAttributes['module']) ? (string)$groupAttributes['module'] : $moduleName;
  165. }
  166. if (is_object($fieldNode) && method_exists($fieldNode, 'attributes')) {
  167. $fieldAttributes = $fieldNode->attributes();
  168. $moduleName = isset($fieldAttributes['module']) ? (string)$fieldAttributes['module'] : $moduleName;
  169. }
  170. return $moduleName;
  171. }
  172. /**
  173. * System configuration section, fieldset or field label getter
  174. *
  175. * @param string $sectionName
  176. * @param string $groupName
  177. * @param string $fieldName
  178. * @return string
  179. */
  180. public function getSystemConfigNodeLabel($sectionName, $groupName = null, $fieldName = null)
  181. {
  182. $sectionName = trim($sectionName, '/');
  183. $path = '//sections/' . $sectionName;
  184. $groupNode = $fieldNode = null;
  185. $sectionNode = $this->_sections->xpath($path);
  186. if (!empty($groupName)) {
  187. $path .= '/groups/' . trim($groupName, '/');
  188. $groupNode = $this->_sections->xpath($path);
  189. }
  190. if (!empty($fieldName)) {
  191. if (!empty($groupName)) {
  192. $path .= '/fields/' . trim($fieldName, '/');
  193. $fieldNode = $this->_sections->xpath($path);
  194. }
  195. else {
  196. Mage::throwException(Mage::helper('adminhtml')->__('The group node name must be specified with field node name.'));
  197. }
  198. }
  199. $moduleName = $this->getAttributeModule($sectionNode, $groupNode, $fieldNode);
  200. $systemNode = $this->_sections->xpath($path);
  201. foreach ($systemNode as $node) {
  202. return Mage::helper($moduleName)->__((string)$node->label);
  203. }
  204. return '';
  205. }
  206. /**
  207. * Look for encrypted node entries in all system.xml files and return them
  208. *
  209. * @return array $paths
  210. */
  211. public function getEncryptedNodeEntriesPaths($explodePathToEntities = false)
  212. {
  213. $paths = array();
  214. $configSections = $this->getSections();
  215. if ($configSections) {
  216. foreach ($configSections->xpath('//sections/*/groups/*/fields/*/backend_model') as $node) {
  217. if ('adminhtml/system_config_backend_encrypted' === (string)$node) {
  218. $section = $node->getParent()->getParent()->getParent()->getParent()->getParent()->getName();
  219. $group = $node->getParent()->getParent()->getParent()->getName();
  220. $field = $node->getParent()->getName();
  221. if ($explodePathToEntities) {
  222. $paths[] = array('section' => $section, 'group' => $group, 'field' => $field);
  223. }
  224. else {
  225. $paths[] = $section . '/' . $group . '/' . $field;
  226. }
  227. }
  228. }
  229. }
  230. return $paths;
  231. }
  232. }