Beispiel #1
0
 function _createAction($action, $base)
 {
     if (is_bool($action)) {
         return $base;
     }
     $url = new SimpleUrl($action);
     return $url->makeAbsolute($base);
 }
Beispiel #2
0
 /**
  *    Combined action attribute with current location
  *    to get an absolute form target.
  *    @param string $action    Action attribute from form tag.
  *    @param SimpleUrl $base   Page location.
  *    @return SimpleUrl        Absolute form target.
  */
 function _createAction($action, $base)
 {
     if ($action === false) {
         return $base;
     }
     if ($action === true) {
         $url = new SimpleUrl('');
     } else {
         $url = new SimpleUrl($action);
     }
     return $url->makeAbsolute($base);
 }
Beispiel #3
0
 /**
  *    Fetches the page until no longer redirected or
  *    until the redirect limit runs out.
  *    @param SimpleUrl $url                  Target to fetch.
  *    @param SimpelFormEncoding $encoding    Additional parameters for request.
  *    @return SimpleHttpResponse             Hopefully the target page.
  *    @access private
  */
 protected function fetchWhileRedirected($url, $encoding)
 {
     $redirects = 0;
     do {
         $response = $this->fetch($url, $encoding);
         if ($response->isError()) {
             return $response;
         }
         $headers = $response->getHeaders();
         if ($this->cookies_enabled) {
             $headers->writeCookiesToJar($this->cookie_jar, $url);
         }
         if (!$headers->isRedirect()) {
             break;
         }
         $location = new SimpleUrl($headers->getLocation());
         $url = $location->makeAbsolute($url);
         $encoding = new SimpleGetEncoding();
     } while (!$this->isTooManyRedirects(++$redirects));
     return $response;
 }
Beispiel #4
0
 function testMakingHostOnlyAbsoluteDoesNotCarryAnyOtherInformation()
 {
     $url = new SimpleUrl('http://www.lastcraft.com');
     $absolute = $url->makeAbsolute('https://host.com:81/here/');
     $this->assertEqual($absolute->getScheme(), 'http');
     $this->assertEqual($absolute->getHost(), 'www.lastcraft.com');
     $this->assertIdentical($absolute->getPort(), false);
     $this->assertEqual($absolute->getPath(), '/');
 }
Beispiel #5
0
 /**
  *    Expands expandomatic URLs into fully qualified
  *    URLs.
  *    @param SimpleUrl $url        Relative URL.
  *    @return SimpleUrl            Absolute URL.
  *    @access protected
  */
 function _makeAbsolute($url)
 {
     if (!is_object($url)) {
         $url = new SimpleUrl($url);
     }
     return $url->makeAbsolute($this->getUrl());
 }
 /**
  *    Turns an incoming URL string into a
  *    URL object, filling the relative URL if
  *    a base URL is present.
  *    @param string $base_url       Browser current URL.
  *    @param string $raw_url        Incoming URL.
  *    @param hash $parameters       Additional request, parameters.
  *    @return SimpleUrl             Absolute URL.
  *    @access public
  *    @static
  */
 function createAbsoluteUrl($base_url, $raw_url, $parameters = false)
 {
     $url = new SimpleUrl($raw_url);
     if ($parameters) {
         $url->addRequestParameters($parameters);
     }
     $url->makeAbsolute($base_url);
     return $url;
 }
Beispiel #7
0
 /**
  *    Expands expandomatic URLs into fully qualified
  *    URLs.
  *    @param SimpleUrl $url        Relative URL.
  *    @return SimpleUrl            Absolute URL.
  *    @access public
  */
 function expandUrl($url)
 {
     if (!is_object($url)) {
         $url = new SimpleUrl($url);
     }
     $location = $this->getBaseUrl() ? $this->getBaseUrl() : new SimpleUrl();
     return $url->makeAbsolute($location->makeAbsolute($this->getUrl()));
 }
 function testMakingAbsoluteAppendedPath()
 {
     $url = new SimpleUrl("./there/somewhere.php");
     $url->makeAbsolute("http://host.com/here/");
     $this->assertEqual($url->getPath(), "/here/there/somewhere.php");
     $base = new SimpleUrl("http://host.com/here/");
 }
