Beispiel #1
0
 /**
  * System configuration section, fieldset or field label getter
  *
  * @param string $sectionName
  * @param string $groupName
  * @param string $fieldName
  * @return string
  */
 public function getSystemConfigNodeLabel($sectionName, $groupName = null, $fieldName = null)
 {
     $sectionName = trim($sectionName, '/');
     $path = '//sections/' . $sectionName;
     $groupNode = $fieldNode = null;
     $sectionNode = $this->_sections->xpath($path);
     if (!empty($groupName)) {
         $path .= '/groups/' . trim($groupName, '/');
         $groupNode = $this->_sections->xpath($path);
     }
     if (!empty($fieldName)) {
         if (!empty($groupName)) {
             $path .= '/fields/' . trim($fieldName, '/');
             $fieldNode = $this->_sections->xpath($path);
         } else {
             Mage::throwException(Mage::helper('Mage_Adminhtml_Helper_Data')->__('The group node name must be specified with field node name.'));
         }
     }
     $moduleName = $this->getAttributeModule($sectionNode, $groupNode, $fieldNode);
     $systemNode = $this->_sections->xpath($path);
     foreach ($systemNode as $node) {
         return Mage::helper($moduleName)->__((string) $node->label);
     }
     return '';
 }
Beispiel #2
0
 /**
  * Returns nodes found by xpath expression
  *
  * @param string $xpath
  * @return array
  */
 public function getXpath($xpath)
 {
     if (empty($this->_xml)) {
         return false;
     }
     if (!($result = @$this->_xml->xpath($xpath))) {
         return false;
     }
     return $result;
 }
 /**
  * @param Varien_Object $context
  * @param Varien_Simplexml_Element $module
  * @param Varien_Simplexml_Element $entity
  * @param Varien_Simplexml_Element $scope
  */
 public function _createPrimaryKey($context, $module, $entity, $scope)
 {
     if ((string) $scope['module'] != $this->getModuleName() || (string) $scope['version'] != $this->getVersion()) {
         return;
     }
     /* @var $configHelper Mana_Db_Helper_Config */
     $configHelper = Mage::helper('mana_db/config');
     $primaryField = $scope->xpath('fields/*[primary="1"]');
     if (empty($primaryField)) {
         $scope->fields->id->type = 'bigint';
         $field = $scope->fields->id;
         $field->primary = 1;
         $field->role = Mana_Db_Helper_Config::ROLE_PRIMARY_KEY;
         $configHelper->propagateName($field);
         $configHelper->propagateAttributes($scope, $field, array('module', 'version'));
     }
 }
 protected function _getBaseClass(Varien_Simplexml_Element $config)
 {
     $model = null;
     if ($config->class) {
         $model = (string) $config->class;
     } elseif ($config->model) {
         $model = (string) $config->model;
     } else {
         /**
          * Backwards compatibility for pre-MMDB extensions. MMDB introduced since Magebto 1.6.0.0
          * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
          * to keep name of previously used nodes, that still may be used by non-updated extensions.
          */
         $deprecatedNodes = $config->xpath('../*[deprecatedNode="' . (string) $config->getName() . '"]');
         if ($deprecatedNodes && $deprecatedNodes[0]->class) {
             $model = (string) $deprecatedNodes[0]->class;
         }
     }
     if (is_null($model)) {
         return false;
     }
     return $this->_getModelClassName($model, $config);
 }
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @throws Exception            Throw exception when xml object is not
  *                              instance of Varien_Simplexml_Element
  * @param Varien_Simplexml_Element|string $value
  * @return bool
  */
 public function isValid($value)
 {
     if (is_string($value)) {
         $value = trim($value);
         try {
             //wrap XML value in the "config" tag because config cannot
             //contain multiple root tags
             $value = new Varien_Simplexml_Element('<config>' . $value . '</config>');
         } catch (Exception $e) {
             $this->_error(self::XML_INVALID);
             return false;
         }
     } elseif (!$value instanceof Varien_Simplexml_Element) {
         throw new Exception(Mage::helper('adminhtml')->__('XML object is not instance of "Varien_Simplexml_Element".'));
     }
     $this->_setValue($value);
     foreach ($this->_protectedExpressions as $key => $xpr) {
         if ($this->_value->xpath($xpr)) {
             $this->_error($key);
             return false;
         }
     }
     return true;
 }
