/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_function_render_location($params, &$smarty) { if (!empty($params['dispatch'])) { $dispatch = $params['dispatch']; } elseif ($smarty->getTemplateVars('exception_status')) { $dispatch = 'no_page'; } else { $dispatch = !empty($_REQUEST['dispatch']) ? $_REQUEST['dispatch'] : 'index.index'; } $location_id = 0; if (!empty($params['location_id'])) { $location_id = $params['location_id']; } $area = !empty($params['area']) ? $params['area'] : AREA; if (!empty($params['dynamic_object'])) { $dynamic_object = $params['dynamic_object']; } elseif (!empty($_REQUEST['dynamic_object']) && $area != 'C') { $dynamic_object = $_REQUEST['dynamic_object']; } else { $dynamic_object_scheme = SchemesManager::getDynamicObject($dispatch, $area); if (!empty($dynamic_object_scheme) && !empty($_REQUEST[$dynamic_object_scheme['key']])) { $dynamic_object['object_type'] = $dynamic_object_scheme['object_type']; $dynamic_object['object_id'] = $_REQUEST[$dynamic_object_scheme['key']]; } else { $dynamic_object = array(); } } $lang_code = !empty($params['lang_code']) ? $params['lang_code'] : DESCR_SL; $br = new RenderManager($dispatch, $area, $dynamic_object, $location_id, $lang_code); return $br->render(); }
function smarty_function_render_block($params, &$smarty) { if (!empty($params['block_id'])) { $block_id = $params['block_id']; $snapping_id = !empty($params['snapping_id']) ? $params['snapping_id'] : 0; if (!empty($params['dispatch'])) { $dispatch = $params['dispatch']; } else { $dispatch = !empty($_REQUEST['dispatch']) ? $_REQUEST['dispatch'] : 'index.index'; } $area = !empty($params['area']) ? $params['area'] : AREA; if (!empty($params['dynamic_object'])) { $dynamic_object = $params['dynamic_object']; } elseif (!empty($_REQUEST['dynamic_object']) && $area != 'C') { $dynamic_object = $_REQUEST['dynamic_object']; } else { $dynamic_object_scheme = SchemesManager::getDynamicObject($dispatch, $area); if (!empty($dynamic_object_scheme) && !empty($_REQUEST[$dynamic_object_scheme['key']])) { $dynamic_object['object_type'] = $dynamic_object_scheme['object_type']; $dynamic_object['object_id'] = $_REQUEST[$dynamic_object_scheme['key']]; } else { $dynamic_object = array(); } } $block = Block::instance()->getById($block_id, $snapping_id, $dynamic_object, DESCR_SL); return RenderManager::renderBlock($block); } }
function fn_twg_get_product_tabs($params) { $allowed_page_types = array('T', 'L', 'F'); $allowed_templates = array('blocks/product_tabs/features.tpl', 'blocks/product_tabs/description.tpl'); $allowed_block_types = array('html_block', 'pages', 'products', 'categories', 'banners'); $tabs = ProductTabs::instance()->getList('', $params['product_id'], $params['descr_sl']); foreach ($tabs as $k => $tab) { $isAllowedType = $tab['tab_type'] == 'B'; $isAllowedType = ($isAllowedType or $tab['tab_type'] == 'T' and in_array($tab['template'], $allowed_templates)); if (empty($params['all_tabs']) && $tab['status'] != 'A' || !$isAllowedType) { unset($tabs[$k]); continue; } if ($tab['tab_type'] == 'B') { $block = TwigmoBlock::getBlock(array('block_id' => $tab['block_id'], 'area' => 'C')); if (empty($block['type']) || !in_array($block['type'], $allowed_block_types)) { unset($tabs[$k]); continue; } $block_scheme = SchemesManager::getBlockScheme($block['type'], array()); if ($block['type'] == 'html_block') { $tabs[$k]['html'] = $block['content']['content']; } elseif (!empty($block_scheme['content']) && !empty($block_scheme['content']['items'])) { // Products and categories: get items $template_variable = 'items'; $field = $block_scheme['content']['items']; $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 (fn_is_empty($items)) { unset($tabs[$k]); continue; } $block_data = array('total_items' => count($items)); // Images $image_params = TwigmoSettings::get('images.cart'); if ($block['type'] == 'products' or $block['type'] == 'categories') { $object_type = $block['type'] == 'products' ? 'product' : 'category'; foreach ($items as $items_id => $item) { $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; $object_type = 'banner'; } $block_data[$block['type']] = Api::getAsList($block['type'], $items); $tabs[$k] = array_merge($tab, $block_data); } } else { if ($tab['template'] == 'blocks/product_tabs/features.tpl') { $tabs[$k]['type'] = 'features'; } if ($tab['template'] == 'blocks/product_tabs/description.tpl') { $tabs[$k]['type'] = 'description'; } } } return array_values($tabs); // reindex }
/** * Updates object data in live content editing mode. * * @param string $params Params to be updated; array with keys name, value, lang_code, and need_render * @return bool */ function fn_live_editor_update_object($params) { $updated = false; /** * Performs actions before updating a live editor object * * @param array $params Params to be updated; array with keys name, value, lang_code, and need_render * @param bool $updated The "already updated" flag */ fn_set_hook('live_editor_update_object_pre', $params, $updated); if ($updated) { return true; } if (strpos($params['name'], ':')) { list($object, $field, $id) = explode(':', $params['name'], 3); $schema = fn_get_schema('customization', 'live_editor_objects'); if (!empty($schema[$object])) { $rule = $schema[$object]; if (!empty($rule['function'])) { $vars = $params + compact('object', 'field', 'id', 'rule'); $args = fn_live_editor_prepare_callback_args($rule['args'], $vars); call_user_func_array($rule['function'], $args); } if (!empty($rule['table'])) { $table = $rule['table']; $condition = array('id' => db_quote("?p = ?s", $rule['id_field'], $id)); if (!empty($rule['lang_code'])) { $condition['lang_code'] = db_quote("lang_code = ?s", $params['lang_code']); } /** * Prepares data for the live editor object update request * * @param array $params Params * @param array $rule Rule * @param array $condition Conditions * @param str $table Table name */ fn_set_hook('live_editor_update_object_table', $params, $rule, $condition, $table); db_query("UPDATE ?:{$table} SET ?u WHERE ?p", array($rule['value_field'] => $params['value']), implode(' AND ', $condition)); $updated = true; } if (!empty($params['need_render'])) { // Block if ($object == 'block' && $field == 'content') { $block = Block::instance()->getById($id); Tygh::$app['view']->assign('no_wrap', true); $content = RenderManager::renderBlock($block); if ($ajax = Tygh::$app['ajax']) { $ajax->assign('rendered_name', $params['name']); $ajax->assign('rendered_content', $content); } } } } } /** * Performs actions after updating a live editor object * * @param array $params Params * @param bool $updated The "already updated" flag */ fn_set_hook('live_editor_update_object_post', $params, $updated); return $updated; }
/** * 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; }
/** * Generates scheme data * @static * @param mixed $item Item from scheme * @return array|mixed */ private static function _getValue($item) { // check, are there any function if (is_array($item)) { if (!empty($item[0]) && is_callable($item[0])) { // If it's a function execute it and return it result $callable = array_shift($item); return call_user_func_array($callable, $item); } elseif (!empty($item['data_function'][0]) && is_callable($item['data_function'][0])) { // If it's a data function, get the values $callable = array_shift($item['data_function']); $item['values'] = call_user_func_array($callable, $item['data_function']); } return $item; } // check for custom folder with templates $_dir = Registry::get('config.dir.root') . '/' . $item; if (is_dir($_dir)) { // If it's dir with templates return list of templates return fn_get_dir_contents($_dir, false, true); } // check for templates in the theme dir $theme_path = RenderManager::getCustomerThemePath(); $tpl_path = $theme_path . $item; if (is_file($tpl_path)) { return array(strval($item) => array('name' => self::generateTemplateName($item, $theme_path))); } // check for templates in given folder and addons too $tpl_files = fn_get_dir_contents($tpl_path, false, true, '.tpl', $item . '/'); foreach (Registry::get('addons') as $addon => $addon_data) { if ($addon_data['status'] == 'A') { $_content = fn_get_dir_contents($theme_path . "addons/{$addon}/{$item}", false, true, '.tpl', "addons/{$addon}/{$item}/"); if (!empty($_content)) { $tpl_files = fn_array_merge($tpl_files, $_content, false); } } } if (!empty($tpl_files)) { $result = array(); foreach ($tpl_files as $file) { $result[$file]['name'] = self::generateTemplateName($file, $theme_path); } return $result; } // if nothing was generated above, return given value return $item; }