Browse Source

API fix default category (#7610)

fix https://github.com/FreshRSS/FreshRSS/issues/7368
Alexandre Alapetite 10 months ago
parent
commit
80c9623f8f
1 changed files with 9 additions and 6 deletions
  1. 9 6
      p/api/greader.php

+ 9 - 6
p/api/greader.php

@@ -332,7 +332,6 @@ final class GReaderAPI {
 			self::internalServerError();
 		}
 		header('Content-Type: application/json; charset=UTF-8');
-		$salt = FreshRSS_Context::systemConf()->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 = [];
@@ -396,11 +395,15 @@ final class GReaderAPI {
 				}
 			}
 			$c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8');
-			$categoryDAO = FreshRSS_Factory::createCategoryDao();
-			$cat = $categoryDAO->searchByName($c_name);
-			$addCatId = $cat === null ? 0 : $cat->id();
-			if ($addCatId === 0) {
-				$addCatId = $categoryDAO->addCategory(['name' => $c_name]) ?: FreshRSS_CategoryDAO::DEFAULTCATEGORYID;
+			if (in_array($c_name, ['', 'Uncategorized', _t('gen.short.default_category')], true)) {
+				$addCatId = FreshRSS_CategoryDAO::DEFAULTCATEGORYID;
+			} else {
+				$categoryDAO = FreshRSS_Factory::createCategoryDao();
+				$cat = $categoryDAO->searchByName($c_name);
+				$addCatId = $cat === null ? 0 : $cat->id();
+				if ($addCatId === 0) {
+					$addCatId = $categoryDAO->addCategory(['name' => $c_name]) ?: FreshRSS_CategoryDAO::DEFAULTCATEGORYID;
+				}
 			}
 		} elseif (str_starts_with($remove, 'user/-/label/')) {
 			$addCatId = FreshRSS_CategoryDAO::DEFAULTCATEGORYID;