Beispiel #9
0
 /**
  *    Combined action attribute with current location
  *    to get an absolute form target.
  *    @param string $action    Action attribute from form tag.
  *    @param SimpleUrl $base   Page location.
  *    @return SimpleUrl        Absolute form target.
  */
 function _createAction($action, $base)
 {
     if ($action === '' || $action === false) {
         return $base;
     }
     $url = new SimpleUrl($action);
     return $url->makeAbsolute($base);
 }
Beispiel #10
0
 /**
  *    Fetches the page until no longer redirected or
  *    until the redirect limit runs out.
  *    @param string $method                  GET, POST, etc.
  *    @param SimpleUrl $url                  Target to fetch.
  *    @param SimpelFormEncoding $parameters  Additional parameters for request.
  *    @return SimpleHttpResponse             Hopefully the target page.
  *    @access private
  */
 function &_fetchWhileRedirected($method, $url, $parameters)
 {
     $redirects = 0;
     do {
         $response =& $this->_fetch($method, $url, $parameters);
         if ($response->isError()) {
             return $response;
         }
         $headers = $response->getHeaders();
         $location = new SimpleUrl($headers->getLocation());
         $url = $location->makeAbsolute($url);
         $this->_addCookiesToJar($url, $headers->getNewCookies());
         if (!$headers->isRedirect()) {
             break;
         }
         $method = 'GET';
         $parameters = false;
     } while (!$this->_isTooManyRedirects(++$redirects));
     return $response;
 }
Beispiel #11
0
 /**
  *    Turns an incoming URL string or object into a
  *    URL object, filling the relative URL if
  *    a base URL is present.
  *    @param string/SimpleUrl $base Browser current URL.
  *    @param string/SimpleUrl $url  Incoming URL.
  *    @return SimpleUrl             Absolute URL.
  *    @access public
  *    @static
  */
 function createAbsoluteUrl($base, $url)
 {
     if (!is_object($url)) {
         $url = new SimpleUrl($url);
     }
     $url->makeAbsolute($base);
     return $url;
 }
Beispiel #12
0
 function testMakingAbsolutehasNoEffectWhenAlreadyAbsolute()
 {
     $url = new SimpleUrl('https://*****:*****@www.lastcraft.com/stuff/');
     $url->makeAbsolute('http://host.com/here/');
     $this->assertEqual($url->getScheme(), 'https');
     $this->assertEqual($url->getUsername(), 'test');
     $this->assertEqual($url->getPassword(), 'secret');
     $this->assertEqual($url->getHost(), 'www.lastcraft.com');
     $this->assertEqual($url->getPath(), '/stuff/');
 }
Beispiel #13
0
 /**
  *    Fetches the page until no longer redirected or
  *    until the redirect limit runs out.
  *    @param SimpleUrl $url                  Target to fetch.
  *    @param SimpelFormEncoding $encoding    Additional parameters for request.
  *    @return SimpleHttpResponse             Hopefully the target page.
  *    @access private
  */
 function &_fetchWhileRedirected($url, $encoding)
 {
     $redirects = 0;
     do {
         $response =& $this->_fetch($url, $encoding);
         if ($response->isError()) {
             return $response;
         }
         $headers = $response->getHeaders();
         $location = new SimpleUrl($headers->getLocation());
         $url = $location->makeAbsolute($url);
         $this->_addCookiesToJar($url, $headers->getNewCookies());
         if (!$headers->isRedirect()) {
             break;
         }
         $encoding = new SimpleGetEncoding();
     } while (!$this->_isTooManyRedirects(++$redirects));
     return $response;
 }