Esempio n. 1
0
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @return bool
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function match(Mage_Core_Controller_Request_Http $request)
 {
     if (!Mage::isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     $identifier = trim($request->getPathInfo(), '/');
     $condition = new Varien_Object(array('identifier' => $identifier, 'continue' => true));
     $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
     $identifier = $condition->getIdentifier();
     if ($condition->getRedirectUrl()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect($condition->getRedirectUrl())->sendResponse();
         $request->setDispatched(true);
         return $this->_controllerFactory->createController('Mage_Core_Controller_Varien_Action_Redirect', array('request' => $request));
     }
     if (!$condition->getContinue()) {
         return null;
     }
     $page = Mage::getModel('Mage_Cms_Model_Page');
     $pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId());
     if (!$pageId) {
         return null;
     }
     $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
     $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, $identifier);
     return $this->_controllerFactory->createController('Mage_Core_Controller_Varien_Action_Forward', array('request' => $request));
 }
Esempio n. 2
0
 /**
  * Save configuration
  */
 public function indexAction()
 {
     try {
         if (false == $this->_isSectionAllowed($this->getRequest()->getParam('section'))) {
             throw new Exception($this->_getHelper()->__('This section is not allowed.'));
         }
         // custom save logic
         $this->_saveSection();
         $section = $this->getRequest()->getParam('section');
         $website = $this->getRequest()->getParam('website');
         $store = $this->getRequest()->getParam('store');
         $configData = array('section' => $section, 'website' => $website, 'store' => $store, 'groups' => $this->_getGroupsForSave());
         /** @var Mage_Backend_Model_Config $configModel  */
         $configModel = $this->_configFactory->create(array('data' => $configData));
         $configModel->save();
         // re-init configuration
         $this->_configModel->reinit();
         $this->_eventManager->dispatch('admin_system_config_section_save_after', array('website' => $website, 'store' => $store, 'section' => $section));
         $this->_app->reinitStores();
         // website and store codes can be used in event implementation, so set them as well
         $this->_eventManager->dispatch("admin_system_config_changed_section_{$section}", array('website' => $website, 'store' => $store));
         $this->_session->addSuccess($this->_getHelper()->__('The configuration has been saved.'));
     } catch (Mage_Core_Exception $e) {
         $messages = explode("\n", $e->getMessage());
         foreach ($messages as $message) {
             $this->_session->addError($message);
         }
     } catch (Exception $e) {
         $this->_session->addException($e, $this->_getHelper()->__('An error occurred while saving this configuration:') . ' ' . $e->getMessage());
     }
     $this->_saveState($this->getRequest()->getPost('config_state'));
     $this->_redirect('*/system_config/edit', array('_current' => array('section', 'website', 'store')));
 }
Esempio n. 3
0
 /**
  * Assign theme to the stores
  *
  * @param int $themeId
  * @param array $stores
  * @param string $scope
  * @param string $area
  * @return Mage_Core_Model_Theme
  * @throws UnexpectedValueException
  */
 public function assignThemeToStores($themeId, array $stores = array(), $scope = Mage_Core_Model_Config::SCOPE_STORES, $area = Mage_Core_Model_App_Area::AREA_FRONTEND)
 {
     /** @var $theme Mage_Core_Model_Theme */
     $theme = $this->_themeFactory->create()->load($themeId);
     if (!$theme->getId()) {
         throw new UnexpectedValueException('Theme is not recognized. Requested id: ' . $themeId);
     }
     $themeCustomization = $theme->isVirtual() ? $theme : $this->createThemeCustomization($theme);
     $configPath = $this->_design->getConfigPathByArea($area);
     // Unassign given theme from stores that were unchecked
     /** @var $config Mage_Core_Model_Config_Data */
     foreach ($this->_getAssignedScopesCollection($scope, $configPath) as $config) {
         if ($config->getValue() == $themeId && !in_array($config->getScopeId(), $stores)) {
             $this->_app->getConfig()->deleteConfig($configPath, $scope, $config->getScopeId());
         }
     }
     if (count($stores) > 0) {
         foreach ($stores as $storeId) {
             $this->_app->getConfig()->saveConfig($configPath, $themeCustomization->getId(), $scope, $storeId);
         }
         $this->_app->cleanCache(Mage_Core_Model_Config::CACHE_TAG);
     }
     $this->_makeTemporaryLayoutUpdatesPermanent($themeId, $stores);
     $this->_app->cleanCache(array('layout', Mage_Core_Model_Layout_Merge::LAYOUT_GENERAL_CACHE_TAG));
     $this->_eventManager->dispatch('assign_theme_to_stores_after', array('themeService' => $this, 'themeId' => $themeId, 'stores' => $stores, 'scope' => $scope, 'area' => $area, 'theme' => $theme, 'themeCustomization' => $themeCustomization));
     return $themeCustomization;
 }
