diff options
author | Nick Frey <nickfrey123@gmail.com> | 2012-11-28 16:57:07 -0600 |
---|---|---|
committer | Nick Frey <nickfrey123@gmail.com> | 2012-11-28 16:57:07 -0600 |
commit | 207c085b30955761beb0e76837fc1838148a648c (patch) | |
tree | 2bc020e596442a60ed55def4e509292964a57cbe /lib | |
parent | a5fd08475355fce0881b87b29ad0d2577e8cfa6e (diff) |
Play audio podcasts from feeds in the News app
Diffstat (limited to 'lib')
-rw-r--r-- | lib/item.php | 32 | ||||
-rw-r--r-- | lib/itemmapper.php | 26 | ||||
-rw-r--r-- | lib/utils.php | 15 |
3 files changed, 66 insertions, 7 deletions
diff --git a/lib/item.php b/lib/item.php index 95a64859c..3d63e24f6 100644 --- a/lib/item.php +++ b/lib/item.php @@ -35,7 +35,8 @@ class Item { private $author; private $date; //date is stored in the Unix format private $feedTitle; - + private $enclosure; // Item_Enclosure object containing media attachment information + public function __construct($url, $title, $guid, $body, $id = null) { $this->title = $title; $this->url = $url; @@ -161,4 +162,33 @@ class Item { public function setDate($date) { $this->date = $date; } + + public function getEnclosure() { + return $this->enclosure; + } + + public function setEnclosure(Item_Enclosure $enclosure) { + $this->enclosure = $enclosure; + } +} + +class Item_Enclosure { + private $mimetype; + private $link; + + public function getMimeType() { + return $this->mimetype; + } + + public function setMimeType($mimetype) { + $this->mimetype = $mimetype; + } + + public function getLink() { + return $this->link; + } + + public function setLink($link) { + $this->link = $link; + } } diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 9b6c613ff..9aac95a37 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -36,18 +36,25 @@ class ItemMapper { * @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; } @@ -195,11 +202,18 @@ class ItemMapper { $title = $item->getTitle(); $body = $item->getBody(); $author = $item->getAuthor(); - + $enclosure_mime = null; + $enclosure_link = null; + + if($enclosure = $item->getEnclosure()) { + $enclosure_mime = $enclosure->getMimeType(); + $enclosure_link = $enclosure->getLink(); + } + $stmt = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . - '(url, title, body, author, guid, guid_hash, pub_date, feed_id, status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + '(url, title, body, author, guid, guid_hash, pub_date, enclosure_mime, enclosure_link, feed_id, status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '); if(empty($title)) { @@ -222,6 +236,8 @@ class ItemMapper { $guid, $guid_hash, $pub_date, + $enclosure_mime, + $enclosure_link, $feedid, $status ); @@ -244,7 +260,7 @@ class ItemMapper { public function findById($id) { $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.id AS id, ' . self::tableName . - '.url AS url, ' . self::tableName . '.title AS title, guid, body, status, author, feed_id, pub_date' . + '.url AS url, ' . self::tableName . '.title AS title, guid, body, status, author, feed_id, pub_date, enclosure_mime, enclosure_link' . ' FROM ' . self::tableName . ' JOIN ' . FeedMapper::tableName . ' ON ' . self::tableName . '.feed_id = ' . FeedMapper::tableName . '.id WHERE (' . self::tableName . '.id = ? AND ' . FeedMapper::tableName . '.user_id = ? )'); diff --git a/lib/utils.php b/lib/utils.php index aa1111dec..52e71b092 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -77,7 +77,7 @@ class Utils { $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()); @@ -87,6 +87,19 @@ class Utils { $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; } } |