public function before() { $fullBaseUrl = Url::base(true); //was user on our site? if (strpos($this->request->referrer(), $fullBaseUrl) === 0) { //now check that a controller set, it wasn't the user controller, and that the session var "noReturn" is not false $uri = parse_url($this->request->referrer(), PHP_URL_PATH); // correct the path for url_base and index_file, in part taken from Kohana_Request::detect_uri() // Get the path from the base URL, including the index file $base_url = parse_url(Kohana::$base_url, PHP_URL_PATH); if (strpos($uri, $base_url) === 0) { // Remove the base URL from the URI $uri = (string) substr($uri, strlen($base_url)); } if (Kohana::$index_file and strpos($uri, Kohana::$index_file) === 0) { // Remove the index file from the URI $uri = (string) substr($uri, strlen(Kohana::$index_file)); } $processedRef = Request::process_uri($uri); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } parent::before(); }
public function before() { $baseUrl = Url::base(true); if (substr($this->request->referrer(), 0, strlen($baseUrl)) == $baseUrl) { $urlPath = ltrim(parse_url($this->request->referrer(), PHP_URL_PATH), '/'); $processedRef = Request::process_uri($urlPath); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } parent::before(); }
/** * Creates a new request object for the given URI. New requests should be * created using the [Request::instance] or [Request::factory] methods. * * $request = new Request($uri); * * If $cache parameter is set, the response for the request will attempt to * be retrieved from the cache. * * @param string $uri URI of the request * @param HTTP_Cache $cache * @param array $injected_routes an array of routes to use, for testing * @return void * @throws Request_Exception * @uses Route::all * @uses Route::matches */ public function __construct($uri, HTTP_Cache $cache = NULL, $injected_routes = array()) { // Initialise the header $this->_header = new HTTP_Header(array()); // Assign injected routes $this->_injected_routes = $injected_routes; // Cleanse query parameters from URI (faster that parse_url()) $split_uri = explode('?', $uri); $uri = array_shift($split_uri); // Initial request has global $_GET already applied if (Request::$initial !== NULL) { if ($split_uri) { parse_str($split_uri[0], $this->_get); } } // Detect protocol (if present) // Always default to an internal request if we don't have an initial. // This prevents the default index.php from being able to proxy // external pages. if (Request::$initial === NULL or strpos($uri, '://') === FALSE) { // Remove trailing slashes from the URI $uri = trim($uri, '/'); $processed_uri = Request::process_uri($uri, $this->_injected_routes); // Return here rather than throw exception. This will allow // use of Request object even with unmatched route if ($processed_uri === NULL) { $this->_uri = $uri; return; } // Store the URI $this->_uri = $uri; // Store the matching route $this->_route = $processed_uri['route']; $params = $processed_uri['params']; // Is this route external? $this->_external = $this->_route->is_external(); if (isset($params['directory'])) { // Controllers are in a sub-directory $this->_directory = $params['directory']; } // Store the controller $this->_controller = $params['controller']; if (isset($params['action'])) { // Store the action $this->_action = $params['action']; } else { // Use the default action $this->_action = Route::$default_action; } // These are accessible as public vars and can be overloaded unset($params['controller'], $params['action'], $params['directory']); // Params cannot be changed once matched $this->_params = $params; // Apply the client $this->_client = new Request_Client_Internal(array('cache' => $cache)); } else { // Create a route $this->_route = new Route($uri); // Store the URI $this->_uri = $uri; // Set the security setting if required if (strpos($uri, 'https://') === 0) { $this->secure(TRUE); } // Set external state $this->_external = TRUE; // Setup the client $this->_client = Request_Client_External::factory(array('cache' => $cache)); } }
public function set_module_routes($routes_config, $uri_base, $prefix, $cache) { $routes = array(); foreach ($routes_config as $name => $route) { $name = $prefix . '<->' . $name; $uri_callback = Arr::get($route, 'uri_callback'); if (is_string($uri_callback)) { $uri_callback = $uri_base . $uri_callback; } $regex = Arr::get($route, 'regex'); $defaults = Arr::get($route, 'defaults'); $route = new Route($uri_callback, $regex, $name); $route->defaults($defaults); $routes[$name] = $route; Route::set($name, $uri_callback, $regex)->defaults($defaults); } $processed_uri = Request::process_uri($this->uri(), $routes); if ($processed_uri !== NULL) { $this->set_dinamic_route($processed_uri, $cache); } }
/** * Creates a new request object for the given URI. New requests should be * created using the [Request::instance] or [Request::factory] methods. * * $request = new Request($uri); * * If $cache parameter is set, the response for the request will attempt to * be retrieved from the cache. * * @param string $uri URI of the request * @param Cache $cache * @param array $injected_routes an array of routes to use, for testing * @return void * @throws Kohana_Request_Exception * @uses Route::all * @uses Route::matches */ public function __construct($uri, Cache $cache = NULL, $injected_routes = array()) { // Initialise the header $this->_header = new HTTP_Header(array()); // Assign injected routes $this->_injected_routes = $injected_routes; // Detect protocol (if present) /** * @todo make this smarter, search for localhost etc */ if (strpos($uri, '://') === FALSE) { // Remove trailing slashes from the URI $uri = trim($uri, '/'); $processed_uri = Request::process_uri($uri, $this->_injected_routes); if ($processed_uri === NULL) { throw new HTTP_Exception_404('Unable to find a route to match the URI: :uri', array(':uri' => $uri)); } // Store the URI $this->_uri = $uri; // Store the matching route $this->_route = $processed_uri['route']; $params = $processed_uri['params']; // Is this route external? $this->_external = $this->_route->is_external(); if (isset($params['directory'])) { // Controllers are in a sub-directory $this->_directory = $params['directory']; } // Store the controller $this->_controller = $params['controller']; if (isset($params['action'])) { // Store the action $this->_action = $params['action']; } else { // Use the default action $this->_action = Route::$default_action; } // These are accessible as public vars and can be overloaded unset($params['controller'], $params['action'], $params['directory']); // Params cannot be changed once matched $this->_params = $params; // Apply the client $this->_client = new Request_Client_Internal(array('cache' => $cache)); } else { // Create a route $this->_route = new Route($uri); // Store the URI $this->_uri = $uri; // Set external state $this->_external = TRUE; // Setup the client $this->_client = new Request_Client_External(array('cache' => $cache)); } }