Esempio n. 4
0
 /**
  * Initialize menu object
  *
  * @return void
  */
 protected function _initMenu()
 {
     if (!$this->_menu) {
         /* @var $director Mage_Backend_Model_Menu_Director_Dom */
         $director = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Director_Dom', array('config' => $this->_getDom(), 'factory' => $this->_appConfig, 'logger' => $this->_logger));
         $director->buildMenu($this->_menuBuilder);
         $this->_menu = $this->_menuBuilder->getResult();
         $this->_eventManager->dispatch('backend_menu_load_after', array('menu' => $this->_menu));
     }
 }
Esempio n. 5
0
 /**
  * Initialize menu object
  *
  * @return void
  */
 protected function _initMenu()
 {
     if (!$this->_menu) {
         $this->_menu = $this->_menuFactory->getMenuInstance();
         if ($this->_cache->canUse('config')) {
             $cache = $this->_cache->load(self::CACHE_MENU_OBJECT);
             if ($cache) {
                 $this->_menu->unserialize($cache);
                 return;
             }
         }
         /* @var $director Mage_Backend_Model_Menu_Builder */
         $menuBuilder = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Builder', array('menu' => $this->_menu, 'itemFactory' => $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Item_Factory')));
         /* @var $director Mage_Backend_Model_Menu_Director_Dom */
         $director = $this->_appConfig->getModelInstance('Mage_Backend_Model_Menu_Director_Dom', array('config' => $this->_getDom(), 'factory' => $this->_appConfig, 'logger' => $this->_logger));
         $director->buildMenu($menuBuilder);
         $this->_menu = $menuBuilder->getResult();
         $this->_eventManager->dispatch('backend_menu_load_after', array('menu' => $this->_menu));
         if ($this->_cache->canUse('config')) {
             $this->_cache->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT, array(Mage_Core_Model_Config::CACHE_TAG));
         }
     }
 }
Esempio n. 6
0
 /**
  * Save config section
  * Require set: section, website, store and groups
  *
  * @return Mage_Backend_Model_Config
  */
 public function save()
 {
     $this->_validate();
     $this->_getScope();
     $this->_eventManager->dispatch('model_config_data_save_before', array('object' => $this));
     $sectionId = $this->getSection();
     $groups = $this->getGroups();
     if (empty($groups)) {
         return $this;
     }
     $oldConfig = $this->_getConfig(true);
     $deleteTransaction = $this->_transactionFactory->create();
     /* @var $deleteTransaction Mage_Core_Model_Resource_Transaction */
     $saveTransaction = $this->_transactionFactory->create();
     /* @var $saveTransaction Mage_Core_Model_Resource_Transaction */
     // Extends for old config data
     $extraOldGroups = array();
     foreach ($groups as $groupId => $groupData) {
         $this->_processGroup($groupId, $groupData, $groups, $sectionId, $extraOldGroups, $oldConfig, $saveTransaction, $deleteTransaction);
     }
     $deleteTransaction->delete();
     $saveTransaction->save();
     return $this;
 }
Esempio n. 7
0
 /**
  * Produce and return block's html output
  *
  * It is a final method, but you can override _toHtml() method in descendants if needed.
  *
  * @return string
  */
 public final function toHtml()
 {
     $this->_eventManager->dispatch('core_block_abstract_to_html_before', array('block' => $this));
     if ($this->_storeConfig->getConfig('advanced/modules_disable_output/' . $this->getModuleName())) {
         return '';
     }
     $html = $this->_loadCache();
     if ($html === false) {
         if ($this->hasData('translate_inline')) {
             $this->_translator->setTranslateInline($this->getData('translate_inline'));
         }
         $this->_beforeToHtml();
         $html = $this->_toHtml();
         $this->_saveCache($html);
         if ($this->hasData('translate_inline')) {
             $this->_translator->setTranslateInline(true);
         }
     }
     $html = $this->_afterToHtml($html);
     /**
      * Check framing options
      */
     if ($this->_frameOpenTag) {
         $html = '<' . $this->_frameOpenTag . '>' . $html . '<' . $this->_frameCloseTag . '>';
     }
     return $html;
 }
