示例#1
0
 /**
  * Resolves the given URL based on the current URL
  * @param String $url URL to resolve
  * $return String The resolved URL
  */
 private function _resolveUrl($url)
 {
     $url = trim($url);
     // Absolute URLs are fine
     if (strpos($url, 'http') === 0) {
         return $url;
     }
     // Empty URLs represent current URL
     if ($url === '') {
         return $this->_curl->get_effective_url();
     }
     /**
      * If the URL begins with a forwards slash, it is absolute based on the current hostname
      */
     if ($url[0] === '/') {
         $port = ':' . parse_url($this->_curl->get_effective_url(), PHP_URL_PORT);
         return parse_url($this->_curl->get_effective_url(), PHP_URL_SCHEME) . '://' . parse_url($this->_curl->get_effective_url(), PHP_URL_HOST) . ($port !== ':' ? $port : '') . $url;
     }
     /**
      * We have a relative URL.
      * First, check if we have a BASE HREF= tag, if so, we're
      * setting the URL relative to that, otherwise, it's
      * relative to the current URL
      */
     $base = dirname($this->_curl->get_effective_url());
     $baseTag = $this->_navigator->query("//base[@href][last()]");
     if ($baseTag->length > 0) {
         $base = $baseTag->item(0)->getAttribute('href');
     }
     return $base . '/' . $url;
 }