aboutsummaryrefslogtreecommitdiff
path: root/p/api
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2020-03-28 12:35:21 +0100
committerGravatar GitHub <noreply@github.com> 2020-03-28 12:35:21 +0100
commitcb4d009ebb986b896b181e27d2592837b2a2c3d8 (patch)
tree1cd49d69b991dce32eb57d45818ac2f741c8a2d6 /p/api
parent22916d6a3ed259b5a5dca5cddb4a58433729384f (diff)
GReader API consistent default category (#2840)
* GReader API consistent default category #Fix https://github.com/FreshRSS/FreshRSS/issues/2839 * Also for subscription/list
Diffstat (limited to 'p/api')
-rw-r--r--p/api/greader.php62
1 files changed, 25 insertions, 37 deletions
diff --git a/p/api/greader.php b/p/api/greader.php
index 1d5808069..409babe91 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -76,10 +76,6 @@ function multiplePosts($name) { //https://bugs.php.net/bug.php?id=51633
return $result;
}
-class MyPDO extends Minz_ModelPdo {
- public $pdo;
-}
-
function debugInfo() {
if (function_exists('getallheaders')) {
$ALL_HEADERS = getallheaders();
@@ -237,31 +233,27 @@ function userInfo() { //https://github.com/theoldreader/api#user-info
function tagList() {
header('Content-Type: application/json; charset=UTF-8');
- $model = new MyPDO();
- $stm = $model->pdo->query('SELECT c.name FROM `_category` c');
- $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
-
$tags = array(
array('id' => 'user/-/state/com.google/starred'),
//array('id' => 'user/-/state/com.google/broadcast', 'sortid' => '2'),
);
- foreach ($res as $cName) {
+ $categoryDAO = FreshRSS_Factory::createCategoryDao();
+ $categories = $categoryDAO->listCategories(true, false);
+ foreach ($categories as $cat) {
$tags[] = array(
- 'id' => 'user/-/label/' . htmlspecialchars_decode($cName, ENT_QUOTES),
- //'sortid' => $cName,
+ 'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
+ //'sortid' => $cat->name(),
'type' => 'folder', //Inoreader
);
}
- unset($res);
-
$tagDAO = FreshRSS_Factory::createTagDao();
$labels = $tagDAO->listTags(true);
foreach ($labels as $label) {
$tags[] = array(
'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
- //'sortid' => $cName,
+ //'sortid' => $label->name(),
'type' => 'tag', //Inoreader
'unread_count' => $label->nbUnread(), //Inoreader
);
@@ -274,34 +266,30 @@ function tagList() {
function subscriptionList() {
header('Content-Type: application/json; charset=UTF-8');
- $model = new MyPDO();
- $stm = $model->pdo->prepare('SELECT f.id, f.name, f.url, f.website, c.id as c_id, c.name as c_name FROM `_feed` f
- INNER JOIN `_category` c ON c.id = f.category AND f.priority >= :priority_normal');
- $stm->bindValue(':priority_normal', FreshRSS_Feed::PRIORITY_NORMAL, PDO::PARAM_INT);
- $stm->execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
-
$salt = FreshRSS_Context::$system_conf->salt;
$faviconsUrl = Minz_Url::display('/f.php?', '', true);
$faviconsUrl = str_replace('/api/greader.php/reader/api/0/subscription', '', $faviconsUrl); //Security if base_url is not set properly
$subscriptions = array();
- foreach ($res as $line) {
- $subscriptions[] = array(
- 'id' => 'feed/' . $line['id'],
- 'title' => escapeToUnicodeAlternative($line['name'], true),
- 'categories' => array(
- array(
- 'id' => 'user/-/label/' . htmlspecialchars_decode($line['c_name'], ENT_QUOTES),
- 'label' => htmlspecialchars_decode($line['c_name'], ENT_QUOTES),
- ),
- ),
- //'sortid' => $line['name'],
- //'firstitemmsec' => 0,
- 'url' => htmlspecialchars_decode($line['url'], ENT_QUOTES),
- 'htmlUrl' => htmlspecialchars_decode($line['website'], ENT_QUOTES),
- 'iconUrl' => $faviconsUrl . hash('crc32b', $salt . $line['url']),
- );
+ $categoryDAO = FreshRSS_Factory::createCategoryDao();
+ foreach ($categoryDAO->listCategories(true, true) as $cat) {
+ foreach ($cat->feeds() as $feed) {
+ $subscriptions[] = [
+ 'id' => 'feed/' . $feed->id(),
+ 'title' => escapeToUnicodeAlternative($feed->name(), true),
+ 'categories' => [
+ [
+ 'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
+ 'label' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
+ ],
+ ],
+ //'sortid' => $feed->name(),
+ //'firstitemmsec' => 0,
+ 'url' => htmlspecialchars_decode($feed->url(), ENT_QUOTES),
+ 'htmlUrl' => htmlspecialchars_decode($feed->website(), ENT_QUOTES),
+ 'iconUrl' => $faviconsUrl . hash('crc32b', $salt . $feed->url()),
+ ];
+ }
}
echo json_encode(array('subscriptions' => $subscriptions), JSON_OPTIONS), "\n";