Beispiel #6
0
 /**
  * Lookup module name for translation from current specified layout node
  *
  * Priorities:
  * 1) "module" attribute in the element
  * 2) "module" attribute in any ancestor element
  * 3) layout handle name - first 1 or 2 parts (namespace is determined automatically)
  *
  * @param Varien_Simplexml_Element $node
  * @return string
  */
 public static function findTranslationModuleName(Varien_Simplexml_Element $node)
 {
     $result = $node->getAttribute('module');
     if ($result) {
         return (string) $result;
     }
     foreach (array_reverse($node->xpath('ancestor::*[@module]')) as $element) {
         $result = $element->getAttribute('module');
         if ($result) {
             return (string) $result;
         }
     }
     foreach ($node->xpath('ancestor-or-self::*[last()-1]') as $handle) {
         $name = Mage::getConfig()->determineOmittedNamespace($handle->getName());
         if ($name) {
             return $name;
         }
     }
     return 'core';
 }
Beispiel #7
0
 /**
  * Lookup module name for translation from current specified layout node
  *
  * Priorities:
  * 1) "module" attribute in the element
  * 2) "module" attribute in any ancestor element
  * 3) layout handle name - first 1 or 2 parts (namespace is determined automatically)
  *
  * @param Varien_Simplexml_Element $node
  * @return string
  */
 public static function findTranslationModuleName(Varien_Simplexml_Element $node)
 {
     // Commented out code uses not yet implemented functionality.
     $result = (string) $node->getAttribute('module');
     if ($result) {
         //return Mage::getConfig()->getModuleConfig($result) ? $result : 'core';
         return $result;
     }
     foreach (array_reverse($node->xpath('ancestor::*[@module]')) as $element) {
         $result = (string) $element->getAttribute('module');
         if ($result) {
             //return Mage::getConfig()->getModuleConfig($result) ? $result : 'core';
             return $result;
         }
     }
     foreach ($node->xpath('ancestor-or-self::*[last()-1]') as $handle) {
         $name = Mage::getConfig()->determineOmittedNamespace($handle->getName(), true);
         if ($name) {
             //return Mage::getConfig()->getModuleConfig($name) ? $name : 'core';
             return $name;
         }
     }
     return 'Mage_Core';
 }
Beispiel #8
0
 /**
  * Cleanup reference node according to the block it refers to
  *
  * Look for the block by reference name and if the block is "unsafe", cleanup the reference node from actions
  *
  * @param Varien_Simplexml_Element $node
  */
 protected static function _sanitizeReference(Varien_Simplexml_Element $node)
 {
     $attributes = $node->attributes();
     $name = $attributes['name'];
     $result = $node->xpath("//block[@name='{$name}']") ?: array();
     foreach ($result as $block) {
         $isTypeSafe = self::_isTypeSafe($block->getAttribute('type'));
         if (!$isTypeSafe || !self::_isParentSafe($block)) {
             self::_deleteNodes($node, 'action');
         }
         break;
     }
 }
Beispiel #9
0
 /**
  * Delete nodes that have "acl" attribute but value is "not allowed"
  *
  * In any case, the "acl" attribute will be unset
  *
  * @param Varien_Simplexml_Element $xml
  */
 public function filterAclNodes(Varien_Simplexml_Element $xml)
 {
     $limitations = $xml->xpath('//*[@acl]') ?: array();
     foreach ($limitations as $node) {
         if (!$this->isAllowed($node['acl'])) {
             $node->unsetSelf();
         } else {
             unset($node['acl']);
         }
     }
 }