absolutize() public method

Create a new IRI object by resolving a relative IRI
public absolutize ( SimplePie_IRI $base, string $relative ) : SimplePie_IRI
$base SimplePie_IRI Base IRI
$relative string Relative IRI
return SimplePie_IRI
Beispiel #1
0
 public static function absolutize_url($relative, $base)
 {
     $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
     if ($iri === false) {
         return false;
     }
     return $iri->get_uri();
 }
Beispiel #2
0
 public static function absolutize_url($relative, $base)
 {
     $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
     //NOTE: this is temporary commented out to bypass issue #214: https://github.com/simplepie/simplepie/issues/214
     if (is_object($iri)) {
         return $iri->get_uri();
     } else {
         return FALSE;
     }
 }
function makeAbsoluteStr($base, $url)
{
    $base = new SimplePie_IRI($base);
    // remove '//' in URL path (causes URLs not to resolve properly)
    if (isset($base->path)) {
        $base->path = preg_replace('!//+!', '/', $base->path);
    }
    if (preg_match('!^https?://!i', $url)) {
        // already absolute
        return $url;
    } else {
        if ($absolute = SimplePie_IRI::absolutize($base, $url)) {
            return $absolute;
        }
        return false;
    }
}
Beispiel #4
0
 /**
  * Try to find the refresh url from the meta.
  *
  * @param string $url  Absolute url
  * @param string $html First characters of the response (hopefully it'll be enough to find some meta)
  *
  * @return false|string
  */
 private function getMetaRefreshURL($url, $html)
 {
     if ($html == '') {
         return false;
     }
     // <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.bernama.com/bernama/v6/newsindex.php?id=943513">
     if (!preg_match('!<meta http-equiv=["\']?refresh["\']? content=["\']?[0-9];\\s*url=["\']?([^"\'>]+)["\']?!i', $html, $match)) {
         return false;
     }
     $redirect_url = trim($match[1]);
     if (preg_match('!^https?://!i', $redirect_url)) {
         // already absolute
         $this->logger->log('debug', 'Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $redirect_url);
         return $redirect_url;
     }
     // absolutize redirect URL
     $base = new \SimplePie_IRI($url);
     // remove '//' in URL path (causes URLs not to resolve properly)
     if (isset($base->ipath)) {
         $base->ipath = str_replace('//', '/', $base->ipath);
     }
     if ($absolute = \SimplePie_IRI::absolutize($base, $redirect_url)) {
         $this->logger->log('debug', 'Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $absolute);
         return $absolute->get_iri();
     }
     return false;
 }
 public static function absolutize_url($relative, $base)
 {
     $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
     return $iri->get_iri();
 }
Beispiel #6
0
 private function makeAbsoluteAttr($base, $e, $attr)
 {
     if ($e->hasAttribute($attr)) {
         // Trim leading and trailing white space. I don't really like this but
         // unfortunately it does appear on some sites. e.g.  <img src=" /path/to/image.jpg" />
         $url = trim(str_replace('%20', ' ', $e->getAttribute($attr)));
         $url = str_replace(' ', '%20', $url);
         if (!preg_match('!https?://!i', $url)) {
             if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
                 $e->setAttribute($attr, $absolute);
             }
         }
     }
 }
Beispiel #7
0
 /**
  * @dataProvider absolutize_tests
  */
 public function testAbsolutizeObject($base, $relative, $expected)
 {
     $base = new SimplePie_IRI($base);
     $expected = new SimplePie_IRI($expected);
     $this->assertEquals($expected, SimplePie_IRI::absolutize($base, $relative));
 }