Example #1
0
 /**
  * Get blocks for the twigmo homepage
  * @param  string $dispatch        Dispatch of needed location
  * @param  array  $allowed_objects - array of blocks types
  * @return array  blocks
  */
 public static final function getBlocksForLocation($dispatch, $allowed_objects)
 {
     $allowed_page_types = array('T', 'L', 'F');
     $blocks = array();
     $location = Location::instance(fn_twg_get_default_layout_id())->get($dispatch);
     if (!$location) {
         return $blocks;
     }
     $get_cont_params = array('location_id' => $location['location_id']);
     $container = Container::getList($get_cont_params);
     if (!$container or !$container['CONTENT']) {
         return $blocks;
     }
     $grids_params = array('container_ids' => $container['CONTENT']['container_id']);
     $grids = Grid::getList($grids_params);
     if (!$grids) {
         return $blocks;
     }
     $block_grids = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($grids));
     $image_params = TwigmoSettings::get('images.catalog');
     foreach ($block_grids as $block_grid) {
         foreach ($block_grid as $block) {
             if ($block['status'] != 'A' or !in_array($block['type'], $allowed_objects)) {
                 continue;
             }
             $block_data = array('block_id' => $block['block_id'], 'title' => $block['name'], 'hide_header' => isset($block['properties']['hide_header']) ? $block['properties']['hide_header'] : 'N', 'user_class' => $block['user_class']);
             $block_scheme = SchemesManager::getBlockScheme($block['type'], array());
             if ($block['type'] == 'html_block') {
                 // Html block
                 if (isset($block['content']['content']) and fn_string_not_empty($block['content']['content'])) {
                     $block_data['html'] = $block['content']['content'];
                 }
             } elseif (!empty($block_scheme['content']) and !empty($block_scheme['content']['items'])) {
                 // Products and categories: get items
                 $template_variable = 'items';
                 $field = $block_scheme['content']['items'];
                 fn_set_hook('render_block_content_pre', $template_variable, $field, $block_scheme, $block);
                 $items = RenderManager::getValue($template_variable, $field, $block_scheme, $block);
                 // Filter pages - only texts, links and forms posible
                 if ($block['type'] == 'pages') {
                     foreach ($items as $item_id => $item) {
                         if (!in_array($item['page_type'], $allowed_page_types)) {
                             unset($items[$item_id]);
                         }
                     }
                 }
                 if (empty($items)) {
                     continue;
                 }
                 $block_data['total_items'] = count($items);
                 // Images
                 if ($block['type'] == 'products' or $block['type'] == 'categories') {
                     $object_type = $block['type'] == 'products' ? 'product' : 'category';
                     foreach ($items as $items_id => $item) {
                         if (!empty($item['main_pair'])) {
                             $main_pair = $item['main_pair'];
                         } else {
                             $main_pair = fn_get_image_pairs($item[$object_type . '_id'], $object_type, 'M', true, true);
                         }
                         if (!empty($main_pair)) {
                             $items[$items_id]['icon'] = TwigmoImage::getApiImageData($main_pair, $object_type, 'icon', $image_params);
                         }
                     }
                 }
                 // Banners properties
                 if ($block['type'] == 'banners') {
                     $rotation = $block['properties']['template'] == 'addons/banners/blocks/carousel.tpl' ? 'Y' : 'N';
                     $block_data['delay'] = $rotation == 'Y' ? $block['properties']['delay'] : 0;
                     $block_data['hide_navigation'] = isset($block['properties']['navigation']) && $block['properties']['navigation'] == 'N' ? 'Y' : 'N';
                 }
                 $block_data[$block['type']] = Api::getAsList($block['type'], $items);
             }
             $blocks[$block['block_id']] = $block_data;
         }
     }
     return $blocks;
 }
Example #2
0
 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')) {
     if ($result === true) {
         Tygh::$app['ajax']->assign('status', 'OK');
     } elseif (is_numeric($result)) {
         Tygh::$app['ajax']->assign('id', intval($result));
         Tygh::$app['ajax']->assign('status', 'OK');
     } else {
Example #3
0
 /**
  * Export blocks to XML structure
  *
  * @param  array              $location_ids
  * @param  array              $params
  * @param  string             $lang_code
  * @return ExSimpleXmlElement
  */
 public function export($layout_id, $location_ids = array(), $params = array(), $lang_code = DESCR_SL)
 {
     /* Exclude unnecessary fields*/
     $except_location_fields = array('location_id', 'company_id');
     $except_container_fields = array('container_id', 'location_id', 'dispatch', 'is_default', 'company_id', 'default');
     $except_grid_fields = array('container_id', 'location_id', 'position', 'grid_id', 'parent_id', 'order', 'children');
     $except_layout_fields = array('layout_id', 'theme_name', 'company_id');
     $except_location_fields = array_flip($except_location_fields);
     $except_container_fields = array_flip($except_container_fields);
     $except_grid_fields = array_flip($except_grid_fields);
     $except_layout_fields = array_flip($except_layout_fields);
     $layout_data = Layout::instance($this->_company_id)->get($layout_id);
     $layout_data = array_diff_key($layout_data, $except_layout_fields);
     $xml_root = new ExSimpleXmlElement('<block_scheme></block_scheme>');
     $xml_root->addAttribute('scheme', '1.0');
     $settings = $xml_root->addChild('settings');
     $settings->addChild('default_language', $lang_code);
     $layout_xml = $xml_root->addChild('layout');
     foreach ($layout_data as $field_name => $field_value) {
         $layout_xml->addChild($field_name, $field_value);
     }
     if (empty($location_ids)) {
         $location_ids = Location::instance($this->_layout_id)->getList(array(), $lang_code);
         $location_ids = array_keys($location_ids);
     }
     foreach ($location_ids as $location_id) {
         $location = Location::instance($this->_layout_id)->getById($location_id);
         $containers = Container::getList(array('location_id' => $location_id));
         $xml_location = $xml_root->addChild('location');
         $location = array_diff_key($location, $except_location_fields);
         foreach ($location as $attr => $value) {
             $xml_location->addAttribute($attr, $value);
         }
         $xml_containers = $xml_location->addChild('containers');
         $xml_translations = $xml_location->addChild('translations');
         $translations = Location::instance($this->_layout_id)->getAllDescriptions($location_id);
         foreach ($translations as $translation) {
             if ($translation['lang_code'] == $lang_code) {
                 // We do not needed default language
                 continue;
             }
             $xml_translation = $xml_translations->addChild('translation');
             $xml_translation->addChildCData('meta_keywords', $translation['meta_keywords']);
             $xml_translation->addChildCData('page_title', $translation['title']);
             $xml_translation->addChildCData('meta_description', $translation['meta_description']);
             $xml_translation->addChild('name', $translation['name']);
             $xml_translation->addAttribute('lang_code', $translation['lang_code']);
         }
         unset($xml_translations);
         foreach ($containers as $position => $container) {
             $grids = Grid::getList(array('container_ids' => $container['container_id']));
             $xml_container = $xml_containers->addChild('container');
             foreach ($container as $attr => $value) {
                 $xml_container->addAttribute($attr, $value);
             }
             if (!empty($grids) && isset($grids[$container['container_id']])) {
                 $grids = $grids[$container['container_id']];
                 $grids = fn_build_hierarchic_tree($grids, 'grid_id');
                 $container = array_diff_key($container, $except_container_fields);
                 $this->_buildGridStructure($xml_container, $grids, $except_grid_fields, $lang_code);
             }
         }
     }
     return $xml_root->asXML();
 }