|
|
@@ -785,9 +785,11 @@ final class GReaderAPI {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param array<string> $e_ids
|
|
|
+ * @param array<string> $e_ids IDs of the items to edit
|
|
|
+ * @param array<string> $as tags to add to all the listed items
|
|
|
+ * @param array<string> $rs tags to remove from all the listed items
|
|
|
*/
|
|
|
- private static function editTag(array $e_ids, string $a, string $r): never {
|
|
|
+ private static function editTag(array $e_ids, array $as, array $rs): never {
|
|
|
foreach ($e_ids as $i => $e_id) {
|
|
|
if (!ctype_digit($e_id) || $e_id[0] === '0') {
|
|
|
$e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/'
|
|
|
@@ -798,64 +800,73 @@ final class GReaderAPI {
|
|
|
$entryDAO = FreshRSS_Factory::createEntryDao();
|
|
|
$tagDAO = FreshRSS_Factory::createTagDao();
|
|
|
|
|
|
- switch ($a) {
|
|
|
- case 'user/-/state/com.google/read':
|
|
|
- $entryDAO->markRead($e_ids, true);
|
|
|
- break;
|
|
|
- case 'user/-/state/com.google/starred':
|
|
|
- $entryDAO->markFavorite($e_ids, true);
|
|
|
- break;
|
|
|
- /*case 'user/-/state/com.google/tracking-kept-unread':
|
|
|
- break;
|
|
|
- case 'user/-/state/com.google/like':
|
|
|
- break;
|
|
|
- case 'user/-/state/com.google/broadcast':
|
|
|
- break;*/
|
|
|
- default:
|
|
|
- $tagName = '';
|
|
|
- if (str_starts_with($a, 'user/-/label/')) {
|
|
|
- $tagName = substr($a, 13);
|
|
|
- } else {
|
|
|
- $user = Minz_User::name() ?? '';
|
|
|
- $prefix = 'user/' . $user . '/label/';
|
|
|
- if (str_starts_with($a, $prefix)) {
|
|
|
- $tagName = substr($a, strlen($prefix));
|
|
|
+ foreach ($as as $a) {
|
|
|
+ switch ($a) {
|
|
|
+ case 'user/-/state/com.google/read':
|
|
|
+ $entryDAO->markRead($e_ids, true);
|
|
|
+ break;
|
|
|
+ case 'user/-/state/com.google/starred':
|
|
|
+ $entryDAO->markFavorite($e_ids, true);
|
|
|
+ break;
|
|
|
+ case 'user/-/state/com.google/broadcast':
|
|
|
+ case 'user/-/state/com.google/like':
|
|
|
+ case 'user/-/state/com.google/tracking-kept-unread':
|
|
|
+ // Not supported
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $tagName = '';
|
|
|
+ if (str_starts_with($a, 'user/-/label/')) {
|
|
|
+ $tagName = substr($a, 13);
|
|
|
+ } else {
|
|
|
+ $user = Minz_User::name() ?? '';
|
|
|
+ $prefix = 'user/' . $user . '/label/';
|
|
|
+ if (str_starts_with($a, $prefix)) {
|
|
|
+ $tagName = substr($a, strlen($prefix));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if ($tagName != '') {
|
|
|
- $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
|
|
|
- $tag = $tagDAO->searchByName($tagName);
|
|
|
- if ($tag == null) {
|
|
|
- $tagDAO->addTag(['name' => $tagName]);
|
|
|
+ if ($tagName !== '') {
|
|
|
+ $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
|
|
|
$tag = $tagDAO->searchByName($tagName);
|
|
|
- }
|
|
|
- if ($tag != null) {
|
|
|
- foreach ($e_ids as $e_id) {
|
|
|
- $tagDAO->tagEntry($tag->id(), $e_id, true);
|
|
|
+ if ($tag === null) {
|
|
|
+ $tagDAO->addTag(['name' => $tagName]);
|
|
|
+ $tag = $tagDAO->searchByName($tagName);
|
|
|
+ }
|
|
|
+ if ($tag !== null) {
|
|
|
+ foreach ($e_ids as $e_id) {
|
|
|
+ $tagDAO->tagEntry($tag->id(), $e_id, true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- break;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- switch ($r) {
|
|
|
- case 'user/-/state/com.google/read':
|
|
|
- $entryDAO->markRead($e_ids, false);
|
|
|
- break;
|
|
|
- case 'user/-/state/com.google/starred':
|
|
|
- $entryDAO->markFavorite($e_ids, false);
|
|
|
- break;
|
|
|
- default:
|
|
|
- if (str_starts_with($r, 'user/-/label/')) {
|
|
|
- $tagName = substr($r, 13);
|
|
|
- $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
|
|
|
- $tag = $tagDAO->searchByName($tagName);
|
|
|
- if ($tag != null) {
|
|
|
- foreach ($e_ids as $e_id) {
|
|
|
- $tagDAO->tagEntry($tag->id(), $e_id, false);
|
|
|
+
|
|
|
+ foreach ($rs as $r) {
|
|
|
+ switch ($r) {
|
|
|
+ case 'user/-/state/com.google/read':
|
|
|
+ $entryDAO->markRead($e_ids, false);
|
|
|
+ break;
|
|
|
+ case 'user/-/state/com.google/starred':
|
|
|
+ $entryDAO->markFavorite($e_ids, false);
|
|
|
+ break;
|
|
|
+ case 'user/-/state/com.google/broadcast':
|
|
|
+ case 'user/-/state/com.google/like':
|
|
|
+ case 'user/-/state/com.google/tracking-kept-unread':
|
|
|
+ // Not supported
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if (str_starts_with($r, 'user/-/label/')) {
|
|
|
+ $tagName = substr($r, 13);
|
|
|
+ $tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
|
|
|
+ $tag = $tagDAO->searchByName($tagName);
|
|
|
+ if ($tag !== null) {
|
|
|
+ foreach ($e_ids as $e_id) {
|
|
|
+ $tagDAO->tagEntry($tag->id(), $e_id, false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- break;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
exit('OK');
|
|
|
@@ -1153,10 +1164,12 @@ final class GReaderAPI {
|
|
|
case 'edit-tag': //http://blog.martindoms.com/2010/01/20/using-the-google-reader-api-part-3/
|
|
|
$token = isset($_POST['T']) ? trim($_POST['T']) : '';
|
|
|
self::checkToken(FreshRSS_Context::userConf(), $token);
|
|
|
- $a = $_POST['a'] ?? ''; //Add: user/-/state/com.google/read user/-/state/com.google/starred
|
|
|
- $r = $_POST['r'] ?? ''; //Remove: user/-/state/com.google/read user/-/state/com.google/starred
|
|
|
+ // Add (Can be repeated to add multiple tags at once): user/-/state/com.google/read user/-/state/com.google/starred
|
|
|
+ $as = multiplePosts('a');
|
|
|
+ // Remove (Can be repeated to remove multiple tags at once): user/-/state/com.google/read user/-/state/com.google/starred
|
|
|
+ $rs = multiplePosts('r');
|
|
|
$e_ids = multiplePosts('i'); //item IDs
|
|
|
- self::editTag($e_ids, $a, $r);
|
|
|
+ self::editTag($e_ids, $as, $rs);
|
|
|
// Always exits
|
|
|
case 'rename-tag': //https://github.com/theoldreader/api
|
|
|
$token = isset($_POST['T']) ? trim($_POST['T']) : '';
|