/** * reads an import specification. * @see README.md * @param Varien_Simplexml_Element $specNode * @param Varien_Simplexml_Element $groupNode * @param string $configPath */ private function _readImportSpec(Varien_Simplexml_Element $specNode, Varien_Simplexml_Element $groupNode, $configPath) { foreach ($specNode->children() as $moduleName => $moduleNode) { Mage::dispatchEvent(self::EVENT_PREFIX . $moduleName, $this->_prepareEventData($groupNode, $moduleNode, $configPath)); } return $this; }
/** * Returns setup resource for module setup scripts * * @param Varien_Simplexml_Element $xml * @return string */ protected function getResourceName(Varien_Simplexml_Element $xml) { foreach ($xml->children() as $resourceNode) { if (isset($resourceNode->setup->module) && (string) $resourceNode->setup->module === $this->_moduleName) { return $resourceNode->getName(); } } return false; }
/** * Returns list of module setup resources * * @param Varien_Simplexml_Element $xml * @return array */ protected function getModuleSetupResources(Varien_Simplexml_Element $xml) { $resourcesForModule = array(); foreach ($xml->children() as $resourceNode) { if (isset($resourceNode->setup->module) && (string) $resourceNode->setup->module === $this->_moduleName) { $resourcesForModule[] = $resourceNode->getName(); } } return $resourcesForModule; }
/** * Extends one node * * @param Varien_Simplexml_Element $source * @param boolean $overwrite * * @return Varien_Simplexml_Element * @access public */ public function extendChild($source, $overwrite = false) { // this will be our new target node $targetChild = null; // name of the source node $sourceName = $source->getName(); // here we have children of our source node $sourceChildren = $source->children(); if (!$source->hasChildren()) { // handle string node if (isset($this->{$sourceName})) { // if target already has children return without regard if ($this->{$sourceName}->children()) { return $this; } if ($overwrite) { if (Mage::registry('conflict_datastore_enabled')) { $factory = new Bronto_Verify_Model_Path_Locator_Factory(); $locator = $factory->getLocator(); $dataStore = Mage::registry('conflict_datastore'); $dataStore->addRewrite((string) $this->{$sourceName}, (string) $source, Mage::registry('conflict_datastore_config_file'), $locator->getPath($source)); } unset($this->{$sourceName}); } else { return $this; } } $targetChild = $this->addChild($sourceName, $source->xmlentities()); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } return $this; } if (isset($this->{$sourceName})) { $targetChild = $this->{$sourceName}; } if (is_null($targetChild)) { // if child target is not found create new and descend $targetChild = $this->addChild($sourceName); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } } // finally add our source node children to resulting new target node foreach ($sourceChildren as $childNode) { $targetChild->extendChild($childNode, $overwrite); } return $this; }
/** * If all ifconfig conditions are ok then action runs * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Smartwave_All_Model_Core_Layout */ private function _runAction($node, $parent) { $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $parent->getBlockName(); } $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method; Varien_Profiler::start($_profilerKey); if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $helperName = explode('/', (string) $arg['helper']); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg); } else { /** * if there is no helper we hope that this is assoc array */ $arr = array(); foreach ($arg as $subkey => $value) { $arr[(string) $subkey] = $value->asArray(); } if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } Varien_Profiler::stop($_profilerKey); return $this; }
/** * translate node * * @access protected * @param Varien_Simplexml_Element $node * @return Ultimate_ModuleCreator_Model_Config * @author Marius Strajeru <*****@*****.**> */ protected function _translateNode(&$node) { if ($node->getAttribute('translate')) { $fields = explode(' ', $node->getAttribute('translate')); $module = $node->getAttribute('module') ? (string) $node->getAttribute('module') : $this->_getDefaultTranslateModule(); foreach ($fields as $field) { if ($node->{$field}) { $node->{$field} = Mage::helper($module)->__((string) $node->{$field}); } } } if ($node->hasChildren()) { foreach ($node->children() as $child) { $this->_translateNode($child); } } return $this; }
public static function toOptionArray() { $result = array(); $path = 'http://facebook.com/translations/FacebookLocales.xml'; if (file_exists($path)) { $xml = new Varien_Simplexml_Element($path, 0, true); $xmlData = $xml->children(); $locales = $xmlData; foreach ($locales as $locale) { $data = $locale->asArray(); $codes = $data['codes']; $code = trim($codes['code']['standard']['representation']); $label = $data['englishName']; $result[] = array('value' => $code, 'label' => $label); } } else { $result[] = array('value' => 'en_US', 'label' => 'English (US)'); } return $result; }
/** * Checks layout definititions for expected file defined in the configuration * * @param Varien_Simplexml_Element $other * @return boolean */ protected function evaluateLayoutDefinition($other) { foreach ($other->children() as $layoutUpdate) { if ((string) $layoutUpdate->file === $this->_expectedValue && ($this->_layoutUpdate === null || $this->_layoutUpdate === $layoutUpdate->getName())) { return true; } } if ($this->_layoutUpdate === null) { $this->_layoutUpdate = 'your_module'; } $expected = clone $other; $expected->addChild($this->_layoutUpdate)->addChild('file', htmlspecialchars($this->_expectedValue)); return $this->compareValues($this->getXmlAsDom($expected), $this->getXmlAsDom($other)); }
/** * Process config value * * @param string $fullPath * @param string $path * @param Varien_Simplexml_Element $node * @return string */ protected function _processConfigValue($fullPath, $path, $node) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } if ($node->hasChildren()) { $aValue = array(); foreach ($node->children() as $k => $v) { $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v); } $this->_configCache[$path] = $aValue; return $aValue; } $sValue = (string) $node; if (!empty($node['backend_model']) && !empty($sValue)) { $backend = Mage::getModel((string) $node['backend_model']); $backend->setPath($path)->setValue($sValue)->afterLoad(); $sValue = $backend->getValue(); } if (is_string($sValue) && preg_match('/{{(.*)}}.*/', $sValue, $matches)) { $placeholder = $matches[1]; $url = false; if ($placeholder == 'unsecure_base_url' || $placeholder == 'unsecure_public_url') { $url = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL); } elseif ($placeholder == 'secure_base_url' || $placeholder == 'secure_public_url') { $url = $this->getConfig(self::XML_PATH_SECURE_BASE_URL); } if ($placeholder == 'unsecure_public_url' || $placeholder == 'secure_public_url') { $pubName = Mage_Core_Model_Config_Options::PUB_DIRECTORY; $url .= substr(dirname($_SERVER['SCRIPT_FILENAME']), -4) == '/' . $pubName ? '' : $pubName . '/'; } if ($url) { $sValue = str_replace('{{' . $placeholder . '}}', $url, $sValue); } elseif (strpos($sValue, '{{base_url}}') !== false) { $sValue = Mage::getConfig()->substDistroServerVars($sValue); } } $this->_configCache[$path] = $sValue; return $sValue; }
/** * Process core config data * * @param Mage_Core_Model_Website $stagingWebsite * @param string $originalBaseUrl * @param string $baseUrl * @param string $mode * @param Varien_Simplexml_Element $xmlConfig */ protected function _saveUrlsInSystemConfig($stagingWebsite, $originalBaseUrl, $baseUrl, $mode = 'unsecure', $xmlConfig) { foreach ($xmlConfig->children() as $nodeName => $nodeValue) { if ($mode == 'secure' || $mode == 'unsecure') { if ($nodeName == 'base_url' || $nodeName == 'base_web_url' || $nodeName == 'base_link_url') { $nodeValue = $baseUrl; } elseif ($mode == 'unsecure') { if (strpos($nodeValue, '{{unsecure_base_url}}') !== false) { $nodeValue = str_replace('{{unsecure_base_url}}', $originalBaseUrl, $nodeValue); } } elseif ($mode == 'secure') { if (strpos($nodeValue, '{{secure_base_url}}') !== false) { $nodeValue = str_replace('{{secure_base_url}}', $originalBaseUrl, $nodeValue); } } } $config = Mage::getModel('core/config_data'); $path = 'web/' . $mode . '/' . $nodeName; $config->setPath($path); $config->setScope('websites'); $config->setScopeId($stagingWebsite->getId()); $config->setValue($nodeValue); $config->save(); } return $this; }
/** * Get tree node * * @param Varien_Simplexml_Element|array $node * @param int $level * @return array */ protected function _getTreeNode($node, $level = 0) { $item = array(); $isResource = false; $isGroup = false; $name = null; if ($level != 0) { $name = $node->getName(); if (!(int) $node->resource) { if (self::NAME_RESOURCE_GROUPS != $name) { $isGroup = true; $item['id'] = self::NAME_GROUP . self::ID_SEPARATOR . $name; } $item['text'] = (string) $node->title; } else { $isResource = true; $item['id'] = self::NAME_RESOURCE . self::ID_SEPARATOR . $name; $item['text'] = $this->__('%s', (string) $node->title); } $item['checked'] = false; $item['sort_order'] = isset($node->sort_order) ? (string) $node->sort_order : 0; } if (isset($node->children)) { $children = $node->children->children(); } else { $children = $node->children(); } if (empty($children)) { /** * Node doesn't have any child nodes * and it should be skipped */ return $item; } $item[self::NAME_CHILDREN] = array(); if ($isResource) { if (self::TYPE_ATTRIBUTE == $this->_type) { if (!$this->_addOperations($item, $node, $name)) { return null; } } elseif (self::TYPE_PRIVILEGE == $this->_type) { if (!$this->_addPrivileges($item, $node, $name)) { return null; } } } /** @var $child Varien_Simplexml_Element */ foreach ($children as $child) { if ($child->getName() != 'title' && $child->getName() != 'sort_order') { if (!(string) $child->title) { continue; } if ($level != 0) { $subNode = $this->_getTreeNode($child, $level + 1); if (!$subNode) { continue; } //if sub-node check then check current node if (!empty($subNode['checked'])) { $item['checked'] = true; } $item[self::NAME_CHILDREN][] = $subNode; } else { $item = $this->_getTreeNode($child, $level + 1); } } } if (!empty($item[self::NAME_CHILDREN])) { usort($item[self::NAME_CHILDREN], array($this, '_sortTree')); } elseif ($isGroup) { //skip empty group return null; } return $item; }
/** * Modified core generate action method * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Mage_Core_Model_Layout */ protected function _generateAction($node, $parent) { if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { $ifConfig = Mage::getStoreConfigFlag($configPath); $nodeArray = (array) $node; $advIfconfig = null; $dependsCheck = false; $requiredDepends = false; if (isset($nodeArray['adv_ifconfig'])) { $advIfconfig = (array) $nodeArray['adv_ifconfig']; if (isset($advIfconfig['depends_check'])) { $dependsCheck = $advIfconfig['depends_check']; } if (isset($advIfconfig['required_depends'])) { $requiredDepends = $advIfconfig['required_depends']; } } if ($ifConfig && $dependsCheck) { if ($dependsCheck == 1 || $dependsCheck == 'tree') { $configPath = explode('/', $configPath); $ifConfig = $ifConfig && Mage::helper('advifconfig')->checkSystemConfigNodeDepends($configPath[0], $configPath[1], $configPath[2], $ifConfig); } if (($dependsCheck == 1 || $dependsCheck == 'required') && $requiredDepends) { $additionalDepends = array_map('trim', explode(',', $requiredDepends)); foreach ($additionalDepends as $depend) { $ifConfig = $ifConfig && Mage::getStoreConfigFlag($depend); } } } if (!$ifConfig) { return $this; } if (isset($advIfconfig['custom_rules'])) { $data = array_merge(array('ifconfig' => false), (array) $advIfconfig['custom_rules']); $data = new Varien_Object($data); Mage::dispatchEvent('adv_ifconfig_custom_rules', $data); if (!$data->getIfconfig()) { return $this; } } } $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $parent->getBlockName(); } $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method; Varien_Profiler::start($_profilerKey); if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); if (isset($args['adv_ifconfig'])) { unset($args['adv_ifconfig']); } foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $helperName = explode('/', (string) $arg['helper']); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg); } else { /** * if there is no helper we hope that this is assoc array */ $arr = array(); foreach ($arg as $subkey => $value) { $arr[(string) $subkey] = $value->asArray(); } if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } Varien_Profiler::stop($_profilerKey); return $this; }
/** * Enter description here ... * @param Varien_Simplexml_Element $config * @param array | null $fields * @param string | null $module */ protected function _translateConfigRecursively($config, $fields = null, $module = null) { if ($fields && in_array($config->getName(), $fields)) { $name = $config->getName(); $parent = $config->getParent(); $value = (string) $config; $moduleName = $module ? $module : $this->_getModuleName(); $parent->{$name} = Mage::app()->getTranslator()->translate(array(new Mage_Core_Model_Translate_Expr($value, $moduleName))); } $fields = isset($config['translate']) ? explode(',', (string) $config['translate']) : null; $module = isset($config['module']) ? (string) $config['module'] : null; foreach ($config->children() as $key => $value) { $this->_translateConfigRecursively($value, $fields, $module); } }
/** * Convert xml to array * * @param Varien_Simplexml_Element $element XML element * @return array|string */ protected function _xmlToArray(Varien_Simplexml_Element $element) { if (!$element->hasChildren()) { return (string) $element; } $result = array(); foreach ($element->children() as $_name => $_child) { if (isset($result[$_name])) { if (!is_array($result[$_name]) || !isset($result[$_name]['__list'])) { $result[$_name] = array($result[$_name]); $result[$_name]['__list'] = true; } $result[$_name][] = $this->_xmlToArray($_child); } else { $result[$_name] = $this->_xmlToArray($_child); } } // Remove temp __list mark array_walk($result, function (&$node) { if (is_array($node)) { unset($node['__list']); } }); return $result; }
/** * Get child by handle * * @param Varien_Simplexml_Element $xmlObject * @param string $handle * @return Varien_Simplexml_Element */ protected function _getChildByHandle($xmlObject, $handle) { foreach ($xmlObject->children() as $child) { if ($child->getName() == $handle) { return $child; } } return $xmlObject->addChild($handle); }
/** * Checks layout definititions for expected file defined in the configuration * * @param Varien_Simplexml_Element $other * @return boolean */ protected function evaluateLayoutDefinition($other) { foreach ($other->children() as $layoutUpdate) { if ((string) $layoutUpdate->file === $this->_expectedValue && ($this->_layoutUpdate === null || $this->_layoutUpdate === $layoutUpdate->getName())) { return true; } } return false; }
/** * Enter description here... * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Mage_Core_Model_Layout */ protected function _generateAction($node, $parent) { if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { if (!Mage::getStoreConfigFlag($configPath)) { return $this; } } $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $parent->getBlockName(); } $_profilerKey = 'BLOCK_ACTION:' . $parentName . '>' . $method; Magento_Profiler::start($_profilerKey); if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $helper = (string) $arg['helper']; if (strpos($helper, '::') === false) { $helperName = explode('/', $helper); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); } else { list($helperName, $helperMethod) = explode('::', $helper); } $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg); } else { /** * if there is no helper we hope that this is assoc array */ $arr = array(); foreach ($arg as $subkey => $value) { $arr[(string) $subkey] = $value->asArray(); } if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Mage::helper('Mage_Core_Helper_Data')->jsonDecode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } Magento_Profiler::stop($_profilerKey); return $this; }
/** * Enter description here... * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Mage_Core_Model_Layout */ protected function _generateAction($node, $parent) { if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { if (!AO::getStoreConfigFlag($configPath)) { return $this; } } $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $this->getBlockName($parent); } $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method; if (VPROF) { Varien_Profiler::start($_profilerKey); } if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof SimpleXMLElement) { if (isset($arg['helper'])) { $helperName = explode('/', (string) $arg['helper']); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); /* $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(AO::helper($helperName), $helperMethod), $arg); */ } else { /** * if there is no helper we hope that this is assoc array */ $arr = array(); foreach ($arg as $subkey => $value) { $arr[(string) $subkey] = (string) $value; } if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Zend_Json::decode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } if (VPROF) { Varien_Profiler::stop($_profilerKey); } return $this; }
/** * Checks ifconfig and conditions to run action or not * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Codnitive_Extifcon_Model_Core_Layout */ protected function _generateAction($node, $parent) { $compiler = Mage::getModel('dgttheme/system_layout_compiler'); if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { $condition = true; if (isset($node['condition'])) { $condition = $compiler->getXmlCondition($compiler->spaceRemover($node['condition'])); } $config = $compiler->getAdminConfig($compiler->spaceRemover($configPath)); if ($config !== $condition) { return $this; } } $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $parent->getBlockName(); } $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method; Varien_Profiler::start($_profilerKey); if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $helperName = explode('/', (string) $arg['helper']); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg); } else { /** * if there is no helper we hope that this is assoc array */ $arr = array(); foreach ($arg as $subkey => $value) { $arr[(string) $subkey] = $value->asArray(); } if (!empty($arr)) { $args[$key] = $arr; } } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } Varien_Profiler::stop($_profilerKey); return $this; }
/** * Return children of all namespaces * * @param Varien_Simplexml_Element $source */ public function getChildren($source) { $children = array(); $namespaces = $source->getNamespaces(true); foreach ($namespaces as $key => $value) { if ($key == '' || $key == 'wsdl') { continue; } $children[$value] = $source->children($value); } $children[''] = $source->children(''); return $children; }
/** * Return children of all namespaces * * @param Varien_Simplexml_Element $source */ public function getChildren($source) { $children = array(); $namespaces = $source->getNamespaces(true); $isWsi = Mage::helper('Mage_Api_Helper_Data')->isComplianceWSI(); foreach ($namespaces as $key => $value) { if ($key == '' || !$isWsi && $key == 'wsdl') { continue; } $children[$value] = $source->children($value); } $children[''] = $source->children(''); return $children; }
/** * Extends one node * * @param Varien_Simplexml_Element $source * @param boolean $overwrite * @return Varien_Simplexml_Element */ public function extendChild($source, $overwrite = false) { // this will be our new target node $targetChild = null; // name of the source node $sourceName = $source->getName(); // here we have children of our source node $sourceChildren = $source->children(); if (!$source->hasChildren()) { // handle string node if (isset($this->{$sourceName})) { // if target already has children return without regard if ($this->{$sourceName}->hasChildren()) { return $this; } if ($overwrite) { unset($this->{$sourceName}); } else { return $this; } } $targetChild = $this->addChild($sourceName, $source->xmlentities()); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } return $this; } if (isset($this->{$sourceName})) { $targetChild = $this->{$sourceName}; } if (is_null($targetChild)) { // if child target is not found create new and descend $targetChild = $this->addChild($sourceName); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } } // finally add our source node children to resulting new target node foreach ($sourceChildren as $childKey => $childNode) { $targetChild->extendChild($childNode, $overwrite); } return $this; }
/** * Enter description here... * * @param Varien_Simplexml_Element $node * @param Varien_Simplexml_Element $parent * @return Mage_Core_Model_Layout */ protected function _generateAction($node, $parent) { if (isset($node['ifconfig']) && ($configPath = (string) $node['ifconfig'])) { if (!Mage::getStoreConfigFlag($configPath)) { return $this; } } $method = (string) $node['method']; if (!empty($node['block'])) { $parentName = (string) $node['block']; } else { $parentName = $parent->getBlockName(); } $_profilerKey = 'BLOCK ACTION: ' . $parentName . ' -> ' . $method; Varien_Profiler::start($_profilerKey); if (!empty($parentName)) { $block = $this->getBlock($parentName); } if (!empty($block)) { $args = (array) $node->children(); unset($args['@attributes']); foreach ($args as $key => $arg) { if ($arg instanceof Mage_Core_Model_Layout_Element) { if (isset($arg['helper'])) { $helperName = explode('/', (string) $arg['helper']); $helperMethod = array_pop($helperName); $helperName = implode('/', $helperName); $arg = $arg->asArray(); unset($arg['@']); $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg); } } } if (isset($node['json'])) { $json = explode(' ', (string) $node['json']); foreach ($json as $arg) { $args[$arg] = Zend_Json::decode($args[$arg]); } } $this->_translateLayoutNode($node, $args); call_user_func_array(array($block, $method), $args); } Varien_Profiler::stop($_profilerKey); return $this; }
/** * Process config value * * @param string $fullPath * @param string $path * @param Varien_Simplexml_Element $node * @return string */ protected function _processConfigValue($fullPath, $path, $node) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } if ($node->hasChildren()) { $aValue = array(); foreach ($node->children() as $k => $v) { $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v); } $this->_configCache[$path] = $aValue; return $aValue; } $sValue = (string) $node; if (!empty($node['backend_model']) && !empty($sValue)) { $backend = Mage::getModel((string) $node['backend_model']); $backend->setPath($path)->setValue($sValue)->afterLoad(); $sValue = $backend->getValue(); } if (is_string($sValue) && strpos($sValue, '{{') !== false) { if (strpos($sValue, '{{unsecure_base_url}}') !== false) { $unsecureBaseUrl = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL); $sValue = str_replace('{{unsecure_base_url}}', $unsecureBaseUrl, $sValue); } elseif (strpos($sValue, '{{secure_base_url}}') !== false) { $secureBaseUrl = $this->getConfig(self::XML_PATH_SECURE_BASE_URL); $sValue = str_replace('{{secure_base_url}}', $secureBaseUrl, $sValue); } elseif (strpos($sValue, '{{base_url}}') === false) { $sValue = Mage::getConfig()->substDistroServerVars($sValue); } } $this->_configCache[$path] = $sValue; return $sValue; }
/** * Appends $source to current node * * @param Varien_Simplexml_Element $source * @return Varien_Simplexml_Element */ public function appendChild($n, $source) { if ($source->children()) { /** * @see http://bugs.php.net/bug.php?id=41867 , fixed in 5.2.4 */ if (version_compare(phpversion(), '5.2.4', '<') === true) { $name = $source->children()->getName(); } else { $name = $source->getName(); } $child = $n->addChild($name); } else { $child = $n->addChild($source->getName(), $this->xmlentities($source)); } $attributes = $source->attributes(); foreach ($attributes as $key => $value) { $child->addAttribute($key, $this->xmlentities($value)); } foreach ($source->children() as $sourceChild) { $this->appendChild($child, $sourceChild); } return $n; }
/** * Prepares all requests data by processing (sitemap) input. * @param InputInterface $input * @param OutputInterface $output * @return mixed */ protected function prepareRequests(InputInterface $input, OutputInterface $output) { $requestSetCollection = array(); // collection of all sets of requests (set = sitemap) // looping through all sitemaps, get, validate and prepare them foreach ($this->_sitemaps as $sitemap) { $requestSet = array(); // a sitemap $requestSet['metadata'] = $sitemap; $xml = ''; // Getting the XML from URL & validate it if (isset($sitemap['sitemap_url'])) { if ($this->validateUrl($sitemap['sitemap_url'])) { try { $curl = $this->getCurl(); $curl->get($sitemap['sitemap_url']); if ($curl->http_status_code == '200') { try { $xml = new \Varien_Simplexml_Element($curl->response); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . ' ' . $sitemap['sitemap_url'] . '</error>'); continue; } } } catch (\Exception $e) { $output->writeln('<error>An error occured while getting the sitemap: ' . $e->getMessage() . '</error>'); continue; } } else { $output->writeln('<error>The URL: ' . $sitemap['sitemap_url'] . ' is not valid.</error>'); continue; } // getting the sitemap from a file } else { if (file_exists($this->_magentoRootFolder . $sitemap['relative_path'])) { try { $xml = new \Varien_Simplexml_Element(file_get_contents($this->_magentoRootFolder . $sitemap['relative_path'])); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . ' ' . $sitemap['relative_path'] . '</error>'); continue; } // converting a txt of urls to magento sitemap structure (hypernode internal) } elseif (file_exists($sitemap['relative_path'])) { if (end(explode('.', $sitemap['relative_path'])) == 'txt') { $xml = new \Varien_Simplexml_Element($this->convertTxtToXml(file_get_contents($sitemap['relative_path']))); } else { $output->writeln('<error>Only a txt url list is currently supported for absolute paths.</error>'); } } } // creating batches if ($xml) { $requestSet['requests'] = array(); $urls = array(); foreach ($xml->children() as $child) { array_push($urls, $child->loc); } $replace = false; // finding out which replace strategy to use if ($this->_options['sitemap'] && $this->_options['compare-url'] && $this->_options['current-url']) { $replace = 3; // Replace and compare } elseif ($requestSet['metadata']['base_url']) { if (!$this->matchUrls($requestSet['metadata']['base_url'], $urls[0])['status']) { $replace = $this->askReplaceOrCompare($input, $output, $requestSet['metadata']['base_url'], $urls[0]); } } $i = 1; foreach ($urls as $url) { $requestBatch = array(); // batch for curling // replace strategy execution if ($replace) { if ($replace == 1) { // Use site from sitemap array_push($requestBatch, $this->replaceUrlByParse($url, $requestSet['metadata']['base_url'])); } elseif ($replace == 2) { // Use both (side by side) array_push($requestBatch, $this->replaceUrlByParse($url, $requestSet['metadata']['base_url'])); //left array_push($requestBatch, (string) $url); // right } elseif ($replace == 3) { array_push($requestBatch, $this->replaceUrl($url, $this->_options['current-url'])); array_push($requestBatch, $this->replaceUrl($url, $this->_options['compare-url'])); } else { array_push($requestBatch, (string) $url); } } else { array_push($requestBatch, (string) $url); // no replace, just crawl } array_push($requestSet['requests'], $requestBatch); if ($this->_options['limit'] && $i >= $this->_options['limit']) { break; } else { $i++; } } //endforeach } //endif $xml @todo verify that no empty set is returned with bad $xml (prio) array_push($requestSetCollection, $requestSet); } return $requestSetCollection; }
protected function _buildModuleMenuChildrenArray(Varien_Simplexml_Element $parent = null, $path = '', $level = 0) { $parentArr = array(); $sortOrder = 0; foreach ($parent->children() as $childName => $child) { $result = $this->_buildModuleMenuChild($childName, $child, $path, $level, $sortOrder); if ($result) { $parentArr[$childName] = $result; $sortOrder++; } } uasort($parentArr, array($this, '_sortMenu')); while (list($key, $value) = each($parentArr)) { $last = $key; } if (isset($last)) { $parentArr[$last]['last'] = true; } return $parentArr; }