Exemplo n.º 1
0
 /**
  * Parses the uri from the current request.
  * This method also sets FRIENDLY_URL as the detected method and applies the
  * results to $_REQUEST and $_GET.
  */
 public function parse_request_uri()
 {
     // Check if we have already defined the request method
     if (self::$parsed_request) {
         return;
     }
     // Mark the request as parsed
     self::$parsed_request = true;
     // Check if script uses friendly urls
     if (!$this->is_eligible()) {
         define('FRIENDLY_URL', FRIENDLY_URL_OFF);
         return;
     }
     // Initialise resolution vars
     $method = $uri = false;
     // Get the requested path info
     $rewrite = false;
     // Check if script is in the uri
     if (stripos(VB_URL_CLEAN, $this->script) !== false) {
         // if the primaryvar was requested then we're not using friendly urls
         if (isset($_GET[$this->idvar])) {
             $method = FRIENDLY_URL_OFF;
             // Get raw uri for 'always_route' friendlies
             if ($this->always_route) {
                 $pat_off = preg_quote($this->script, '#') . '\\?' . preg_quote($this->idvar, '#') . '=([^=]*)(?:\\?|&|$)';
                 $matches = array();
                 if (preg_match("#{$pat_off}#sui", VB_URL_CLEAN, $matches)) {
                     $uri = $matches[1];
                 }
             } else {
                 // the friendly will build the uri from the parsed query
                 $uri = false;
             }
         } else {
             // Check for BASIC and ADVANCED
             $pat_basic = preg_quote($this->script, '#') . '\\?([^=]*)(?:\\?|&|$)';
             $pat_advanced = preg_quote($this->script, '#') . '/([^\\?]*)';
             $matches = array();
             if (preg_match("#{$pat_basic}#si", VB_URL_CLEAN, $matches)) {
                 $method = FRIENDLY_URL_BASIC;
                 $uri = $matches[1];
             } else {
                 if (preg_match("#{$pat_advanced}#i", VB_URL_CLEAN, $matches)) {
                     $method = FRIENDLY_URL_ADVANCED;
                     $uri = $matches[1];
                 }
             }
         }
     } else {
         // Check for REWRITE
         $pat_rewrite = '(?:' . preg_quote($this->rewrite_segment, '#') . '/)*' . preg_quote($this->rewrite_segment, '#') . '/([^\\?]*|$)';
         /* Alternate fix for VBIV-14475 if the first fix has issues
         			$modifier = is_browser('ie') ? 'siu' : 'siu';
         			if (preg_match("#$pat_rewrite#{$modifier}", VB_URL_CLEAN, $matches))
         			 */
         if (preg_match("#{$pat_rewrite}#sui", VB_URL_CLEAN, $matches)) {
             $method = FRIENDLY_URL_REWRITE;
             $uri = $matches[1];
         }
     }
     // Check if we didn't detect a method
     if (!$method) {
         $method = FRIENDLY_URL_OFF;
     }
     // Set the decoded uri
     self::$request_uri = urldecode($uri);
     // Define the resolved friendly url method
     define('FRIENDLY_URL', $method);
     // If friendly url is off then there's nothing more to do
     if (FRIENDLY_URL == FRIENDLY_URL_OFF) {
         return;
     }
     // Remove the request uri from the query string
     if (FRIENDLY_URL == FRIENDLY_URL_BASIC) {
         unset($_REQUEST[self::$request_uri]);
         array_shift($_GET);
     }
     // Fix a known issue with apache
     if (is_server('apache') and isset($_SERVER['REDIRECT_URL'])) {
         self::fix_query_string($url);
     }
     // Set the request based on the decoded fragment
     if ($this->always_route) {
         $_REQUEST[$this->idvar] = $_GET[$this->idvar] = self::$request_uri;
     } else {
         $this->set_request(self::$request_uri);
     }
     $this->registry->input->convert_shortvars($_GET, true);
 }