Exemplo n.º 1
0
function fn_get_seo_rules($params = array(), $items_per_page = 0, $lang_code = DESCR_SL)
{
    $condition = fn_get_seo_company_condition('?:seo_names.company_id');
    $lang_code = fn_get_corrected_seo_lang_code($lang_code);
    $global_total = db_get_fields("SELECT dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' ?p GROUP BY dispatch", $condition);
    $local_total = db_get_fields("SELECT dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p", $lang_code, $condition);
    if ($diff = array_diff($global_total, $local_total)) {
        foreach ($diff as $disp) {
            fn_create_seo_name(0, 's', str_replace('.', '-', $disp), 0, $disp, '', DESCR_SL);
        }
    }
    // Init filter
    $params = LastView::instance()->update('seo_rules', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $condition .= db_quote(" AND name LIKE ?l", "%" . trim($params['name']) . "%");
    }
    if (isset($params['rule_params']) && fn_string_not_empty($params['rule_params'])) {
        $condition .= db_quote(" AND dispatch LIKE ?l", "%" . trim($params['rule_params']) . "%");
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p", $lang_code, $condition);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $seo_data = db_get_array("SELECT name, dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p ORDER BY dispatch {$limit}", $lang_code, $condition);
    return array($seo_data, $params);
}
Exemplo n.º 2
0
function fn_get_seo_redirects($params = array(), $items_per_page = 0, $lang_code = DESCR_SL)
{
    // Init filter
    $params = LastView::instance()->update('seo_redirects', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $condition = '';
    if (isset($params['src']) && fn_string_not_empty($params['src'])) {
        $condition .= db_quote(" AND src LIKE ?l", "%" . trim($params['src']) . "%");
    }
    if (!empty($params['type'])) {
        $condition .= db_quote(" AND type = ?s", $params['type']);
    }
    if (!empty($params['lang_code'])) {
        $condition .= db_quote(" AND lang_code = ?s", $params['lang_code']);
    }
    $condition .= fn_get_seo_company_condition('?:seo_redirects.company_id');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:seo_redirects WHERE 1 ?p", $condition);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $seo_redirects = db_get_hash_array("SELECT * FROM ?:seo_redirects WHERE 1 ?p ORDER BY src {$limit}", 'redirect_id', $condition);
    if (!empty($seo_redirects)) {
        foreach ($seo_redirects as $key => $seo_redirect) {
            $seo_redirects[$key]['parsed_url'] = fn_generate_seo_url_from_schema($seo_redirect);
        }
    }
    return array($seo_redirects, $params);
}
Exemplo n.º 3
0
function fn_seo_settings_update($type, $option, $new_value, $redirect_only)
{
    $old_value = Registry::get('addons.seo.' . $option);
    fn_iterate_through_seo_names(function ($seo_name) use($option, $old_value, $new_value, $redirect_only) {
        // We shouldn't consider null value
        if (false === fn_check_seo_object_exists($seo_name['object_id'], $seo_name['type'], $seo_name['company_id'])) {
            fn_delete_seo_name($seo_name['object_id'], $seo_name['type'], '', $seo_name['company_id']);
            return;
        }
        Registry::set('addons.seo.' . $option, $old_value);
        $url = fn_generate_seo_url_from_schema(array('type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'lang_code' => $seo_name['lang_code']), false);
        fn_seo_update_redirect(array('src' => $url, 'type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'company_id' => $seo_name['company_id'], 'lang_code' => $seo_name['lang_code']), 0, false);
        if (!$redirect_only) {
            Registry::set('addons.seo.' . $option, $new_value);
            fn_create_seo_name($seo_name['object_id'], $seo_name['type'], $seo_name['name'], 0, '', $seo_name['company_id'], $seo_name['lang_code'], true);
        }
    }, db_quote("type = ?s ?p", $type, fn_get_seo_company_condition('?:seo_names.company_id', $type)));
}
function fn_seo_settings_update($type, $option, $new_value, $redirect_only)
{
    $i = 0;
    $items_per_pass = 100;
    $old_value = Registry::get('addons.seo.' . $option);
    $company_condition = fn_get_seo_company_condition('?:seo_names.company_id', $type);
    while ($update_data = db_get_array("SELECT * FROM ?:seo_names WHERE type = ?s ?p LIMIT {$i}, {$items_per_pass}", $type, $company_condition)) {
        foreach ($update_data as $data) {
            Registry::set('addons.seo.' . $option, $old_value);
            $url = fn_generate_seo_url_from_schema(array('type' => $data['type'], 'object_id' => $data['object_id'], 'lang_code' => $data['lang_code']), false);
            fn_seo_update_redirect(array('src' => $url, 'type' => $data['type'], 'object_id' => $data['object_id'], 'company_id' => $data['company_id'], 'lang_code' => $data['lang_code']), 0, false);
            if (!$redirect_only) {
                Registry::set('addons.seo.' . $option, $new_value);
                fn_create_seo_name($data['object_id'], $data['type'], $data['name'], 0, '', $data['company_id'], $data['lang_code'], true);
            }
        }
        $i += $items_per_pass;
    }
}
Exemplo n.º 5
0
function fn_seo_update_language_post(&$language_data, &$lang_id, &$action)
{
    if ($action == 'update') {
        return false;
    }
    $condition = fn_get_seo_company_condition('?:seo_names.company_id');
    if (!empty($language_data['lang_code'])) {
        $is_exists = db_get_field("SELECT COUNT(*) FROM ?:seo_names WHERE lang_code = ?s ?p", $language_data['lang_code'], $condition);
        if (empty($is_exists)) {
            $global_total = db_get_fields("SELECT dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' ?p GROUP BY dispatch", $condition);
            foreach ($global_total as $disp) {
                fn_create_seo_name(0, 's', str_replace('.', '-', $disp), 0, $disp, '', $language_data['lang_code']);
            }
        }
    }
}
Exemplo n.º 6
0
    return fn_category_exists($category_id);
}), 'p' => array('tree' => true, 'path_function' => function ($object_id, $company_id = 0) {
    static $cache = array();
    if (!isset($cache[$company_id][$object_id])) {
        $path = db_get_hash_single_array("SELECT c.id_path, p.link_type FROM ?:categories as c LEFT JOIN ?:products_categories as p ON p.category_id = c.category_id WHERE p.product_id = ?i ?p", array('link_type', 'id_path'), $object_id, fn_get_seo_company_condition('c.company_id', '', $company_id));
        $cache[$company_id][$object_id] = !empty($path['M']) ? $path['M'] : $path['A'];
    }
    return $cache[$company_id][$object_id];
}, 'parent_type' => 'c', 'name' => 'product', 'picker' => 'pickers/products/picker.tpl', 'picker_params' => array('type' => 'single', 'view_mode' => 'button'), 'table' => '?:product_descriptions', 'description' => 'product', 'dispatch' => 'products.view', 'item' => 'product_id', 'condition' => '', 'not_shared' => true, 'tree_options' => array('product_category_nohtml', 'product_category'), 'html_options' => array('product_category', 'product_file'), 'option' => 'seo_product_type', 'exist_function' => function ($product_id, $company_id) {
    $result = fn_product_exists($product_id);
    // Check whether product is shared for given company
    if ($result && fn_allowed_for('ULTIMATE')) {
        $result = $result && in_array($company_id, fn_ult_get_shared_product_companies($product_id));
    }
    return $result;
}), 'a' => array('tree' => true, 'path_function' => function ($object_id) {
    static $cache = array();
    if (!isset($cache[$object_id])) {
        $path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $object_id);
        $apath = explode('/', $path);
        array_pop($apath);
        $cache[$object_id] = implode('/', $apath);
    }
    return $cache[$object_id];
}, 'parent_type' => 'a', 'name' => 'page', 'picker' => 'pickers/pages/picker.tpl', 'picker_params' => array('multiple' => false, 'use_keys' => 'N'), 'table' => '?:page_descriptions', 'description' => 'page', 'dispatch' => 'pages.view', 'item' => 'page_id', 'condition' => '', 'tree_options' => array('page', 'page_nohtml'), 'html_options' => array('file', 'page'), 'pager' => true, 'option' => 'seo_page_type', 'exist_function' => function ($page_id) {
    return fn_page_exists($page_id);
}), 'e' => array('table' => '?:product_feature_variant_descriptions', 'description' => 'variant', 'dispatch' => 'product_features.view', 'item' => 'variant_id', 'condition' => '', 'name' => 'feature', 'html_options' => array('file'), 'option' => 'seo_other_type'), 's' => array('table' => '?:seo_names', 'description' => 'name', 'dispatch' => '', 'item' => 'object_id', 'condition' => fn_get_seo_company_condition('?:seo_names.company_id'), 'not_shared' => true, 'name' => 'custom', 'html_options' => array('file'), 'option' => 'seo_other_type'));
if (fn_allowed_for('MULTIVENDOR')) {
    $schema['m'] = array('table' => '?:companies', 'description' => 'company', 'dispatch' => 'companies.products', 'item' => 'company_id', 'condition' => '', 'skip_lang_condition' => true, 'name' => 'company', 'html_options' => array('file'), 'option' => 'seo_other_type');
}
return $schema;
Exemplo n.º 7
0
/**
 * Hook is used to replace non-cached dispatch rules with non-cached path rules.
 * Paths will be generated using corresponding SEO names.
 *
 * @param \Tygh\Addons\FullPageCache\Varnish\VclGenerator $vcl_generator VCL generator instance
 */
function fn_seo_varnish_generate_vcl_pre($vcl_generator)
{
    $dispatch_to_find_list = array();
    $controllers_to_find_condition = array('0');
    foreach ($vcl_generator->getNonCachedDispatches() as $dispatch) {
        if (strpos($dispatch, '.*') !== false) {
            list($controller, $asterisk) = explode('.', $dispatch);
            $controllers_to_find_condition[] = db_quote('OR `dispatch` LIKE ?l', $controller . '.%');
        } else {
            $dispatch_to_find_list[] = $dispatch;
        }
    }
    $seo_rules_paths = db_get_fields("SELECT `name` FROM ?:seo_names" . " WHERE `type` = 's' AND (`dispatch` IN (?a) OR (?p)) ?p", empty($dispatch_to_find_list) ? array('') : $dispatch_to_find_list, implode(' ', $controllers_to_find_condition), fn_get_seo_company_condition('?:seo_names.company_id', 's', $vcl_generator->getStorefront()->id));
    $seo_rules_paths = array_map(function ($path) {
        return trim($path, '\\/') . '/';
    }, $seo_rules_paths);
    // Add paths generated using SEO-names
    $vcl_generator->addNonCachedPaths($seo_rules_paths);
}
Exemplo n.º 8
0
****************************************************************************/
$schema = array('c' => array('tree' => true, 'path_function' => function ($object_id) {
    static $cache = array();
    if (!isset($cache[$object_id])) {
        $path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $object_id);
        $apath = explode('/', $path);
        array_pop($apath);
        $cache[$object_id] = implode('/', $apath);
    }
    return $cache[$object_id];
}, 'parent_type' => 'c', 'name' => 'category', 'picker' => 'pickers/categories/picker.tpl', 'picker_params' => array('multiple' => false, 'use_keys' => 'N'), 'table' => '?:category_descriptions', 'description' => 'category', 'dispatch' => 'categories.view', 'item' => 'category_id', 'condition' => '', 'not_shared' => true, 'tree_options' => array('category', 'category_nohtml'), 'html_options' => array('file', 'category'), 'pager' => true, 'option' => 'seo_category_type', 'indexed_pages' => array('categories.catalog' => array(), 'categories.view' => array('index' => array('category_id'), 'noindex' => array('features_hash')))), 'p' => array('tree' => true, 'path_function' => function ($object_id) {
    static $cache = array();
    if (!isset($cache[$object_id])) {
        $path = db_get_hash_single_array("SELECT c.id_path, p.link_type FROM ?:categories as c LEFT JOIN ?:products_categories as p ON p.category_id = c.category_id WHERE p.product_id = ?i ?p", array('link_type', 'id_path'), $object_id, fn_get_seo_company_condition('c.company_id'));
        $cache[$object_id] = !empty($path['M']) ? $path['M'] : $path['A'];
    }
    return $cache[$object_id];
}, 'parent_type' => 'c', 'name' => 'product', 'picker' => 'pickers/products/picker.tpl', 'picker_params' => array('type' => 'single', 'view_mode' => 'button'), 'table' => '?:product_descriptions', 'description' => 'product', 'dispatch' => 'products.view', 'item' => 'product_id', 'condition' => '', 'not_shared' => true, 'tree_options' => array('product_category_nohtml', 'product_category'), 'html_options' => array('product_category', 'product_file'), 'option' => 'seo_product_type', 'indexed_pages' => array('products.view' => array('index' => array('product_id')))), 'a' => array('tree' => true, 'path_function' => function ($object_id) {
    static $cache = array();
    if (!isset($cache[$object_id])) {
        $path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $object_id);
        $apath = explode('/', $path);
        array_pop($apath);
        $cache[$object_id] = implode('/', $apath);
    }
    return $cache[$object_id];
}, 'parent_type' => 'a', 'name' => 'page', 'picker' => 'pickers/pages/picker.tpl', 'picker_params' => array('multiple' => false, 'use_keys' => 'N'), 'table' => '?:page_descriptions', 'description' => 'page', 'dispatch' => 'pages.view', 'item' => 'page_id', 'condition' => '', 'tree_options' => array('page', 'page_nohtml'), 'html_options' => array('file', 'page'), 'pager' => true, 'option' => 'seo_page_type', 'indexed_pages' => array('pages.view' => array('index' => array('page_id')))), 'e' => array('table' => '?:product_feature_variant_descriptions', 'description' => 'variant', 'dispatch' => 'product_features.view', 'item' => 'variant_id', 'condition' => '', 'name' => 'feature', 'html_options' => array('file'), 'option' => 'seo_other_type', 'indexed_pages' => array('product_features.view' => array('index' => array('variant_id'), 'noindex' => array('features_hash')))), 's' => array('table' => '?:seo_names', 'description' => 'name', 'dispatch' => '', 'item' => 'object_id', 'condition' => fn_get_seo_company_condition('?:seo_names.company_id'), 'not_shared' => true, 'name' => 'custom', 'html_options' => array('file'), 'option' => 'seo_other_type', 'indexed_pages' => array('index.index' => array(), 'sitemap.view' => array())));
if (fn_allowed_for('MULTIVENDOR')) {
    $schema['m'] = array('table' => '?:companies', 'description' => 'company', 'dispatch' => 'companies.view', 'item' => 'company_id', 'condition' => '', 'skip_lang_condition' => true, 'name' => 'company', 'html_options' => array('file'), 'option' => 'seo_other_type', 'indexed_pages' => array('companies.view' => array('index' => array('company_id'))));
}
return $schema;