summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-28 20:22:50 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-02-28 20:22:50 +0100
commitf44683b5671b323ba96f0c4cd47ba9458e934679 (patch)
tree7dc93c1deecfc7f89212c5ba98d00ccbf98d6777
parentd79da54c984fb4bb94bf4226d4318bfd408628db (diff)
API streamContents for categories and feeds
https://github.com/marienfressinaud/FreshRSS/issues/13
-rwxr-xr-xapp/Controllers/configureController.php2
-rw-r--r--app/Models/CategoryDAO.php6
-rw-r--r--app/Models/EntryDAO.php4
-rw-r--r--app/Models/FeedDAO.php6
-rw-r--r--lib/lib_opml.php2
-rw-r--r--p/api/greader.php22
6 files changed, 26 insertions, 16 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index f831f25d0..41a7920f0 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -44,7 +44,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
'name' => $cat->name (),
);
- if ($catDAO->searchByName ($newCat) == false) {
+ if ($catDAO->searchByName ($newCat) == null) {
$catDAO->addCategory ($values);
}
}
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index 5355228a5..f3c02e3e4 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -64,7 +64,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
if (isset ($cat[0])) {
return $cat[0];
} else {
- return false;
+ return null;
}
}
public function searchByName ($name) {
@@ -80,7 +80,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
if (isset ($cat[0])) {
return $cat[0];
} else {
- return false;
+ return null;
}
}
@@ -120,7 +120,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
public function checkDefault () {
$def_cat = $this->searchById (1);
- if ($def_cat === false) {
+ if ($def_cat == null) {
$cat = new FreshRSS_Category (Minz_Translate::t ('default_category'));
$cat->_id (1);
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index b25ae444b..3fc7a05ef 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -307,7 +307,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$entries = self::daoToEntry ($res);
- return isset ($entries[0]) ? $entries[0] : false;
+ return isset ($entries[0]) ? $entries[0] : null;
}
public function searchById ($id) {
@@ -320,7 +320,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$entries = self::daoToEntry ($res);
- return isset ($entries[0]) ? $entries[0] : false;
+ return isset ($entries[0]) ? $entries[0] : null;
}
public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $keepHistoryDefault = 0) {
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 79d8cff90..fb4a847a0 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -170,7 +170,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
if (isset ($feed[$id])) {
return $feed[$id];
} else {
- return false;
+ return null;
}
}
public function searchByUrl ($url) {
@@ -186,7 +186,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
if (isset ($feed)) {
return $feed;
} else {
- return false;
+ return null;
}
}
@@ -198,7 +198,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
return self::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
}
- public function listCategoryNames() {
+ public function arrayCategoryNames() {
$sql = 'SELECT f.id, c.name as c_name FROM `' . $this->prefix . 'feed` f '
. 'INNER JOIN `' . $this->prefix . 'category` c ON c.id = f.category';
$stm = $this->bd->prepare ($sql);
diff --git a/lib/lib_opml.php b/lib/lib_opml.php
index 9feb12ae0..05e54d85e 100644
--- a/lib/lib_opml.php
+++ b/lib/lib_opml.php
@@ -58,7 +58,7 @@ function opml_import ($xml) {
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
$catDAO = new FreshRSS_CategoryDAO ();
$cat = $catDAO->searchByName ($title);
- if ($cat === false) {
+ if ($cat == null) {
$cat = new FreshRSS_Category ($title);
$values = array (
'name' => $cat->name ()
diff --git a/p/api/greader.php b/p/api/greader.php
index 291bcdf1f..e99e1c0c8 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -266,7 +266,7 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex
header('Content-Type: application/json; charset=UTF-8');
$feedDAO = new FreshRSS_FeedDAO();
- $feedCategoryNames = $feedDAO->listCategoryNames();
+ $arrayFeedCategoryNames = $feedDAO->arrayCategoryNames();
switch ($path) {
case 'reading-list':
@@ -275,8 +275,14 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex
case 'starred':
$type = 's';
break;
+ case 'feed':
+ $type = 'f';
+ break;
case 'label':
$type = 'c';
+ $categoryDAO = new FreshRSS_CategoryDAO();
+ $cat = $categoryDAO->searchByName($include_target);
+ $include_target = $cat == null ? -1 : $cat->id();
break;
default:
$type = 'A';
@@ -298,7 +304,7 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex
$items = array();
foreach ($entries as $entry) {
$f_id = $entry->feed();
- $c_name = isset($feedCategoryNames[$f_id]) ? $feedCategoryNames[$f_id] : '_';
+ $c_name = isset($arrayFeedCategoryNames[$f_id]) ? $arrayFeedCategoryNames[$f_id] : '_';
$item = array(
'id' => /*'tag:google.com,2005:reader/item/' .*/ dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
'crawlTimeMsec' => substr($entry->id(), 0, -3),
@@ -352,9 +358,11 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude
$type = 'f';
$id = basename($streamId);
} elseif (strpos($streamId, 'user/-/label/') === 0) {
- $type = 'C';
+ $type = 'c';
$c_name = basename($streamId);
- notImplemented(); //TODO
+ $categoryDAO = new FreshRSS_CategoryDAO();
+ $cat = $categoryDAO->searchByName($c_name);
+ $id = $cat == null ? -1 : $cat->id();
}
switch ($exclude_target) {
@@ -441,7 +449,7 @@ function markAllAsRead($streamId, $olderThanId) {
logMe('----------------------------------------------------------------'."\n");
logMe(print_r($debugInfo, true));
-$pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : $_SERVER['PATH_INFO'];
+$pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']);
$pathInfos = explode('/', $pathInfo);
logMe('pathInfos => ' . print_r($pathInfos, true));
@@ -471,7 +479,9 @@ if ($user != null) {
Minz_Session::_param('currentUser', $user);
-if (count($pathInfos)<3) badRequest();
+if (count($pathInfos) < 3) {
+ badRequest();
+}
elseif ($pathInfos[1] === 'accounts') {
if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd']))
clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']);