Example #1
0
 /**
  * @brief Fetch a feed from remote
  * @param url remote url of the feed
  * @returns an instance of OC_News_Feed
  */
 public static function fetch($url)
 {
     $spfeed = new \SimplePie_Core();
     $spfeed->set_feed_url($url);
     $spfeed->enable_cache(false);
     if (!$spfeed->init()) {
         return null;
     }
     //temporary try-catch to bypass SimplePie bugs
     try {
         $spfeed->handle_content_type();
         $title = $spfeed->get_title();
         $items = array();
         if ($spitems = $spfeed->get_items()) {
             foreach ($spitems as $spitem) {
                 $itemUrl = $spitem->get_permalink();
                 $itemTitle = $spitem->get_title();
                 $itemGUID = $spitem->get_id();
                 $itemBody = $spitem->get_content();
                 $item = new Item($itemUrl, $itemTitle, $itemGUID, $itemBody);
                 $spAuthor = $spitem->get_author();
                 if ($spAuthor !== null) {
                     $item->setAuthor($spAuthor->get_name());
                 }
                 //date in Item is stored in UNIX timestamp format
                 $itemDate = $spitem->get_date('U');
                 $item->setDate($itemDate);
                 // associated media file, for podcasts
                 $itemEnclosure = $spitem->get_enclosure();
                 if ($itemEnclosure !== null) {
                     $enclosureType = $itemEnclosure->get_type();
                     $enclosureLink = $itemEnclosure->get_link();
                     if (stripos($enclosureType, "audio/") !== FALSE) {
                         $enclosure = new Item_Enclosure();
                         $enclosure->setMimeType($enclosureType);
                         $enclosure->setLink($enclosureLink);
                         $item->setEnclosure($enclosure);
                     }
                 }
                 $items[] = $item;
             }
         }
         $feed = new Feed($url, $title, $items);
         $favicon = $spfeed->get_image_url();
         if ($favicon !== null && self::checkFavicon($favicon)) {
             // use favicon from feed
             $feed->setFavicon($favicon);
         } else {
             // try really hard to find a favicon
             $webFavicon = self::discoverFavicon($url);
             if ($webFavicon !== null) {
                 $feed->setFavicon($webFavicon);
             }
         }
         return $feed;
     } catch (Exception $e) {
         return null;
     }
 }
Example #2
0
 /**
  * @brief 
  * @param row a row from the items table of the database
  * @returns an object of the class OC_News_Item
  */
 public function fromRow($row)
 {
     $url = $row['url'];
     $title = $row['title'];
     $guid = $row['guid'];
     $body = $row['body'];
     $id = $row['id'];
     $item = new Item($url, $title, $guid, $body, $id);
     $item->setStatus($row['status']);
     $item->setAuthor($row['author']);
     $item->setDate(Utils::dbtimestampToUnixtime($row['pub_date']));
     return $item;
 }
Example #3
0
 /**
  * @brief
  * @param row a row from the items table of the database
  * @returns an object of the class OC_News_Item
  */
 public function fromRow($row)
 {
     $url = $row['url'];
     $title = $row['title'];
     $guid = $row['guid'];
     $body = $row['body'];
     $id = $row['id'];
     $item = new Item($url, $title, $guid, $body, $id);
     $item->setStatus($row['status']);
     $item->setAuthor($row['author']);
     $item->setFeedId($row['feed_id']);
     $item->setDate(Utils::dbtimestampToUnixtime($row['pub_date']));
     if ($row['enclosure_mime'] !== null && $row['enclosure_link'] !== null) {
         $enclosure = new Item_Enclosure();
         $enclosure->setMimeType($row['enclosure_mime']);
         $enclosure->setLink($row['enclosure_link']);
         $item->setEnclosure($enclosure);
     }
     return $item;
 }
Example #4
0
 public function testSetAuthor()
 {
     $item = new Item();
     $item->setAuthor('<a>my link</li>');
     $this->assertEquals('my link', $item->getAuthor());
     $this->assertContains('author', $item->getUpdatedFields());
 }
Example #5
0
									post_category, 
									category_id, 
									category_name 
								FROM post 
								LEFT JOIN category ON category_id = post_category_id 
								WHERE post_valid=1 
								LIMIT 10');
    while ($row = mysql_fetch_object($request)) {
        // Creating a new feed item
        $rssItem = new Item();
        $rssItem->setTitle($row->post_title);
        $rssItem->setDescription($row->post_description);
        $rssItem->setLink('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id);
        $rssItem->setGuid('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id, true);
        $rssItem->setComments('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id . '#comments');
        $rssItem->setAuthor($row->post_author_email, $row->post_author_name);
        $rssItem->setPubDate($row->post_date);
        $rssItem->setSource($row->post_source_uri, $row->post_source_name);
        $rssItem->setEnclosure('http://www.mywebsite.com/blog/images/nopicture.jpg', 2800, 'image/jpg');
        $rssItem->setCategory('http://www.mywebsite.com/blog/category.php.idCat=' . $row->category_id, $row->category_name);
        // Add the item to the feed
        $rssFeed->appendItem($rssItem);
    }
    // Save the feed
    $rssFeed->save();
    // SQL connection closing
    mysql_close();
    // Send headers to the browser
    header('Content-Type: text/xml; charset=utf-8');
    // Display the feed
    $rssFeed->display();
Example #6
0
 /**
  * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setAuthor
  */
 public function testSetAuthor()
 {
     $newAuthor = 'New Contributor';
     $this->object->setAuthor($newAuthor);
     $this->assertEquals($newAuthor, $this->object->getAuthor());
 }