Exemple #1
0
/**
 * Looks for "dispatch" parameter in REQUEST array and extracts controller, mode, action and extra parameters.
 *
 * @param array $req Request parameters
 * @param string $area Area
 * @return boolean always true
 */
function fn_get_route(&$req, $area = AREA)
{
    $result = array(INIT_STATUS_OK);
    $is_allowed_url = fn_check_requested_url();
    if (!$is_allowed_url) {
        $request_uri = fn_get_request_uri($_SERVER['REQUEST_URI']);
        $router = new Router($req);
        $router->addRoutes(fn_get_schema('routes', 'objects'));
        if ($params = $router->match($request_uri)) {
            $is_allowed_url = true;
            $req = $params;
        }
    }
    fn_set_hook('get_route', $req, $result, $area, $is_allowed_url);
    if (!$is_allowed_url) {
        $req = array('dispatch' => '_no_page');
    }
    if (!empty($req['dispatch'])) {
        $dispatch = is_array($req['dispatch']) ? key($req['dispatch']) : $req['dispatch'];
    } else {
        $dispatch = 'index.index';
    }
    rtrim($dispatch, '/.');
    $dispatch = str_replace('/', '.', $dispatch);
    $parts = explode('.', $dispatch);
    Registry::set('runtime.controller', !empty($parts[0]) ? basename($parts[0]) : 'index');
    Registry::set('runtime.mode', !empty($parts[1]) ? basename($parts[1]) : 'index');
    Registry::set('runtime.action', !empty($parts[2]) ? $parts[2] : '');
    Registry::set('runtime.dispatch_extra', !empty($parts[3]) ? $parts[3] : '');
    Registry::set('runtime.checkout', false);
    Registry::set('runtime.root_template', 'index.tpl');
    $req['dispatch'] = $dispatch;
    // URL's assignments
    Registry::set('config.current_url', fn_url_remove_service_params(Registry::get('config.' . ACCOUNT_TYPE . '_index') . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')));
    return $result;
}
/**
 * Looks for "dispatch" parameter in REQUEST array and extracts controller, mode, action and extra parameters.
 *
 * @param array $req Request parameters
 * @param string $area Area
 * @return boolean always true
 */
function fn_get_route(&$req, $area = AREA)
{
    $result = array(INIT_STATUS_OK);
    $is_allowed_url = fn_check_requested_url();
    fn_set_hook('get_route', $req, $result, $area, $is_allowed_url);
    if (!$is_allowed_url) {
        $current_path = Registry::get('config.current_path');
        $clean_uri = substr($_SERVER['REQUEST_URI'], strlen($current_path) + 1);
        $images_substring = 'images/thumbnails/';
        if (strpos($clean_uri, $images_substring) !== false) {
            list(, $clean_uri) = explode($images_substring, $clean_uri);
            if (preg_match("/^(\\d+)[\\/]?(\\d+)?\\/(.*)\$/", $clean_uri, $m)) {
                $req['dispatch'] = 'image.thumbnail';
                $req['w'] = $m[1];
                $req['h'] = $m[2];
                $req['image_path'] = $m[3];
                $is_allowed_url = true;
            }
        }
        if (!$is_allowed_url) {
            $req = array('dispatch' => '_no_page');
        }
    }
    if (!empty($req['dispatch'])) {
        $dispatch = is_array($req['dispatch']) ? key($req['dispatch']) : $req['dispatch'];
    } else {
        $dispatch = 'index.index';
    }
    rtrim($dispatch, '/.');
    $dispatch = str_replace('/', '.', $dispatch);
    @(list($c, $m, $a, $e) = explode('.', $dispatch));
    Registry::set('runtime.controller', empty($c) ? 'index' : $c);
    Registry::set('runtime.mode', empty($m) ? 'index' : $m);
    Registry::set('runtime.action', $a);
    Registry::set('runtime.dispatch_extra', $e);
    Registry::set('runtime.checkout', false);
    Registry::set('runtime.root_template', 'index.tpl');
    $req['dispatch'] = $dispatch;
    // URL's assignments
    Registry::set('config.current_url', fn_url_remove_service_params(Registry::get('config.' . ACCOUNT_TYPE . '_index') . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')));
    return $result;
}