PicoFeed\Filter\Attribute::rewriteAbsoluteUrl PHP Method

rewriteAbsoluteUrl() public method

Convert all relative links to absolute url.
public rewriteAbsoluteUrl ( string $tag, string $attribute, string &$value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean
    public function rewriteAbsoluteUrl($tag, $attribute, &$value)
    {
        if ($this->isResource($attribute)) {
            $value = Url::resolve($value, $this->website);
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 public function testRewriteAbsoluteUrl()
 {
     $filter = new Attribute(new Url('http://www.la-grange.net'));
     $url = '/2014/08/03/4668-noisettes';
     $this->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url));
     $this->assertEquals('http://www.la-grange.net/2014/08/03/4668-noisettes', $url);
     $filter = new Attribute(new Url('http://google.com'));
     $url = 'test';
     $this->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url));
     $this->assertEquals('http://google.com/test', $url);
     $url = 'http://127.0.0.1:8000/test';
     $this->assertTrue($filter->rewriteAbsoluteUrl('img', 'src', $url));
     $this->assertEquals('http://127.0.0.1:8000/test', $url);
     $url = '//example.com';
     $this->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url));
     $this->assertEquals('http://example.com/', $url);
     $filter = new Attribute(new Url('https://google.com'));
     $url = '//example.com/?youpi';
     $this->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url));
     $this->assertEquals('https://example.com/?youpi', $url);
     $filter = new Attribute(new Url('https://127.0.0.1:8000/here/'));
     $url = 'image.png?v=2';
     $this->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url));
     $this->assertEquals('https://127.0.0.1:8000/here/image.png?v=2', $url);
     $filter = new Attribute(new Url('https://truc/'));
     $this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => '//www.youtube.com/test')));
     $filter = new Attribute(new Url('http://truc/'));
     $this->assertEquals(array('href' => 'http://google.fr/'), $filter->filter('a', array('href' => '//google.fr')));
 }