diff options
-rw-r--r-- | ajax/loadfeed.php | 2 | ||||
-rw-r--r-- | appinfo/database.xml | 411 | ||||
-rw-r--r-- | appinfo/version | 2 | ||||
-rw-r--r-- | lib/feed.php | 2 | ||||
-rw-r--r-- | lib/feedmapper.php | 47 | ||||
-rw-r--r-- | lib/item.php | 9 | ||||
-rw-r--r-- | lib/itemmapper.php | 27 |
7 files changed, 267 insertions, 233 deletions
diff --git a/ajax/loadfeed.php b/ajax/loadfeed.php index 020f7a706..d87c71328 100644 --- a/ajax/loadfeed.php +++ b/ajax/loadfeed.php @@ -31,5 +31,5 @@ $feedTitle = $feed->getTitle(); OCP\JSON::success(array('data' => array( 'message' => $l->t('Feed loaded!'), 'feedTitle' => $feedTitle, - 'feedItems' => $feedItems ))); + 'feedItems' => $feedItems ))); diff --git a/appinfo/database.xml b/appinfo/database.xml index 1fbfe29a4..1d5cef5b9 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -1,199 +1,216 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> <database> - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - <charset>latin1</charset> - <table> - <name>*dbprefix*news_folders</name> - <declaration> - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <length>4</length> - </field> - <field> - <name>parent_id</name> - <type>integer</type> - <notnull>false</notnull> - <length>4</length> - </field> - <field> - <name>name</name> - <type>text</type> - <notnull>true</notnull> - <length>100</length> - </field> - <field> - <name>user_id</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>64</length> - </field> - - <index> - <name>folder_id</name> - <unique>true</unique> - <field> - <name>id</name> - <sorting>descending</sorting> - </field> - </index> - <index> - <name>user_id</name> - <field> - <name>user_id</name> - </field> - </index> - </declaration> - </table> - - <table> - <name>*dbprefix*news_feeds</name> - <declaration> - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <length>4</length> - </field> - <field> - <name>user_id</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>64</length> - </field> - <field> - <name>url</name> - <type>text</type> - <notnull>true</notnull> - <length>100</length> - </field> - <field> - <name>title</name> - <type>text</type> - <notnull>true</notnull> - <length>100</length> - </field> - <field> - <name>favicon_link</name> - <type>text</type> - <notnull>false</notnull> - <length>100</length> - </field> - <field> - <name>added</name> - <type>integer</type> - <default></default> - <notnull>false</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - <field> - <name>lastmodified</name> - <type>integer</type> - <default></default> - <notnull>false</notnull> - <unsigned>true</unsigned> - <length>4</length> - </field> - <field> - <name>folder_id</name> - <type>integer</type> - <notnull>true</notnull> - <length>4</length> - </field> - - <index> - <name>feed_id</name> - <unique>true</unique> - <primary>true</primary> - <field> - <name>id</name> - <sorting>descending</sorting> - </field> - </index> - - <index> - <name>feed_url</name> - <unique>true</unique> - <primary>false</primary> - <field> - <name>url</name> - </field> - </index> - </declaration> - </table> - - <table> - <name>*dbprefix*news_items</name> - <declaration> - <field> - <name>id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <length>4</length> - </field> - <field> - <name>guid</name> - <type>text</type> - <notnull>true</notnull> - <length>300</length> - </field> - <field> - <name>url</name> - <type>text</type> - <length>300</length> - </field> - <field> - <name>title</name> - <type>text</type> - <length>300</length> - </field> - <field> - <name>feed_id</name> - <type>integer</type> - <notnull>true</notnull> - <length>4</length> - </field> - <field> - <name>body</name> - <type>text</type> - <length>4000</length> - </field> - <field> - <name>status</name> - <type>integer</type> - <length>1</length> - </field> - - <index> - <name>item_id</name> - <unique>true</unique> - <field> - <name>id</name> - <sorting>descending</sorting> - </field> - </index> - <index> - <name>item_guid</name> - <unique>true</unique> - <field> - <name>guid</name> - </field> - <field> - <name>feed_id</name> - </field> - </index> - </declaration> - </table> + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + <charset>latin1</charset> + <table> + <name>*dbprefix*news_folders</name> + <declaration> + <field> + <name>id</name> + <type>integer</type> + <notnull>true</notnull> + <autoincrement>1</autoincrement> + </field> + <field> + <name>parent_id</name> + <type>integer</type> + <notnull>false</notnull> + </field> + <field> + <name>name</name> + <type>text</type> + <length>100</length> + <notnull>true</notnull> + </field> + <field> + <name>user_id</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>64</length> + </field> + + <index> + <name>PRIMARY</name> + <unique>true</unique> + <primary>true</primary> + <field> + <name>id</name> + <sorting>descending</sorting> + </field> + </index> + + <index> + <name>user_id</name> + <field> + <name>user_id</name> + </field> + </index> + </declaration> + </table> + + <table> + <name>*dbprefix*news_feeds</name> + <declaration> + <field> + <name>id</name> + <type>integer</type> + <notnull>true</notnull> + <autoincrement>1</autoincrement> + </field> + <field> + <name>user_id</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>64</length> + </field> + <field> + <name>url_hash</name> + <type>text</type> + <length>32</length> + <notnull>true</notnull> + </field> + <field> + <name>url</name> + <type>clob</type> + <notnull>true</notnull> + </field> + <field> + <name>title</name> + <type>clob</type> + <notnull>true</notnull> + </field> + <field> + <name>favicon_link</name> + <type>clob</type> + <notnull>false</notnull> + </field> + <field> + <name>added</name> + <type>integer</type> + <default></default> + <notnull>false</notnull> + <unsigned>true</unsigned> + </field> + <field> + <name>lastmodified</name> + <type>integer</type> + <default></default> + <notnull>false</notnull> + <unsigned>true</unsigned> + </field> + <field> + <name>folder_id</name> + <type>integer</type> + <notnull>true</notnull> + </field> + + <index> + <name>PRIMARY</name> + <unique>true</unique> + <primary>true</primary> + <field> + <name>id</name> + <sorting>descending</sorting> + </field> + </index> + + <index> + <name>feed_url</name> + <unique>true</unique> + <primary>false</primary> + <field> + <name>url_hash</name> + </field> + </index> + </declaration> + </table> + + <table> + <name>*dbprefix*news_items</name> + <declaration> + <field> + <name>id</name> + <type>integer</type> + <notnull>true</notnull> + <autoincrement>1</autoincrement> + </field> + <field> + <name>guid_hash</name> + <type>text</type> + <notnull>true</notnull> + <length>32</length> + </field> + <field> + <name>guid</name> + <type>clob</type> + <notnull>true</notnull> + </field> + <field> + <name>url</name> + <type>clob</type> + </field> + <field> + <name>title</name> + <type>clob</type> + </field> + <field> + <name>author</name> + <type>clob</type> + <notnull>false</notnull> + </field> + <field> + <name>date</name> + <type>integer</type> + <default></default> + <notnull>false</notnull> + <unsigned>true</unsigned> + </field> + <field> + <name>body</name> + <type>clob</type> + <notnull>false</notnull> + </field> + <field> + <name>feed_id</name> + <type>integer</type> + <notnull>true</notnull> + </field> + <field> + <name>status</name> + <type>integer</type> + </field> + + + <index> + <name>PRIMARY</name> + <unique>true</unique> + <primary>true</primary> + <field> + <name>id</name> + <sorting>descending</sorting> + </field> + </index> + + <index> + <name>feed_id</name> + <field> + <name>feed_id</name> + </field> + </index> + + <index> + <name>item_guid</name> + <unique>true</unique> + <field> + <name>guid_hash</name> + </field> + <field> + <name>feed_id</name> + </field> + </index> + </declaration> + </table> </database> diff --git a/appinfo/version b/appinfo/version index 1f2be2a26..295ec490e 100644 --- a/appinfo/version +++ b/appinfo/version @@ -1 +1 @@ -6.3
\ No newline at end of file +6.8.2
\ No newline at end of file diff --git a/lib/feed.php b/lib/feed.php index ecff8f67a..6dfdcbcfb 100644 --- a/lib/feed.php +++ b/lib/feed.php @@ -17,8 +17,8 @@ namespace OCA\News; */ class Feed extends Collection { + private $title; private $url; - private $spfeed; //encapsulate a SimplePie_Core object private $items; //array that contains all the items of the feed private $favicon; diff --git a/lib/feedmapper.php b/lib/feedmapper.php index 596858538..dfc0d6054 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -30,13 +30,21 @@ class FeedMapper { /** * @brief * @param row a row from the feeds table of the database - * @returns an object of the class OC_News_Feed + * @returns an object of the class OCA\News\Feed */ public function fromRow($row){ + $url = $row['url']; + $title = htmlspecialchars_decode($row['title']); + $id = $row['id']; + $feed = new Feed($url, $title, null, $id); + $favicon = $row['favicon_link']; + $feed->setFavicon($favicon); + + return $feed; } /** - * @brief + * @brief as a list that can be easily parsed using JSON * @param userid * @returns */ @@ -72,10 +80,7 @@ class FeedMapper { $result = $stmt->execute(array($id)); if(!$row = $result->fetchRow()) return null; - - $url = $row['url']; - $title = htmlspecialchars_decode($row['title']); - $feed = new Feed($url, $title, null, $id); + $feed = self::fromRow($row); return $feed; } @@ -89,12 +94,7 @@ class FeedMapper { $result = $stmt->execute(array($this->userid, $folderid)); $feeds = array(); while ($row = $result->fetchRow()) { - $url = $row['url']; - $title = htmlspecialchars_decode($row['title']); - $id = $row['id']; - $feed = new Feed($url, $title, null, $id); - $favicon = $row['favicon_link']; - $feed->setFavicon($favicon); + $feed = self::fromRow($row); $feeds[] = $feed; } return $feeds; @@ -104,17 +104,14 @@ class FeedMapper { /** * @brief Retrieve a feed and all its items from the database * @param id The id of the feed in the database table. - * @returns an instance of OC_News_Feed + * @returns an instance of OCA\News\Feed */ public function findWithItems($id){ $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); $result = $stmt->execute(array($id)); $row = $result->fetchRow(); - $url = $row['url']; - $title = htmlspecialchars_decode($row['title']); - $feed = new Feed($url, $title, null,$id); - $favicon = $row['favicon_link']; - $feed->setFavicon($favicon); + + $feed = self::fromRow($row); $itemMapper = new ItemMapper(); $items = $itemMapper->findAll($id); $feed->setItems($items); @@ -129,8 +126,9 @@ class FeedMapper { * null - if there is no such feed */ public function findIdFromUrl($url){ - $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url = ?'); - $result = $stmt->execute(array($url)); + $url_hash = md5($url); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url_hash = ?'); + $result = $stmt->execute(array($url_hash)); $row = $result->fetchRow(); $id = null; if ($row != null){ @@ -168,7 +166,8 @@ class FeedMapper { } $title = $feed->getTitle(); - $url = htmlspecialchars_decode($feed->getUrl()); + $url = $feed->getUrl(); + $url_hash = md5($url); if(empty($title)) { $l = \OC_L10N::get('news'); @@ -180,12 +179,13 @@ class FeedMapper { if ($feedid == null){ $query = \OCP\DB::prepare(" INSERT INTO " . self::tableName . - "(url, title, favicon_link, folder_id, user_id, added, lastmodified) - VALUES (?, ?, ?, ?, ?, $_ut, $_ut) + "(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified) + VALUES (?, ?, ?, ?, ?, ?, $_ut, $_ut) "); $params=array( $url, + $url_hash, $title, $feed->getFavicon(), $folderid, @@ -221,6 +221,7 @@ class FeedMapper { return true; } + public function delete(Feed $feed){ $id = $feed->getId(); return deleteById($id); diff --git a/lib/item.php b/lib/item.php index ffbf71760..3e9b3f5b7 100644 --- a/lib/item.php +++ b/lib/item.php @@ -32,6 +32,7 @@ class Item { private $body; private $status; //a bit-field set with status flags private $id; //id of the item in the database table + private $author; public function __construct($url, $title, $guid, $body, $id = null){ $this->title = $title; @@ -121,4 +122,12 @@ class Item { public function setBody($body){ $this->body = $body; } + + public function getAuthor(){ + return $this->author; + } + + public function setAuthor($author){ + $this->author = $author; + } } diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 40693071f..35060f0a4 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -34,6 +34,9 @@ class ItemMapper { $id = $row['id']; $item = new Item($url, $title, $guid, $body, $id); $item->setStatus($status); + $date = $row['date']; + $author = $row['author']; + $item->setAuthor($author); return $item; } @@ -75,13 +78,14 @@ class ItemMapper { return $items; } - public function findIdFromGuid($guid, $feedid){ + public function findIdFromGuid($guid_hash, $guid, $feedid){ $stmt = \OCP\DB::prepare(' SELECT * FROM ' . self::tableName . ' - WHERE guid = ? + WHERE guid_hash = ? AND feed_id = ? '); - $result = $stmt->execute(array($guid, $feedid)); + $result = $stmt->execute(array($guid_hash, $feedid)); + //TODO: if there is more than one row, falling back to comparing $guid $row = $result->fetchRow(); $id = null; if ($row != null){ @@ -120,9 +124,11 @@ class ItemMapper { */ public function save(Item $item, $feedid){ $guid = $item->getGuid(); + $guid_hash = md5($guid); + $status = $item->getStatus(); - $itemid = $this->findIdFromGuid($guid, $feedid); + $itemid = $this->findIdFromGuid($guid_hash, $guid, $feedid); if ($itemid == null){ $title = $item->getTitle(); @@ -130,8 +136,8 @@ class ItemMapper { $stmt = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . - '(url, title, body, guid, feed_id, status) - VALUES (?, ?, ?, ?, ?, ?) + '(url, title, body, guid, guid_hash, feed_id, status) + VALUES (?, ?, ?, ?, ?, ?, ?) '); if(empty($title)) { @@ -143,12 +149,13 @@ class ItemMapper { $l = \OC_L10N::get('news'); $body = $l->t('no body'); } - + $params=array( - htmlspecialchars_decode($item->getUrl()), - htmlspecialchars_decode($title), + $item->getUrl(), + $title, $body, - htmlspecialchars_decode($guid), + $guid, + $guid_hash, $feedid, $status ); |