Example #1
0
    public function testIsRelativeUrl()
    {
        $url = new Url('http://www.google.fr/');
        $this->assertFalse($url->isRelativeUrl());
        $url = new Url('//www.google.fr/');
        $this->assertFalse($url->isRelativeUrl());
        $url = new Url('/path');
        $this->assertTrue($url->isRelativeUrl());
        $url = new Url('../../path');
        $this->assertTrue($url->isRelativeUrl());
        $url = new Url('anything');
        $this->assertTrue($url->isRelativeUrl());
        $url = new Url('/2014/08/03/4668-noisettes');
        $this->assertTrue($url->isRelativeUrl());
        $url = new Url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==');
        $this->assertFalse($url->isRelativeUrl());
    }
Example #2
0
 /**
  * Find feed urls inside a HTML document
  *
  * @access public
  * @param  string    $url        Website url
  * @param  string    $html       HTML content
  * @return array                 List of feed links
  */
 public function find($url, $html)
 {
     Logger::setMessage(get_called_class() . ': Try to discover subscriptions');
     $dom = XmlParser::getHtmlDocument($html);
     $xpath = new DOMXPath($dom);
     $links = array();
     $queries = array('//link[@type="application/rss+xml"]', '//link[@type="application/atom+xml"]');
     foreach ($queries as $query) {
         $nodes = $xpath->query($query);
         foreach ($nodes as $node) {
             $link = $node->getAttribute('href');
             if (!empty($link)) {
                 $feedUrl = new Url($link);
                 $siteUrl = new Url($url);
                 $links[] = $feedUrl->getAbsoluteUrl($feedUrl->isRelativeUrl() ? $siteUrl->getBaseUrl() : '');
             }
         }
     }
     Logger::setMessage(get_called_class() . ': ' . implode(', ', $links));
     return $links;
 }