Example #1
0
//
// $Id: block_manager.php 10488 2010-08-23 08:34:45Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    fn_trusted_vars('block', 'block_items');
    $suffix = '';
    if ($mode == 'add') {
        if (!empty($_REQUEST['block'])) {
            $block = $_REQUEST['block'];
            $block['location'] = $_REQUEST['add_selected_section'];
            $bid = fn_update_block($block, $_REQUEST['add_selected_section'], $_REQUEST['add_selected_section']);
            // if the block doesn't require assigning to the one object (product, category etc)
            if (fn_check_static_location($block['location'])) {
                fn_assign_block(array('block_id' => $bid, 'location' => $block['location'], 'status' => 'A'));
            }
        }
        $suffix = "&selected_section={$_REQUEST['add_selected_section']}";
    }
    if ($mode == 'enable_disable' && !empty($_REQUEST['block_id'])) {
        fn_assign_block($_REQUEST);
        exit;
    }
    if ($mode == 'update') {
        fn_update_block($_REQUEST['block'], $_REQUEST['block']['location'], $_REQUEST['redirect_location']);
        $suffix .= "&selected_section={$_REQUEST['redirect_location']}";
    }
    if ($mode == 'update_location') {
        fn_update_location($_REQUEST['block']);
Example #2
0
/**
 * The function returns the list of the blocks
 *
 * @param array $params
 * @param string $lang_code
 * @return array of blocks
 */
function fn_get_blocks($params = array(), $allow_sorting = true, $lang_code = CART_LANGUAGE)
{
    $condition = '';
    $_blocks = $block_ids = array();
    $object_id = 0;
    $location_properties = fn_get_block_locations();
    if (empty($params['all'])) {
        $condition .= " AND ?:blocks.status = 'A'";
    }
    $fields = array('?:blocks.*', '?:block_descriptions.description', '?:block_links.item_ids', '?:block_links.enable AS assigned');
    if (!empty($params)) {
        if (!empty($location_properties[$params['location']]) && !empty($params[$location_properties[$params['location']]])) {
            $object_id = (int) $params[$location_properties[$params['location']]];
        }
        if (!empty($params['location']) && $params['location'] == 'checkout' && MODE == 'cart') {
            $params['location'] = 'cart';
        }
        if (AREA == 'A') {
            $condition .= db_quote(" AND ?:blocks.location = ?s", $params['location']);
        } else {
            $condition .= db_quote(" AND ?:blocks.status = 'A'");
            $condition .= db_quote(" AND NOT FIND_IN_SET(?s, ?:blocks.disabled_locations)", $params['location']);
            if (!empty($object_id)) {
                $condition .= db_quote(" AND ((?:blocks.block_type = 'B' AND ?:block_links.enable = 'Y' AND (?:block_links.location = 'all_pages' OR (?:block_links.location = ?s AND (?:block_links.object_id = ?i OR ?:block_links.object_id = '0')))) OR ?:blocks.block_type = 'G')", $params['location'], $object_id);
            } else {
                $condition .= db_quote(" AND ((?:blocks.block_type = 'B' AND ?:block_links.enable = 'Y' AND (?:block_links.location = 'all_pages' OR ?:block_links.location = ?s)) OR ?:blocks.block_type = 'G')", $params['location']);
            }
        }
    }
    if (!empty($params['block_type'])) {
        $condition .= db_quote(" AND ?:blocks.block_type = ?s", $params['block_type']);
    }
    $blocks = db_get_hash_array('SELECT ' . implode(',', $fields) . " FROM ?:blocks LEFT JOIN ?:block_links ON ?:block_links.block_id = ?:blocks.block_id AND (?:block_links.object_id = ?i OR ?:block_links.object_id = '0') LEFT JOIN ?:block_descriptions ON ?:block_descriptions.block_id = ?:blocks.block_id AND ?:block_descriptions.object_type = 'B' AND ?:block_descriptions.lang_code = ?s WHERE 1 ?p", 'block_id', $object_id, $lang_code, $condition);
    if (!empty($blocks)) {
        $block_ids = array_keys($blocks);
    }
    $specific_settings = fn_get_block_specific_settings();
    if (!empty($blocks)) {
        foreach ($blocks as $block_id => $block) {
            if (!empty($block['properties'])) {
                $blocks[$block_id]['properties'] = fn_unserialize_block_properties($block['properties'], !empty($params['block_properties_location']) ? $params['block_properties_location'] : (!empty($params['location']) ? $params['location'] : $blocks[$block_id]['location']), $block['block_type'], $block['text_id']);
            }
        }
        if (AREA == 'A') {
            $assigned = db_get_hash_single_array("SELECT block_id, COUNT(*) as c FROM ?:block_links WHERE block_id IN (?n) AND enable = 'Y' GROUP BY block_id", array('block_id', 'c'), array_keys($blocks));
        }
        foreach ($blocks as $block_id => $block) {
            if (!empty($location_properties[$block['location']])) {
                $blocks[$block_id]['object_id'] = $location_properties[$block['location']];
            }
            if (isset($blocks[$block_id]['properties']['list_object']) && isset($specific_settings['list_object'][$blocks[$block_id]['properties']['list_object']]['settings'])) {
                foreach ($specific_settings['list_object'][$blocks[$block_id]['properties']['list_object']]['settings'] as $property => $value) {
                    if (!is_array($value)) {
                        $val = strtolower(str_replace('%', '', $value));
                        if (isset($blocks[$block_id][$val])) {
                            if (isset($_REQUEST[$blocks[$block_id][$val]])) {
                                $value = $_REQUEST[$blocks[$block_id][$val]];
                            }
                        }
                    }
                    $blocks[$block_id]['properties'][$property] = $value;
                }
            }
            if (AREA == 'A') {
                if (!empty($blocks[$block_id]['properties']['list_object'])) {
                    if (strpos($blocks[$block_id]['properties']['list_object'], '.tpl') === false) {
                        $blocks[$block_id]['items_count'] = empty($block['item_ids']) ? 0 : substr_count($block['item_ids'], ',') + 1;
                        $blocks[$block_id]['properties']['content_name'] = fn_get_lang_var($blocks[$block_id]['properties']['list_object']);
                    } else {
                        $blocks[$block_id]['properties']['content_name'] = fn_get_block_template_description($blocks[$block_id]['properties']['list_object']);
                    }
                }
                if (!fn_check_static_location($block['location'])) {
                    $blocks[$block_id]['assigned_to'] = !empty($assigned[$block_id]) ? $assigned[$block_id] : 0;
                }
            }
        }
    }
    fn_set_hook('get_blocks', $blocks, $params, $lang_code);
    if (AREA == 'A' || AREA != 'A' && !empty($params['product_id'])) {
        fn_get_product_tabs_blocks($object_id, $blocks, $params, $lang_code);
    }
    if (!empty($allow_sorting)) {
        $blocks = fn_sort_blocks($object_id, $params['location'], $blocks);
    }
    return array($blocks, $object_id);
}