Exemple #1
0
/**
 * Converts URN to URI
 *
 * @param string $url URN (Uniform Resource Name or Query String)
 * @param string $area Area
 * @param string $protocol Output URL protocol (protocol://). If equals 'rel', no protocol will be included
 * @param string $lang_code 2 letters language code
 * @param bool $override_area
 * @return string URI
 */
function fn_url($url = '', $area = AREA, $protocol = 'current', $lang_code = CART_LANGUAGE, $override_area = false)
{
    static $init_vars = false;
    static $indexes, $_admin_index, $vendor_index, $customer_index, $http_location, $https_location, $current_location;
    /**
     * Prepares parameters before building URL
     *
     * @param  string $url           URN (Uniform Resource Name or Query String)
     * @param  string $area          Area
     * @param  string $protocol      Output URL protocol (protocol://). If equals 'rel', no protocol will be included
     * @param  string $lang_code     2 letters language code
     * @param  bool   $override_area
     * @return bool   Always true
     */
    fn_set_hook('url_pre', $url, $area, $protocol, $lang_code, $override_area);
    if (!$init_vars) {
        $vendor_index = Registry::get('config.vendor_index');
        $_admin_index = Registry::get('config.admin_index');
        $customer_index = Registry::get('config.customer_index');
        $http_location = Registry::get('config.http_location');
        $https_location = Registry::get('config.https_location');
        $current_location = Registry::get('config.current_location');
        $init_vars = true;
    }
    $admin_index_area = $override_area ? 'A' : ACCOUNT_TYPE;
    if (isset($indexes[$admin_index_area])) {
        $admin_index = $indexes[$admin_index_area];
    } else {
        $admin_index = $indexes[$admin_index_area] = fn_get_index_script($admin_index_area);
    }
    if ($area != 'A' && $area != 'C') {
        $prev_admin_index = $admin_index;
        if (isset($indexes[$area])) {
            $admin_index = $indexes[$area];
        } else {
            $admin_index = $indexes[$area] = fn_get_index_script($area);
        }
        $area = 'A';
    }
    $url = str_replace('&', '&', $url);
    $parsed_url = parse_url($url);
    $no_shorted = false;
    $full_query = false;
    if (!empty($parsed_url['scheme']) || !empty($parsed_url['host'])) {
        if (!empty($parsed_url['scheme'])) {
            // do not prefix URL is its absolute already
            $protocol = 'no_prefix';
        }
        $no_shorted = true;
    } else {
        if (!empty($parsed_url['path'])) {
            if (stripos($parsed_url['path'], $_admin_index) !== false) {
                $area = 'A';
                $no_shorted = true;
            } elseif (stripos($parsed_url['path'], $customer_index) !== false) {
                $area = 'C';
                $no_shorted = true;
            } elseif (!empty($vendor_index) && stripos($parsed_url['path'], $vendor_index) !== false) {
                $area = 'A';
                $no_shorted = true;
            }
        } else {
            if (strpos($url, '?') === 0) {
                $full_query = true;
            } else {
                $no_shorted = true;
                $url = $_url = $area == 'C' ? $customer_index : $admin_index;
            }
        }
    }
    $index_script = $area == 'C' ? $customer_index : $admin_index;
    $_url = '';
    if ($no_shorted) {
        // full url passed
        $_url = $url;
    } elseif ($full_query) {
        // full query passed
        $_url = $index_script . $url;
    } else {
        $_url = $index_script . '?dispatch=' . str_replace('?', '&', $url);
    }
    if ($protocol != 'rel' || defined('DISPLAY_FULL_PATHS')) {
        if ($protocol == 'http') {
            $_url = $http_location . '/' . $_url;
        } elseif ($protocol == 'https') {
            $_url = $https_location . '/' . $_url;
        } elseif ($protocol == 'current' || defined('DISPLAY_FULL_PATHS')) {
            $_url = $current_location . '/' . $_url;
        }
    }
    $company_id_in_url = fn_get_company_id_from_uri($url);
    /**
     * Prepares parameters before building URL
     *
     * @param string $_url              Output URL
     * @param string $area              Area
     * @param string $url               Input URL
     * @param string $lang_code         2 letters language code
     * @param string $protocol          Output URL protocol (protocol://). If equals 'rel', no protocol will be included
     * @param int    $company_id_in_url Equals company_id if it is present in $url, otherwise false
     */
    fn_set_hook('url_post', $_url, $area, $url, $protocol, $company_id_in_url, $lang_code);
    if (!empty($prev_admin_index)) {
        $admin_index = $prev_admin_index;
    }
    return $_url;
}
Exemple #2
0
 $areas = array('A' => 'admin', 'V' => 'vendor', 'C' => 'customer');
 fn_init_user_session_data($sess_data, $_REQUEST['user_id'], true);
 $old_sess_id = Session::getId();
 $redirect_url = !empty($_REQUEST['redirect_url']) ? $_REQUEST['redirect_url'] : '';
 if ($area != 'C') {
     Session::setName($areas[$area]);
     $sess_id = Session::regenerateId();
     Session::save($sess_id, $sess_data, $area);
     Session::setName(ACCOUNT_TYPE);
     Session::setId($old_sess_id, false);
 } else {
     // Save unique key for session
     $key = fn_crc32(microtime()) . fn_crc32(microtime() + 1);
     fn_set_storage_data('session_' . $key . '_data', serialize($sess_data));
     if (fn_allowed_for('ULTIMATE')) {
         $company_id_in_url = fn_get_company_id_from_uri($redirect_url);
         if (Registry::get('runtime.company_id') || !empty($user_data['company_id']) || Registry::get('runtime.simple_ultimate') || !empty($company_id_in_url)) {
             // Redirect to the personal frontend
             $company_id = !empty($user_data['company_id']) ? $user_data['company_id'] : Registry::get('runtime.company_id');
             if (!$company_id && Registry::get('runtime.simple_ultimate')) {
                 $company_id = fn_get_default_company_id();
             } elseif (!$company_id) {
                 $company_id = $company_id_in_url;
             }
             $url = $area == 'C' ? fn_link_attach($redirect_url, 'skey=' . $key . '&company_id=' . $company_id) : $redirect_url;
             return array(CONTROLLER_STATUS_REDIRECT, fn_url($url, $area), true);
         }
     } else {
         $url = fn_link_attach($redirect_url, 'skey=' . $key);
         return array(CONTROLLER_STATUS_REDIRECT, fn_url($url, $area), true);
     }