From c391ca62f1ad4130202b995bb5bb9111894e65ff Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 28 Dec 2014 18:05:02 +0100 Subject: Remove all old references to LOG_PATH See https://github.com/FreshRSS/FreshRSS/issues/729 --- p/api/greader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 1a66c30fb..80714d478 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -77,7 +77,7 @@ class MyPDO extends Minz_ModelPdo { } function logMe($text) { - file_put_contents(LOG_PATH . '/api.log', $text, FILE_APPEND); + file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), $text, FILE_APPEND); } function debugInfo() { -- cgit v1.2.3 From 60563283cc5594f50fd8943661e03e350e529913 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 6 Jan 2015 23:16:57 +0100 Subject: Fix greader api script with new config system See https://github.com/FreshRSS/FreshRSS/issues/730 --- p/api/greader.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 80714d478..30530d60d 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -150,13 +150,12 @@ function authorizationToUserConf() { if (count($headerAuthX) === 2) { $user = $headerAuthX[0]; if (ctype_alnum($user)) { - try { - $conf = new FreshRSS_Configuration($user); - } catch (Exception $e) { - logMe($e->getMessage() . "\n"); + $conf = get_user_configuration($user); + if (is_null($conf)) { unauthorized(); } - if ($headerAuthX[1] === sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash)) { + $system_conf = Minz_Configuration::get('system'); + if ($headerAuthX[1] === sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash)) { return $conf; } else { logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n"); @@ -177,16 +176,16 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); } - try { - $conf = new FreshRSS_Configuration($email); - } catch (Exception $e) { - logMe($e->getMessage() . "\n"); - Minz_Log::warning('Invalid API user ' . $email); + + $conf = get_user_configuration($email); + if (is_null($conf)) { unauthorized(); } + if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) { header('Content-Type: text/plain; charset=UTF-8'); - $auth = $email . '/' . sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash); + $system_conf = Minz_Configuration::get('system'); + $auth = $email . '/' . sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash); echo 'SID=', $auth, "\n", 'Auth=', $auth, "\n"; exit(); @@ -204,7 +203,8 @@ function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php logMe('token('. $conf->user . ")\n"); //TODO: Implement real token that expires - $token = str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters + $system_conf = Minz_Configuration::get('system'); + $token = str_pad(sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); } @@ -212,7 +212,8 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken logMe('checkToken(' . $token . ")\n"); - if ($token === str_pad(sha1(Minz_Configuration::salt() . $conf->user . $conf->apiPasswordHash), 57, 'Z')) { + $system_conf = Minz_Configuration::get('system'); + if ($token === str_pad(sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash), 57, 'Z')) { return true; } unauthorized(); @@ -536,9 +537,11 @@ logMe('----------------------------------------------------------------'."\n"); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); $pathInfos = explode('/', $pathInfo); -Minz_Configuration::init(); - -if (!Minz_Configuration::apiEnabled()) { +Minz_Configuration::register('system', + DATA_PATH . '/config.php', + DATA_PATH . '/config.default.php'); +$system_conf = Minz_Configuration::get('system'); +if (!$system_conf->api_enabled) { serviceUnavailable(); } -- cgit v1.2.3 From e7e7a320d61a03141823ccb47c8587bb2541ba2e Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 13 Jan 2015 14:13:27 +0100 Subject: Add a log line in greader API. See https://github.com/FreshRSS/FreshRSS/issues/747 --- p/api/greader.php | 1 + 1 file changed, 1 insertion(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 30530d60d..bbde2a867 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -152,6 +152,7 @@ function authorizationToUserConf() { if (ctype_alnum($user)) { $conf = get_user_configuration($user); if (is_null($conf)) { + logMe('Invalid configuration API file for user ' . $user); unauthorized(); } $system_conf = Minz_Configuration::get('system'); -- cgit v1.2.3 From f3545208ab29ac646e3f104892aabcabe575411d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 13 Jan 2015 15:00:06 +0100 Subject: Add log in API See https://github.com/FreshRSS/FreshRSS/issues/747 --- p/api/greader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index bbde2a867..069fcd5a8 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -152,7 +152,7 @@ function authorizationToUserConf() { if (ctype_alnum($user)) { $conf = get_user_configuration($user); if (is_null($conf)) { - logMe('Invalid configuration API file for user ' . $user); + Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.'); unauthorized(); } $system_conf = Minz_Configuration::get('system'); @@ -180,6 +180,7 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 $conf = get_user_configuration($email); if (is_null($conf)) { + Minz_Log::warning('Invalid API user ' . $email . ': configuration cannot be found.'); unauthorized(); } -- cgit v1.2.3 From 59760580d2e6856ee66dedb0ae33829aea29c971 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 13 Jan 2015 15:14:55 +0100 Subject: Fix greader API $conf->user didn't exist anymore since #730. User name had to be retrieved by another way. It uses sessions now. Fix https://github.com/FreshRSS/FreshRSS/issues/747 --- p/api/greader.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 069fcd5a8..2c23b30a2 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -143,7 +143,7 @@ function checkCompatibility() { exit(); } -function authorizationToUserConf() { +function authorizationToUser() { $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth'); //Input is 'GoogleLogin auth', but PHP replaces spaces by '_' http://php.net/language.variables.external if ($headerAuth != '') { $headerAuthX = explode('/', $headerAuth, 2); @@ -156,8 +156,8 @@ function authorizationToUserConf() { unauthorized(); } $system_conf = Minz_Configuration::get('system'); - if ($headerAuthX[1] === sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash)) { - return $conf; + if ($headerAuthX[1] === sha1($system_conf->salt . $user . $conf->apiPasswordHash)) { + return $user; } else { logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n"); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); @@ -187,7 +187,7 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) { header('Content-Type: text/plain; charset=UTF-8'); $system_conf = Minz_Configuration::get('system'); - $auth = $email . '/' . sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash); + $auth = $email . '/' . sha1($system_conf->salt . $email . $conf->apiPasswordHash); echo 'SID=', $auth, "\n", 'Auth=', $auth, "\n"; exit(); @@ -204,18 +204,20 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php - logMe('token('. $conf->user . ")\n"); //TODO: Implement real token that expires + $user = Minz_Session::_param('currentUser', '_'); + logMe('token('. $user . ")\n"); //TODO: Implement real token that expires $system_conf = Minz_Configuration::get('system'); - $token = str_pad(sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters + $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); } function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken + $user = Minz_Session::_param('currentUser', '_'); logMe('checkToken(' . $token . ")\n"); $system_conf = Minz_Configuration::get('system'); - if ($token === str_pad(sha1($system_conf->salt . $conf->user . $conf->apiPasswordHash), 57, 'Z')) { + if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } unauthorized(); @@ -549,8 +551,11 @@ if (!$system_conf->api_enabled) { Minz_Session::init('FreshRSS'); -$conf = authorizationToUserConf(); -$user = $conf == null ? '' : $conf->user; +$user = authorizationToUser(); +if (is_null($user)) { + unauthorized(); +} +$conf = get_user_configuration($user); logMe('User => ' . $user . "\n"); -- cgit v1.2.3 From e8556ac1a4c00b4e44e88a7d73feca6f7462fc34 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 13 Jan 2015 15:26:42 +0100 Subject: Change behaviour if authorizationToUser is null authorizationToUser() returns now an empty string by default If it returns an empty string, conf is set to null and api don't die anymore. Fix https://github.com/FreshRSS/FreshRSS/issues/747 --- p/api/greader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 2c23b30a2..20f72cc3b 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -168,7 +168,7 @@ function authorizationToUser() { } } } - return null; + return ''; } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html @@ -552,10 +552,10 @@ if (!$system_conf->api_enabled) { Minz_Session::init('FreshRSS'); $user = authorizationToUser(); -if (is_null($user)) { - unauthorized(); +$conf = null; +if ($user !== '') { + $conf = get_user_configuration($user); } -$conf = get_user_configuration($user); logMe('User => ' . $user . "\n"); -- cgit v1.2.3 From f1ffdd8b9d1f3d8742f1328dfa805664a66e34aa Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 14 Jan 2015 21:13:38 +0100 Subject: Fix stupid bug in greader API Replace Minz_Session::_param() by Minz_Session::param() in token() and checkToken() functions. Fix https://github.com/FreshRSS/FreshRSS/issues/747 --- p/api/greader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 20f72cc3b..ab1a02244 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -204,7 +204,7 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php - $user = Minz_Session::_param('currentUser', '_'); + $user = Minz_Session::param('currentUser', '_'); logMe('token('. $user . ")\n"); //TODO: Implement real token that expires $system_conf = Minz_Configuration::get('system'); $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters @@ -214,7 +214,7 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken - $user = Minz_Session::_param('currentUser', '_'); + $user = Minz_Session::param('currentUser', '_'); logMe('checkToken(' . $token . ")\n"); $system_conf = Minz_Configuration::get('system'); if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { @@ -649,7 +649,7 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo markAllAsRead($streamId, $ts); break; case 'token': - Token($conf); + token($conf); break; } } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') { -- cgit v1.2.3 From f3f8d73dda3c9882f383e721eb3cc47be5a6c706 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Tue, 3 Mar 2015 22:35:22 -0500 Subject: Fix API to use the search object Since the internal of the listWhere method was changed, the API wasn't working. It was still calling the method with the old parameters. I didn't test it but now, it should work. --- p/api/greader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index ab1a02244..060aa45ee 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -371,7 +371,7 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex } $entryDAO = FreshRSS_Factory::createEntryDao(); - $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, '', $start_time); + $entries = $entryDAO->listWhere($type, $include_target, $state, $order === 'o' ? 'ASC' : 'DESC', $count, $continuation, new FreshRSS_Search(''), $start_time); $items = array(); foreach ($entries as $entry) { -- cgit v1.2.3 From d1c9378d338027e39174fecb5f7a047218ad2113 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Wed, 4 Mar 2015 23:04:12 -0500 Subject: Fix entry DAO query usage I did not fix the call in the previous commit. I hope this one is the last change needed. We definitely need a templating engine so we could use the same controller to output different things. This will remove code duplication between the api and the web interface. It will allows us to build other type of api, and also refactor the rss feed as a different view of the same dataset. --- p/api/greader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 060aa45ee..4554a3f9c 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -465,7 +465,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } $entryDAO = FreshRSS_Factory::createEntryDao(); - $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', '', $start_time); + $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', new FreshRSS_Search(''), $start_time); $itemRefs = array(); foreach ($ids as $id) { -- cgit v1.2.3 From 10d98e0ce97d15882a06865b894136d3c0444d79 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 21 May 2015 19:46:32 +0200 Subject: Google Reader API: work-around for News+ bug https://github.com/noinnion/newsplus/issues/84#issuecomment-57834632 https://github.com/FreshRSS/FreshRSS/issues/443 --- p/api/greader.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 4554a3f9c..5a23af006 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -467,6 +467,9 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude $entryDAO = FreshRSS_Factory::createEntryDao(); $ids = $entryDAO->listIdsWhere($type, $id, $state, $order === 'o' ? 'ASC' : 'DESC', $count, '', new FreshRSS_Search(''), $start_time); + if (empty($ids)) { //For News+ bug https://github.com/noinnion/newsplus/issues/84#issuecomment-57834632 + $ids[] = 0; + } $itemRefs = array(); foreach ($ids as $id) { $itemRefs[] = array( -- cgit v1.2.3 From 481c2a671913cdd6099a1b6ee4d5491dff16c0bf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Oct 2015 22:25:48 +0200 Subject: Clean logs Reduced login of API and PubSubHubbub (both are quite stable now). When clearing logs as admin, also clear API and PubSubHubbub logs. https://github.com/FreshRSS/FreshRSS/issues/988 --- app/Controllers/feedController.php | 4 ++-- app/Models/LogDAO.php | 5 +++++ p/api/greader.php | 38 +++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ec3dce777..4ec661115 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -307,9 +307,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled(); if ((!$simplePiePush) && (!$id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) { - $text = 'Skip pull of feed using PubSubHubbub: ' . $url; + //$text = 'Skip pull of feed using PubSubHubbub: ' . $url; //Minz_Log::debug($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + //file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); continue; //When PubSubHubbub is used, do not pull refresh so often } diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index 4c56e3150..ab258cd58 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -21,5 +21,10 @@ class FreshRSS_LogDAO { public static function truncate() { file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), ''); + if (FreshRSS_Auth::hasAccess('admin')) { + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), ''); + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), ''); + file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), ''); + } } } diff --git a/p/api/greader.php b/p/api/greader.php index 5a23af006..b9942f0bc 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -77,7 +77,7 @@ class MyPDO extends Minz_ModelPdo { } function logMe($text) { - file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), $text, FILE_APPEND); + file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), date('c') . "\t" . $text . "\n", FILE_APPEND); } function debugInfo() { @@ -96,7 +96,7 @@ function debugInfo() { } function badRequest() { - logMe("badRequest()\n"); + logMe("badRequest()"); logMe(debugInfo()); header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain; charset=UTF-8'); @@ -104,7 +104,7 @@ function badRequest() { } function unauthorized() { - logMe("unauthorized()\n"); + logMe("unauthorized()"); logMe(debugInfo()); header('HTTP/1.1 401 Unauthorized'); header('Content-Type: text/plain; charset=UTF-8'); @@ -113,7 +113,7 @@ function unauthorized() { } function notImplemented() { - logMe("notImplemented()\n"); + logMe("notImplemented()"); logMe(debugInfo()); header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=UTF-8'); @@ -121,14 +121,14 @@ function notImplemented() { } function serviceUnavailable() { - logMe("serviceUnavailable()\n"); + logMe("serviceUnavailable()"); header('HTTP/1.1 503 Service Unavailable'); header('Content-Type: text/plain; charset=UTF-8'); die('Service Unavailable!'); } function checkCompatibility() { - logMe("checkCompatibility()\n"); + logMe("checkCompatibility()"); header('Content-Type: text/plain; charset=UTF-8'); if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) { die('FAIL 64-bit or GMP extension!'); @@ -159,7 +159,7 @@ function authorizationToUser() { if ($headerAuthX[1] === sha1($system_conf->salt . $user . $conf->apiPasswordHash)) { return $user; } else { - logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1] . "\n"); + logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); unauthorized(); } @@ -172,7 +172,7 @@ function authorizationToUser() { } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html - logMe('clientLogin(' . $email . ")\n"); + //logMe('clientLogin(' . $email . ")"); if (ctype_alnum($email)) { if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); @@ -205,7 +205,7 @@ function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); - logMe('token('. $user . ")\n"); //TODO: Implement real token that expires + //logMe('token('. $user . ")"); //TODO: Implement real token that expires $system_conf = Minz_Configuration::get('system'); $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; @@ -215,7 +215,7 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); - logMe('checkToken(' . $token . ")\n"); + //logMe('checkToken(' . $token . ")"); $system_conf = Minz_Configuration::get('system'); if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; @@ -224,7 +224,7 @@ function checkToken($conf, $token) { } function tagList() { - logMe("tagList()\n"); + //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -249,7 +249,7 @@ function tagList() { } function subscriptionList() { - logMe("subscriptionList()\n"); + //logMe("subscriptionList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -283,7 +283,7 @@ function subscriptionList() { } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count - logMe("unreadCount()\n"); + //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; @@ -330,7 +330,7 @@ function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-googl function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)\n"); + //logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)"); header('Content-Type: application/json; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -436,7 +436,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)\n"); + //logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)"); $type = 'A'; $id = ''; @@ -484,7 +484,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } function editTag($e_ids, $a, $r) { - logMe("editTag()\n"); + //logMe("editTag()"); foreach ($e_ids as $i => $e_id) { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' @@ -520,7 +520,7 @@ function editTag($e_ids, $a, $r) { } function markAllAsRead($streamId, $olderThanId) { - logMe("markAllAsRead($streamId, $olderThanId)\n"); + //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -538,7 +538,7 @@ function markAllAsRead($streamId, $olderThanId) { exit(); } -logMe('----------------------------------------------------------------'."\n"); +//logMe('----------------------------------------------------------------'); //logMe(debugInfo()); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); @@ -560,7 +560,7 @@ if ($user !== '') { $conf = get_user_configuration($user); } -logMe('User => ' . $user . "\n"); +//logMe('User => ' . $user); Minz_Session::_param('currentUser', $user); -- cgit v1.2.3 From 9534ea0e6b54cd899ac4432f1ae8f14258613ae6 Mon Sep 17 00:00:00 2001 From: Purexo Date: Mon, 23 Nov 2015 08:30:00 +0100 Subject: Update greader.php streamContents can know exclude target unread item --- p/api/greader.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index b9942f0bc..3fa367299 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -361,6 +361,9 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex case 'user/-/state/com.google/read': $state = FreshRSS_Entry::STATE_NOT_READ; break; + case 'user/-/state/com.google/unread': + $state = FreshRSS_Entry::STATE_READ; + break; default: $state = FreshRSS_Entry::STATE_ALL; break; -- cgit v1.2.3 From 7db99b838223649fe3aec973516b8d32d58ca5dd Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 8 Mar 2016 19:30:24 +0100 Subject: API limit INPUT to 1MB --- p/api/greader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 3fa367299..62782ce1a 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -23,7 +23,7 @@ Server-side API compatible with Google Reader API layer 2 require('../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -$ORIGINAL_INPUT = file_get_contents('php://input'); +$ORIGINAL_INPUT = file_get_contents('php://input', false, null, -1, 1048576); if (PHP_INT_SIZE < 8) { //32-bit function dec2hex($dec) { -- cgit v1.2.3 From 06189cb6661edf75079037f90cf82276ab5f5648 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 10 Apr 2016 11:52:16 +0200 Subject: API support for REDIRECT HTTP headers https://github.com/FreshRSS/FreshRSS/issues/1127 --- p/api/greader.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 62782ce1a..894c2e960 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -46,6 +46,8 @@ function headerVariable($headerName, $varName) { $upName = 'HTTP_' . strtoupper($headerName); if (isset($_SERVER[$upName])) { $header = $_SERVER[$upName]; + } elseif (isset($_SERVER['REDIRECT_' . $upName])) { + $header = $_SERVER['REDIRECT_' . $upName]; } elseif (function_exists('getallheaders')) { $ALL_HEADERS = getallheaders(); if (isset($ALL_HEADERS[$headerName])) { @@ -134,6 +136,7 @@ function checkCompatibility() { die('FAIL 64-bit or GMP extension!'); } if ((!array_key_exists('HTTP_AUTHORIZATION', $_SERVER)) && //Apache mod_rewrite trick should be fine + (!array_key_exists('REDIRECT_HTTP_AUTHORIZATION', $_SERVER)) && //Apache mod_rewrite with FCGI (empty($_SERVER['SERVER_SOFTWARE']) || (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') === false)) && //nginx should be fine (empty($_SERVER['SERVER_SOFTWARE']) || (stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false)) && //lighttpd should be fine ((!function_exists('getallheaders')) || (stripos(php_sapi_name(), 'cgi') !== false))) { //Main problem is Apache/CGI mode -- cgit v1.2.3 From 4a9cc67d90ac167d745c50f98aa1738f6d1131e9 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 15 Sep 2016 11:36:31 +0200 Subject: API: add iconUrl https://github.com/jangernert/FeedReader/issues/59#issuecomment-247182291 https://github.com/FreshRSS/FreshRSS/issues/1252 --- p/api/greader.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 894c2e960..98ae60475 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -158,7 +158,7 @@ function authorizationToUser() { Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.'); unauthorized(); } - $system_conf = Minz_Configuration::get('system'); + global $system_conf; if ($headerAuthX[1] === sha1($system_conf->salt . $user . $conf->apiPasswordHash)) { return $user; } else { @@ -189,7 +189,7 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) { header('Content-Type: text/plain; charset=UTF-8'); - $system_conf = Minz_Configuration::get('system'); + global $system_conf; $auth = $email . '/' . sha1($system_conf->salt . $email . $conf->apiPasswordHash); echo 'SID=', $auth, "\n", 'Auth=', $auth, "\n"; @@ -209,7 +209,7 @@ function token($conf) { //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); //logMe('token('. $user . ")"); //TODO: Implement real token that expires - $system_conf = Minz_Configuration::get('system'); + global $system_conf; $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); @@ -219,7 +219,7 @@ function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); //logMe('checkToken(' . $token . ")"); - $system_conf = Minz_Configuration::get('system'); + global $system_conf; if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } @@ -261,6 +261,8 @@ function subscriptionList() { $stm->execute(); $res = $stm->fetchAll(PDO::FETCH_ASSOC); + global $system_conf; + $salt = $system_conf->salt; $subscriptions = array(); foreach ($res as $line) { @@ -277,7 +279,7 @@ function subscriptionList() { //'firstitemmsec' => 0, 'url' => $line['url'], 'htmlUrl' => $line['website'], - //'iconUrl' => '', + 'iconUrl' => Minz_Url::display('/f.php?' . hash('crc32b', $salt . $line['url']), '', true), ); } -- cgit v1.2.3 From 12fa756bbc10685438c8972dcca046c90ed4f548 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 17 Sep 2016 01:24:04 +0200 Subject: API: start draft of edit subscriptions https://github.com/FreshRSS/FreshRSS/issues/443 https://github.com/FreshRSS/FreshRSS/issues/1252 https://github.com/jangernert/FeedReader/issues/59#issuecomment-247484124 --- p/api/greader.php | 90 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 9 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 98ae60475..3da1156c2 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -287,6 +287,66 @@ function subscriptionList() { exit(); } +function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') { + //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki + switch ($action) { + case 'subscribe': + case 'unsubscribe': + case 'edit': + default: + badRequest(); + } + $addCatId = 0; + $categoryDAO = null; + if ($add != '' || $remove != '') { + $categoryDAO = new FreshRSS_CategoryDAO(); + } + if ($add != '' && strpos($add, 'user/-/label/') === 0) { //user/-/label/Example + $c_name = basename($add); + $cat = $categoryDAO->searchByName($c_name); + $addCatId = $cat == null ? -1 : $cat->id(); + } else if ($remove != '' && strpos($remove, 'user/-/label/') { + $addCatId = 1; //Default category + } + $feedDAO = FreshRSS_Factory::createFeedDao(); + for ($i = count($streamNames) - 1; $i >= 0; $i--) { + $streamName = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338 + if (strpos($streamName, 'feed/') === 0) { + $streamName = basename($streamName); + $feedId = 0; + if (ctype_digit($streamName)) { + if ($action === 'subscribe') { + continue; + } + $feedId = $streamName; + } else { + $feed = $feedDAO->searchByUrl($streamName); + $feedId = $feed == null ? -1 : $feed->id(); + } + $title = isset($titles[$i]) ? $titles[$i] : ''; + switch ($action) { + case 'subscribe': + if ($feedId <= 0) { + //TODO + } + break; + case 'unsubscribe': + if ($feedId > 0) { + //TODO + } + break; + case 'edit': + if ($feedId > 0) { + //TODO + } + break; + } + } + } + notImplemented(); + exit('OK'); +} + function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); @@ -523,8 +583,7 @@ function editTag($e_ids, $a, $r) { break; } - echo 'OK'; - exit(); + exit('OK'); } function markAllAsRead($streamId, $olderThanId) { @@ -542,8 +601,7 @@ function markAllAsRead($streamId, $olderThanId) { $entryDAO->markReadEntries($olderThanId, false, -1); } - echo 'OK'; - exit(); + exit('OK'); } //logMe('----------------------------------------------------------------'); @@ -625,14 +683,28 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo if (isset($pathInfos[5]) && $pathInfos[5] === 'list') { $output = isset($_GET['output']) ? $_GET['output'] : ''; if ($output !== 'json') notImplemented(); - tagList($_GET['output']); + tagList($output); } break; case 'subscription': - if (isset($pathInfos[5]) && $pathInfos[5] === 'list') { - $output = isset($_GET['output']) ? $_GET['output'] : ''; - if ($output !== 'json') notImplemented(); - subscriptionList($_GET['output']); + if (isset($pathInfos[5])) { + switch ($pathInfos[5]) { + case 'list': + $output = isset($_GET['output']) ? $_GET['output'] : ''; + if ($output !== 'json') notImplemented(); + subscriptionList($_GET['output']); + break; + case 'edit': + if (isset($_POST['s']) && isset($_POST['ac'])) { + $streamNames = multiplePosts('s'); //StreamId to operate on. The parameter may be repeated to edit multiple subscriptions at once + $titles = multiplePosts('t'); //Title to use for the subscription. For the `subscribe` action, if not specified then the feed's current title will be used. Can be used with the `edit` action to rename a subscription + $action = $_POST['ac']; //Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit` + $add = isset($_POST['a']) ? $_POST['a'] : ''; //StreamId to add the subscription to (generally a user label) + $remove = isset($_POST['r']) ? $_POST['r'] : ''; //StreamId to remove the subscription from (generally a user label) + subscriptionEdit($streamNames, $titles $action, $add, $remove); + } + break; + } } break; case 'unread-count': -- cgit v1.2.3 From 44f22ab8b4c46befab98440f69a05725928bed75 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Sep 2016 17:36:33 +0200 Subject: API move feed to another category https://github.com/jangernert/FeedReader/issues/59 https://github.com/FreshRSS/FreshRSS/issues/443 --- app/Controllers/feedController.php | 14 +------------- app/Models/FeedDAO.php | 13 +++++++++++++ p/api/greader.php | 7 +++++-- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ffda1450d..c64b67a80 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -511,21 +511,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feed_id = Minz_Request::param('f_id'); $cat_id = Minz_Request::param('c_id'); - - if ($cat_id === false) { - // If category was not given get the default one. - $catDAO = new FreshRSS_CategoryDAO(); - $catDAO->checkDefault(); - $def_cat = $catDAO->getDefault(); - $cat_id = $def_cat->id(); - } - $feedDAO = FreshRSS_Factory::createFeedDao(); - $values = array('category' => $cat_id); - $feed = $feedDAO->searchById($feed_id); - if ($feed && ($feed->category() == $cat_id || - $feedDAO->updateFeed($feed_id, $values))) { + if ($feedDAO->moveFeed($feed_id, $cat_id)) { // TODO: return something useful } else { Minz_Log::warning('Cannot move feed `' . $feed_id . '` ' . diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 475d39286..2fd2c6194 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -136,6 +136,19 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { } } + public function moveFeed($feed_id, $cat_id) { + if ($cat_id <= 0) { + // If category was not given get the default one. + $catDAO = new FreshRSS_CategoryDAO(); + $catDAO->checkDefault(); + $def_cat = $catDAO->getDefault(); + $cat_id = $def_cat->id(); + } + $feed = $this->searchById($feed_id); + return $feed && ($feed->category() == $cat_id || + $this->updateFeed($feed_id, array('category' => $cat_id))); + } + public function deleteFeed($id) { $sql = 'DELETE FROM `' . $this->prefix . 'feed` WHERE id=?'; $stm = $this->bd->prepare($sql); diff --git a/p/api/greader.php b/p/api/greader.php index 3da1156c2..426f3fe44 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -337,14 +337,17 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' break; case 'edit': if ($feedId > 0) { - //TODO + if ($feedDAO->moveFeed($feed_id, $cat_id)) { + exit('OK'); + } else { + badRequest(); + } } break; } } } notImplemented(); - exit('OK'); } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count -- cgit v1.2.3 From f1f8ea2da3a9334d20d54c083735855c90a21d9e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Sep 2016 18:10:53 +0200 Subject: API fix change feed category --- p/api/greader.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 426f3fe44..7094fb381 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -288,12 +288,15 @@ function subscriptionList() { } function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') { + //logMe("subscriptionEdit()"); //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki switch ($action) { case 'subscribe': case 'unsubscribe': case 'edit': + break; default: + logMe("Bad action: $action"); badRequest(); } $addCatId = 0; @@ -305,7 +308,7 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' $c_name = basename($add); $cat = $categoryDAO->searchByName($c_name); $addCatId = $cat == null ? -1 : $cat->id(); - } else if ($remove != '' && strpos($remove, 'user/-/label/') { + } else if ($remove != '' && strpos($remove, 'user/-/label/')) { $addCatId = 1; //Default category } $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -328,21 +331,22 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' case 'subscribe': if ($feedId <= 0) { //TODO + } else { + badRequest(); } break; case 'unsubscribe': if ($feedId > 0) { //TODO + } else { + badRequest(); } break; case 'edit': - if ($feedId > 0) { - if ($feedDAO->moveFeed($feed_id, $cat_id)) { - exit('OK'); - } else { - badRequest(); - } + if ($feedId > 0 && $feedDAO->moveFeed($feedId, $addCatId)) { + exit('OK'); } + badRequest(); break; } } @@ -704,7 +708,7 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo $action = $_POST['ac']; //Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit` $add = isset($_POST['a']) ? $_POST['a'] : ''; //StreamId to add the subscription to (generally a user label) $remove = isset($_POST['r']) ? $_POST['r'] : ''; //StreamId to remove the subscription from (generally a user label) - subscriptionEdit($streamNames, $titles $action, $add, $remove); + subscriptionEdit($streamNames, $titles, $action, $add, $remove); } break; } -- cgit v1.2.3 From d6b4186040011aad16a173a1ceaa5a5084025470 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Sep 2016 19:26:40 +0200 Subject: API implement delete feed + refactor move feed --- app/Controllers/feedController.php | 45 ++++++++++++++++++++++++++++--------- app/Models/FeedDAO.php | 13 ----------- p/api/greader.php | 46 +++++++++++++++++--------------------- 3 files changed, 54 insertions(+), 50 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index c64b67a80..0ff27e0da 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -492,6 +492,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { return $updated_feeds; } + public static function moveFeed($feed_id, $cat_id) { + if ($feed_id <= 0) { + return false; + } + if ($cat_id <= 0) { + // If category was not given get the default one. + $catDAO = new FreshRSS_CategoryDAO(); + $catDAO->checkDefault(); + $def_cat = $catDAO->getDefault(); + $cat_id = $def_cat->id(); + } + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feed = $feedDAO->searchById($feed_id); + return $feed && ($feed->category() == $cat_id || + $feedDAO->updateFeed($feed_id, array('category' => $cat_id))); + } + /** * This action changes the category of a feed. * @@ -511,9 +528,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feed_id = Minz_Request::param('f_id'); $cat_id = Minz_Request::param('c_id'); - $feedDAO = FreshRSS_Factory::createFeedDao(); - if ($feedDAO->moveFeed($feed_id, $cat_id)) { + if (self::moveFeed($feed_id, $cat_id)) { // TODO: return something useful } else { Minz_Log::warning('Cannot move feed `' . $feed_id . '` ' . @@ -522,6 +538,21 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } + public static function deleteFeed($feed_id) { + $feedDAO = FreshRSS_Factory::createFeedDao(); + if ($feedDAO->deleteFeed($feed_id)) { + // TODO: Delete old favicon + + // Remove related queries + FreshRSS_Context::$user_conf->queries = remove_query_by_get( + 'f_' . $feed_id, FreshRSS_Context::$user_conf->queries); + FreshRSS_Context::$user_conf->save(); + + return true; + } + return false; + } + /** * This action deletes a feed. * @@ -540,21 +571,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if (!$redirect_url) { $redirect_url = array('c' => 'subscription', 'a' => 'index'); } - if (!Minz_Request::isPost()) { Minz_Request::forward($redirect_url, true); } $id = Minz_Request::param('id'); - $feedDAO = FreshRSS_Factory::createFeedDao(); - if ($feedDAO->deleteFeed($id)) { - // TODO: Delete old favicon - - // Remove related queries - FreshRSS_Context::$user_conf->queries = remove_query_by_get( - 'f_' . $id, FreshRSS_Context::$user_conf->queries); - FreshRSS_Context::$user_conf->save(); + if (self::deleteFeed($id)) { Minz_Request::good(_t('feedback.sub.feed.deleted'), $redirect_url); } else { Minz_Request::bad(_t('feedback.sub.feed.error'), $redirect_url); diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 2fd2c6194..475d39286 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -136,19 +136,6 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable { } } - public function moveFeed($feed_id, $cat_id) { - if ($cat_id <= 0) { - // If category was not given get the default one. - $catDAO = new FreshRSS_CategoryDAO(); - $catDAO->checkDefault(); - $def_cat = $catDAO->getDefault(); - $cat_id = $def_cat->id(); - } - $feed = $this->searchById($feed_id); - return $feed && ($feed->category() == $cat_id || - $this->updateFeed($feed_id, array('category' => $cat_id))); - } - public function deleteFeed($id) { $sql = 'DELETE FROM `' . $this->prefix . 'feed` WHERE id=?'; $stm = $this->bd->prepare($sql); diff --git a/p/api/greader.php b/p/api/greader.php index 7094fb381..9b07e0729 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -153,13 +153,12 @@ function authorizationToUser() { if (count($headerAuthX) === 2) { $user = $headerAuthX[0]; if (ctype_alnum($user)) { - $conf = get_user_configuration($user); - if (is_null($conf)) { + FreshRSS_Context::$user_conf = get_user_configuration($user); + if (FreshRSS_Context::$user_conf == null) { Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.'); unauthorized(); } - global $system_conf; - if ($headerAuthX[1] === sha1($system_conf->salt . $user . $conf->apiPasswordHash)) { + if ($headerAuthX[1] === sha1(FreshRSS_Context::$system_conf->salt . $user . FreshRSS_Context::$user_conf->apiPasswordHash)) { return $user; } else { logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); @@ -181,16 +180,15 @@ function clientLogin($email, $pass) { //http://web.archive.org/web/2013060409104 include_once(LIB_PATH . '/password_compat.php'); } - $conf = get_user_configuration($email); - if (is_null($conf)) { + FreshRSS_Context::$user_conf = get_user_configuration($email); + if (FreshRSS_Context::$user_conf == null) { Minz_Log::warning('Invalid API user ' . $email . ': configuration cannot be found.'); unauthorized(); } - if ($conf->apiPasswordHash != '' && password_verify($pass, $conf->apiPasswordHash)) { + if (FreshRSS_Context::$user_conf->apiPasswordHash != '' && password_verify($pass, FreshRSS_Context::$user_conf->apiPasswordHash)) { header('Content-Type: text/plain; charset=UTF-8'); - global $system_conf; - $auth = $email . '/' . sha1($system_conf->salt . $email . $conf->apiPasswordHash); + $auth = $email . '/' . sha1(FreshRSS_Context::$system_conf->salt . $email . FreshRSS_Context::$user_conf->apiPasswordHash); echo 'SID=', $auth, "\n", 'Auth=', $auth, "\n"; exit(); @@ -209,8 +207,7 @@ function token($conf) { //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); //logMe('token('. $user . ")"); //TODO: Implement real token that expires - global $system_conf; - $token = str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters + $token = str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); } @@ -219,8 +216,7 @@ function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); //logMe('checkToken(' . $token . ")"); - global $system_conf; - if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { + if ($token === str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } unauthorized(); @@ -261,8 +257,7 @@ function subscriptionList() { $stm->execute(); $res = $stm->fetchAll(PDO::FETCH_ASSOC); - global $system_conf; - $salt = $system_conf->salt; + $salt = FreshRSS_Context::$system_conf->salt; $subscriptions = array(); foreach ($res as $line) { @@ -296,7 +291,6 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' case 'edit': break; default: - logMe("Bad action: $action"); badRequest(); } $addCatId = 0; @@ -336,14 +330,14 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' } break; case 'unsubscribe': - if ($feedId > 0) { - //TODO + if ($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId)) { + exit('OK'); } else { badRequest(); } break; case 'edit': - if ($feedId > 0 && $feedDAO->moveFeed($feedId, $addCatId)) { + if ($feedId > 0 && FreshRSS_feed_Controller::moveFeed($feedId, $addCatId)) { exit('OK'); } badRequest(); @@ -620,17 +614,17 @@ $pathInfos = explode('/', $pathInfo); Minz_Configuration::register('system', DATA_PATH . '/config.php', DATA_PATH . '/config.default.php'); -$system_conf = Minz_Configuration::get('system'); -if (!$system_conf->api_enabled) { +FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); +if (!FreshRSS_Context::$system_conf->api_enabled) { serviceUnavailable(); } Minz_Session::init('FreshRSS'); $user = authorizationToUser(); -$conf = null; +FreshRSS_Context::$user_conf = null; if ($user !== '') { - $conf = get_user_configuration($user); + FreshRSS_Context::$user_conf = get_user_configuration($user); } //logMe('User => ' . $user); @@ -722,7 +716,7 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo break; case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/ $token = isset($_POST['T']) ? trim($_POST['T']) : ''; - checkToken($conf, $token); + checkToken(FreshRSS_Context::$user_conf, $token); $a = isset($_POST['a']) ? $_POST['a'] : ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred $r = isset($_POST['r']) ? $_POST['r'] : ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred $e_ids = multiplePosts('i'); //item IDs @@ -730,7 +724,7 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo break; case 'mark-all-as-read': $token = isset($_POST['T']) ? trim($_POST['T']) : ''; - checkToken($conf, $token); + checkToken(FreshRSS_Context::$user_conf, $token); $streamId = $_POST['s']; //StreamId $ts = isset($_POST['ts']) ? $_POST['ts'] : '0'; //Older than timestamp in nanoseconds if (!ctype_digit($ts)) { @@ -739,7 +733,7 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo markAllAsRead($streamId, $ts); break; case 'token': - token($conf); + token(FreshRSS_Context::$user_conf); break; } } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') { -- cgit v1.2.3 From 6a812b0d31df275d9b8b211a90628400ee097644 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Sep 2016 19:54:46 +0200 Subject: API rename feed --- app/Controllers/feedController.php | 12 +++++++++--- p/api/greader.php | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 0ff27e0da..0364424f5 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -492,6 +492,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController { return $updated_feeds; } + public static function renameFeed($feed_id, $feed_name) { + if ($feed_id <= 0 || $feed_name == '') { + return false; + } + $feedDAO = FreshRSS_Factory::createFeedDao(); + return $feedDAO->updateFeed($feed_id, array('name' => $feed_name)); + } + public static function moveFeed($feed_id, $cat_id) { if ($feed_id <= 0) { return false; @@ -504,9 +512,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $cat_id = $def_cat->id(); } $feedDAO = FreshRSS_Factory::createFeedDao(); - $feed = $feedDAO->searchById($feed_id); - return $feed && ($feed->category() == $cat_id || - $feedDAO->updateFeed($feed_id, array('category' => $cat_id))); + return $feedDAO->updateFeed($feed_id, array('category' => $cat_id)); } /** diff --git a/p/api/greader.php b/p/api/greader.php index 9b07e0729..131eb65c5 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -325,27 +325,32 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' case 'subscribe': if ($feedId <= 0) { //TODO + notImplemented(); } else { badRequest(); } break; case 'unsubscribe': - if ($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId)) { - exit('OK'); - } else { + if (!($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId))) { badRequest(); } break; case 'edit': - if ($feedId > 0 && FreshRSS_feed_Controller::moveFeed($feedId, $addCatId)) { - exit('OK'); + if ($feedId > 0) { + if ($addCatId > 0) { + FreshRSS_feed_Controller::moveFeed($feedId, $addCatId); + } + if ($title != '') { + FreshRSS_feed_Controller::renameFeed($feedId, $title); + } + } else { + badRequest(); } - badRequest(); break; } } } - notImplemented(); + exit('OK'); } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count -- cgit v1.2.3 From 71b98a0ffc41ea869e8c49c2889cda5b3e113030 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 25 Sep 2016 00:14:36 +0200 Subject: API add feed --- app/Controllers/feedController.php | 10 +++++----- p/api/greader.php | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index c6adc64cb..faf670e6e 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -26,7 +26,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - public static function addFeed($url, $cat_id = 0, $new_cat_name = '', $http_auth = '') { + public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { @set_time_limit(300); $catDAO = new FreshRSS_CategoryDAO(); @@ -40,9 +40,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } if ($cat == null) { $catDAO->checkDefault(); - $def_cat = $catDAO->getDefault(); - $cat = $def_cat->id(); + $cat = $catDAO->getDefault(); } + $cat_id = $cat->id(); $feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception $feed->_httpAuth($http_auth); @@ -63,7 +63,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $values = array( 'url' => $feed->url(), 'category' => $feed->category(), - 'name' => $feed->name(), + 'name' => $title != '' ? $title : $feed->name(), 'website' => $feed->website(), 'description' => $feed->description(), 'lastUpdate' => time(), @@ -149,7 +149,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } try { - $feed = self::addFeed($url, $cat, $new_cat_name, $http_auth); + $feed = self::addFeed($url, '', $cat, $new_cat_name, $http_auth); } catch (FreshRSS_BadUrl_Exception $e) { // Given url was not a valid url! Minz_Log::warning($e->getMessage()); diff --git a/p/api/greader.php b/p/api/greader.php index 131eb65c5..dc8dd92bc 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -298,18 +298,22 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' if ($add != '' || $remove != '') { $categoryDAO = new FreshRSS_CategoryDAO(); } + $c_name = ''; if ($add != '' && strpos($add, 'user/-/label/') === 0) { //user/-/label/Example - $c_name = basename($add); + $c_name = substr($add, 13); $cat = $categoryDAO->searchByName($c_name); $addCatId = $cat == null ? -1 : $cat->id(); } else if ($remove != '' && strpos($remove, 'user/-/label/')) { $addCatId = 1; //Default category } + if ($addCatId <= 0 && $c_name = '') { + $addCatId = 1; //Default category + } $feedDAO = FreshRSS_Factory::createFeedDao(); for ($i = count($streamNames) - 1; $i >= 0; $i--) { $streamName = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338 if (strpos($streamName, 'feed/') === 0) { - $streamName = basename($streamName); + $streamName = substr($streamName, 5); $feedId = 0; if (ctype_digit($streamName)) { if ($action === 'subscribe') { @@ -324,11 +328,15 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' switch ($action) { case 'subscribe': if ($feedId <= 0) { - //TODO - notImplemented(); - } else { - badRequest(); + $http_auth = ''; //TODO + try { + $feed = FreshRSS_feed_Controller::addFeed($streamName, $title, $addCatId, $c_name, $http_auth); + continue; + } catch (Exception $e) { + logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + } } + badRequest(); break; case 'unsubscribe': if (!($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId))) { -- cgit v1.2.3 From 36e6c10f21aa682a737aa3754750f8ee8820598e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 25 Sep 2016 01:05:00 +0200 Subject: API rename category --- p/api/greader.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index dc8dd92bc..96c2b2ee3 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -600,6 +600,22 @@ function editTag($e_ids, $a, $r) { exit('OK'); } +function renameTag($s, $dest) { + //logMe("renameTag()"); + if ($s != '' && strpos($s, 'user/-/label/') === 0 && + $dest != '' && strpos($dest, 'user/-/label/') === 0) { + $s = substr($s, 13); + $categoryDAO = new FreshRSS_CategoryDAO(); + $cat = $categoryDAO->searchByName($s); + if ($cat != null) { + $dest = substr($dest, 13); + $categoryDAO->updateCategory($cat->id(), array('name' => $dest)); + exit('OK'); + } + } + badRequest(); +} + function markAllAsRead($streamId, $olderThanId) { //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); @@ -735,6 +751,13 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo $e_ids = multiplePosts('i'); //item IDs editTag($e_ids, $a, $r); break; + case 'rename-tag': //https://github.com/theoldreader/api + $token = isset($_POST['T']) ? trim($_POST['T']) : ''; + checkToken(FreshRSS_Context::$user_conf, $token); + $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder + $dest = isset($_POST['dest']) ? $_POST['dest'] : ''; //user/-/label/NewFolder + renameTag($s, $dest); + break; case 'mark-all-as-read': $token = isset($_POST['T']) ? trim($_POST['T']) : ''; checkToken(FreshRSS_Context::$user_conf, $token); -- cgit v1.2.3 From 86a470b1483a8a0cb77ed00da53813f1777a1895 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 25 Sep 2016 01:11:52 +0200 Subject: API delete category --- p/api/greader.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'p/api/greader.php') diff --git a/p/api/greader.php b/p/api/greader.php index 96c2b2ee3..e77ef3726 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -616,6 +616,21 @@ function renameTag($s, $dest) { badRequest(); } +function disableTag($s, $dest) { + //logMe("renameTag()"); + if ($s != '' && strpos($s, 'user/-/label/') === 0) { + $s = substr($s, 13); + $categoryDAO = new FreshRSS_CategoryDAO(); + $cat = $categoryDAO->searchByName($s); + if ($cat != null) { + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feedDAO->changeCategory($cat->id(), 0); + exit('OK'); + } + } + badRequest(); +} + function markAllAsRead($streamId, $olderThanId) { //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); @@ -758,6 +773,12 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo $dest = isset($_POST['dest']) ? $_POST['dest'] : ''; //user/-/label/NewFolder renameTag($s, $dest); break; + case 'disable-tag': //https://github.com/theoldreader/api + $token = isset($_POST['T']) ? trim($_POST['T']) : ''; + checkToken(FreshRSS_Context::$user_conf, $token); + $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder + disableTag($s); + break; case 'mark-all-as-read': $token = isset($_POST['T']) ? trim($_POST['T']) : ''; checkToken(FreshRSS_Context::$user_conf, $token); -- cgit v1.2.3 From e1528845d8827716c11322f15a5f9ce1523fd2d7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 25 Sep 2016 15:45:06 +0200 Subject: API subscription/quickadd https://github.com/FreshRSS/FreshRSS/issues/1254 --- CHANGELOG.md | 2 +- p/api/greader.php | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'p/api/greader.php') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c8dbec9b..a1fe033bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2016-XX-XX FreshRSS 1.6.0-dev * API - * Support for editing feeds and categories from client applications [#1261](https://github.com/FreshRSS/FreshRSS/pull/1261) + * Support for editing feeds and categories from client applications [#1254](https://github.com/FreshRSS/FreshRSS/issues/1254) * Features * Better control of number of entries per page or RSS feed [#1249](https://github.com/FreshRSS/FreshRSS/issues/1249) * Since X hours: `https://freshrss.example/i/?a=rss&hours=3` diff --git a/p/api/greader.php b/p/api/greader.php index e77ef3726..e2d7dc039 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -361,6 +361,23 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' exit('OK'); } +function quickadd($url) { + //logMe("quickadd($url)"); + try { + $feed = FreshRSS_feed_Controller::addFeed($url); + exit(json_encode(array( + 'numResults' => 1, + 'streamId' => $feed->id(), + ))); + } catch (Exception $e) { + logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + die(json_encode(array( + 'numResults' => 0, + 'error' => $e->getMessage(), + ))); + } +} + function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); @@ -531,7 +548,7 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude $id = basename($streamId); } elseif (strpos($streamId, 'user/-/label/') === 0) { $type = 'c'; - $c_name = basename($streamId); + $c_name = substr($streamId, 13); $categoryDAO = new FreshRSS_CategoryDAO(); $cat = $categoryDAO->searchByName($c_name); $id = $cat == null ? -1 : $cat->id(); @@ -638,7 +655,7 @@ function markAllAsRead($streamId, $olderThanId) { $f_id = basename($streamId); $entryDAO->markReadFeed($f_id, $olderThanId); } elseif (strpos($streamId, 'user/-/label/') === 0) { - $c_name = basename($streamId); + $c_name = substr($streamId, 13); $categoryDAO = new FreshRSS_CategoryDAO(); $cat = $categoryDAO->searchByName($c_name); $entryDAO->markReadCat($cat === null ? -1 : $cat->id(), $olderThanId); @@ -749,6 +766,11 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo subscriptionEdit($streamNames, $titles, $action, $add, $remove); } break; + case 'quickadd': //https://github.com/theoldreader/api + if (isset($_GET['quickadd'])) { + quickadd($_GET['quickadd']); + } + break; } } break; -- cgit v1.2.3 From 9291748c4745ff8f4be2beaa2998869fd26e907e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 26 Sep 2016 10:44:44 +0200 Subject: API implement user-info and fix edits https://github.com/FreshRSS/FreshRSS/issues/1254 https://github.com/jangernert/FeedReader/issues/59#issuecomment-249491580 --- app/Controllers/feedController.php | 20 +++++++++++----- app/Models/CategoryDAO.php | 3 +++ data/users/_/config.default.php | 1 + p/api/greader.php | 47 ++++++++++++++++++++++++++++++-------- 4 files changed, 55 insertions(+), 16 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index faf670e6e..ca7a818c6 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -473,17 +473,25 @@ class FreshRSS_feed_Controller extends Minz_ActionController { return $feedDAO->updateFeed($feed_id, array('name' => $feed_name)); } - public static function moveFeed($feed_id, $cat_id) { + public static function moveFeed($feed_id, $cat_id, $new_cat_name = '') { if ($feed_id <= 0) { return false; } - if ($cat_id <= 0) { - // If category was not given get the default one. - $catDAO = new FreshRSS_CategoryDAO(); + + $catDAO = new FreshRSS_CategoryDAO(); + if ($cat_id > 0) { + $cat = $catDAO->searchById($cat_id); + $cat_id = $cat == null ? 0 : $cat->id(); + } + if ($cat_id <= 1 && $new_cat_name != '') { + $cat_id = $catDAO->addCategory(array('name' => $new_cat_name)); + } + if ($cat_id <= 1) { $catDAO->checkDefault(); - $def_cat = $catDAO->getDefault(); - $cat_id = $def_cat->id(); + $cat = $catDAO->getDefault(); + $cat_id = $cat->id(); } + $feedDAO = FreshRSS_Factory::createFeedDao(); return $feedDAO->updateFeed($feed_id, array('category' => $cat_id)); } diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index fc431553e..c103163a1 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -50,6 +50,9 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable } public function deleteCategory($id) { + if ($id <= 1) { + return false; + } $sql = 'DELETE FROM `' . $this->prefix . 'category` WHERE id=?'; $stm = $this->bd->prepare($sql); diff --git a/data/users/_/config.default.php b/data/users/_/config.default.php index 2c56d5f45..6e1d497bc 100644 --- a/data/users/_/config.default.php +++ b/data/users/_/config.default.php @@ -5,6 +5,7 @@ return array ( 'old_entries' => 3, 'keep_history_default' => 0, 'ttl_default' => 3600, + 'mail_login' => '', 'token' => '', 'passwordHash' => '', 'apiPasswordHash' => '', diff --git a/p/api/greader.php b/p/api/greader.php index e2d7dc039..8b1e0ffb1 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -222,6 +222,17 @@ function checkToken($conf, $token) { unauthorized(); } +function userInfo() { //https://github.com/theoldreader/api#user-info + //logMe("userInfo()"); + $user = Minz_Session::param('currentUser', '_'); + exit(json_encode(array( + 'userId' => $user, + 'userName' => $user, + 'userProfileId' => $user, + 'userEmail' => FreshRSS_Context::$user_conf->mail_login, + ))); +} + function tagList() { //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); @@ -299,14 +310,24 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' $categoryDAO = new FreshRSS_CategoryDAO(); } $c_name = ''; - if ($add != '' && strpos($add, 'user/-/label/') === 0) { //user/-/label/Example - $c_name = substr($add, 13); + if ($add != '' && strpos($add, 'user/') === 0) { //user/-/label/Example ; user/username/label/Example + if (strpos($add, 'user/-/label/') === 0) { + $c_name = substr($add, 13); + } else { + $user = Minz_Session::param('currentUser', '_'); + $prefix = 'user/' . $user . '/label/'; + if (strpos($add, $prefix) === 0) { + $c_name = substr($add, strlen($prefix)); + } else { + $c_name = ''; + } + } $cat = $categoryDAO->searchByName($c_name); $addCatId = $cat == null ? -1 : $cat->id(); } else if ($remove != '' && strpos($remove, 'user/-/label/')) { $addCatId = 1; //Default category } - if ($addCatId <= 0 && $c_name = '') { + if ($addCatId <= 0 && $c_name == '') { $addCatId = 1; //Default category } $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -345,9 +366,7 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' break; case 'edit': if ($feedId > 0) { - if ($addCatId > 0) { - FreshRSS_feed_Controller::moveFeed($feedId, $addCatId); - } + FreshRSS_feed_Controller::moveFeed($feedId, $addCatId, $c_name); if ($title != '') { FreshRSS_feed_Controller::renameFeed($feedId, $title); } @@ -633,8 +652,8 @@ function renameTag($s, $dest) { badRequest(); } -function disableTag($s, $dest) { - //logMe("renameTag()"); +function disableTag($s) { + //logMe("disableTag($s)"); if ($s != '' && strpos($s, 'user/-/label/') === 0) { $s = substr($s, 13); $categoryDAO = new FreshRSS_CategoryDAO(); @@ -642,6 +661,9 @@ function disableTag($s, $dest) { if ($cat != null) { $feedDAO = FreshRSS_Factory::createFeedDao(); $feedDAO->changeCategory($cat->id(), 0); + if ($cat->id() > 1) { + $categoryDAO->deleteCategory($cat->id()); + } exit('OK'); } } @@ -798,8 +820,10 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo case 'disable-tag': //https://github.com/theoldreader/api $token = isset($_POST['T']) ? trim($_POST['T']) : ''; checkToken(FreshRSS_Context::$user_conf, $token); - $s = isset($_POST['s']) ? $_POST['s'] : ''; //user/-/label/Folder - disableTag($s); + $s_s = multiplePosts('s'); + foreach ($s_s as $s) { + disableTag($s); //user/-/label/Folder + } break; case 'mark-all-as-read': $token = isset($_POST['T']) ? trim($_POST['T']) : ''; @@ -814,6 +838,9 @@ elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfo case 'token': token(FreshRSS_Context::$user_conf); break; + case 'user-info': + userInfo(); + break; } } elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') { checkCompatibility(); -- cgit v1.2.3 From d5ca360ca967d327a184429a2e37aed196add7a0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 26 Sep 2016 15:20:02 +0200 Subject: API fix feed rename https://github.com/FreshRSS/FreshRSS/issues/1254 https://github.com/jangernert/FeedReader/issues/59#issuecomment-249558202 --- app/Controllers/feedController.php | 2 +- p/api/greader.php | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'p/api/greader.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index ca7a818c6..c2a22aeb3 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -474,7 +474,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } public static function moveFeed($feed_id, $cat_id, $new_cat_name = '') { - if ($feed_id <= 0) { + if ($feed_id <= 0 || ($cat_id <= 0 && $new_cat_name == '')) { return false; } diff --git a/p/api/greader.php b/p/api/greader.php index 8b1e0ffb1..4965ffd3b 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -323,13 +323,10 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' } } $cat = $categoryDAO->searchByName($c_name); - $addCatId = $cat == null ? -1 : $cat->id(); + $addCatId = $cat == null ? 0 : $cat->id(); } else if ($remove != '' && strpos($remove, 'user/-/label/')) { $addCatId = 1; //Default category } - if ($addCatId <= 0 && $c_name == '') { - $addCatId = 1; //Default category - } $feedDAO = FreshRSS_Factory::createFeedDao(); for ($i = count($streamNames) - 1; $i >= 0; $i--) { $streamName = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338 @@ -366,7 +363,9 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' break; case 'edit': if ($feedId > 0) { - FreshRSS_feed_Controller::moveFeed($feedId, $addCatId, $c_name); + if ($addCatId > 0 || $c_name != '') { + FreshRSS_feed_Controller::moveFeed($feedId, $addCatId, $c_name); + } if ($title != '') { FreshRSS_feed_Controller::renameFeed($feedId, $title); } -- cgit v1.2.3