コード例 #1
0
ファイル: itemmapper.php プロジェクト: netcon-source/apps
 /**
  * @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;
 }
コード例 #2
0
ファイル: utils.php プロジェクト: netcon-source/apps
 /**
  * @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;
     }
 }