Example #1
0
function fn_get_request_uri($request_uri)
{
    $url_pattern = @parse_url(urldecode($request_uri));
    if (empty($url_pattern)) {
        $url_pattern = @parse_url($request_uri);
    }
    if (empty($url_pattern)) {
        return false;
    }
    $current_path = Registry::get('config.current_path');
    if (fn_allowed_for('ULTIMATE')) {
        $urls = fn_get_storefront_urls(Registry::get('runtime.company_id'));
        if (!empty($urls)) {
            $current_path = $urls['current_path'];
        }
    }
    return rtrim(substr($url_pattern['path'], strlen($current_path)), '/');
}
function fn_init_store_params_by_host(&$request, $area = AREA)
{
    if ($area == 'A' && empty($request['allow_initialization'])) {
        return array(INIT_STATUS_OK);
    }
    $host = $_SERVER['HTTP_HOST'];
    $host = preg_replace('#^www.#i', '', $host);
    $field = defined('HTTPS') ? 'secure_storefront' : 'storefront';
    $companies = db_get_array("SELECT company_id, {$field} FROM ?:companies WHERE {$field} LIKE ?l OR {$field} LIKE ?l", $host . '%', 'www.' . $host . '%');
    if (!empty($companies)) {
        if (count($companies) == 1) {
            $request['switch_company_id'] = $companies[0]['company_id'];
        } else {
            $found_companies = array();
            foreach ($companies as $company) {
                $parsed_url = parse_url('http://' . $company[$field]);
                // protocol prefix does not matter
                if (empty($parsed_url['path'])) {
                    $found_companies[0] = $company['company_id'];
                } elseif (!empty($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($parsed_url['path'], '/') . "([\\/\\?].*?)?\$/", $_SERVER['REQUEST_URI'], $m)) {
                    $priority = count(explode('/', $parsed_url['path']));
                    $found_companies[$priority] = $company['company_id'];
                }
            }
            if (!empty($found_companies)) {
                krsort($found_companies);
                $request['switch_company_id'] = reset($found_companies);
            }
        }
    }
    if (!empty($request['switch_company_id']) && $request['switch_company_id'] != 'all' && !isset($request['skip_config_changing'])) {
        // theme for company with id = 0 cannot be loaded.
        $company_data = db_get_row('SELECT company_id, storefront, secure_storefront, redirect_customer FROM ?:companies WHERE company_id = ?i', $request['switch_company_id']);
        if (empty($company_data)) {
            return array(INIT_STATUS_OK);
        }
        if ($company_data['redirect_customer'] == 'Y' && !fn_get_cookie('storefront_redirect_' . $request['switch_company_id'])) {
            $_ip = fn_get_ip(true);
            $_country = fn_get_country_by_ip($_ip['host']);
            if (!empty($_country)) {
                // Check if found country assigned to some companies
                $redirect = db_get_hash_array('SELECT company_id, storefront FROM ?:companies WHERE FIND_IN_SET(?s, countries_list) LIMIT 1', 'company_id', $_country);
                if (!empty($redirect) && !isset($redirect[$request['switch_company_id']])) {
                    if (!defined('CRAWLER')) {
                        $redirect_url = reset($redirect);
                        $redirect_url = 'http://' . $redirect_url['storefront'];
                        fn_set_cookie('storefront_redirect_' . $request['switch_company_id'], true);
                        return array(INIT_STATUS_REDIRECT, $redirect_url);
                    }
                }
            }
        }
        $config = Registry::get('config');
        $url_data = fn_get_storefront_urls(0, $company_data);
        $config = fn_array_merge($config, $url_data);
        $config['images_path'] = $config['current_path'] . '/media/images/';
        $config['origin_http_location'] = $config['http_location'];
        $config['origin_https_location'] = $config['https_location'];
        Registry::set('config', $config);
    } else {
        return array(INIT_STATUS_FAIL, '', 'No storefronts defined for this domain');
    }
    return array(INIT_STATUS_OK);
}
Example #3
0
/**
 * Generates URL according to schema definition
 * @param array $redirect_data redirect data
 * @param boolean $full generated full URL if true and URI part if false
 * @param array $query_string additional params to attach to URL
 * @return string URL
 */
function fn_generate_seo_url_from_schema($redirect_data, $full = true, $query_string = array())
{
    $seo_vars = fn_get_seo_vars();
    if ($redirect_data['type'] == 's') {
        $http_path = Registry::get('config.http_path');
        if (fn_allowed_for('ULTIMATE')) {
            $urls = fn_get_storefront_urls(Registry::get('runtime.company_id'));
            if (!empty($urls)) {
                $http_path = $urls['http_path'];
            }
        }
        $url = $http_path . $redirect_data['dest'];
    } else {
        $url = $seo_vars[$redirect_data['type']]['dispatch'] . '?' . $seo_vars[$redirect_data['type']]['item'] . '=' . $redirect_data['object_id'];
    }
    // do not add company_id to static routes
    if (fn_allowed_for('ULTIMATE') && $redirect_data['type'] != 's') {
        $url = fn_link_attach($url, 'company_id=' . Registry::get('runtime.company_id'));
    }
    if (!empty($query_string)) {
        $url = fn_link_attach($url, http_build_query($query_string));
    }
    $lang_code = !empty($redirect_data['lang_code']) ? $redirect_data['lang_code'] : Registry::get('settings.Appearance.frontend_default_language');
    if ($full) {
        $url = fn_url($url, 'C', 'http', $lang_code);
    } else {
        $url = fn_get_request_uri(fn_url($url, 'C', 'rel', $lang_code));
    }
    return $url;
}
Example #4
0
function fn_ult_get_storefront_url($protocol, $company_id, &$url)
{
    if (empty($company_id)) {
        $company_id = Registry::get('runtime.company_id');
    }
    $urls = fn_get_storefront_urls($company_id);
    if (!empty($urls[$protocol . '_location'])) {
        $url = $urls[$protocol . '_location'];
    }
}