summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-10-14 21:15:16 +0200
committerBart Visscher <bartv@thisnet.nl>2012-10-14 21:15:47 +0200
commit1e37bc139bb28e6fe9b0dd0d477e2dbef5a2cab9 (patch)
treefa56b07316b914f39e2dd02b70a61b05b016b967 /lib
parent365cecd2ec1bf2552ae0d8e064680ed36b0bf04e (diff)
Whitespace cleanup
Diffstat (limited to 'lib')
-rw-r--r--lib/backgroundjob.php16
-rw-r--r--lib/collection.php12
-rw-r--r--lib/feed.php8
-rw-r--r--lib/feedmapper.php20
-rw-r--r--lib/folder.php4
-rw-r--r--lib/foldermapper.php30
-rw-r--r--lib/item.php30
-rw-r--r--lib/itemmapper.php66
-rw-r--r--lib/utils.php10
9 files changed, 98 insertions, 98 deletions
diff --git a/lib/backgroundjob.php b/lib/backgroundjob.php
index 896fd6f03..9495086f0 100644
--- a/lib/backgroundjob.php
+++ b/lib/backgroundjob.php
@@ -37,7 +37,7 @@ class Backgroundjob {
return 1;
}
}
-
+
static public function run() {
if( \OC::$CLI ) {
self::cliStep();
@@ -46,25 +46,25 @@ class Backgroundjob {
self::webStep();
}
}
-
+
static private function cliStep() {
$feedmapper = new FeedMapper();
-
+
// Iterate over all feeds
$feeds = $feedmapper->findAll();
foreach( $feeds as $feed ) {
self::updateFeed( $feedmapper, $feed );
}
}
-
+
static private function webStep() {
// Iterate over all users
$lastid = \OCP\Config::getAppValue('news', 'backgroundjob_lastid',0);
-
+
$feedmapper = new FeedMapper();
$feeds = $feedmapper->findAll();
usort( $feeds, array( 'OCA\News\Backgroundjob', 'sortFeeds' ));
-
+
$done = false;
foreach( $feeds as $feed ) {
if( $feed['id'] > $lastid ) {
@@ -74,12 +74,12 @@ class Backgroundjob {
self::updateFeed( $feedmapper, $feed );
}
}
-
+
if( !$done ) {
\OCP\Config::setAppValue('news', 'backgroundjob_lastid',0);
}
}
-
+
static private function updateFeed( $feedmapper, $feed ) {
$newfeed = null;
$newfeed = Utils::fetch( $feed['url'] );
diff --git a/lib/collection.php b/lib/collection.php
index 3c36dbceb..30b926c00 100644
--- a/lib/collection.php
+++ b/lib/collection.php
@@ -4,10 +4,10 @@
*
* @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;
@@ -16,9 +16,9 @@ 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;
}
@@ -26,9 +26,9 @@ class Collection {
public function getId() {
return $this->id;
}
-
+
public function setId($id) {
$this->id = $id;
}
-
+
}
diff --git a/lib/feed.php b/lib/feed.php
index 4f82404f6..e99ba3c75 100644
--- a/lib/feed.php
+++ b/lib/feed.php
@@ -4,10 +4,10 @@
*
* @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;
@@ -35,7 +35,7 @@ class Feed extends Collection {
parent::__construct($id);
}
}
-
+
public function getUrl() {
return $this->url;
}
@@ -43,7 +43,7 @@ class Feed extends Collection {
public function getTitle() {
return $this->title;
}
-
+
public function setTitle($title) {
$this->title = $title;
}
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index 35847acdf..4220f99d7 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -41,7 +41,7 @@ class FeedMapper {
$feed = new Feed($url, $title, null, $id);
$favicon = $row['favicon_link'];
$feed->setFavicon($favicon);
-
+
return $feed;
}
@@ -125,7 +125,7 @@ class FeedMapper {
$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);
@@ -179,9 +179,9 @@ class FeedMapper {
$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) {
@@ -203,20 +203,20 @@ class FeedMapper {
$feedid = \OCP\DB::insertid(self::tableName);
}
- else {
+ 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);
+ $stmt->execute($params);
}
$feed->setId($feedid);
@@ -228,10 +228,10 @@ class FeedMapper {
$itemMapper->save($item, $feedid);
}
}
-
+
return $feedid;
}
-
+
public function deleteById($id) {
if ($id == null) {
@@ -247,7 +247,7 @@ class FeedMapper {
return true;
}
-
+
public function delete(Feed $feed) {
$id = $feed->getId();
return deleteById($id);
diff --git a/lib/folder.php b/lib/folder.php
index 93a37baa2..2e3c96a7c 100644
--- a/lib/folder.php
+++ b/lib/folder.php
@@ -62,11 +62,11 @@ class Folder extends Collection {
public function addChild(Collection $child) {
$this->children[] = $child;
}
-
+
public function addChildren($children) {
$this->children = $children;
}
-
+
public function getChildren() {
return $this->children;
}
diff --git a/lib/foldermapper.php b/lib/foldermapper.php
index a30759d2d..5d7145176 100644
--- a/lib/foldermapper.php
+++ b/lib/foldermapper.php
@@ -33,15 +33,15 @@ class FolderMapper {
/**
* @brief Returns the forest (list of trees) of folders children of $parentid
- * @param
- * @returns
+ * @param
+ * @returns
*/
public function childrenOf($parentid) {
- $folderlist = array();
+ $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);
@@ -50,25 +50,25 @@ class FolderMapper {
$folder->addChildren($children);
$folderlist[] = $folder;
}
-
+
return $folderlist;
}
/**
- * @brief Returns the forest (list of trees) of folders children of $parentid,
+ * @brief Returns the forest (list of trees) of folders children of $parentid,
* including the feeds that they contain
- * @param
- * @returns
+ * @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);
@@ -77,18 +77,18 @@ class FolderMapper {
$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
@@ -148,7 +148,7 @@ class FolderMapper {
* @param folder the folder to be updated
*/
public function update(Folder $folder) {
- $query = \OCP\DB::prepare('UPDATE ' . self::tableName
+ $query = \OCP\DB::prepare('UPDATE ' . self::tableName
. ' SET name = ?, opened = ?' . ' WHERE id = ?');
$params = array($folder->getName(), $folder->getOpened(), $folder->getId());
diff --git a/lib/item.php b/lib/item.php
index 577b6d8e8..f2d4fbd63 100644
--- a/lib/item.php
+++ b/lib/item.php
@@ -4,10 +4,10 @@
*
* @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;
@@ -34,7 +34,7 @@ class Item {
private $id; //id of the item in the database table
private $author;
private $date; //date is stored in the Unix format
-
+
public function __construct($url, $title, $guid, $body, $id = null) {
$this->title = $title;
$this->url = $url;
@@ -77,38 +77,38 @@ class Item {
}
public function setUnread() {
- $this->status |= StatusFlag::UNREAD;
+ $this->status |= StatusFlag::UNREAD;
}
public function isRead() {
return !($this->status & StatusFlag::UNREAD);
}
-
+
public function setImportant() {
- $this->status |= StatusFlag::IMPORTANT;
+ $this->status |= StatusFlag::IMPORTANT;
}
-
+
public function setUnimportant() {
$this->status &= ~StatusFlag::IMPORTANT;
}
-
+
public function isImportant() {
return ($this->status & StatusFlag::IMPORTANT);
}
-
+
/**
- * NOTE: this is needed to store items in the database, otherwise
+ * NOTE: this is needed to store items in the database, otherwise
* the status of an item should be retrieved with methods: isRead(), isImportant(), ...
*/
public function getStatus() {
return $this->status;
}
-
+
public function setStatus($status) {
$this->status = $status;
}
-
- /* change the following method with set/get magic methods
+
+ /* change the following method with set/get magic methods
* http://www.php.net/manual/en/language.oop5.overloading.php#object.get
*/
@@ -135,7 +135,7 @@ class Item {
public function setBody($body) {
$this->body = $body;
}
-
+
public function getAuthor() {
return $this->author;
}
@@ -147,7 +147,7 @@ class Item {
public function getDate() {
return $this->date;
}
-
+
//TODO: check if the parameter is in the Unix format
public function setDate($date) {
$this->date = $date;
diff --git a/lib/itemmapper.php b/lib/itemmapper.php
index 2f4e295b2..58894cce8 100644
--- a/lib/itemmapper.php
+++ b/lib/itemmapper.php
@@ -4,10 +4,10 @@
*
* @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;
@@ -31,7 +31,7 @@ class ItemMapper {
}
/**
- * @brief
+ * @brief
* @param row a row from the items table of the database
* @returns an object of the class OC_News_Item
*/
@@ -46,10 +46,10 @@ class ItemMapper {
$item->setAuthor($row['author']);
$item->setFeedId($row['feed_id']);
$item->setDate(Utils::dbtimestampToUnixtime($row['pub_date']));
-
+
return $item;
}
-
+
/**
* @brief Retrieve all the item corresponding to a feed from the database
* @param feedid The id of the feed in the database table.
@@ -57,7 +57,7 @@ class ItemMapper {
public function findByFeedId($feedid) {
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feed_id = ? ORDER BY pub_date DESC');
$result = $stmt->execute(array($feedid));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -66,7 +66,7 @@ class ItemMapper {
return $items;
}
-
+
/**
* @brief Retrieve all the items corresponding to a feed from the database with a particular status
@@ -74,12 +74,12 @@ class ItemMapper {
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function findAllStatus($feedid, $status) {
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . '
WHERE feed_id = ?
- AND ((status & ?) > 0)
+ AND ((status & ?) > 0)
ORDER BY pub_date DESC');
$result = $stmt->execute(array($feedid, $status));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -88,20 +88,20 @@ class ItemMapper {
return $items;
}
-
+
/*
* @brief Retrieve all the items from the database with a particular status
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function findEveryItemByStatus($status) {
- $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.* FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.* FROM ' . self::tableName . '
JOIN '. FeedMapper::tableName .' ON
'. FeedMapper::tableName .'.id = ' . self::tableName . '.feed_id
WHERE '. FeedMapper::tableName .'.user_id = ?
AND ((' . self::tableName . '.status & ?) > 0)
ORDER BY ' . self::tableName . '.pub_date DESC');
$result = $stmt->execute(array($this->userid, $status));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -112,19 +112,19 @@ class ItemMapper {
}
public function countAllStatus($feedid, $status) {
- $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
WHERE feed_id = ?
AND ((status & ?) > 0)');
$result=$stmt->execute(array($feedid, $status))->fetchRow();
return $result['size'];
}
-
+
/**
* @brief Count all the items from the database with a particular status
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function countEveryItemByStatus($status) {
- $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
JOIN '. FeedMapper::tableName .' ON
'. FeedMapper::tableName .'.id = ' . self::tableName . '.feed_id
WHERE '. FeedMapper::tableName .'.user_id = ?
@@ -136,7 +136,7 @@ class ItemMapper {
public function findIdFromGuid($guid_hash, $guid, $feedid) {
$stmt = \OCP\DB::prepare('
- SELECT * FROM ' . self::tableName . '
+ SELECT * FROM ' . self::tableName . '
WHERE guid_hash = ?
AND feed_id = ?
');
@@ -155,25 +155,25 @@ class ItemMapper {
* @returns The item whose status has changed.
*/
public function update(Item $item) {
-
+
$itemid = $item->getId();
$status = $item->getStatus();
-
+
$stmt = \OCP\DB::prepare('
UPDATE ' . self::tableName .
' SET status = ?
WHERE id = ?
');
-
+
$params=array(
$status,
$itemid
);
$stmt->execute($params);
-
+
return true;
}
-
+
/**
* @brief Save the feed and all its items into the database
* @returns The id of the feed in the database table.
@@ -181,11 +181,11 @@ class ItemMapper {
public function save(Item $item, $feedid) {
$guid = $item->getGuid();
$guid_hash = md5($guid);
-
+
$status = $item->getStatus();
$itemid = $this->findIdFromGuid($guid_hash, $guid, $feedid);
-
+
if ($itemid == null) {
$title = $item->getTitle();
$body = $item->getBody();
@@ -206,9 +206,9 @@ class ItemMapper {
$l = \OC_L10N::get('news');
$body = $l->t('no body');
}
-
+
$pub_date = Utils::unixtimeToDbtimestamp($item->getDate());
-
+
$params=array(
$item->getUrl(),
$title,
@@ -220,9 +220,9 @@ class ItemMapper {
$feedid,
$status
);
-
+
$stmt->execute($params);
-
+
$itemid = \OCP\DB::insertid(self::tableName);
}
else {
@@ -231,7 +231,7 @@ class ItemMapper {
$item->setId($itemid);
return $itemid;
}
-
+
/**
* @brief Retrieve an item from the database
* @param id The id of the feed in the database table.
@@ -242,16 +242,16 @@ class ItemMapper {
$row = $result->fetchRow();
$item = $this->fromRow($row);
-
+
return $item;
}
-
+
/**
* @brief Permanently delete all items belonging to a feed from the database
* @param feedid The id of the feed that we wish to delete
- * @return
+ * @return
*/
public function deleteAll($feedid) {
if ($feedid == null) {
@@ -260,7 +260,7 @@ class ItemMapper {
$stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE feed_id = ?');
$result = $stmt->execute(array($feedid));
-
+
return $result;
}
} \ No newline at end of file
diff --git a/lib/utils.php b/lib/utils.php
index ab80018d6..e7ae2107e 100644
--- a/lib/utils.php
+++ b/lib/utils.php
@@ -100,9 +100,9 @@ class Utils {
}
/**
- * Perform a "slim" fetch of a feed from remote.
+ * Perform a "slim" fetch of a feed from remote.
* Differently from Utils::fetch(), it doesn't retrieve items nor a favicon
- *
+ *
* @param url remote url of the feed
* @returns an instance of OC_News_Feed
*/
@@ -121,7 +121,7 @@ class Utils {
$title = $spfeed->get_title();
$feed = new Feed($url, $title);
-
+
return $feed;
}
catch (Exception $e) {
@@ -130,7 +130,7 @@ class Utils {
}
public static function checkFavicon($favicon) {
- if ($favicon === null || $favicon == false)
+ if ($favicon === null || $favicon == false)
return false;
$file = new \SimplePie_File($favicon);
@@ -158,7 +158,7 @@ class Utils {
//try to extract favicon from web page
$absoluteUrl = \SimplePie_Misc::absolutize_url('/', $url);
-
+
$handle = curl_init ( );
curl_setopt ( $handle, CURLOPT_URL, $absoluteUrl );
curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, 1 );