summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/bootstrap.php31
-rw-r--r--appinfo/routes.php118
-rw-r--r--controller/feedcontroller.php55
-rw-r--r--controller/foldercontroller.php2
-rw-r--r--db/feed.php13
-rw-r--r--db/feedmapper.php5
-rw-r--r--db/folder.php16
-rw-r--r--db/foldermapper.php12
-rw-r--r--db/itemmapper.php4
-rw-r--r--external_api/feed.php55
-rw-r--r--external_api/folder.php59
-rw-r--r--feed.bl.php33
-rw-r--r--folder.bl.php38
13 files changed, 414 insertions, 27 deletions
diff --git a/appinfo/bootstrap.php b/appinfo/bootstrap.php
index 72423c399..ae011cc45 100644
--- a/appinfo/bootstrap.php
+++ b/appinfo/bootstrap.php
@@ -2,7 +2,7 @@
/**
* ownCloud - News app
*
-* @author Alessandro Copyright
+* @author Alessandro Cosentino
* @author Bernhard Posselt
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
@@ -46,6 +46,12 @@ namespace OCA\News;
\OC::$CLASSPATH['OCA\News\NewsController'] = 'apps/news/controller/news.controller.php';
\OC::$CLASSPATH['OCA\News\NewsAjaxController'] = 'apps/news/controller/news.ajax.controller.php';
+\OC::$CLASSPATH['OCA\News\FolderBl'] = 'apps/news/folder.bl.php';
+\OC::$CLASSPATH['OCA\News\FeedBl'] = 'apps/news/feed.bl.php';
+
+\OC::$CLASSPATH['OCA\News\FolderApi'] = 'apps/news/external_api/folder.php';
+\OC::$CLASSPATH['OCA\News\FeedApi'] = 'apps/news/external_api/feed.php';
+
/**
* @return a new DI container with prefilled values for the news app
@@ -106,5 +112,28 @@ function createDIContainer(){
$c['FolderMapper'], $c['ItemMapper']);
};
+ /**
+ * BUSINESS LAYER OBJECTS
+ */
+ $newsContainer['FolderBl'] = $newsContainer->share(function($c){
+ return new FolderBl($c['FolderMapper']);
+ });
+
+ $newsContainer['FeedBl'] = $newsContainer->share(function($c){
+ return new FeedBl($c['FeedMapper']);
+ });
+
+ /**
+ * EXTERNAL API LAYER
+ */
+ $newsContainer['FolderApi'] = $newsContainer->share(function($c){
+ return new FolderApi($c['FolderBl']);
+ });
+
+ $newsContainer['FeedApi'] = $newsContainer->share(function($c){
+ return new FeedApi($c['FeedBl']);
+ });
+
+
return $newsContainer;
} \ No newline at end of file
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 21c1de90d..767e59f09 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -26,7 +26,7 @@ require_once \OC_App::getAppPath('news') . '/appinfo/bootstrap.php';
function callController($controllerName, $methodName, $urlParams, $disableAdminCheck=true,
$isAjax=false){
$container = createDIContainer();
-
+
// run security checks
$security = $container['Security'];
runSecurityChecks($security, $isAjax, $disableAdminCheck);
@@ -60,7 +60,7 @@ function callAjaxController($controllerName, $methodName, $urlParams, $disableAd
*/
function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
if($disableAdminCheck){
- $security->setIsAdminCheck(false);
+ $security->setIsAdminCheck(false);
}
if($isAjax){
@@ -80,19 +80,19 @@ function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
* Normal Routes
*/
$this->create('news_index', '/')->action(
- function($params){
+ function($params){
callController('NewsController', 'index', $params, true);
}
);
$this->create('news_index_feed', '/feed/{feedid}')->action(
- function($params){
+ function($params){
callController('NewsController', 'index', $params, true);
}
);
$this->create('news_export_opml', '/export/opml')->action(
- function($params){
+ function($params){
callController('NewsController', 'exportOPML', $params, true);
}
);
@@ -102,13 +102,13 @@ $this->create('news_export_opml', '/export/opml')->action(
* AJAX Routes
*/
$this->create('news_ajax_init', '/ajax/init')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'init', $params);
}
);
$this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setShowAll', $params);
}
);
@@ -118,25 +118,25 @@ $this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
* Folders
*/
$this->create('news_ajax_collapsefolder', '/ajax/collapsefolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'collapseFolder', $params);
}
);
$this->create('news_ajax_changefoldername', '/ajax/changefoldername')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'changeFolderName', $params);
}
);
$this->create('news_ajax_createfolder', '/ajax/createfolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'createFolder', $params);
}
);
$this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'deleteFolder', $params);
}
);
@@ -146,31 +146,31 @@ $this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
* Feeds
*/
$this->create('news_ajax_loadfeed', '/ajax/loadfeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'loadFeed', $params);
}
);
$this->create('news_ajax_deletefeed', '/ajax/deletefeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'deleteFeed', $params);
}
);
$this->create('news_ajax_movefeedtofolder', '/ajax/movefeedtofolder')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'moveFeedToFolder', $params);
}
);
$this->create('news_ajax_updatefeed', '/ajax/updatefeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'updateFeed', $params);
}
);
$this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'createFeed', $params);
}
);
@@ -180,13 +180,13 @@ $this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
* Items
*/
$this->create('news_ajax_setitemstatus', '/ajax/setitemstatus')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setItemStatus', $params);
}
);
$this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'setAllItemsRead', $params);
}
);
@@ -196,7 +196,87 @@ $this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
* Import stuff
*/
$this->create('news_ajax_importOPML', '/import')->action(
- function($params){
+ function($params){
callAjaxController('NewsAjaxController', 'uploadOPML', $params);
}
);
+
+
+/**
+ * External API
+ */
+
+/**
+ * Feed API
+ */
+
+\OCP\API::register(
+ 'get', '/news/feeds',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FeedApi']->getAll($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'get', '/news/feeds/{feedid}',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FeedApi']->getById($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/feeds/create',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FeedApi']->create($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/feeds/{feedid}/delete',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FeedApi']->delete($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+
+/**
+ * Folder API
+ */
+
+\OCP\API::register(
+ 'get', '/news/folders',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->getAll($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/folders/create',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->create($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+
+\OCP\API::register(
+ 'get', '/news/folders/{folderid}/delete',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->delete($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/folders/{folderid}/modify',
+ function($urlParams) {
+ $container = createDIContainer();
+ return $container['FolderApi']->modify($urlParams);
+ },
+ 'news', \OC_API::USER_AUTH
+);
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
new file mode 100644
index 000000000..4357d7682
--- /dev/null
+++ b/controller/feedcontroller.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Controller;
+
+use \OCA\AppFramework\Controller\Controller;
+use \OCA\AppFramework\Core\API;
+use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+
+
+class FeedController extends Controller {
+
+
+ public function __construct(API $api, Request $request, $feedMapper){
+ parent::__construct($api, $request);
+ $this->feedMapper = $feedMapper;
+ }
+
+
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ *
+ * Returns all feeds
+ */
+ public function getAll(){
+ $feeds = $this->feedMapper->findAll();
+ return $this->renderJSON($feeds);
+ }
+} \ No newline at end of file
diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php
index dcd6f9ca5..0f3ec83a2 100644
--- a/controller/foldercontroller.php
+++ b/controller/foldercontroller.php
@@ -3,7 +3,7 @@
/**
* ownCloud - News
*
-* @author Alessandro Copyright
+* @author Alessandro Cosentino
* @author Bernhard Posselt
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
diff --git a/db/feed.php b/db/feed.php
index 0f2e861b7..eda225302 100644
--- a/db/feed.php
+++ b/db/feed.php
@@ -25,7 +25,7 @@ class Feed extends Collection {
// if $items = null, it means that feed has not been fetched yet
// if $id = null, it means that the feed has not been stored in the db yet
- public function __construct($url, $title, $items = null, $id = null) {
+ public function __construct($url, $title = null, $items = null, $id = null) {
$this->url = $url;
$this->title = $title;
if ($items !== null) {
@@ -71,5 +71,16 @@ class Feed extends Collection {
public function getFolderId(){
return $this->folderId;
}
+
+ public function jsonSerialize(){
+ //TODO: this is just for test
+ $encoding = array(
+ 'id' => $this->getId(),
+ 'url' => $this->getUrl(),
+ 'title' => $this->getTitle(),
+ 'folderId' => $this->getFolderId()
+ );
+ return $encoding;
+ }
}
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 906ced069..62a7d41f5 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -163,10 +163,10 @@ class FeedMapper {
*/
//TODO: handle error case
public function save(Feed $feed, $folderid) {
- $title = $feed->getTitle();
$url = $feed->getUrl();
$url_hash = md5($url);
+ $title = $feed->getTitle();
if(empty($title)) {
$l = \OC_L10N::get('news');
$title = $l->t('no title');
@@ -199,11 +199,12 @@ class FeedMapper {
//update the db. it needs to be done, since it might be the first save after a full fetch
$stmt = \OCP\DB::prepare('
UPDATE ' . self::tableName .
- ' SET favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
+ ' SET title = ? , favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
WHERE id = ?
');
$params=array(
+ $title,
$favicon,
$folderid,
$feedid
diff --git a/db/folder.php b/db/folder.php
index 2e3c96a7c..5dfa738f3 100644
--- a/db/folder.php
+++ b/db/folder.php
@@ -51,6 +51,12 @@ class Folder extends Collection {
public function setOpened($opened) {
$this->opened = $opened;
}
+
+ public function setParentId() {
+ if ($this->parent !== null) {
+
+ }
+ }
public function getParentId() {
if ($this->parent === null) {
@@ -71,6 +77,14 @@ class Folder extends Collection {
return $this->children;
}
-
+ public function jsonSerialize() {
+ //TODO: this is just for test
+ $encoding = array(
+ 'id' => $this->getId(),
+ 'parentId' => $this->getParentId(),
+ 'title' => $this->getName(),
+ );
+ return $encoding;
+ }
} \ No newline at end of file
diff --git a/db/foldermapper.php b/db/foldermapper.php
index 5d7145176..d9040b50b 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -55,6 +55,15 @@ class FolderMapper {
}
/**
+ * @brief Returns the forest (list of trees) of folders children of $parentid
+ * @param
+ * @returns
+ */
+ public function getAll() {
+ return $this->childrenOf(0);
+ }
+
+ /**
* @brief Returns the forest (list of trees) of folders children of $parentid,
* including the feeds that they contain
* @param
@@ -102,6 +111,9 @@ class FolderMapper {
$result = $stmt->execute(array($this->userid, $id));
$row = $result->fetchRow();
+ if(!$row)
+ return null;
+
$folder = new Folder($row['name'], $row['id']);
$folder->setOpened($row['opened']);
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 3399e2e03..3791c3a49 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -355,7 +355,7 @@ class ItemMapper {
break;
case FeedType::FOLDER:
- $feedMapper = new FeedMapper($this->userId);
+ $feedMapper = new FeedMapper($this->userid);
$feeds = $feedMapper->findByFolderId($feedId);
foreach($feeds as $feed){
$unreadCount += $this->countAllStatus($feed->getId(), StatusFlag::UNREAD);
@@ -405,7 +405,7 @@ class ItemMapper {
// folder
} elseif ($feedType === FeedType::FOLDER){
- $feedMapper = new FeedMapper($this->userId);
+ $feedMapper = new FeedMapper($this->userid);
$feeds = $feedMapper->findByFolderId($feedId);
foreach($feeds as $feed){
diff --git a/external_api/feed.php b/external_api/feed.php
new file mode 100644
index 000000000..a56cd2253
--- /dev/null
+++ b/external_api/feed.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace OCA\News;
+
+use \OCA\News\Controller\FeedController;
+
+class FeedApi {
+
+ public function __construct($bl){
+ $this->bl = $bl;
+ }
+
+ public function getAll() {
+ $feeds = $this->bl->getAll();
+ $serializedFeeds = array();
+ foreach ($feeds as $feed) {
+ $serializedFeeds[] = $feed->jsonSerialize();
+ }
+ return new \OC_OCS_Result($serializedFeeds);
+ }
+
+ public function getById($params) {
+ $feed = $this->bl->getById($feedid);
+ $serializedFeed = array($feed->jsonSerialize());
+ return new \OC_OCS_Result($serializedFeed);
+ }
+
+ public function delete($params) {
+ //TODO: check parameters here
+
+ $success = $this->bl->delete($params["feedid"]);
+
+ if ($success) {
+ return new \OC_OCS_Result();
+ }
+ else {
+ return new \OC_OCS_Result(null, 101);
+ }
+ }
+
+ public function create() {
+ $url = $_POST['url'];
+ $folderId = $_POST['folderid'];
+ //TODO: check parameters here
+
+ $success = $this->bl->create($url, $folderId);
+
+ if ($success) {
+ return new \OC_OCS_Result();
+ }
+ else {
+ return new \OC_OCS_Result(null, 101);
+ }
+ }
+}
diff --git a/external_api/folder.php b/external_api/folder.php
new file mode 100644
index 000000000..68c8ff523
--- /dev/null
+++ b/external_api/folder.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace OCA\News;
+
+use \OCA\News\Controller\FolderController;
+
+class FolderApi {
+
+ public function __construct($bl){
+ $this->bl = $bl;
+ }
+
+ public function getAll() {
+ $folders = $this->bl->getAll();
+ $serializedFolders = array();
+
+ //TODO: check the behaviour for nested folders
+ foreach ($folders as $folder) {
+ $serializedFolders[] = $folder->jsonSerialize();
+ }
+ return new \OC_OCS_Result($serializedFolders);
+ }
+
+ public function create() {
+ $name = $_POST['name'];
+ $parentId = $_POST['parentid'];
+
+ $this->bl->create($name, $parentId);
+
+ return new \OC_OCS_Result();
+ }
+
+ public function delete($params) {
+ $id = $params['folderid'];
+ if(!is_numeric($id))
+ return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer');
+
+ if($this->bl->delete($id))
+ return new \OC_OCS_Result();
+ else
+ return new \OC_OCS_Result(null,999,'Could not delete folder');
+ }
+
+ public function modify($params) {
+ $id = $params['folderid'];
+ if(!is_numeric($id))
+ return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer'.$id);
+
+ $name = $_POST['name'];
+ $parentId = $_POST['parentid'];
+ $opened = $_POST['opened'];
+
+ if($this->bl->modify($id, $name, $parentid, $opened))
+ return new \OC_OCS_Result();
+ else
+ return new \OC_OCS_Result(null,999,'Could not modify folder');
+ }
+}
+
diff --git a/feed.bl.php b/feed.bl.php
new file mode 100644
index 000000000..43e0faf6f
--- /dev/null
+++ b/feed.bl.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace OCA\News;
+
+class FeedBl {
+
+ public function __construct($feedMapper){
+ $this->feedMapper = $feedMapper;
+ }
+
+ public function getAll() {
+ return $this->feedMapper->findAll();
+ }
+
+ public function getById($feedid) {
+ return $this->feedMapper->findById($feedid);
+ }
+
+ public function delete($feedid) {
+ return $this->feedMapper->deleteById($feedid);
+ }
+
+ public function create($url, $folderid) {
+ $feed = new Feed($url);
+ $this->feedMapper->save($feed, $folderid);
+ $feed = Utils::fetch($url);
+ if ($feed != null) {
+ $this->feedMapper->save($feed, $folderid);
+ }
+ return true;
+ }
+
+}
diff --git a/folder.bl.php b/folder.bl.php
new file mode 100644
index 000000000..85c386d90
--- /dev/null
+++ b/folder.bl.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace OCA\News;
+
+class FolderBl {
+
+ public function __construct($folderMapper){
+ $this->folderMapper = $folderMapper;
+ }
+
+ public function getAll() {
+ return $this->folderMapper->getAll();
+ }
+
+ public function create($name, $parentId) {
+ //TODO: change the setparentid in the model class Folder
+ $folder = new Folder($name, null, null);
+ return $this->folderMapper->save($folder);
+ }
+
+ public function delete($folderid) {
+ return $this->folderMapper->deleteById($folderid);
+ }
+
+ public function modify($folderid, $name = null, $parent = null, $opened = null) {
+ $folder = $this->folderMapper->find($folderid);
+ if(!$folder)
+ return false;
+
+ if($name)
+ $folder->setName($name);
+ if($parent)
+ $folder->setParentId($parent);
+ if($opened)
+ $folder->setOpened($opened);
+ return $this->folderMapper->update($folder);
+ }
+}