Esempio n. 8
0
 /**
  * Save config section
  * Require set: section, website, store and groups
  *
  * @return Mage_Backend_Model_Config
  */
 public function save()
 {
     $this->_validate();
     $this->_getScope();
     $this->_eventManager->dispatch('model_config_data_save_before', array('object' => $this));
     $section = $this->getSection();
     $website = $this->getWebsite();
     $store = $this->getStore();
     $groups = $this->getGroups();
     $scope = $this->getScope();
     $scopeId = $this->getScopeId();
     if (empty($groups)) {
         return $this;
     }
     $sections = $this->_structureReader->getConfiguration()->getSections();
     $oldConfig = $this->_getConfig(true);
     $deleteTransaction = $this->_transactionFactory->create();
     /* @var $deleteTransaction Mage_Core_Model_Resource_Transaction */
     $saveTransaction = $this->_transactionFactory->create();
     /* @var $saveTransaction Mage_Core_Model_Resource_Transaction */
     // Extends for old config data
     $oldConfigAdditionalGroups = array();
     foreach ($groups as $group => $groupData) {
         /**
          * Map field names if they were cloned
          */
         $groupConfig = $sections[$section]['groups'][$group];
         if ($clonedFields = isset($groupConfig['clone_fields']) && !empty($groupConfig['clone_fields'])) {
             if (isset($groupConfig['clone_model']) && $groupConfig['clone_model']) {
                 $cloneModel = $this->_objectFactory->getModelInstance((string) $groupConfig['clone_model']);
             } else {
                 Mage::throwException('Config form fieldset clone model required to be able to clone fields');
             }
             $mappedFields = array();
             if (isset($groupConfig['fields'])) {
                 $fieldsConfig = $groupConfig['fields'];
                 foreach ($fieldsConfig as $field => $node) {
                     foreach ($cloneModel->getPrefixes() as $prefix) {
                         $mappedFields[$prefix['field'] . (string) $field] = (string) $field;
                     }
                 }
             }
         }
         // set value for group field entry by fieldname
         // use extra memory
         $fieldsetData = array();
         foreach ($groupData['fields'] as $field => $fieldData) {
             $fieldsetData[$field] = is_array($fieldData) && isset($fieldData['value']) ? $fieldData['value'] : null;
         }
         foreach ($groupData['fields'] as $field => $fieldData) {
             /**
              * Get field backend model
              */
             if (isset($groupConfig['fields'][$field]['backend_model'])) {
                 $backendClass = $groupConfig['fields'][$field]['backend_model'];
             } else {
                 if ($clonedFields && isset($mappedFields[$field]) && isset($groupConfig['fields'][$mappedFields[$field]]['backend_model'])) {
                     $backendClass = $groupConfig['fields'][$mappedFields[$field]]['backend_model'];
                 } else {
                     $backendClass = 'Mage_Core_Model_Config_Data';
                 }
             }
             /* @var $dataObject Mage_Core_Model_Config_Data */
             $dataObject = $this->_objectFactory->getModelInstance($backendClass);
             if (!$dataObject instanceof Mage_Core_Model_Config_Data) {
                 Mage::throwException('Invalid config field backend model: ' . $backendClass);
             }
             if (isset($groupConfig['fields'][$field])) {
                 $fieldConfig = $groupConfig['fields'][$field];
             } else {
                 if ($clonedFields && isset($mappedFields[$field])) {
                     $fieldConfig = $groupConfig['fields'][$mappedFields[$field]];
                 }
             }
             $dataObject->setField($field)->setGroups($groups)->setGroupId($group)->setStoreCode($store)->setWebsiteCode($website)->setScope($scope)->setScopeId($scopeId)->setFieldConfig($fieldConfig)->setFieldsetData($fieldsetData);
             $this->_checkSingleStoreMode($fieldConfig, $dataObject);
             if (!isset($fieldData['value'])) {
                 $fieldData['value'] = null;
             }
             $path = $section . '/' . $group . '/' . $field;
             /**
              * Look for custom defined field path
              */
             if ($fieldConfig && isset($fieldConfig['config_path'])) {
                 $configPath = (string) $fieldConfig['config_path'];
                 if (!empty($configPath) && strrpos($configPath, '/') > 0) {
                     // Extend old data with specified section group
                     $groupPath = substr($configPath, 0, strrpos($configPath, '/'));
                     if (!isset($oldConfigAdditionalGroups[$groupPath])) {
                         $oldConfig = $this->extendConfig($groupPath, true, $oldConfig);
                         $oldConfigAdditionalGroups[$groupPath] = true;
                     }
                     $path = $configPath;
                 }
             }
             $inherit = !empty($fieldData['inherit']);
             $dataObject->setPath($path)->setValue($fieldData['value']);
             if (isset($oldConfig[$path])) {
                 $dataObject->setConfigId($oldConfig[$path]['config_id']);
                 /**
                  * Delete config data if inherit
                  */
                 if (!$inherit) {
                     $saveTransaction->addObject($dataObject);
                 } else {
                     $deleteTransaction->addObject($dataObject);
                 }
             } elseif (!$inherit) {
                 $dataObject->unsConfigId();
                 $saveTransaction->addObject($dataObject);
             }
         }
     }
     $deleteTransaction->delete();
     $saveTransaction->save();
     return $this;
 }
Esempio n. 9
0
 /**
  * Clearing object for correct deleting by garbage collector
  *
  * @return Mage_Core_Model_Abstract
  */
 public final function clearInstance()
 {
     $this->_clearReferences();
     $this->_eventDispatcher->dispatch($this->_eventPrefix . '_clear', $this->_getEventData());
     $this->_clearData();
     return $this;
 }
Esempio n. 10
0
 public function dispatch($eventName, array $data = array())
 {
     $this->_commerceBugCollectedEvents[] = $eventName;
     return parent::dispatch($eventName, $data);
 }