summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
commitae7393db3d99a7ac223ae917129cccd9f49888e3 (patch)
tree7f54b72b0d01c38afd1378365a67e4f192922423 /lib
parent483784caa38bd6131405ac474347a215584e30a5 (diff)
merged the angularjs branch
Diffstat (limited to 'lib')
-rw-r--r--lib/api.php163
-rw-r--r--lib/backgroundjob.php12
-rw-r--r--lib/collection.php34
-rw-r--r--lib/controller.php108
-rw-r--r--lib/feed.php67
-rw-r--r--lib/feedmapper.php271
-rw-r--r--lib/feedtypes.php22
-rw-r--r--lib/folder.php76
-rw-r--r--lib/foldermapper.php198
-rw-r--r--lib/item.php194
-rw-r--r--lib/itemmapper.php297
-rw-r--r--lib/request.php83
-rw-r--r--lib/response.php218
-rw-r--r--lib/search.php16
-rw-r--r--lib/security.php104
-rw-r--r--lib/utils.php4
16 files changed, 697 insertions, 1170 deletions
diff --git a/lib/api.php b/lib/api.php
new file mode 100644
index 000000000..d3d0e1f1b
--- /dev/null
+++ b/lib/api.php
@@ -0,0 +1,163 @@
+<?php
+
+/**
+* ownCloud - App Template Example
+*
+* @author Bernhard Posselt
+* @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;
+
+/**
+ * This is used to wrap the owncloud static api calls into an object to make the
+ * code better abstractable for use in the dependency injection container
+ *
+ * Extend this to your needs
+ */
+class API {
+
+ private $appName;
+
+ /**
+ * @param string $appName: the name of your application
+ */
+ public function __construct($appName){
+ $this->appName = $appName;
+ }
+
+
+ /**
+ * @return the name of your application
+ */
+ public function getAppName(){
+ return $this->appName;
+ }
+
+
+ /**
+ * @return: the user id of the current user
+ */
+ public function getUserId(){
+ return \OCP\USER::getUser();
+ }
+
+
+ /**
+ * Sets the current navigation entry to the currently running app
+ */
+ public function activateNavigationEntry(){
+ \OCP\App::setActiveNavigationEntry($this->appName);
+ }
+
+
+ /**
+ * Adds a new javascript file
+ * @param string $scriptName: the name of the javascript in js/
+ * without the suffix
+ */
+ public function addScript($scriptName){
+ \OCP\Util::addScript($this->appName, $scriptName);
+ }
+
+
+ /**
+ * Adds a new css file
+ * @param string $styleName: the name of the css file in css/
+ * without the suffix
+ */
+ public function addStyle($styleName){
+ \OCP\Util::addStyle($this->appName, $styleName);
+ }
+
+
+ /**
+ * @brief shorthand for addScript for files in the 3rdparty directory
+ * @param string $name: the name of the file without the suffix
+ */
+ public function add3rdPartyScript($name){
+ \OCP\Util::addScript($this->appName . '/3rdparty', $name);
+ }
+
+
+ /**
+ * @brief shorthand for addStyle for files in the 3rdparty directory
+ * @param string $name: the name of the file without the suffix
+ */
+ public function add3rdPartyStyle($name){
+ \OCP\Util::addStyle($this->appName . '/3rdparty', $name);
+ }
+
+ /**
+ * Looks up a systemwide defined value
+ * @param string $key: the key of the value, under which it was saved
+ * @return the saved value
+ */
+ public function getSystemValue($key){
+ return \OCP\Config::getSystemValue($key, '');
+ }
+
+
+ /**
+ * Sets a new systemwide value
+ * @param string $key: the key of the value, under which will be saved
+ * @param $value: the value that should be stored
+ */
+ public function setSystemValue($key, $value){
+ return \OCP\Config::setSystemValue($key, $value);
+ }
+
+
+ /**
+ * Shortcut for setting a user defined value
+ * @param $key the key under which the value is being stored
+ * @param $value the value that you want to store
+ */
+ public function setUserValue($key, $value){
+ \OCP\Config::setUserValue($this->getUserId(), $this->appName, $key, $value);
+ }
+
+
+ /**
+ * Shortcut for getting a user defined value
+ * @param $key the key under which the value is being stored
+ */
+ public function getUserValue($key){
+ return \OCP\Config::getUserValue($this->getUserId(), $this->appName, $key);
+ }
+
+
+ /**
+ * Returns the translation object
+ * @return the translation object
+ */
+ public function getTrans(){
+ return \OC_L10N::get($this->appName);
+ }
+
+
+ public function getLocalFilePath($path){
+ return \OC_Filesystem::getLocalFile($path);
+ }
+
+
+ public function openEventSource(){
+ return new \OC_EventSource();
+ }
+
+} \ No newline at end of file
diff --git a/lib/backgroundjob.php b/lib/backgroundjob.php
index 9495086f0..098ff8393 100644
--- a/lib/backgroundjob.php
+++ b/lib/backgroundjob.php
@@ -27,10 +27,10 @@ namespace OCA\News;
*/
class Backgroundjob {
static public function sortFeeds( $a, $b ) {
- if( $a['id'] == $b['id'] ) {
+ if( $a->getId() == $b->getId() ) {
return 0;
}
- elseif( $a['id'] < $b['id'] ) {
+ elseif( $a->getId() < $b->getId() ) {
return -1;
}
else{
@@ -67,9 +67,9 @@ class Backgroundjob {
$done = false;
foreach( $feeds as $feed ) {
- if( $feed['id'] > $lastid ) {
+ if( $feed->getId() > $lastid ) {
// set lastid BEFORE updating feed!
- \OCP\Config::setAppValue('news', 'backgroundjob_lastid',$feed['id']);
+ \OCP\Config::setAppValue('news', 'backgroundjob_lastid',$feed->getId());
$done = true;
self::updateFeed( $feedmapper, $feed );
}
@@ -82,10 +82,10 @@ class Backgroundjob {
static private function updateFeed( $feedmapper, $feed ) {
$newfeed = null;
- $newfeed = Utils::fetch( $feed['url'] );
+ $newfeed = Utils::fetch( $feed->getUrl() );
if( $newfeed !== null ) {
$feedmapper = new FeedMapper();
- $newfeedid = $feedmapper->save($newfeed, $feed['folderid'] );
+ $newfeedid = $feedmapper->save($newfeed, $feed->getFolderId() );
}
}
}
diff --git a/lib/collection.php b/lib/collection.php
deleted file mode 100644
index 30b926c00..000000000
--- a/lib/collection.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-/**
- * This class models a collection, which is either a feed or a folder.
- */
-class Collection {
-
- private $id;
-
- public function __construct($id) {
- $this->id = $id;
- }
-
- public function getId() {
- return $this->id;
- }
-
- public function setId($id) {
- $this->id = $id;
- }
-
-}
diff --git a/lib/controller.php b/lib/controller.php
new file mode 100644
index 000000000..292e25a18
--- /dev/null
+++ b/lib/controller.php
@@ -0,0 +1,108 @@
+<?php
+/**
+* ownCloud - News app
+*
+* @author Bernhard Posselt
+* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
+*
+* This file is licensed under the Affero General Public License version 3 or later.
+* See the COPYING-README file
+*
+*/
+
+namespace OCA\News;
+
+class Controller {
+
+ protected $userId;
+ protected $appName;
+ protected $request;
+ protected $api;
+ protected $trans;
+
+ public function __construct($request, $api){
+ $this->api = $api;
+ $this->userId = $api->getUserId();
+ $this->appName = $api->getAppName();
+ $this->request = $request;
+ $this->trans = $api->getTrans();
+ }
+
+
+ /**
+ * @brief lets you access post and get parameters by the index
+ * @param string $key: the key which you want to access in the $_POST or
+ * $_GET array. If both arrays store things under the same
+ * key, return the value in $_POST
+ * @param $default: the value that is returned if the key does not exist
+ * @return: the content of the array
+ */
+ protected function params($key, $default=null){
+ $postValue = $this->request->getPOST($key);
+ $getValue = $this->request->getGET($key);
+
+ if($postValue !== null){
+ return $postValue;
+ }
+
+ if($getValue !== null){
+ return $getValue;
+ }
+
+ return $default;
+ }
+
+ /**
+ * Shortcut for accessing an uploaded file through the $_FILES array
+ * @param string $key: the key that will be taken from the $_FILES array
+ * @return the file in the $_FILES element
+ */
+ protected function getUploadedFile($key){
+ return $this->request->getFILES($key);
+ }
+
+
+ /**
+ * Binds variables to the template and prints it
+ * The following values are always assigned: userId, trans
+ * @param $templateName the name of the template
+ * @param $arguments an array with arguments in $templateVar => $content
+ * @param string $renderAs: admin, user or blank: admin renders the page on
+ * the admin settings page, user renders a normal
+ * owncloud page, blank renders the template alone
+ */
+ protected function render($templateName, $arguments=array(),
+ $renderAs='user'){
+ $response = new TemplateResponse($this->appName, $templateName);
+ $response->setParams($arguments);
+ $response->renderAs($renderAs);
+ return $response;
+ }
+
+
+ /**
+ * @brief renders a json success
+ * @param array $params an array which will be converted to JSON
+ */
+ protected function renderJSON($params=array()){
+ $response = new JSONResponse($this->appName);
+ $response->setParams($params);
+ return $response;
+ }
+
+
+ /**
+ * @brief renders a json error
+ * @param string $msg: the error message
+ * @param string $file: the file that it occured in
+ * @param array $params an array which will be converted to JSON
+ */
+ protected function renderJSONError($msg, $file="", $params=array()){
+ $response = new JSONResponse($this->appName);
+ $response->setParams($params);
+ $response->setErrorMessage($msg, $file);
+ return $response;
+ }
+
+
+}
diff --git a/lib/feed.php b/lib/feed.php
deleted file mode 100644
index e99ba3c75..000000000
--- a/lib/feed.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-
-/**
- * This class models a feed.
- */
-class Feed extends Collection {
-
- private $title;
- private $url;
- private $items; //array that contains all the items of the feed
- private $favicon;
-
- // 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) {
- $this->url = $url;
- $this->title = $title;
- if ($items !== null) {
- $this->items = $items;
- }
- if ($id !== null) {
- parent::__construct($id);
- }
- }
-
- public function getUrl() {
- return $this->url;
- }
-
- public function getTitle() {
- return $this->title;
- }
-
- public function setTitle($title) {
- $this->title = $title;
- }
-
- public function getFavicon() {
- return $this->favicon;
- }
-
- public function setFavicon($favicon) {
- $this->favicon = $favicon;
- }
-
- public function setItems($items) {
- $this->items = $items;
- }
-
- public function getItems() {
- return $this->items;
- }
-
-}
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
deleted file mode 100644
index a8e6d3b03..000000000
--- a/lib/feedmapper.php
+++ /dev/null
@@ -1,271 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-/**
- * This class maps a feed to an entry in the feeds table of the database.
- */
-class FeedMapper {
-
- const tableName = '*PREFIX*news_feeds';
- private $userid;
-
- public function __construct($userid = null) {
- if ($userid !== null) {
- $this->userid = $userid;
- }
- else {
- $this->userid = \OCP\USER::getUser();
- }
- }
-
- /**
- * @brief
- * @param row a row from the feeds table of the database
- * @returns an object of the class OCA\News\Feed
- */
- public function fromRow($row) {
- $url = $row['url'];
- $title = $row['title'];
- $id = $row['id'];
- $feed = new Feed($url, $title, null, $id);
- $favicon = $row['favicon_link'];
- $feed->setFavicon($favicon);
-
- return $feed;
- }
-
- /**
- * @brief as a list that can be easily parsed using JSON
- * @returns
- */
- public function findAll() {
- $query = 'SELECT * FROM ' . self::tableName;
- $params = array();
- if( $this->userid ) {
- $query = $query.' WHERE user_id = ?';
- $params[] = $this->userid;
- }
-
- $stmt = \OCP\DB::prepare( $query );
- $result = $stmt->execute( $params );
- $feeds = array();
- while ($row = $result->fetchRow()) {
- $url = $row['url'];
- $id = $row['id'];
- $folderid = $row['folder_id'];
- $userid = $row['user_id'];
- $title = $row['title'];
- $feeds[] = array("url" => $url, "id" => $id, "folderid" => $folderid,
- 'userid' => $userid, 'title' => $title );
- }
-
- return $feeds;
- }
-
- /**
- * @brief returns the number of feeds that a user has
- * @returns the number of feeds that a user has
- */
- public function feedCount() {
- $query = 'SELECT COUNT(*) AS size FROM ' . self::tableName . ' WHERE user_id = ?';
- $stmt = \OCP\DB::prepare($query);
- $result = $stmt->execute(array($this->userid))->fetchRow();
- return $result['size'];
- }
-
-
- /**
- * @brief Retrieve a feed from the database
- * @param id The id of the feed in the database table.
- * @returns
- */
- public function findById($id) {
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?');
- $result = $stmt->execute(array($id));
- if(!$row = $result->fetchRow())
- return null;
- $feed = self::fromRow($row);
- return $feed;
- }
-
- /**
- * @brief Retrieve all the feeds contained in the folder $folderid
- * @param folderid The id of the folder in the database table.
- * @returns a list of feeds
- */
- public function findByFolderId($folderid) {
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE user_id = ? AND folder_id = ?');
- $result = $stmt->execute(array($this->userid, $folderid));
- $feeds = array();
- while ($row = $result->fetchRow()) {
- $feed = self::fromRow($row);
- $feeds[] = $feed;
- }
- return $feeds;
- }
-
-
- /**
- * @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 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();
-
- $feed = self::fromRow($row);
- $itemMapper = new ItemMapper();
- $items = $itemMapper->findById($id);
- $feed->setItems($items);
-
- return $feed;
- }
-
- /**
- * @brief Find the id of a feed and all its items from the database
- * @param url url of the feed
- * @return id of the feed corresponding to the url passed as parameters
- * null - if there is no such feed
- */
- public function findIdFromUrl($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) {
- $id = $row['id'];
- }
- return $id;
- }
-
- 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');
- $result = $stmt->execute();
- $row = $result->fetchRow();
- $id = null;
- if ($row != null) {
- $id = $row['id'];
- }
- return $id;
- }
-
- /**
- * @brief Save the feed and all its items into the database
- * @param feed the feed to be saved
- * @returns The id of the feed in the database table.
- */
- //TODO: handle error case
- public function save(Feed $feed, $folderid) {
- $title = $feed->getTitle();
- $url = $feed->getUrl();
- $url_hash = md5($url);
-
- if(empty($title)) {
- $l = \OC_L10N::get('news');
- $title = $l->t('no title');
- }
-
- $favicon = $feed->getFavicon();
-
- //FIXME: Detect when feed contains already a database id
- $feedid = $this->findIdFromUrl($url);
- if ($feedid === null) {
- $query = \OCP\DB::prepare("
- INSERT INTO " . self::tableName .
- "(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified)
- VALUES (?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
- ");
-
- $params=array(
- $url,
- $url_hash,
- $title,
- $favicon,
- $folderid,
- $this->userid
- );
- $query->execute($params);
-
- $feedid = \OCP\DB::insertid(self::tableName);
- }
- else {
- //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 = ?
- WHERE id = ?
- ');
-
- $params=array(
- $favicon,
- $folderid,
- $feedid
- );
- $stmt->execute($params);
- }
- $feed->setId($feedid);
-
- $itemMapper = new ItemMapper();
-
- $items = $feed->getItems();
- if ($items !== null) {
- foreach($items as $item) {
- $itemMapper->save($item, $feedid);
- }
- }
-
- return $feedid;
- }
-
-
- public function deleteById($id) {
- if ($id == null) {
- return false;
- }
- $stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ? AND user_id = ?');
-
- $result = $stmt->execute(array($id, $this->userid));
-
- $itemMapper = new ItemMapper();
- //TODO: handle the value that the execute returns
- $itemMapper->deleteAll($id);
-
- return true;
- }
-
- public function delete(Feed $feed) {
- $id = $feed->getId();
- return deleteById($id);
- }
-
- public function deleteAll($folderid) {
- if ($folderid == null) {
- return false;
- }
-
- $stmt = \OCP\DB::prepare('SELECT id FROM ' . self::tableName . ' WHERE folder_id = ? AND user_id = ?');
-
- $result = $stmt->execute(array($folderid, $this->userid));
- while ($row = $result->fetchRow()) {
- if(!self::deleteById($row['id']))
- return false;
- }
-
- return true;
- }
-}
diff --git a/lib/feedtypes.php b/lib/feedtypes.php
deleted file mode 100644
index d330a5b2a..000000000
--- a/lib/feedtypes.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Bernhard Posselt
-* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-
-class FeedType {
- const FEED = 0;
- const FOLDER = 1;
- const STARRED = 2;
- const SUBSCRIPTIONS = 3;
- const SHARED = 4;
-}; \ No newline at end of file
diff --git a/lib/folder.php b/lib/folder.php
deleted file mode 100644
index 2e3c96a7c..000000000
--- a/lib/folder.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-/**
- * This class models a folder that contains feeds.
- */
-class Folder extends Collection {
-
- private $name;
- private $children;
- private $parent;
- private $opened;
-
- public function __construct($name, $id = null, Collection $parent = null) {
- $this->name = $name;
- if ($id !== null) {
- parent::__construct($id);
- }
- $this->children = array();
- if ($parent !== null) {
- $this->parent = $parent;
- }
- if($this->opened === null){
- $this->opened = true;
- }
- }
-
- public function getName() {
- return $this->name;
- }
-
- public function setName($name) {
- $this->name = $name;
- }
-
- public function getOpened() {
- return $this->opened;
- }
-
- public function setOpened($opened) {
- $this->opened = $opened;
- }
-
- public function getParentId() {
- if ($this->parent === null) {
- return 0;
- }
- return $this->parent->getId();
- }
-
- public function addChild(Collection $child) {
- $this->children[] = $child;
- }
-
- public function addChildren($children) {
- $this->children = $children;
- }
-
- public function getChildren() {
- return $this->children;
- }
-
-
-
-} \ No newline at end of file
diff --git a/lib/foldermapper.php b/lib/foldermapper.php
deleted file mode 100644
index 5d7145176..000000000
--- a/lib/foldermapper.php
+++ /dev/null
@@ -1,198 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-/**
- * This class maps a feed to an entry in the feeds table of the database.
- */
-class FolderMapper {
-
- const tableName = '*PREFIX*news_folders';
-
- private $userid;
-
- public function __construct($userid = null) {
- if ($userid !== null) {
- $this->userid = $userid;
- }
- else {
- $this->userid = \OCP\USER::getUser();
- }
- }
-
-
- /**
- * @brief Returns the forest (list of trees) of folders children of $parentid
- * @param
- * @returns
- */
- public function childrenOf($parentid) {
- $folderlist = array();
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName .
- ' WHERE user_id = ? AND parent_id = ?');
- $result = $stmt->execute(array($this->userid, $parentid));
-
- while( $row = $result->fetchRow()) {
- $folderid = $row['id'];
- $folder = new Folder($row['name'], $folderid);
- $folder->setOpened($row['opened']);
- $children = self::childrenOf($folderid);
- $folder->addChildren($children);
- $folderlist[] = $folder;
- }
-
- return $folderlist;
- }
-
- /**
- * @brief Returns the forest (list of trees) of folders children of $parentid,
- * including the feeds that they contain
- * @param
- * @returns
- */
- public function childrenOfWithFeeds($parentid) {
-
- $feedmapper = new FeedMapper();
- $collectionlist = $feedmapper->findByFolderId($parentid);
-
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName .
- ' WHERE user_id = ? AND parent_id = ?');
- $result = $stmt->execute(array($this->userid, $parentid));
-
- while( $row = $result->fetchRow()) {
- $folderid = $row['id'];
- $folder = new Folder($row['name'], $folderid);
- $folder->setOpened($row['opened']);
- $children = self::childrenOfWithFeeds($folderid);
- $folder->addChildren($children);
- $collectionlist[] = $folder;
- }
-
- return $collectionlist;
- }
-
-
- /**
- * This is being used for consistency
- */
- public function findById($id){
- return $this->find($id);
- }
-
-
- /**
- * @brief Retrieve a folder from the database
- * @param id The id of the folder in the database table.
- * @returns an instance of OC_News_Folder
- */
- public function find($id) {
- $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 Folder($row['name'], $row['id']);
- $folder->setOpened($row['opened']);
-
- return $folder;
- }
-
- /**
- * @brief Store the folder and all its feeds into the database
- * @param folder the folder to be saved
- * @returns The id of the folder in the database table.
- */
- public function save(Folder $folder) {
- $query = \OCP\DB::prepare('
- INSERT INTO ' . self::tableName .
- '(name, parent_id, user_id, opened)
- VALUES (?, ?, ?, ?)
- ');
-
- $name = $folder->getName();
-
- if(empty($name)) {
- $l = \OC_L10N::get('news');
- $name = $l->t('no name');
- }
-
- $parentid = $folder->getParentId();
-
- $params=array(
- $name,
- $parentid,
- $this->userid,
- $folder->getOpened()
- );
- $query->execute($params);
- $folderid = \OCP\DB::insertid(self::tableName);
-
- $folder->setId($folderid);
- return $folderid;
- }
-
-
- /**
- * @brief Updates the folder
- * @param folder the folder to be updated
- */
- public function update(Folder $folder) {
- $query = \OCP\DB::prepare('UPDATE ' . self::tableName
- . ' SET name = ?, opened = ?' . ' WHERE id = ?');
-
- $params = array($folder->getName(), $folder->getOpened(), $folder->getId());
- $query->execute($params);
- return true;
- }
-
- /**
- * @brief Delete the folder and all its feeds from the database
- * @param folder the folder to be deleted (an instance of OCA\News\Folder)
- * @returns true if the folder has been deleted, false if an error occurred
- */
- public function delete(Folder $folder) {
- $folderid = $folder->getId();
- return deleteById(folderid);
- }
-
- /**
- * @brief Delete the folder and all its feeds from the database
- * @param folder the folder to be deleted (an instance of OCA\News\Folder)
- * @returns true if the folder has been deleted, false if an error occurred
- */
- public function deleteById($folderid) {
- if ($folderid == null) {
- return false;
- }
-
- // delete child folders
- $stmt = \OCP\DB::prepare('SELECT id FROM ' . self::tableName .' WHERE parent_id = ? AND user_id = ?');
- $result = $stmt->execute(array($folderid, $this->userid));
- while ($row = $result->fetchRow()) {
- if (!self::deleteById($row['id']))
- return false;
- }
-
- $stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE id = ? AND user_id = ?');
- $result = $stmt->execute(array($folderid, $this->userid));
-
- $feedMapper = new FeedMapper($this->userid);
- //TODO: handle the value that the execute returns
- if(!$feedMapper->deleteAll($folderid))
- return false;
-
- return true;
- }
-
-} \ No newline at end of file
diff --git a/lib/item.php b/lib/item.php
deleted file mode 100644
index 3d63e24f6..000000000
--- a/lib/item.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-/**
-* ownCloud - News app
-*
-* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
-*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
-*
-*/
-
-namespace OCA\News;
-
-class StatusFlag{
- const UNREAD = 0x02;
- const IMPORTANT = 0x04;
- const DELETED = 0x08;
- const UPDATED = 0x16;
-}
-
-/**
- * This class models an item.
- *
- * It encapsulate a SimplePie_Item object and adds a status flag to it
- */
-class Item {
-
- private $url;
<