diff options
-rw-r--r-- | ajax/createfeed.php | 6 | ||||
-rw-r--r-- | ajax/createfolder.php | 6 | ||||
-rw-r--r-- | ajax/deletefeed.php | 2 | ||||
-rw-r--r-- | ajax/deletefolder.php | 2 | ||||
-rw-r--r-- | ajax/feedlist.php | 2 | ||||
-rw-r--r-- | ajax/importopml.php | 6 | ||||
-rw-r--r-- | ajax/markitem.php | 2 | ||||
-rw-r--r-- | ajax/populateroot.php | 2 | ||||
-rw-r--r-- | ajax/updatefeed.php | 6 | ||||
-rw-r--r-- | appinfo/app.php | 16 | ||||
-rw-r--r-- | index.php | 6 | ||||
-rw-r--r-- | lib/backgroundjob.php | 8 | ||||
-rw-r--r-- | lib/collection.php | 6 | ||||
-rw-r--r-- | lib/feed.php | 4 | ||||
-rw-r--r-- | lib/feedmapper.php | 46 | ||||
-rw-r--r-- | lib/folder.php | 8 | ||||
-rw-r--r-- | lib/foldermapper.php | 38 | ||||
-rw-r--r-- | lib/item.php | 4 | ||||
-rw-r--r-- | lib/itemmapper.php | 28 | ||||
-rw-r--r-- | lib/utils.php | 20 | ||||
-rw-r--r-- | opmlparser.php | 4 | ||||
-rw-r--r-- | templates/part.feeds.php | 8 | ||||
-rw-r--r-- | templates/part.folderlist.php | 6 | ||||
-rw-r--r-- | templates/part.items.header.php | 2 | ||||
-rw-r--r-- | templates/part.items.php | 2 | ||||
-rw-r--r-- | templates/test.php | 2 |
26 files changed, 129 insertions, 113 deletions
diff --git a/ajax/createfeed.php b/ajax/createfeed.php index 728cf4844..896a9b1fa 100644 --- a/ajax/createfeed.php +++ b/ajax/createfeed.php @@ -10,7 +10,7 @@ * */ -//register_shutdown_function("shutdown"); +register_shutdown_function("shutdown"); /* handle the case of fatal error */ function shutdown() { @@ -35,13 +35,13 @@ $userid = OCP\USER::getUser(); $feedurl = trim($_POST['feedurl']); $folderid = trim($_POST['folderid']); -$feedmapper = new OC_News_FeedMapper(); +$feedmapper = new FeedMapper(); $feedid = $feedmapper->findIdFromUrl($feedurl); $l = OC_L10N::get('news'); if ($feedid === null) { - $feed = OC_News_Utils::fetch($feedurl); + $feed = OCA\News\Utils::fetch($feedurl); if ($feed !== null) { $feedid = $feedmapper->save($feed, $folderid); diff --git a/ajax/createfolder.php b/ajax/createfolder.php index 09d43e966..6a6add1d1 100644 --- a/ajax/createfolder.php +++ b/ajax/createfolder.php @@ -20,12 +20,12 @@ $userid = OCP\USER::getUser(); $name = trim($_POST['name']); $parentid = trim($_POST['parentid']); -$foldermapper = new OC_News_FolderMapper($userid); +$foldermapper = new OCA\News\FolderMapper($userid); if($parentid != 0) { - $folder = new OC_News_Folder($name, NULL, $foldermapper->find($parentid)); + $folder = new OCA\News\Folder($name, NULL, $foldermapper->find($parentid)); } else { - $folder = new OC_News_Folder($name); + $folder = new OCA\News\Folder($name); } $folderid = $foldermapper->save($folder); diff --git a/ajax/deletefeed.php b/ajax/deletefeed.php index 71574aa1b..c9c9056ca 100644 --- a/ajax/deletefeed.php +++ b/ajax/deletefeed.php @@ -19,7 +19,7 @@ $userid = OCP\USER::getUser(); $feedid = $_POST['feedid']; -$feedmapper = new OC_News_FeedMapper(); +$feedmapper = new OCA\News\FeedMapper(); $success = $feedmapper->deleteById($feedid); $l = OC_L10N::get('news'); diff --git a/ajax/deletefolder.php b/ajax/deletefolder.php index 65eec5bdf..a6950ed40 100644 --- a/ajax/deletefolder.php +++ b/ajax/deletefolder.php @@ -21,7 +21,7 @@ $folderid = trim($_POST['folderid']); $shownfeedid = trim($_POST['shownfeedid']); $part_items = false; -$foldermapper = new OC_News_FolderMapper(); +$foldermapper = new OCA\News\FolderMapper(); if(!$foldermapper->deleteById($folderid)) { OCP\JSON::error(array('data' => array('message' => $l->t('Error removing folder.')))); diff --git a/ajax/feedlist.php b/ajax/feedlist.php index a1a6b7190..ce3128125 100644 --- a/ajax/feedlist.php +++ b/ajax/feedlist.php @@ -17,7 +17,7 @@ OCP\JSON::callCheck(); $userid = OCP\USER::getUser(); -$feedmapper = new OC_News_FeedMapper($userid); +$feedmapper = new OCA\News\FeedMapper($userid); $feeds = $feedmapper->findAll(); $l = OC_L10N::get('news'); diff --git a/ajax/importopml.php b/ajax/importopml.php index 04b745db6..7911a4db9 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -45,13 +45,13 @@ if ($parsed == null) { $data = $parsed->getData(); function createFeed($feedurl, $folderid) { - $feedmapper = new OC_News_FeedMapper(); + $feedmapper = new OCA\News\FeedMapper(); $feedid = $feedmapper->findIdFromUrl($feedurl); $l = OC_L10N::get('news'); if ($feedid === null) { - $feed = OC_News_Utils::fetch($feedurl); + $feed = OCA\News\Utils::fetch($feedurl); if ($feed !== null) { $feedid = $feedmapper->save($feed, $folderid); @@ -71,7 +71,7 @@ function createFeed($feedurl, $folderid) { $countadded = 0; foreach($data as $collection) { - if ($collection instanceOf OC_News_Feed) { + if ($collection instanceOf Feed) { $feedurl = $collection->getUrl(); $folderid = 0; if (createFeed($feedurl, $folderid)) { diff --git a/ajax/markitem.php b/ajax/markitem.php index c42dc9350..a6efc8521 100644 --- a/ajax/markitem.php +++ b/ajax/markitem.php @@ -17,7 +17,7 @@ OCP\JSON::callCheck(); $itemid = $_POST['itemid']; -$itemmapper = new OC_News_ItemMapper(); +$itemmapper = new OCA\News\ItemMapper(); $item = $itemmapper->find($itemid); $item->setRead(); $success = $itemmapper->update($item); diff --git a/ajax/populateroot.php b/ajax/populateroot.php index 73b986a3e..6a258910a 100644 --- a/ajax/populateroot.php +++ b/ajax/populateroot.php @@ -3,7 +3,7 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('news'); -$foldermapper = new OC_News_FolderMapper(OCP\USER::getUser()); +$foldermapper = new OCA\News\FolderMapper(OCP\USER::getUser()); $l = new OC_l10n('news'); $folder = new OC_News_Folder($l->t('Everything'), 0); diff --git a/ajax/updatefeed.php b/ajax/updatefeed.php index fe286d3c1..f8dc2b13d 100644 --- a/ajax/updatefeed.php +++ b/ajax/updatefeed.php @@ -21,12 +21,12 @@ $feedid = $_POST['feedid']; $feedurl = $_POST['feedurl']; $folderid = $_POST['folderid']; -$newfeed = OC_News_Utils::fetch($feedurl); +$newfeed = OCA\News\Utils::fetch($feedurl); $newfeedid = false; if ($newfeed !== null) { - $feedmapper = new OC_News_FeedMapper(); + $feedmapper = new OCA\News\FeedMapper(); $newfeedid = $feedmapper->save($newfeed, $folderid); } @@ -39,7 +39,7 @@ if(!$newfeedid) { } else { //TODO: maybe make this more efficient by coding it into OC_News_FeedMapper->save() - $itemmapper = new OC_News_ItemMapper(); + $itemmapper = new OCA\News\ItemMapper(); $items = $itemmapper->findAll($newfeedid); $unreadcounter = 0; foreach($items as $item) { diff --git a/appinfo/app.php b/appinfo/app.php index 6134d28de..1bb2c2151 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -10,16 +10,16 @@ * */ -OC::$CLASSPATH['OC_News_Item'] = 'apps/news/lib/item.php'; -OC::$CLASSPATH['OC_News_Collection'] = 'apps/news/lib/collection.php'; -OC::$CLASSPATH['OC_News_Feed'] = 'apps/news/lib/feed.php'; -OC::$CLASSPATH['OC_News_Folder'] = 'apps/news/lib/folder.php'; +OC::$CLASSPATH['OCA\News\Item'] = 'apps/news/lib/item.php'; +OC::$CLASSPATH['OCA\News\Collection'] = 'apps/news/lib/collection.php'; +OC::$CLASSPATH['OCA\News\Feed'] = 'apps/news/lib/feed.php'; +OC::$CLASSPATH['OCA\News\Folder'] = 'apps/news/lib/folder.php'; -OC::$CLASSPATH['OC_News_FeedMapper'] = 'apps/news/lib/feedmapper.php'; -OC::$CLASSPATH['OC_News_ItemMapper'] = 'apps/news/lib/itemmapper.php'; -OC::$CLASSPATH['OC_News_FolderMapper'] = 'apps/news/lib/foldermapper.php'; +OC::$CLASSPATH['OCA\News\FeedMapper'] = 'apps/news/lib/feedmapper.php'; +OC::$CLASSPATH['OCA\News\ItemMapper'] = 'apps/news/lib/itemmapper.php'; +OC::$CLASSPATH['OCA\News\FolderMapper'] = 'apps/news/lib/foldermapper.php'; -OC::$CLASSPATH['OC_News_Utils'] = 'apps/news/lib/utils.php'; +OC::$CLASSPATH['OCA\News\Utils'] = 'apps/news/lib/utils.php'; OC::$CLASSPATH['OCA\News\Backgroundjob'] = 'apps/news/lib/backgroundjob.php'; OCP\Backgroundjob::addRegularTask( 'OCA\News\Backgroundjob', 'run' ); @@ -25,16 +25,16 @@ $l = OC_L10N::get('news'); $userid = OCP\USER::getUser(); -$foldermapper = new OC_News_FolderMapper($userid); +$foldermapper = new OCA\News\FolderMapper($userid); -$folder = new OC_News_Folder($l->t('Everything'), 0); +$folder = new OCA\News\Folder($l->t('Everything'), 0); $allfeeds = $foldermapper->populate($folder); if ($allfeeds) { $feedid = isset( $_GET['feedid'] ) ? $_GET['feedid'] : null; if ($feedid == null) { - $feedmapper = new OC_News_FeedMapper(OCP\USER::getUser($userid)); + $feedmapper = new OCA\News\FeedMapper(OCP\USER::getUser($userid)); $feedid = $feedmapper->mostRecent(); } } diff --git a/lib/backgroundjob.php b/lib/backgroundjob.php index 1c12cbc4f..c9f37d3d4 100644 --- a/lib/backgroundjob.php +++ b/lib/backgroundjob.php @@ -48,7 +48,7 @@ class Backgroundjob { } static private function cliStep(){ - $feedmapper = new \OC_News_FeedMapper(); + $feedmapper = new FeedMapper(); // Iterate over all feeds $feeds = $feedmapper->findAll(); @@ -61,7 +61,7 @@ class Backgroundjob { // Iterate over all users $lastid = \OCP\Config::getAppValue('news', 'backgroundjob_lastid',0); - $feedmapper = new \OC_News_FeedMapper(); + $feedmapper = new FeedMapper(); $feeds = $feedmapper->findAll(); usort( $feeds, array( 'OCA\News\Backgroundjob', 'sortFeeds' )); @@ -82,9 +82,9 @@ class Backgroundjob { static private function updateFeed( $feedmapper, $feed ){ $newfeed = null; - $newfeed = \OC_News_Utils::fetch( $feed['url'] ); + $newfeed = Utils::fetch( $feed['url'] ); if( $newfeed !== null ){ - $feedmapper = new \OC_News_FeedMapper(); + $feedmapper = new FeedMapper(); $newfeedid = $feedmapper->save($newfeed, $feed['folderid'] ); } } diff --git a/lib/collection.php b/lib/collection.php index 2ebbb646f..4f7f06d7a 100644 --- a/lib/collection.php +++ b/lib/collection.php @@ -10,10 +10,12 @@ * */ +namespace OCA\News; + /** * This class models a collection, which is either a feed or a folder. */ -class OC_News_Collection { +class Collection { private $id; @@ -29,4 +31,4 @@ class OC_News_Collection { $this->id = $id; } -}
\ No newline at end of file +} diff --git a/lib/feed.php b/lib/feed.php index 496faa224..ecff8f67a 100644 --- a/lib/feed.php +++ b/lib/feed.php @@ -10,10 +10,12 @@ * */ +namespace OCA\News; + /** * This class models a feed. */ -class OC_News_Feed extends OC_News_Collection { +class Feed extends Collection { private $url; private $spfeed; //encapsulate a SimplePie_Core object diff --git a/lib/feedmapper.php b/lib/feedmapper.php index a8292cd39..3d11ff0e6 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -10,10 +10,12 @@ * */ +namespace OCA\News; + /** * This class maps a feed to an entry in the feeds table of the database. */ -class OC_News_FeedMapper { +class FeedMapper { const tableName = '*PREFIX*news_feeds'; private $userid; @@ -22,7 +24,7 @@ class OC_News_FeedMapper { if ($userid !== null) { $this->userid = $userid; } - $this->userid = OCP\USER::getUser(); + $this->userid = \OCP\USER::getUser(); } /** @@ -46,7 +48,7 @@ class OC_News_FeedMapper { $params[] = $this->userid; } - $stmt = OCP\DB::prepare( $query ); + $stmt = \OCP\DB::prepare( $query ); $result = $stmt->execute( $params ); $feeds = array(); while ($row = $result->fetchRow()) { @@ -66,14 +68,14 @@ class OC_News_FeedMapper { * @returns */ public function findById($id){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); $result = $stmt->execute(array($id)); if(!$row = $result->fetchRow()) return null; $url = $row['url']; $title = htmlspecialchars_decode($row['title']); - $feed = new OC_News_Feed($url, $title, null, $id); + $feed = new Feed($url, $title, null, $id); return $feed; } @@ -83,14 +85,14 @@ class OC_News_FeedMapper { * @returns an instance of OC_News_Feed */ public function findByFolderId($folderid){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE folder_id = ?'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE folder_id = ?'); $result = $stmt->execute(array($folderid)); $feeds = array(); while ($row = $result->fetchRow()) { $url = $row['url']; $title = htmlspecialchars_decode($row['title']); $id = $row['id']; - $feed = new OC_News_Feed($url, $title, null, $id); + $feed = new Feed($url, $title, null, $id); $favicon = $row['favicon_link']; $feed->setFavicon($favicon); $feeds[] = $feed; @@ -105,15 +107,15 @@ class OC_News_FeedMapper { * @returns an instance of OC_News_Feed */ public function findWithItems($id){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE 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 OC_News_Feed($url, $title, null,$id); + $feed = new Feed($url, $title, null,$id); $favicon = $row['favicon_link']; $feed->setFavicon($favicon); - $itemMapper = new OC_News_ItemMapper(); + $itemMapper = new ItemMapper(); $items = $itemMapper->findAll($id); $feed->setItems($items); @@ -127,7 +129,7 @@ class OC_News_FeedMapper { * null - if there is no such feed */ public function findIdFromUrl($url){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url = ?'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url = ?'); $result = $stmt->execute(array($url)); $row = $result->fetchRow(); $id = null; @@ -139,7 +141,7 @@ class OC_News_FeedMapper { public function mostRecent(){ //FIXME: does something like SELECT TOP 1 * exists in pear/mdb2 ?? - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' ORDER BY lastmodified'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' ORDER BY lastmodified'); $result = $stmt->execute(); $row = $result->fetchRow(); $id = null; @@ -155,8 +157,8 @@ class OC_News_FeedMapper { * @returns The id of the feed in the database table. */ //TODO: handle error case - public function save(OC_News_Feed $feed, $folderid){ - $CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" ); + public function save(Feed $feed, $folderid){ + $CONFIG_DBTYPE = \OCP\Config::getSystemValue( "dbtype", "sqlite" ); if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ $_ut = "strftime('%s','now')"; } elseif($CONFIG_DBTYPE == 'pgsql') { @@ -169,14 +171,14 @@ class OC_News_FeedMapper { $url = htmlspecialchars_decode($feed->getUrl()); if(empty($title)) { - $l = OC_L10N::get('news'); + $l = \OC_L10N::get('news'); $title = $l->t('no title'); } //FIXME: Detect when feed contains already a database id $feedid = $this->findIdFromUrl($url); if ($feedid == null){ - $query = OCP\DB::prepare(" + $query = \OCP\DB::prepare(" INSERT INTO " . self::tableName . "(url, title, favicon_link, folder_id, user_id, added, lastmodified) VALUES (?, ?, ?, ?, ?, $_ut, $_ut) @@ -191,11 +193,11 @@ class OC_News_FeedMapper { ); $query->execute($params); - $feedid = OCP\DB::insertid(self::tableName); + $feedid = \OCP\DB::insertid(self::tableName); } $feed->setId($feedid); - $itemMapper = new OC_News_ItemMapper(); + $itemMapper = new ItemMapper(); $items = $feed->getItems(); foreach($items as $item){ @@ -209,17 +211,17 @@ class OC_News_FeedMapper { if ($id == null) { return false; } - $stmt = OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ?'); + $stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ?'); $result = $stmt->execute(array($id)); - $itemMapper = new OC_News_ItemMapper(); + $itemMapper = new ItemMapper(); //TODO: handle the value that the execute returns $itemMapper->deleteAll($id); return true; } - public function delete(OC_News_Feed $feed){ + public function delete(Feed $feed){ $id = $feed->getId(); return deleteById($id); } @@ -229,7 +231,7 @@ class OC_News_FeedMapper { return false; } - $stmt = OCP\DB::prepare('SELECT id FROM ' . self::tableName . ' WHERE folder_id = ?'); + $stmt = \OCP\DB::prepare('SELECT id FROM ' . self::tableName . ' WHERE folder_id = ?'); $result = $stmt->execute(array($folderid)); while ($row = $result->fetchRow()) { diff --git a/lib/folder.php b/lib/folder.php index 14951d57c..41577d844 100644 --- a/lib/folder.php +++ b/lib/folder.php @@ -10,16 +10,18 @@ * */ +namespace OCA\News; + /** * This class models a folder that contains feeds. */ -class OC_News_Folder extends OC_News_Collection { +class Folder extends Collection { private $name; private $children; private $parent; - public function __construct($name, $id = null, OC_News_Collection $parent = null){ + public function __construct($name, $id = null, Collection $parent = null){ $this->name = $name; if ($id !== null){ parent::__construct($id); @@ -45,7 +47,7 @@ class OC_News_Folder extends OC_News_Collection { return $this->parent->getId(); } - public function addChild(OC_News_Collection $child){ + public function addChild(Collection $child){ $this->children[] = $child; } diff --git a/lib/foldermapper.php b/lib/foldermapper.php index 91c005bc9..cf22b55b7 100644 --- a/lib/foldermapper.php +++ b/lib/foldermapper.php @@ -10,10 +10,12 @@ * */ +namespace OCA\News; + /** * This class maps a feed to an entry in the feeds table of the database. */ -class OC_News_FolderMapper { +class FolderMapper { const tableName = '*PREFIX*news_folders'; @@ -23,7 +25,7 @@ class OC_News_FolderMapper { if ($userid !== null) { $this->userid = $userid; } - $this->userid = OCP\USER::getUser(); + $this->userid = \OCP\USER::getUser(); } /** @@ -33,20 +35,20 @@ class OC_News_FolderMapper { */ public function populate($folder){ // first add child feeds - $feedmapper = new OC_News_FeedMapper(); + $feedmapper = new FeedMapper(); $feeds = $feedmapper->findByFolderId($folder->getId()); foreach ($feeds as $feed){ $folder->addChild($feed); } // and second child folders - $stmt = OCP\DB::prepare('SELECT * + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE user_id = ? AND parent_id = ?'); $result = $stmt->execute(array($this->userid, $folder->getId())); while( $row = $result->fetchRow()){ - $unpopfolder = new OC_News_Folder($row['name'], $row['id']); + $unpopfolder = new Folder($row['name'], $row['id']); $popfolder = self::populate($unpopfolder); $folder->addChild($popfolder); } @@ -60,13 +62,13 @@ class OC_News_FolderMapper { * @returns an instance of OC_News_Folder */ public function find($id){ - $stmt = OCP\DB::prepare('SELECT * + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE user_id = ? AND id = ?'); $result = $stmt->execute(array($this->userid, $id)); $row = $result->fetchRow(); - $folder = new OC_News_Folder($row['name'], $row['id']); + $folder = new Folder($row['name'], $row['id']); return $folder; } @@ -77,14 +79,14 @@ class OC_News_FolderMapper { * @returns */ public function findWithItems($id){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); $result = $stmt->execute(array($id)); $row = $result->fetchRow(); $url = $row['url']; $title = $row['title']; - $feed = new OC_News_Feed($url, $title, null,$id); + $feed = new Feed($url, $title, null,$id); - $itemMapper = new OC_News_ItemMapper($feed); + $itemMapper = new ItemMapper($feed); $items = $itemMapper->findAll(); $feed->setItems($items); @@ -96,8 +98,8 @@ class OC_News_FolderMapper { * @param folder the folder to be saved * @returns The id of the folder in the database table. */ - public function save(OC_News_Folder $folder){ - $query = OCP\DB::prepare(' + public function save(Folder $folder){ + $query = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(name, parent_id, user_id) VALUES (?, ?, ?) @@ -106,7 +108,7 @@ class OC_News_FolderMapper { $name = $folder->getName(); if(empty($name)) { - $l = OC_L10N::get('news'); + $l = \OC_L10N::get('news'); $name = $l->t('no name'); } @@ -118,13 +120,13 @@ class OC_News_FolderMapper { $this->userid ); $query->execute($params); - $folderid = OCP\DB::insertid(self::tableName); + $folderid = \OCP\DB::insertid(self::tableName); $folder->setId($folderid); return $folderid; } - public function delete(OC_News_Folder $folder){ + public function delete(Folder $folder){ $folderid = $folder->getId(); return deleteById(folderid); } @@ -135,17 +137,17 @@ class OC_News_FolderMapper { } // delete child folders - $stmt = OCP\DB::prepare('SELECT id FROM ' . self::tableName .' WHERE parent_id = ?'); + $stmt = \OCP\DB::prepare('SELECT id FROM ' . self::tableName .' WHERE parent_id = ?'); $result = $stmt->execute(array($folderid)); while ($row = $result->fetchRow()) { if (!self::deleteById($row['id'])) return false; } - $stmt = OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ?'); + $stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ?'); $result = $stmt->execute(array($folderid)); - $feedMapper = new OC_News_FeedMapper(); + $feedMapper = new FeedMapper(); //TODO: handle the value that the execute returns if(!$feedMapper->deleteAll($folderid)) return false; diff --git a/lib/item.php b/lib/item.php index 64ae368c3..ffbf71760 100644 --- a/lib/item.php +++ b/lib/item.php @@ -10,6 +10,8 @@ * */ +namespace OCA\News; + class StatusFlag{ const Unread = 0x02; const Important = 0x04; @@ -22,7 +24,7 @@ class StatusFlag{ * * It encapsulate a SimplePie_Item object and adds a status flag to it */ -class OC_News_Item { +class Item { private $url; private $title; diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 27f56eb3f..9ecfa8fc6 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -10,11 +10,13 @@ * */ +namespace OCA\News; + /** * This class maps an item to a row of the items table in the database. * It follows the Data Mapper pattern (see http://martinfowler.com/eaaCatalog/dataMapper.html). */ -class OC_News_ItemMapper { +class ItemMapper { const tableName = '*PREFIX*news_items'; @@ -30,7 +32,7 @@ class OC_News_ItemMapper { $status = $row['status']; $body = $row['body']; $id = $row['id']; - $item = new OC_News_Item($url, $title, $guid, $body, $id); + $item = new Item($url, $title, $guid, $body, $id); $item->setStatus($status); return $item; @@ -41,7 +43,7 @@ class OC_News_ItemMapper { * @param feedid The id of the feed in the database table. */ public function findAll($feedid){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feed_id = ?'); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feed_id = ?'); $result = $stmt->execute(array($feedid)); $items = array(); @@ -54,7 +56,7 @@ class OC_News_ItemMapper { } public function findIdFromGuid($guid, $feedid){ - $stmt = OCP\DB::prepare(' + $stmt = \OCP\DB::prepare(' SELECT * FROM ' . self::tableName . ' WHERE guid = ? AND feed_id = ? @@ -72,12 +74,12 @@ class OC_News_ItemMapper { * @brief Update the item after its status has changed * @returns The item whose status has changed. */ - public function update(OC_News_Item $item){ + public function update(Item $item){ $itemid = $item->getId(); $status = $item->getStatus(); - $stmt = OCP\DB::prepare(' + $stmt = \OCP\DB::prepare(' UPDATE ' . self::tableName . ' SET status = ? WHERE id = ? @@ -96,7 +98,7 @@ class OC_News_ItemMapper { * @brief Save the feed and all its items into the database * @returns The id of the feed in the database table. */ - public function save(OC_News_Item $item, $feedid){ + public function save(Item $item, $feedid){ $guid = $item->getGuid(); $status = $item->getStatus(); @@ -106,19 +108,19 @@ class OC_News_ItemMapper { $title = $item->getTitle(); $body = $item->getBody(); - $stmt = OCP\DB::prepare(' + $stmt = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(url, title, body, guid, feed_id, status) VALUES (?, ?, ?, ?, ?, ?) '); if(empty($title)) { - $l = OC_L10N::get('news'); + $l = \OC_L10N::get('news'); $title = $l->t('no title'); } if(empty($body)) { - $l = OC_L10N::get('news'); + $l = \OC_L10N::get('news'); |