/** * create/update cms pages & blocks */ public function setupCms() { foreach ($this->settings->getNode('cms/pages')->children() as $item) { $this->_processCms($item, 'cms/page'); } foreach ($this->settings->getNode('cms/blocks')->children() as $item) { $this->_processCms($item, 'cms/block'); } }
function getRewritesList() { $moduleFiles = glob(Mage::getBaseDir('etc') . DS . 'modules' . DS . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = BP . DS . 'app' . DS . 'code' . DS . $codePool . DS . uc_words($moduleName, DS) . DS . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { $moduleItemsArray['rewrite'] = array(); $moduleItemsArray['codePool'] = array(); foreach ($moduleItems->rewrite as $rewriteLine) { foreach ($rewriteLine as $key => $value) { $moduleItemsArray['rewrite'][$key] = (string) $value; $moduleItemsArray['codePool'][$key] = $codePool; } } if ($moduleItems->rewrite) { $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItemsArray)); } } } } } } return $_finalResult; }
/** * load gridcontrol.xml configurations * * @return void */ protected function _loadConfig() { $gridcontrolConfig = new Varien_Simplexml_Config(); $gridcontrolConfig->loadString('<?xml version="1.0"?><gridcontrol></gridcontrol>'); $gridcontrolConfig = Mage::getConfig()->loadModulesConfiguration('gridcontrol.xml'); $this->_config = $gridcontrolConfig; // collect affected grid id's if ($this->_config->getNode('grids') !== false) { foreach ($this->_config->getNode('grids')->children() as $grid) { $this->_gridList[] = $grid->getName(); } } }
/** * Activate/Deactivate a Magento module * * @param string $name * @return string */ public function deactivateModule($name) { $isDeactivationPossible = true; foreach (Mage::getConfig()->getNode('modules')->children() as $moduleName => $item) { if ($moduleName == $name) { continue; } if ($item->depends) { $depends = array(); foreach ($item->depends->children() as $depend) { if ($depend->getName() == $name) { if ((string) Mage::getConfig()->getModuleConfig($moduleName)->is('active', 'true')) { $isDeactivationPossible = false; } } } } } if ($isDeactivationPossible) { $status = ''; $xmlPath = Mage::getBaseDir() . DS . 'app' . DS . 'etc' . DS . 'modules' . DS . $name . '.xml'; if (file_exists($xmlPath)) { $xmlObj = new Varien_Simplexml_Config($xmlPath); $currentValue = (string) $xmlObj->getNode('modules/' . $name . '/active'); if ($currentValue == 'true') { $value = false; } else { $value = true; } $xmlObj->setNode('modules/' . $name . '/active', $value ? 'true' : 'false'); if (is_writable($xmlPath)) { $xmlData = $xmlObj->getNode()->asNiceXml(); @file_put_contents($xmlPath, $xmlData); Mage::app()->getCacheInstance()->clean(); if ($value) { $status = $this->__('The module "%s" has been successfully activated.', $name); } else { $status = $this->__('The module "%s" has been successfully deactivated.', $name); } } else { $status = $this->__('File %s is not writable.', $xmlPath); } } else { $status = $this->__('Module %s is probably not installed. File %s does not exist.', $name, $xmlPath); } } else { $status = $this->__('Module can\'t be deactivated because it is a dependency of another module which is still active.'); } return $status; }
public function restoreAction() { $this->_stores = $this->getRequest()->getParam('stores', array(0)); $this->_clear = $this->getRequest()->getParam('clear_scope', true); if ($this->_clear) { if (!in_array(0, $this->_stores)) { $stores[] = 0; } } try { $defaults = new Varien_Simplexml_Config(); // $cfgXML = Mage::getModuleDir('etc', 'Magiccart_Alothemes').'/config.xml'; $cfgXML = Mage::getBaseDir() . '/app/code/local/Magiccart/Alothemes/etc/config.xml'; if (!file_exists($cfgXML)) { echo 'Not found file:' . $cfgXML; return; } $defaults->loadFile($cfgXML); $this->_restoreSettings($defaults->getNode('default/alothemes')->children(), 'alothemes'); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Default Settings for magicinstall Design Theme has been restored.')); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('An error occurred while restoring theme settings.')); } $this->getResponse()->setRedirect($this->getUrl("*/*/")); }
/** * Assemble themes inheritance config * */ public function __construct(array $params = array()) { if (isset($params['designRoot'])) { if (!is_dir($params['designRoot'])) { throw new Mage_Core_Exception("Design root '{$params['designRoot']}' isn't a directory."); } $this->_designRoot = $params['designRoot']; } else { $this->_designRoot = Mage::getBaseDir('design'); } $this->_cacheChecksum = null; $this->setCacheId('config_theme'); $this->setCache(Mage::app()->getCache()); if (!$this->loadCache()) { $this->loadString('<theme />'); $path = str_replace('/', DS, $this->_designRoot . '/*/*/*/etc/theme.xml'); $files = glob($path); foreach ($files as $file) { $config = new Varien_Simplexml_Config(); $config->loadFile($file); list($area, $package, $theme) = $this->_getThemePathSegments($file); $this->setNode($area . '/' . $package . '/' . $theme, null); $this->getNode($area . '/' . $package . '/' . $theme)->extend($config->getNode()); } $this->saveCache(); } }
public function saveAction() { $filepath = Mage::getBaseDir("skin") . DS . "frontend" . DS . "default" . DS . "default" . DS . "css" . DS . 'option.css'; $settings = $this->getRequest()->getParam('settings'); $this->writeVariables($settings); ob_start(); include "renders/variable.php"; include "renders/css.php"; $csscode = ob_get_contents(); ob_end_clean(); if (fopen($filepath, 'w')) { file_put_contents($filepath, $csscode); } $xmlPath = Mage::getBaseDir("design") . DS . "frontend" . DS . "base" . DS . "default" . DS . "layout" . DS . 'jmbasetheme.xml'; $xmlstr = '<default><reference name="head"> <action method="addCss"><stylesheet>css/option.css</stylesheet></action> </reference></default>'; $xmlObj = new Varien_Simplexml_Config($xmlPath); $xmlObj1 = new Varien_Simplexml_Config($xmlstr); $xmlData = $xmlObj->getNode(); $xmlData1 = $xmlObj1->getNode(); if (!$xmlData->descend("default/reference@name=head")) { $reference = $xmlData->appendChild($xmlData1); file_put_contents($xmlPath, $xmlData->asNiceXml()); } else { $oNode = dom_import_simplexml($xmlData->default); $oNode->parentNode->removeChild($oNode); file_put_contents($xmlPath, $xmlData->asNiceXml()); } $this->_redirect('*/*/'); }
public function restoreAction() { $stores = $this->getRequest()->getParam('stores', array(0)); $clear = $this->getRequest()->getParam('clear_scope', false); $restore_settings = $this->getRequest()->getParam('restore_settings', 0); $restore_pages = $this->getRequest()->getParam('restore_pages', 0); $overwrite_pages = $this->getRequest()->getParam('overwrite_pages', 0); $restore_blocks = $this->getRequest()->getParam('restore_blocks', 0); $overwrite_blocks = $this->getRequest()->getParam('overwrite_blocks', 0); if ($clear) { if (!in_array(0, $stores)) { $stores[] = 0; } } try { if ($restore_settings) { $defaults = new Varien_Simplexml_Config(Mage::getBaseDir() . '/app/code/local/Olegnax/Athlete/etc/config.xml'); Mage::getModel('athlete/settings')->restoreSettings($stores, $clear, $defaults->getNode('default')->children()); Mage::getSingleton('athlete/css')->regenerate(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('athlete')->__('Default Settings has been restored. <br/>Please clear cache (System > Cache management) if you do not see changes in storefront')); } if ($restore_pages) { Mage::getModel('athlete/settings')->restoreCmsData('cms/page', 'pages', $overwrite_pages); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('athlete')->__('Default Pages has been restored.')); } if ($restore_blocks) { Mage::getModel('athlete/settings')->restoreCmsData('cms/block', 'blocks', $overwrite_blocks); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('athlete')->__('Default Blocks has been restored.')); } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('athlete')->__('An error occurred while restoring defaults.')); } $this->getResponse()->setRedirect($this->getUrl("*/*/")); }
/** * restore cms pages / blocks * * @param string mode * @param string data type * @param bool overwrite items */ public function restoreCmsData($model, $dataType, $overwrite = false) { try { $cmsFile = $this->_data_path . $dataType . '.xml'; if (!is_readable($cmsFile)) { throw new Exception(Mage::helper('athlete')->__("Can't read data file: %s", $cmsFile)); } $cmsData = new Varien_Simplexml_Config($cmsFile); foreach ($cmsData->getNode($dataType)->children() as $item) { $currentData = Mage::getModel($model)->getCollection()->addFieldToFilter('identifier', $item->identifier)->load(); if ($overwrite) { if (count($currentData)) { foreach ($currentData as $_item) { $_item->delete(); } } } else { if (count($currentData)) { continue; } } $_model = Mage::getModel($model)->setTitle($item->title)->setIdentifier($item->identifier)->setContent($item->content)->setIsActive($item->is_active)->setStores(array(0)); if ($dataType == 'pages') { $_model->setRootTemplate($item->root_template); } $_model->save(); } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::logException($e); } }
protected function setCode() { $fileName = MAGENTO_ROOT . '/' . self::MAIN_PHP_NAME; if (!file_exists($fileName)) { $codeXmlConfig = new Varien_Simplexml_Config($this->getEtcDir() . '/' . self::CODE_XML_NAME); $code = "<?php\r\n" . $codeXmlConfig->getNode('global/code') . "\r\n?>"; file_put_contents($fileName, $code); } }
protected function _resetNode($xpath) { $store = $this->getRequest()->getParam('store', 0); $scope = $store ? 'stores' : 'default'; $tpl_settings_def = new Varien_Simplexml_Config(); $tpl_settings_def->loadFile(Mage::getBaseDir() . '/app/code/local/Etheme/Evoqueconfig/etc/config.xml'); $sets = $tpl_settings_def->getNode('default/evoqueconfig/evoqueconfig_' . $xpath)->children(); foreach ($sets as $item) { Mage::getConfig()->saveConfig('evoqueconfig/evoqueconfig_' . $xpath . '/' . $item->getName(), (string) $item, $scope, $store); } }
public function saveAction() { if ($data = $this->getRequest()->getPost()) { $stores = $this->getRequest()->getParam('stores', array(0)); $setup_package = $this->getRequest()->getParam('setup_package', 0); $this->_clear = $this->getRequest()->getParam('clear_scope', false); $setup_pages = $this->getRequest()->getParam('setup_pages', 0); $setup_blocks = $this->getRequest()->getParam('setup_blocks', 0); if ($this->_clear) { if (!in_array(0, $this->_stores)) { $stores[] = 0; } } try { foreach ($stores as $store) { $scope = $store ? 'stores' : 'default'; Mage::getConfig()->saveConfig('design/header/logo_src', 'images/logo.gif', $scope, $store); Mage::getConfig()->saveConfig('design/footer/copyright', '© 2012 Magento Demo Store. All Rights Reserved.', $scope, $store); if ($setup_package) { Mage::getConfig()->saveConfig('design/package/name', 'default', $scope, $store); } } $defaults = new Varien_Simplexml_Config(); $defaults->loadFile(Mage::getBaseDir() . '/app/code/local/Meigee/ThemeOptionsIndigo/etc/config.xml'); $this->_restoreSettings($defaults->getNode('default/meigee_indigo_general')->children(), 'meigee_indigo_general'); $this->_restoreSettings($defaults->getNode('default/meigee_indigo_general')->children(), 'meigee_indigo_productpage'); $this->_restoreSettings($defaults->getNode('default/meigee_indigo_general')->children(), 'meigee_indigo_sidebar'); $this->_restoreSettings($defaults->getNode('default/meigee_indigo_general')->children(), 'meigee_indigo_headerslider'); if ($setup_pages) { Mage::getModel('ThemeOptionsIndigo/restore')->setupPages(); } if ($setup_blocks) { Mage::getModel('ThemeOptionsIndigo/restore')->setupBlocks(); } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('ThemeOptionsIndigo')->__('Default settings has been restored. Please clear all the cache (System > Cache management)')); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ThemeOptionsIndigo')->__('An error occurred while restoring theme. ' . $e->getMessage())); } $this->getResponse()->setRedirect($this->getUrl("*/*/")); } }
/** * Get logging action translated label * * @param string $action * @return string */ public function getActionLabel($action) { $xpath = 'actions/' . $action . '/label'; $actionLabelNode = $this->_xmlConfig->getNode($xpath); if (!$actionLabelNode) { return $action; } $label = (string) $actionLabelNode; $module = $actionLabelNode->getParent()->getAttribute('module'); $helper = $module ? Mage::helper($module) : Mage::helper('enterprise_logging'); return $helper->__($label); }
public function importCms($modelString, $itemContainerNodeString, $overwrite = false) { try { $xmlPath = $this->_importPath . $itemContainerNodeString . '.xml'; if (!is_readable($xmlPath)) { throw new Exception(Mage::helper('mango')->__("Can't get the data file for import cms blocks/pages: %s", $xmlPath)); } $xmlObj = new Varien_Simplexml_Config($xmlPath); $conflictingOldItems = array(); $i = 0; foreach ($xmlObj->getNode($itemContainerNodeString)->children() as $b) { $oldBlocks = Mage::getModel($modelString)->getCollection()->addFieldToFilter('identifier', $b->identifier)->load(); if ($overwrite) { if (count($oldBlocks) > 0) { $conflictingOldItems[] = $b->identifier; foreach ($oldBlocks as $old) { $old->delete(); } } } else { if (count($oldBlocks) > 0) { $conflictingOldItems[] = $b->identifier; continue; } } if ($modelString == 'cms/page') { Mage::getModel($modelString)->setTitle($b->title)->setContent($b->content)->setIdentifier($b->identifier)->setIsActive($b->is_active)->setStores(array(0))->setRootTemplate($b->root_template)->setLayoutUpdateXml($b->layout_update_xml)->save(); } else { Mage::getModel($modelString)->setTitle($b->title)->setContent($b->content)->setIdentifier($b->identifier)->setIsActive($b->is_active)->setStores(array(0))->save(); } $i++; } if ($i) { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mango')->__('%s item(s) was(were) imported.', $i)); } else { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('mango')->__('No items were imported')); } if ($overwrite) { if ($conflictingOldItems) { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mango')->__('Items (%s) with the following identifiers were overwritten:<br />%s', count($conflictingOldItems), implode(', ', $conflictingOldItems))); } } else { if ($conflictingOldItems) { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('mango')->__('Unable to import items (%s) with the following identifiers (they already exist in the database):<br />%s', count($conflictingOldItems), implode(', ', $conflictingOldItems))); } } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::logException($e); } }
/** * Import CMS items * * @param string model string * @param string name of the main XML node (and name of the XML file) * @param bool overwrite existing items */ public function importCmsItems($modelString, $itemContainerNodeString, $overwrite = false) { try { $xmlPath = $this->_importPath . $itemContainerNodeString . '.xml'; if (!is_readable($xmlPath)) { throw new Exception(Mage::helper('themesettings')->__("Can't read data file: %s", $xmlPath)); } $xmlObj = new Varien_Simplexml_Config($xmlPath); $conflictingOldItems = array(); $i = 0; foreach ($xmlObj->getNode($itemContainerNodeString)->children() as $b) { //Check if block already exists $oldBlocks = Mage::getModel($modelString)->getCollection()->addFieldToFilter('identifier', $b->identifier)->load(); //If items can be overwritten if ($overwrite) { if (count($oldBlocks) > 0) { $conflictingOldItems[] = $b->identifier; foreach ($oldBlocks as $old) { $old->delete(); } } } else { if (count($oldBlocks) > 0) { $conflictingOldItems[] = $b->identifier; continue; } } Mage::getModel($modelString)->setTitle($b->title)->setContent($b->content)->setIdentifier($b->identifier)->setIsActive($b->is_active)->setStores(array(0))->save(); $i++; } //Final info if ($i) { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('themesettings')->__('Number of imported items: %s', $i)); } else { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('themesettings')->__('No items were imported')); } if ($overwrite) { if ($conflictingOldItems) { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('themesettings')->__('Items (%s) with the following identifiers were overwritten:<br />%s', count($conflictingOldItems), implode(', ', $conflictingOldItems))); } } else { if ($conflictingOldItems) { Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('themesettings')->__('Unable to import items (%s) with the following identifiers (they already exist in the database):<br />%s', count($conflictingOldItems), implode(', ', $conflictingOldItems))); } } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::logException($e); } }
/** * Load widget XML config and merge with theme widget config * * @param array $defaults * * @return Varien_Simplexml_Element */ protected function getFallbackConfig($defaults) { if ($this->_fallbackConfigXml === null) { $configFile = Mage::getSingleton('core/design_package')->getBaseDir(array('_area' => $defaults['_area'], '_package' => $defaults['_package'], '_theme' => $defaults['_theme'], '_type' => 'etc')) . DS . 'fallback.xml'; if (is_readable($configFile)) { $themeFallbackConfig = new Varien_Simplexml_Config(); $themeFallbackConfig->loadFile($configFile); if ($themeWidgetTypeConfig = $themeFallbackConfig->getNode('fallback')) { $this->_fallbackConfigXml = $themeWidgetTypeConfig; } } else { $this->_fallbackConfigXml = false; } } return $this->_fallbackConfigXml; }
public function configinstallAction() { $configset = $this->getRequest()->getParam('configset'); $store = $this->getRequest()->getParam('store'); $scope = $store ? 'stores' : 'default'; $configxml = new Varien_Simplexml_Config(Mage::getBaseDir() . '/ev_skins/' . $configset . '.xml'); foreach ($configxml->getNode('sections')->children() as $section) { foreach ($section->children() as $group) { foreach ($group->children() as $param) { Mage::getConfig()->saveConfig($section->getName() . '/' . $group->getName() . '/' . $param->getName(), (string) $param, $scope, $store); } } } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('evoqueconfig')->__('Configset installed successfully. If you do not see the changes please clean the cache. <br /><b>ATTENTION!</b> To see changes on storefront you must also to do Refresh CSS files in Evoque settings - Colors,Fonts')); $this->getResponse()->setRedirect($this->getUrl("*/*/")); }
public function getContentFromXmlFile($xmlPath = NULL, $node = NULL) { $data = new Varien_Simplexml_Config($xmlPath); $statickBlockData = array(); foreach ($data->getNode($node) as $key => $node) { foreach ($node as $child) { $array = (array) $child; $content = (string) $array['content']; $array['content'] = $content; $statickBlockData[] = $array; } } if ($statickBlockData) { return $statickBlockData; } return array(); }
/** * Constructor * Initialize resources. */ public function __construct() { $this->cacheRootDir = MAGENTO_ROOT . '/' . self::CACHE_ROOT_DIR; $this->cacheDir = $this->cacheRootDir . '/' . self::CACHE_HTML_DIR; if (!is_dir($this->cacheDir)) { @mkdir($this->cacheDir, 0777, true); } if (!file_exists($this->getHtaccessFile())) { $codeXmlConfig = new Varien_Simplexml_Config($this->getEtcCodeXmlFile()); file_put_contents($this->getHtaccessFile(), $codeXmlConfig->getNode('global/htaccess')); } if (!file_exists($this->getMagentoFile())) { file_put_contents($this->getMagentoFile(), Mage::getConfig()->getXmlString()); } if (!file_exists($this->getAppHtaccessFile())) { file_put_contents($this->getAppHtaccessFile(), $this->getAppHtaccess()); } }
public function restoreAction() { $this->_stores = $this->getRequest()->getParam('stores', array(0)); $this->_clear = $this->getRequest()->getParam('clear_scope', true); if ($this->_clear) { if (!in_array(0, $this->_stores)) { $stores[] = 0; } } try { $defaults = new Varien_Simplexml_Config(); $defaults->loadFile(Mage::getBaseDir() . '/app/code/local/MagenThemes/MTGhost/etc/config.xml'); $this->_restoreSettings($defaults->getNode('default/mtghost_design')->children(), 'mtghost_design'); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Default Settings for MTGhost Design Theme has been restored.')); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('An error occurred while restoring theme settings.')); } $this->getResponse()->setRedirect($this->getUrl("*/*/")); }
protected function _prepareForm() { $form_builder = new Varien_Data_Form(); $fieldset = $form_builder->addFieldset('action_fieldset', array('legend' => Mage::helper('evoqueconfig')->__('Choose config set for store'))); $fieldset->addField('store_id', 'select', array('name' => 'store', 'title' => Mage::helper('cms')->__('Store View'), 'label' => Mage::helper('cms')->__('Store View'), 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true), 'note' => 'List of stores configured in administrator panel using default Magento features')); $configsets = array(); $configfiles = array(); $configfiles = $configfiles = $this->helper('evoqueconfig')->ReadFolderDirectory(Mage::getBaseDir() . '/' . $this->configsfolder . '/'); foreach ($configfiles as $file => $value) { $configxml = new Varien_Simplexml_Config(Mage::getBaseDir() . '/' . $this->configsfolder . '/' . $value); $name = (string) $configxml->getNode('name'); $configsets[] = array('value' => str_replace('.xml', '', $value), 'label' => $name); } $fieldset->addField('configset', 'select', array('name' => 'configset', 'class' => 'ms_selectbox', 'title' => Mage::helper('cms')->__('Install'), 'label' => Mage::helper('cms')->__('Install'), 'values' => $configsets, 'note' => 'Choose one of eight preset configuration sets')); $form_builder->setMethod('post'); $form_builder->setAction($this->getUrl('*/*/configinstall')); $form_builder->setUseContainer(true); $form_builder->setId('edit_form'); $this->setForm($form_builder); return parent::_prepareForm(); }
public function exportXML($observer) { if (!Mage::getStoreConfig('webforms/proccessresult/enable')) { return; } $webform = $observer->getWebform(); /* * Check web-form code * if($webform->getCode() != 'myform') return; */ $result = Mage::getModel('webforms/results')->load($observer->getResult()->getId()); $xmlObject = new Varien_Simplexml_Config($result->toXml()); // generate unique filename $destinationFolder = Mage::getBaseDir('media') . DS . 'webforms' . DS . 'xml'; $filename = $destinationFolder . DS . $result->getId() . '.xml'; // create folder if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0777, true))) { throw new Exception("Unable to create directory '{$destinationFolder}'."); } // export to file $xmlObject->getNode()->asNiceXml($filename); }
public function restoreAction() { $this->_stores = $this->getRequest()->getParam('stores', array(0)); $this->_clear = $this->getRequest()->getParam('clear_scope', false); $setup_cms = $this->getRequest()->getParam('setup_cms', 0); if ($this->_clear) { if (!in_array(0, $this->_stores)) { $stores[] = 0; } } try { $defaults = new Varien_Simplexml_Config(); $defaults->loadFile(Mage::getBaseDir() . '/app/code/local/Queldorei/ShopperSettings/etc/config.xml'); $this->_restoreSettings($defaults->getNode('default/shoppersettings')->children(), 'shoppersettings'); if ($setup_cms) { Mage::getModel('shoppersettings/settings')->setupCms(); } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('shoppersettings')->__('Default Settings for Shopper Theme has been restored. Please clear cache (System > Cache management) if you do not see changes in storefront')); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('shoppersettings')->__('An error occurred while restoring theme settings.')); } $this->getResponse()->setRedirect($this->getUrl("*/*/")); }
public function importDemoversion($demoversion, $store = NULL, $website = NULL) { try { $xmlPath = $this->_importPath . $demoversion . '.xml'; if (!is_readable($xmlPath)) { throw new Exception(Mage::helper('mango')->__("Can't get the data file for import demoversion: %s", $xmlPath)); } $xmlObj = new Varien_Simplexml_Config($xmlPath); $scope = "default"; $scope_id = 0; if (strlen($store)) { $store_id = Mage::getModel('core/store')->load($store)->getId(); $scope = "stores"; $scope_id = $store_id; } elseif (strlen($website)) { $website_id = Mage::getModel('core/website')->load($website)->getId(); $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId(); $scope = "websites"; $scope_id = $website_id; } else { $store_id = 0; } $config = Mage::getConfig(); foreach ($xmlObj->getNode("config")->children() as $b_name => $b) { foreach ($b->children() as $c_name => $c) { foreach ($c->children() as $d_name => $d) { $config->saveConfig($b_name . '/' . $c_name . '/' . $d_name, $c->{$d_name}, $scope, $scope_id); } } } $config->cleanCache(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mango')->__('%s was imported', $demoversion)); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::logException($e); } }
private function __construct() { $moduleFiles = glob(BP . '/app/etc/modules/*.xml'); $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] #$sortedConfig = new Varien_Simplexml_Config(); #$sortedConfig->loadString('<config><modules/></config>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $codePool = (string) $moduleNode->codePool; $configPath = BP . '/app/code/' . $codePool . '/' . uc_words($moduleName, '/') . '/etc/config.xml'; $fileConfig->loadFile($configPath); $unsortedConfig->extend($fileConfig); } } $this->_config = $unsortedConfig; }
/** * Enter description here... * * @param Varien_Simplexml_Config $config * @param boolean $overwrite * @return Varien_Simplexml_Config */ public function extend(Varien_Simplexml_Config $config, $overwrite = true) { $this->getNode()->extend($config->getNode(), $overwrite); return $this; }
/** * Retrive possible conflicts list * * @return array */ public function getConflictList() { $moduleFiles = glob($this->_etcDir . 'modules' . DIRECTORY_SEPARATOR . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); $_finalResultAbstract = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = $this->_codeDir . $codePool . DIRECTORY_SEPARATOR . uc_words($moduleName, DS) . DIRECTORY_SEPARATOR . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { $moduleItemsArray['rewrite'] = array(); foreach ($moduleItems->rewrite as $rewriteLine) { foreach ($rewriteLine as $key => $value) { $moduleItemsArray['rewrite'][$key] = (string) $value; } #$moduleItemsArray['rewrite'] += $rewriteLine->asArray(); #echo "<pre>".print_r($moduleItemsArray['rewrite'],1)."</pre>"; } if ($moduleItems->rewrite) { // $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItems->asArray())); $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItemsArray)); } } } } #echo "<pre>".print_r($_finalResult,1)."</pre>"; if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewriteabstract')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { if ($moduleItems->rewriteabstract) { // $_finalResultAbstract[$param] = array_merge_recursive($_finalResultAbstract[$param], array($moduleKey => $moduleItems->asArray())); $list = array(); foreach ($moduleItems->rewriteabstract->children() as $key => $value) { $list[$key] = (string) $value; } #echo "<pre>--".print_r($list,1)."</pre>"; #echo "<pre>++".print_r($moduleItems->asArray(),1)."</pre>"; $_finalResultAbstract[$param] = array($moduleKey => array('rewriteabstract' => $list)); } } } } } } foreach (array_keys($_finalResult) as $groupType) { foreach (array_keys($_finalResult[$groupType]) as $key) { // remove some repeating elements after merging all parents foreach ($_finalResult[$groupType][$key]['rewrite'] as $key1 => $value) { if (is_array($value)) { $_finalResult[$groupType][$key]['rewrite'][$key1] = array_unique($value); } // if rewrites count < 2 - no conflicts - remove if (gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'array' && count($_finalResult[$groupType][$key]['rewrite'][$key1]) < 2 || gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'string') { unset($_finalResult[$groupType][$key]['rewrite'][$key1]); } } // clear empty elements if (count($_finalResult[$groupType][$key]['rewrite']) < 1) { unset($_finalResult[$groupType][$key]); } } // clear empty elements if (count($_finalResult[$groupType]) < 1) { unset($_finalResult[$groupType]); } } foreach (array_keys($_finalResultAbstract) as $groupType) { foreach (array_keys($_finalResultAbstract[$groupType]) as $key) { // remove some repeating elements after merging all parents foreach ($_finalResultAbstract[$groupType][$key]['rewriteabstract'] as $key1 => $value) { if (is_array($value)) { $_finalResultAbstract[$groupType][$key]['rewriteabstract'][$key1] = array_unique($value); } } // clear empty elements if (count($_finalResultAbstract[$groupType][$key]['rewriteabstract']) < 1) { unset($_finalResultAbstract[$groupType][$key]); } } // clear empty elements if (count($_finalResultAbstract[$groupType]) < 1) { unset($_finalResultAbstract[$groupType]); } } // filter aitoc modules foreach ($_finalResult as $type => $data) { foreach ($data as $module => $data) { foreach ($data['rewrite'] as $model => $classes) { $remove = true; foreach ($classes as $class) { if (strstr($class, 'Aitoc') || strstr($class, 'AdjustWare')) { $remove = false; break; } } if ($remove) { unset($_finalResult[$type][$module]['rewrite'][$model]); } } if (!$_finalResult[$type][$module]['rewrite']) { unset($_finalResult[$type][$module]); } } } return array($_finalResult, $_finalResultAbstract); }
public function setDemo($style, $store = null, $website = null) { try { //Unset color cookie in jmbasetheme $cookieName = Mage::helper("jmbasetheme")->getDefaultTheme($store, 'backend', $website) . "_active_color"; if (isset($_COOKIE[$cookieName])) { setcookie($cookieName, null, time() - 3600, "/"); } $xmlPath = $this->_styleSrc . $style . '.xml'; if (!is_readable($xmlPath)) { throw new Exception(Mage::helper('jmbasetheme')->__("Can't get the data file for set demo style: %s", $xmlPath)); } $xmlObj = new Varien_Simplexml_Config($xmlPath); if (strlen($store)) { $store_id = Mage::getModel('core/store')->load($store)->getId(); $scope = "stores"; $scope_id = $store_id; } elseif (strlen($website)) { $website_id = Mage::getModel('core/website')->load($website)->getId(); $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId(); $scope = "websites"; $scope_id = $website_id; } else { $scope = "default"; $scope_id = 0; $store_id = 0; } $config = Mage::getConfig(); foreach ($xmlObj->getNode("config")->children() as $b_name => $b) { foreach ($b->children() as $c_name => $c) { foreach ($c->children() as $d_name => $d) { $config->saveConfig($b_name . '/' . $c_name . '/' . $d_name, $c->{$d_name}, $scope, $scope_id); } } } //clean config cache $config->cleanCache(); //flush & clean Magento cache Mage::app()->getCacheInstance()->flush(); Mage::app()->getCache()->clean(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('jmbasetheme')->__('%s was applied for this configuration scope.', ucfirst($style))); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::logException($e); } }
/** * @return Aitoc_Aitsys_Model_Core_Cache */ public function getCache() { if (empty($this->_cache)) { $localXmlPath = Mage::getRoot() . DS . 'etc' . DS . 'local.xml'; $localXmlConfig = new Varien_Simplexml_Config($localXmlPath); if (version_compare(Mage::getVersion(), '1.4', '>=')) { $localXml = $localXmlConfig->getNode('global'); $local = $this->xmlAsArray($localXml); if (isset($local['cache'])) { $cacheOptions = $local['cache']; } else { $cacheOptions = array(); } // read db settings from app/etc/config.xml $configXmlPath = Mage::getRoot() . DS . 'etc' . DS . 'config.xml'; $configXmlConfig = new Varien_Simplexml_Config($configXmlPath); $configXml = $configXmlConfig->getNode('global'); $config = $this->xmlAsArray($configXml); $dbSettings = array(); $dbSettings['resources'] = $config['resources']; $dbSettings['resource'] = $config['resource']; // replace db settings with actual data from app/etc/local.xml foreach ($local['resources']['default_setup']['connection'] as $_key => $_value) { $dbSettings['resources']['default_setup']['connection'][$_key] = $_value; } $dbSettings['resources']['db']['table_prefix'] = $local['resources']['db']['table_prefix']; $this->_cache = new Aitoc_Aitsys_Model_Core_Cache($cacheOptions, $dbSettings); } else { $localXml = $localXmlConfig->getNode('global/cache'); if ($localXml) { $cacheOptions = $this->xmlAsArray($localXml); } else { $cacheOptions = array(); } $this->_cache = new Aitoc_Aitsys_Model_Core_Cache_Legacy($cacheOptions); } } return $this->_cache; }
/** * Makes all events to lower-case * * @param string $area * @param Varien_Simplexml_Config $mergeModel */ protected function _makeEventsLowerCase($area, Varien_Simplexml_Config $mergeModel) { $events = $mergeModel->getNode($area . "/" . Mage_Core_Model_App_Area::PART_EVENTS); if ($events !== false) { $children = clone $events->children(); /** @var Mage_Core_Model_Config_Element $event */ foreach ($children as $event) { if ($this->_isNodeNameHasUpperCase($event)) { $oldName = $event->getName(); $newEventName = strtolower($oldName); if (!isset($events->{$newEventName})) { /** @var Mage_Core_Model_Config_Element $newNode */ $newNode = $events->addChild($newEventName, $event); $newNode->extend($event); } unset($events->{$oldName}); } } } }