if ($mode == 'delete_location' && !empty($_REQUEST['location_id'])) { Location::instance()->remove($_REQUEST['location_id']); } if ($mode == 'delete_layout') { Layout::instance()->delete($_REQUEST['layout_id']); } if ($mode == 'set_default_layout') { if (!empty($_REQUEST['layout_id'])) { Layout::instance()->setDefault($_REQUEST['layout_id']); fn_set_notification('N', __('notice'), __('text_changes_saved')); } return array(CONTROLLER_STATUS_OK, 'block_manager.manage' . $suffix); } if ($mode == 'set_custom_container') { if (!empty($_REQUEST['container_id']) && !empty($_REQUEST['linked_to_default'])) { Container::update($_REQUEST); if ($_REQUEST['linked_to_default'] == 'N') { // Check if we need to clone grids and blocks from the default container $grids = Grid::getList(array('container_ids' => array($_REQUEST['container_id']))); if (empty($grids)) { // Clone data from the default container $default_containers = Container::getList(array('default_location' => true)); $current_container = Container::getById($_REQUEST['container_id']); Grid::copy($default_containers[$current_container['position']]['container_id'], $current_container['container_id']); } } } $selected_location = empty($_REQUEST['selected_location']) ? 0 : $_REQUEST['selected_location']; $suffix = '?selected_location=' . $selected_location; } if (defined('AJAX_REQUEST')) {
/** * Imports blocks from XML structure * * @param ExSimpleXmlElement $structure * @param array $params * @return bool True on success false otherwise */ public function import($structure, $params = array()) { if ($structure === false) { fn_set_notification('E', __('error'), __('text_unable_to_parse_xml')); return false; } if (empty($structure->location)) { // We have no locations and cannot proceed return false; } $import_style = empty($params['import_style']) ? 'update' : $params['import_style']; $layout_data = empty($structure->layout) ? array() : (array) $structure->layout; unset($layout_data['layout_id'], $layout_data['company_id']); // FIXME: Backward compability if (empty($layout_data) && $import_style == 'create') { $layout_data = array('name' => 'Main', 'is_default' => 1, 'width' => 16, 'layout_width' => 'fixed', 'min_width' => 760, 'max_width' => 960, 'style_id' => ''); } if ($import_style == 'create' && empty($layout_data)) { fn_set_notification('E', __('error'), __('text_unable_to_create_layout_empty_data')); return false; } if (!empty($layout_data['@attributes']['edition'])) { $allowed_editions = explode(',', $layout_data['@attributes']['edition']); if (!in_array(PRODUCT_EDITION, $allowed_editions)) { return false; } } if ($import_style == 'create') { $layout_data['theme_name'] = $this->_theme_name; $layout_id = Layout::instance($this->_company_id)->update($layout_data); $this->_layout_id = $layout_id; } elseif (!empty($layout_data)) { $layout_data['theme_name'] = $this->_theme_name; $layout_id = Layout::instance($this->_company_id)->update($layout_data, $this->_layout_id); } else { $layout_id = $this->_layout_id; } if (!isset($params['override_by_dispatch'])) { $params['override_by_dispatch'] = 'Y'; } $settings = (array) $structure->settings; if (!empty($params['clean_up']) && $params['clean_up'] == 'Y') { $location_ids = Location::instance($this->_layout_id)->getList(array(), DESCR_SL); $location_ids = array_keys($location_ids); foreach ($location_ids as $location_id) { Location::instance($this->_layout_id)->remove($location_id, true); } } foreach ($structure->location as $location) { // Create location first $location_attrs = $this->_getNodeAttrs($location); if ($this->_company_id) { $location_attrs['company_id'] = $this->_company_id; } // Check if location already exists $_existing = array(); $location_existing = false; if ($params['override_by_dispatch'] == 'Y') { $_existing = Location::instance($this->_layout_id)->get($location_attrs['dispatch']); if (!empty($_existing)) { $location_existing = $_existing['dispatch'] == $location_attrs['dispatch'] ? true : false; } } // Imported locations cannot be assingned to dynamic objects $location_attrs['object_ids'] = ''; $location_id = Location::instance($this->_layout_id)->update($location_attrs); if (!empty($location_attrs['is_default'])) { Location::instance($this->_layout_id)->setDefault($location_id); } if (!empty($location_existing)) { Location::instance($this->_layout_id)->remove($_existing['location_id']); } $_default_containers = Container::getList(array('location_id' => $location_id)); foreach ($location->containers->container as $container) { $container_attrs = $this->_getNodeAttrs($container); $container_attrs['location_id'] = $location_id; $container_attrs['container_id'] = $_default_containers[$container_attrs['position']]['container_id']; Container::update($container_attrs); $container_id = $container_attrs['container_id']; if (isset($container->grid)) { $this->_parseGridStructure($container, $container_id); } } if (!empty($location->translations)) { $avail_langs = array_keys(fn_get_translation_languages()); foreach ($location->translations->translation as $translation) { $translation_lang_code = (string) $translation['lang_code']; if (!in_array($translation_lang_code, $avail_langs)) { continue; } $location_attrs = array('location_id' => $location_id, 'lang_code' => $translation_lang_code, 'meta_description' => (string) $translation->meta_description, 'meta_keywords' => (string) $translation->meta_keywords, 'title' => (string) $translation->page_title, 'name' => (string) $translation->name); Location::instance($this->_layout_id)->update($location_attrs); } } } return $layout_id; }