Exemplo n.º 1
0
Arquivo: Rss.php Projeto: nogo/feedbox
 /**
  * @return string
  */
 public function getUpdateInterval()
 {
     /**
      * @var $syndication Syndication
      */
     $syndication = $this->feed->getExtension('Syndication');
     return $syndication->getUpdatePeriod();
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(DOMDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $atomClass = Reader\Reader::getPluginLoader()->getClassName('Atom\\Feed');
     $this->_extensions['Atom\\Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     $atomClass = Reader\Reader::getPluginLoader()->getClassName('DublinCore\\Feed');
     $this->_extensions['DublinCore\\Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     foreach ($this->_extensions as $extension) {
         $extension->setXpathPrefix('/atom:feed');
     }
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(\DomDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $dublinCoreClass = Reader\Reader::getPluginLoader()->getClassName('DublinCore\\Feed');
     $this->_extensions['DublinCore\\Feed'] = new $dublinCoreClass($dom, $this->_data['type'], $this->_xpath);
     $atomClass = Reader\Reader::getPluginLoader()->getClassName('Atom\\Feed');
     $this->_extensions['Atom\\Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     if ($this->getType() !== Reader\Reader::TYPE_RSS_10 && $this->getType() !== Reader\Reader::TYPE_RSS_090) {
         $xpathPrefix = '/rss/channel';
     } else {
         $xpathPrefix = '/rdf:RDF/rss:channel';
     }
     foreach ($this->_extensions as $extension) {
         $extension->setXpathPrefix($xpathPrefix);
     }
 }
Exemplo n.º 4
0
 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(DOMDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $manager = Reader\Reader::getExtensionManager();
     $atomFeed = $manager->get('Atom\\Feed');
     $atomFeed->setDomDocument($dom);
     $atomFeed->setType($this->data['type']);
     $atomFeed->setXpath($this->xpath);
     $this->extensions['Atom\\Feed'] = $atomFeed;
     $atomFeed = $manager->get('DublinCore\\Feed');
     $atomFeed->setDomDocument($dom);
     $atomFeed->setType($this->data['type']);
     $atomFeed->setXpath($this->xpath);
     $this->extensions['DublinCore\\Feed'] = $atomFeed;
     foreach ($this->extensions as $extension) {
         $extension->setXpathPrefix('/atom:feed');
     }
 }
Exemplo n.º 5
0
Arquivo: Rss.php Projeto: tillk/vufind
 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(DOMDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $manager = Reader\Reader::getExtensionManager();
     $feed = $manager->get('DublinCore\\Feed');
     $feed->setDomDocument($dom);
     $feed->setType($this->data['type']);
     $feed->setXpath($this->xpath);
     $this->extensions['DublinCore\\Feed'] = $feed;
     $feed = $manager->get('Atom\\Feed');
     $feed->setDomDocument($dom);
     $feed->setType($this->data['type']);
     $feed->setXpath($this->xpath);
     $this->extensions['Atom\\Feed'] = $feed;
     if ($this->getType() !== Reader\Reader::TYPE_RSS_10 && $this->getType() !== Reader\Reader::TYPE_RSS_090) {
         $xpathPrefix = '/rss/channel';
     } else {
         $xpathPrefix = '/rdf:RDF/rss:channel';
     }
     foreach ($this->extensions as $extension) {
         $extension->setXpathPrefix($xpathPrefix);
     }
 }
Exemplo n.º 6
0
 /**
  * Detect the feed type of the provided feed
  *
  * @param  Feed\AbstractFeed|DOMDocument|string $feed
  * @param  bool $specOnly
  * @return string
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public static function detectType($feed, $specOnly = false)
 {
     if ($feed instanceof Feed\AbstractFeed) {
         $dom = $feed->getDomDocument();
     } elseif ($feed instanceof DOMDocument) {
         $dom = $feed;
     } elseif (is_string($feed) && !empty($feed)) {
         ErrorHandler::start(E_NOTICE | E_WARNING);
         ini_set('track_errors', 1);
         $oldValue = libxml_disable_entity_loader(true);
         $dom = new DOMDocument();
         $status = $dom->loadXML($feed);
         foreach ($dom->childNodes as $child) {
             if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
                 throw new Exception\InvalidArgumentException('Invalid XML: Detected use of illegal DOCTYPE');
             }
         }
         libxml_disable_entity_loader($oldValue);
         ini_restore('track_errors');
         ErrorHandler::stop();
         if (!$status) {
             if (!isset($phpErrormsg)) {
                 if (function_exists('xdebug_is_enabled')) {
                     $phpErrormsg = '(error message not available, when XDebug is running)';
                 } else {
                     $phpErrormsg = '(error message not available)';
                 }
             }
             throw new Exception\RuntimeException("DOMDocument cannot parse XML: {$phpErrormsg}");
         }
     } else {
         throw new Exception\InvalidArgumentException('Invalid object/scalar provided: must' . ' be of type Zend\\Feed\\Reader\\Feed, DomDocument or string');
     }
     $xpath = new DOMXPath($dom);
     if ($xpath->query('/rss')->length) {
         $type = self::TYPE_RSS_ANY;
         $version = $xpath->evaluate('string(/rss/@version)');
         if (strlen($version) > 0) {
             switch ($version) {
                 case '2.0':
                     $type = self::TYPE_RSS_20;
                     break;
                 case '0.94':
                     $type = self::TYPE_RSS_094;
                     break;
                 case '0.93':
                     $type = self::TYPE_RSS_093;
                     break;
                 case '0.92':
                     $type = self::TYPE_RSS_092;
                     break;
                 case '0.91':
                     $type = self::TYPE_RSS_091;
                     break;
             }
         }
         return $type;
     }
     $xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
     if ($xpath->query('/rdf:RDF')->length) {
         $xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
         if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
             return self::TYPE_RSS_10;
         }
         $xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
         if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
             return self::TYPE_RSS_090;
         }
     }
     $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
     if ($xpath->query('//atom:feed')->length) {
         return self::TYPE_ATOM_10;
     }
     if ($xpath->query('//atom:entry')->length) {
         if ($specOnly == true) {
             return self::TYPE_ATOM_10;
         } else {
             return self::TYPE_ATOM_10_ENTRY;
         }
     }
     $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
     if ($xpath->query('//atom:feed')->length) {
         return self::TYPE_ATOM_03;
     }
     return self::TYPE_ANY;
 }
Exemplo n.º 7
0
    /**
     * Detect the feed type of the provided feed
     *
     * @param  Feed\AbstractFeed|DOMDocument|string $feed
     * @return string
     * @throws Exception\ExceptionInterface
     */
    public static function detectType($feed, $specOnly = false)
    {
        if ($feed instanceof Feed\AbstractFeed) {
            $dom = $feed->getDomDocument();
        } elseif($feed instanceof DOMDocument) {
            $dom = $feed;
        } elseif(is_string($feed) && !empty($feed)) {
            @ini_set('track_errors', 1);
            $dom = new DOMDocument;
            $status = @$dom->loadXML($feed);
            @ini_restore('track_errors');
            if (!$status) {
                if (!isset($php_errormsg)) {
                    if (function_exists('xdebug_is_enabled')) {
                        $php_errormsg = '(error message not available, when XDebug is running)';
                    } else {
                        $php_errormsg = '(error message not available)';
                    }
                }
                throw new Exception\RuntimeException("DOMDocument cannot parse XML: $php_errormsg");
            }
        } else {
            throw new Exception\InvalidArgumentException('Invalid object/scalar provided: must'
            . ' be of type Zend\Feed\Reader\Feed, DomDocument or string');
        }
        $xpath = new DOMXPath($dom);

        if ($xpath->query('/rss')->length) {
            $type = self::TYPE_RSS_ANY;
            $version = $xpath->evaluate('string(/rss/@version)');

            if (strlen($version) > 0) {
                switch($version) {
                    case '2.0':
                        $type = self::TYPE_RSS_20;
                        break;

                    case '0.94':
                        $type = self::TYPE_RSS_094;
                        break;

                    case '0.93':
                        $type = self::TYPE_RSS_093;
                        break;

                    case '0.92':
                        $type = self::TYPE_RSS_092;
                        break;

                    case '0.91':
                        $type = self::TYPE_RSS_091;
                        break;
                }
            }

            return $type;
        }

        $xpath->registerNamespace('rdf', self::NAMESPACE_RDF);

        if ($xpath->query('/rdf:RDF')->length) {
            $xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);

            if ($xpath->query('/rdf:RDF/rss:channel')->length
                || $xpath->query('/rdf:RDF/rss:image')->length
                || $xpath->query('/rdf:RDF/rss:item')->length
                || $xpath->query('/rdf:RDF/rss:textinput')->length
            ) {
                return self::TYPE_RSS_10;
            }

            $xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);

            if ($xpath->query('/rdf:RDF/rss:channel')->length
                || $xpath->query('/rdf:RDF/rss:image')->length
                || $xpath->query('/rdf:RDF/rss:item')->length
                || $xpath->query('/rdf:RDF/rss:textinput')->length
            ) {
                return self::TYPE_RSS_090;
            }
        }

        $type = self::TYPE_ATOM_ANY;
        $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);

        if ($xpath->query('//atom:feed')->length) {
            return self::TYPE_ATOM_10;
        }

        if ($xpath->query('//atom:entry')->length) {
            if ($specOnly == true) {
                return self::TYPE_ATOM_10;
            } else {
                return self::TYPE_ATOM_10_ENTRY;
            }
        }

        $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);

        if ($xpath->query('//atom:feed')->length) {
            return self::TYPE_ATOM_03;
        }

        return self::TYPE_ANY;
    }
Exemplo n.º 8
0
 /**
  * Import a feed by providing a Zend_Feed_Abstract object
  *
  * @param  \Zend\Feed\Feed_Abstract $feed A fully instantiated \Zend\Feed\Feed object
  * @return \Zend\Feed\Reader\FeedInterface
  */
 public static function importFeed(Feed\AbstractFeed $feed)
 {
     $dom = $feed->getDOM()->ownerDocument;
     $type = self::detectType($dom);
     self::_registerCoreExtensions();
     if (substr($type, 0, 3) == 'rss') {
         $reader = new Feed\RSS($dom, $type);
     } else {
         $reader = new Feed\Atom\Atom($dom, $type);
     }
     return $reader;
 }