public static function find_uri() { parent::find_uri(); if (preg_match('~^[a-z]{2}(?=/|$)~i', Router::$current_uri, $matches) and isset($matches[0])) { $lang = strtolower($matches[0]); if (array_key_exists($lang, Kohana::config('locale.languages'))) { Router::$language = $lang; Router::$current_uri = substr(Router::$current_uri, 3); } } }
/** * Page par défaut du jeu (homepage). * * @param bool Afficher directement ou return la vue * @return void */ public function index() { if (!strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) { Router_Core::$controller = 'browser'; return Browser_Controller::index(); } elseif (!$this->user) { Router_Core::$controller = 'logger'; return Logger_Controller::index(); } $this->css = 'css/core'; $this->script[] = 'js/compile'; $this->template->content = new View('home/index'); $this->template->content->admin = in_array('admin', $this->role->name); $this->template->content->region = $this->user->region_id; $this->template->content->info_user = new View('user/information'); $this->template->content->info_user->user = $this->user; }
public static function setup() { parent::setup(); /* $route_conditions = array('action'=>'[a-zA-Z_-]+[0-9]*[a-zA-Z_-]*','format'=>'html|xml|json|result','id'=>'[0-9]+','name'=>'[a-zA-Zs]+','misc' => '([a-zA-Z]+( :)[a-zA-Z0-9,]+(/){0,1})+'); $defaults = array( 'controller' => 'spl', 'action' => 'index', 'format' => null, 'id' => null, 'name' => null, 'misc' => array() ); parent::Route::set('default', '(<controller>(/<action>)(/<id>)(/<name>))(/<misc>)(.<format>)',$route_conditions)->defaults($defaults); */ }
/** * Generates routed URI from given URI. * * @param string URI to convert * @return string Routed uri */ public static function routed_uri($uri) { if (self::$routes === NULL) { // Load routes self::$routes = Kohana::config('routes'); } // Prepare variables $routed_uri = $uri = trim($uri, '/'); if (isset(self::$routes[$uri])) { // Literal match, no need for regex $routed_uri = self::$routes[$uri]; } else { // Loop through the routes and see if anything matches foreach (self::$routes as $key => $val) { if ($key === '_default') { continue; } // Trim slashes $key = trim($key, '/'); $val = trim($val, '/'); if (preg_match('#^' . $key . '$#u', $uri)) { if (strpos($val, '$') !== FALSE) { // Use regex routing $routed_uri = preg_replace('#^' . $key . '$#u', $val, $uri); } else { // Standard routing $routed_uri = $val; } // A valid route has been found break; } } } if (isset(self::$routes[$routed_uri])) { // Check for double routing (without regex) $routed_uri = self::$routes[$routed_uri]; } return trim($routed_uri, '/'); }
/** * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. * * @return void */ public static function find_uri() { if (PHP_SAPI === 'cli') { // Command line requires a bit of hacking if (isset($_SERVER['argv'][1])) { self::$current_uri = $_SERVER['argv'][1]; // Remove GET string from segments if (($query = strpos(self::$current_uri, '?')) !== FALSE) { list(self::$current_uri, $query) = explode('?', self::$current_uri, 2); // Parse the query string into $_GET parse_str($query, $_GET); // Convert $_GET to UTF-8 $_GET = utf8::clean($_GET); } } } elseif (isset($_GET['Eight_uri'])) { // Use the URI defined in the query string self::$current_uri = $_GET['Eight_uri']; // Remove the URI from $_GET unset($_GET['Eight_uri']); // Remove the URI from $_SERVER['QUERY_STRING'] $_SERVER['QUERY_STRING'] = preg_replace('~\\bEight_uri\\b[^&]*+&?~', '', $_SERVER['QUERY_STRING']); // Fixes really strange handling of a suffix in a GET string if ($suffix = Eight::config('core.url_suffix') and substr(self::$current_uri, -strlen($suffix)) === '_' . substr($suffix, 1)) { self::$current_uri = substr(self::$current_uri, 0, -strlen($suffix)); } } elseif (isset($_SERVER['PATH_INFO']) and $_SERVER['PATH_INFO']) { self::$current_uri = $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['ORIG_PATH_INFO']) and $_SERVER['ORIG_PATH_INFO']) { self::$current_uri = $_SERVER['ORIG_PATH_INFO']; } elseif (isset($_SERVER['PHP_SELF']) and $_SERVER['PHP_SELF']) { self::$current_uri = $_SERVER['PHP_SELF']; } // The front controller directory and filename $fc = substr(realpath($_SERVER['SCRIPT_FILENAME']), strlen(DOCROOT)); if (($strpos_fc = strpos(self::$current_uri, $fc)) !== FALSE) { // Remove the front controller from the current URI self::$current_uri = substr(self::$current_uri, $strpos_fc + strlen($fc)); } // Remove all dot-paths from the URI, they are not valid self::$current_uri = preg_replace('#\\.[\\s./]*/#', '', self::$current_uri); // Reduce multiple slashes into single slashes, remove trailing slashes self::$current_uri = trim(preg_replace('#//+#', '/', self::$current_uri), '/'); // Make sure the URL is not tainted with HTML characters self::$current_uri = html::specialchars(self::$current_uri, FALSE); if (!empty($_SERVER['QUERY_STRING'])) { // Set the query string to the current query string self::$query_string = '?' . trim($_SERVER['QUERY_STRING'], '&'); } }