Context.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * The context object handles the current configuration file and different
  5. * useful functions associated to the current view state.
  6. */
  7. final class FreshRSS_Context {
  8. /** @var array<int,FreshRSS_Category> where the key is the category ID */
  9. private static array $categories = [];
  10. /** @var array<int,FreshRSS_Tag> where the key is the label ID */
  11. private static array $tags = [];
  12. public static string $name = '';
  13. public static string $description = '';
  14. public static int $total_unread = 0;
  15. public static int $total_important_unread = 0;
  16. /** @var array{all:int,read:int,unread:int} */
  17. public static array $total_starred = [
  18. 'all' => 0,
  19. 'read' => 0,
  20. 'unread' => 0,
  21. ];
  22. public static int $get_unread = 0;
  23. /** @var array{all:bool,A:bool,starred:bool,important:bool,feed:int|false,category:int|false,tag:int|false,tags:bool,Z:bool} */
  24. public static array $current_get = [
  25. 'all' => false,
  26. 'A' => false,
  27. 'starred' => false,
  28. 'important' => false,
  29. 'feed' => false,
  30. 'category' => false,
  31. 'tag' => false,
  32. 'tags' => false,
  33. 'Z' => false,
  34. ];
  35. public static string $next_get = 'a';
  36. public static int $state = 0;
  37. /** @var 'ASC'|'DESC' */
  38. public static string $order = 'DESC';
  39. /** @var 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' */
  40. public static string $sort = 'id';
  41. public static int $number = 0;
  42. public static int $offset = 0;
  43. public static FreshRSS_BooleanSearch $search;
  44. /** @var numeric-string */
  45. public static string $continuation_id = '0';
  46. /** @var numeric-string */
  47. public static string $id_max = '0';
  48. public static int $sinceHours = 0;
  49. public static bool $isCli = false;
  50. /**
  51. * @access private
  52. * @deprecated Will be made `private`; use `FreshRSS_Context::systemConf()` instead.
  53. * @internal
  54. */
  55. public static ?FreshRSS_SystemConfiguration $system_conf = null;
  56. /**
  57. * @access private
  58. * @deprecated Will be made `private`; use `FreshRSS_Context::userConf()` instead.
  59. * @internal
  60. */
  61. public static ?FreshRSS_UserConfiguration $user_conf = null;
  62. /**
  63. * Initialize the context for the global system.
  64. */
  65. public static function initSystem(bool $reload = false): void {
  66. if ($reload || FreshRSS_Context::$system_conf === null) {
  67. //TODO: Keep in session what we need instead of always reloading from disk
  68. FreshRSS_Context::$system_conf = FreshRSS_SystemConfiguration::init(DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');
  69. }
  70. }
  71. /**
  72. * @throws FreshRSS_Context_Exception
  73. */
  74. public static function &systemConf(): FreshRSS_SystemConfiguration {
  75. if (FreshRSS_Context::$system_conf === null) {
  76. throw new FreshRSS_Context_Exception('System configuration not initialised!');
  77. }
  78. return FreshRSS_Context::$system_conf;
  79. }
  80. public static function hasSystemConf(): bool {
  81. return FreshRSS_Context::$system_conf !== null;
  82. }
  83. /**
  84. * Initialize the context for the current user.
  85. */
  86. public static function initUser(string $username = '', bool $userMustExist = true): void {
  87. FreshRSS_Context::$user_conf = null;
  88. if (!isset($_SESSION)) {
  89. Minz_Session::init('FreshRSS');
  90. }
  91. Minz_Session::lock();
  92. if ($username == '') {
  93. $username = Minz_User::name() ?? '';
  94. }
  95. if (($username === Minz_User::INTERNAL_USER || FreshRSS_user_Controller::checkUsername($username)) &&
  96. (!$userMustExist || FreshRSS_user_Controller::userExists($username))) {
  97. try {
  98. //TODO: Keep in session what we need instead of always reloading from disk
  99. FreshRSS_Context::$user_conf = FreshRSS_UserConfiguration::init(
  100. USERS_PATH . '/' . $username . '/config.php',
  101. FRESHRSS_PATH . '/config-user.default.php');
  102. Minz_User::change($username);
  103. } catch (Exception $ex) {
  104. Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/' . LOG_FILENAME);
  105. }
  106. }
  107. if (FreshRSS_Context::$user_conf == null) {
  108. Minz_Session::_params([
  109. 'loginOk' => false,
  110. Minz_User::CURRENT_USER => false,
  111. ]);
  112. }
  113. Minz_Session::unlock();
  114. if (FreshRSS_Context::$user_conf == null) {
  115. return;
  116. }
  117. FreshRSS_Context::$search = new FreshRSS_BooleanSearch('');
  118. //Legacy
  119. $oldEntries = FreshRSS_Context::$user_conf->attributeInt('old_entries') ?? 0;
  120. $keepMin = FreshRSS_Context::$user_conf->attributeInt('keep_history_default') ?? -5;
  121. if ($oldEntries > 0 || $keepMin > -5) { //Freshrss < 1.15
  122. $archiving = FreshRSS_Context::$user_conf->archiving;
  123. $archiving['keep_max'] = false;
  124. if ($oldEntries > 0) {
  125. $archiving['keep_period'] = 'P' . $oldEntries . 'M';
  126. }
  127. if ($keepMin > 0) {
  128. $archiving['keep_min'] = $keepMin;
  129. } elseif ($keepMin == -1) { //Infinite
  130. $archiving['keep_period'] = false;
  131. $archiving['keep_min'] = false;
  132. }
  133. FreshRSS_Context::$user_conf->archiving = $archiving;
  134. }
  135. //Legacy < 1.16.1
  136. if (!in_array(FreshRSS_Context::$user_conf->display_categories, [ 'active', 'remember', 'all', 'none' ], true)) {
  137. FreshRSS_Context::$user_conf->display_categories = FreshRSS_Context::$user_conf->display_categories === true ? 'all' : 'active';
  138. }
  139. // FreshRSS 1.27.1+
  140. if (isset(FreshRSS_Context::$user_conf->shortcuts['close_dropdown'])) {
  141. $shortcuts = FreshRSS_Context::$user_conf->shortcuts;
  142. $shortcuts['close_menus'] = $shortcuts['close_dropdown'];
  143. unset($shortcuts['close_dropdown']);
  144. FreshRSS_Context::$user_conf->shortcuts = $shortcuts;
  145. FreshRSS_Context::$user_conf->save();
  146. }
  147. FreshRSS_Context::$user_conf->language = preg_replace_callback(
  148. '/-(\\w{2})$/',
  149. static fn (array $matches): string => strtoupper($matches[0]),
  150. FreshRSS_Context::$user_conf->language ?? Minz_Translate::DEFAULT_LANGUAGE
  151. ) ?? Minz_Translate::DEFAULT_LANGUAGE;
  152. }
  153. /**
  154. * @throws FreshRSS_Context_Exception
  155. */
  156. public static function &userConf(): FreshRSS_UserConfiguration {
  157. if (FreshRSS_Context::$user_conf === null) {
  158. throw new FreshRSS_Context_Exception('User configuration not initialised!');
  159. }
  160. return FreshRSS_Context::$user_conf;
  161. }
  162. public static function hasUserConf(): bool {
  163. return FreshRSS_Context::$user_conf !== null;
  164. }
  165. public static function clearUserConf(): void {
  166. FreshRSS_Context::$user_conf = null;
  167. }
  168. /**
  169. * @internal
  170. */
  171. public static function setUserConf(?FreshRSS_UserConfiguration $user_conf): void {
  172. FreshRSS_Context::$user_conf = $user_conf;
  173. }
  174. /** @return array<int,FreshRSS_Category> where the key is the category ID */
  175. public static function categories(): array {
  176. if (empty(self::$categories)) {
  177. $catDAO = FreshRSS_Factory::createCategoryDao();
  178. self::$categories = $catDAO->listSortedCategories(prePopulateFeeds: true, details: false);
  179. }
  180. return self::$categories;
  181. }
  182. /** @return array<int,FreshRSS_Feed> where the key is the feed ID */
  183. public static function feeds(): array {
  184. return FreshRSS_Category::findFeeds(self::categories());
  185. }
  186. /** @return array<int,FreshRSS_Tag> where the key is the label ID */
  187. public static function labels(bool $precounts = false): array {
  188. if (empty(self::$tags) || $precounts) {
  189. $tagDAO = FreshRSS_Factory::createTagDao();
  190. self::$tags = $tagDAO->listTags($precounts);
  191. }
  192. return self::$tags;
  193. }
  194. /**
  195. * This action updates the Context object by using request parameters.
  196. *
  197. * HTTP GET request parameters are:
  198. * - state (default: conf->default_view)
  199. * - search (default: empty string)
  200. * - order (default: conf->sort_order)
  201. * - nb (default: conf->posts_per_page)
  202. * - next (default: empty string)
  203. * - hours (default: 0)
  204. * @throws FreshRSS_Context_Exception
  205. * @throws Minz_ConfigurationNamespaceException
  206. * @throws Minz_PDOConnectionException
  207. */
  208. public static function updateUsingRequest(bool $computeStatistics): void {
  209. if ($computeStatistics && self::$total_unread === 0) {
  210. // Update number of read / unread variables.
  211. $entryDAO = FreshRSS_Factory::createEntryDao();
  212. self::$total_starred = $entryDAO->countUnreadReadFavorites();
  213. self::$total_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_MAIN_STREAM);
  214. self::$total_important_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_IMPORTANT);
  215. }
  216. self::_get(Minz_Request::paramString('get', plaintext: true) ?: 'a');
  217. self::$state = Minz_Request::paramInt('state') ?: FreshRSS_Context::userConf()->default_state;
  218. $state_forced_by_user = Minz_Request::paramString('state', plaintext: true) !== '';
  219. if (!$state_forced_by_user) {
  220. if (FreshRSS_Context::userConf()->show_fav_unread && (self::isCurrentGet('s') || self::isCurrentGet('T') || self::isTag())) {
  221. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  222. } elseif (FreshRSS_Context::userConf()->default_view === 'all') {
  223. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  224. } elseif (FreshRSS_Context::userConf()->default_view === 'unread_or_favorite') {
  225. self::$state = FreshRSS_Entry::STATE_OR_NOT_READ | FreshRSS_Entry::STATE_OR_FAVORITE;
  226. } elseif (FreshRSS_Context::userConf()->default_view === 'adaptive' && self::$get_unread <= 0) {
  227. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  228. }
  229. }
  230. self::$search = new FreshRSS_BooleanSearch(Minz_Request::paramString('search', plaintext: true));
  231. $order = Minz_Request::paramString('order', plaintext: true) ?: FreshRSS_Context::userConf()->sort_order;
  232. self::$order = in_array($order, ['ASC', 'DESC'], true) ? $order : 'DESC';
  233. $sort = Minz_Request::paramString('sort', plaintext: true) ?: FreshRSS_Context::userConf()->sort;
  234. self::$sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand', 'lastUserModified', 'length'], true) ? $sort : 'id';
  235. self::$number = Minz_Request::paramInt('nb') ?: FreshRSS_Context::userConf()->posts_per_page;
  236. if (self::$number > FreshRSS_Context::userConf()->max_posts_per_rss) {
  237. self::$number = max(
  238. FreshRSS_Context::userConf()->max_posts_per_rss,
  239. FreshRSS_Context::userConf()->posts_per_page);
  240. }
  241. self::$offset = Minz_Request::paramInt('offset');
  242. $id_max = Minz_Request::paramString('idMax', plaintext: true);
  243. self::$id_max = ctype_digit($id_max) ? $id_max : '0';
  244. $continuation_id = Minz_Request::paramString('cid', plaintext: true);
  245. self::$continuation_id = ctype_digit($continuation_id) ? $continuation_id : '0';
  246. self::$sinceHours = Minz_Request::paramInt('hours');
  247. }
  248. /**
  249. * Returns if the current state includes $state parameter.
  250. */
  251. public static function isStateEnabled(int $state): int {
  252. return self::$state & $state;
  253. }
  254. /**
  255. * Returns the current state with or without $state parameter.
  256. */
  257. public static function getRevertState(int $state): int {
  258. if (self::$state & $state) {
  259. return self::$state & ~$state;
  260. }
  261. return self::$state | $state;
  262. }
  263. /**
  264. * Return the current get as a string or an array.
  265. *
  266. * If $array is true, the first item of the returned value is 'f' or 'c' or 't' and the second is the id.
  267. * @phpstan-return ($asArray is true ? array{'a'|'A'|'c'|'f'|'i'|'s'|'t'|'T'|'Z',bool|int} : string)
  268. * @return string|array{string,bool|int}
  269. */
  270. public static function currentGet(bool $asArray = false): string|array {
  271. if (self::$current_get['all']) {
  272. return $asArray ? ['a', true] : 'a';
  273. } elseif (self::$current_get['A']) {
  274. return $asArray ? ['A', true] : 'A';
  275. } elseif (self::$current_get['important']) {
  276. return $asArray ? ['i', true] : 'i';
  277. } elseif (self::$current_get['starred']) {
  278. return $asArray ? ['s', true] : 's';
  279. } elseif (self::$current_get['feed']) {
  280. if ($asArray) {
  281. return ['f', self::$current_get['feed']];
  282. } else {
  283. return 'f_' . self::$current_get['feed'];
  284. }
  285. } elseif (self::$current_get['category']) {
  286. if ($asArray) {
  287. return ['c', self::$current_get['category']];
  288. } else {
  289. return 'c_' . self::$current_get['category'];
  290. }
  291. } elseif (self::$current_get['tag']) {
  292. if ($asArray) {
  293. return ['t', self::$current_get['tag']];
  294. } else {
  295. return 't_' . self::$current_get['tag'];
  296. }
  297. } elseif (self::$current_get['tags']) {
  298. return $asArray ? ['T', true] : 'T';
  299. } elseif (self::$current_get['Z']) {
  300. return $asArray ? ['Z', true] : 'Z';
  301. }
  302. return '';
  303. }
  304. /**
  305. * @return bool true if the current request targets all feeds (main view), false otherwise.
  306. */
  307. public static function isAll(): bool {
  308. return self::$current_get['all'] != false;
  309. }
  310. public static function isAllAndCategories(): bool {
  311. return self::$current_get['A'] != false;
  312. }
  313. public static function isAllAndArchived(): bool {
  314. return self::$current_get['Z'] != false;
  315. }
  316. /**
  317. * @return bool true if the current request targets important feeds, false otherwise.
  318. */
  319. public static function isImportant(): bool {
  320. return self::$current_get['important'] != false;
  321. }
  322. /**
  323. * @return bool true if the current request targets a category, false otherwise.
  324. */
  325. public static function isCategory(): bool {
  326. return self::$current_get['category'] != false;
  327. }
  328. /**
  329. * @return bool true if the current request targets a feed (and not a category or all articles), false otherwise.
  330. */
  331. public static function isFeed(): bool {
  332. return self::$current_get['feed'] != false;
  333. }
  334. /**
  335. * @return bool true if the current request targets a tag (though not all tags), false otherwise.
  336. */
  337. public static function isTag(): bool {
  338. return self::$current_get['tag'] != false;
  339. }
  340. /**
  341. * @return bool whether $get parameter corresponds to the $current_get attribute.
  342. */
  343. public static function isCurrentGet(string $get): bool {
  344. $type = substr($get, 0, 1);
  345. $id = substr($get, 2);
  346. return match ($type) {
  347. 'a' => self::$current_get['all'],
  348. 'A' => self::$current_get['A'],
  349. 'i' => self::$current_get['important'],
  350. 's' => self::$current_get['starred'],
  351. 'f' => self::$current_get['feed'] == $id,
  352. 'c' => self::$current_get['category'] == $id,
  353. 't' => self::$current_get['tag'] == $id,
  354. 'T' => self::$current_get['tags'] || self::$current_get['tag'],
  355. 'Z' => self::$current_get['Z'],
  356. default => false,
  357. };
  358. }
  359. /**
  360. * Set the current $get attribute.
  361. *
  362. * Valid $get parameter are:
  363. * - a
  364. * - s
  365. * - f_<feed id>
  366. * - c_<category id>
  367. * - t_<tag id>
  368. *
  369. * $name and $get_unread attributes are also updated as $next_get
  370. * Raise an exception if id or $get is invalid.
  371. * @throws FreshRSS_Context_Exception
  372. * @throws Minz_ConfigurationNamespaceException
  373. * @throws Minz_PDOConnectionException
  374. */
  375. private static function _get(string $get): void {
  376. $type = $get[0];
  377. $id = (int)substr($get, 2);
  378. if (empty(self::$categories)) {
  379. // TODO: Check whether this section is used
  380. $catDAO = FreshRSS_Factory::createCategoryDao();
  381. $details = $type === 'f'; // Load additional feed details in the case of feed view
  382. self::$categories = $catDAO->listCategories(prePopulateFeeds: true, details: $details);
  383. }
  384. switch ($type) {
  385. case 'a': // All PRIORITY_MAIN_STREAM
  386. self::$current_get['all'] = true;
  387. self::$description = FreshRSS_Context::systemConf()->meta_description;
  388. self::$get_unread = self::$total_unread;
  389. break;
  390. case 'A': // All except PRIORITY_HIDDEN
  391. self::$current_get['A'] = true;
  392. self::$description = FreshRSS_Context::systemConf()->meta_description;
  393. self::$get_unread = self::$total_unread;
  394. break;
  395. case 'Z': // All including PRIORITY_HIDDEN
  396. self::$current_get['Z'] = true;
  397. self::$name = _t('index.feed.title');
  398. self::$description = FreshRSS_Context::systemConf()->meta_description;
  399. self::$get_unread = self::$total_unread;
  400. break;
  401. case 'i': // Priority important feeds
  402. self::$current_get['important'] = true;
  403. self::$name = _t('index.menu.important');
  404. self::$description = FreshRSS_Context::systemConf()->meta_description;
  405. self::$get_unread = self::$total_unread;
  406. break;
  407. case 's':
  408. self::$current_get['starred'] = true;
  409. self::$name = _t('index.feed.title_fav');
  410. self::$description = FreshRSS_Context::systemConf()->meta_description;
  411. self::$get_unread = self::$total_starred['unread'];
  412. // Update state if favorite is not yet enabled.
  413. self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE;
  414. break;
  415. case 'f':
  416. // We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description
  417. $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id);
  418. if ($feed === null) {
  419. throw new FreshRSS_Context_Exception('Invalid feed: ' . $id);
  420. }
  421. self::$current_get['feed'] = $id;
  422. self::$current_get['category'] = $feed->categoryId();
  423. self::$name = $feed->name();
  424. self::$description = $feed->description();
  425. self::$get_unread = $feed->nbNotRead();
  426. break;
  427. case 'c':
  428. // We try to find the corresponding category.
  429. self::$current_get['category'] = $id;
  430. $cat = null;
  431. foreach (self::$categories as $category) {
  432. if ($category->id() === $id) {
  433. $cat = $category;
  434. break;
  435. }
  436. }
  437. if ($cat === null) {
  438. throw new FreshRSS_Context_Exception('Invalid category: ' . $id);
  439. }
  440. self::$name = $cat->name();
  441. self::$get_unread = $cat->nbNotRead();
  442. break;
  443. case 't':
  444. // We try to find the corresponding tag.
  445. self::$current_get['tag'] = $id;
  446. $tag = null;
  447. foreach (self::$tags as $t) {
  448. if ($t->id() === $id) {
  449. $tag = $t;
  450. break;
  451. }
  452. }
  453. if ($tag === null) {
  454. $tagDAO = FreshRSS_Factory::createTagDao();
  455. $tag = $tagDAO->searchById($id);
  456. if ($tag === null) {
  457. throw new FreshRSS_Context_Exception('Invalid tag: ' . $id);
  458. }
  459. }
  460. self::$name = $tag->name();
  461. self::$get_unread = $tag->nbUnread();
  462. break;
  463. case 'T':
  464. $tagDAO = FreshRSS_Factory::createTagDao();
  465. self::$current_get['tags'] = true;
  466. self::$name = _t('index.menu.mylabels');
  467. self::$get_unread = $tagDAO->countNotRead();
  468. break;
  469. default:
  470. throw new FreshRSS_Context_Exception('Invalid getter: ' . $get);
  471. }
  472. self::_nextGet();
  473. }
  474. /**
  475. * Set the value of $next_get attribute.
  476. */
  477. private static function _nextGet(): void {
  478. $get = self::currentGet();
  479. // By default, $next_get == $get
  480. self::$next_get = $get;
  481. if (empty(self::$categories)) {
  482. $catDAO = FreshRSS_Factory::createCategoryDao();
  483. self::$categories = $catDAO->listCategories(prePopulateFeeds: true);
  484. }
  485. if (FreshRSS_Context::userConf()->onread_jump_next && strlen($get) > 2) {
  486. $another_unread_id = '';
  487. $found_current_get = false;
  488. switch ($get[0]) {
  489. case 'f':
  490. // We search the next unread feed with the following priorities: next in same category, or previous in same category, or next, or previous.
  491. foreach (self::$categories as $cat) {
  492. $sameCat = false;
  493. foreach ($cat->feeds() as $feed) {
  494. if ($found_current_get) {
  495. if ($feed->nbNotRead() > 0) {
  496. $another_unread_id = $feed->id();
  497. break 2;
  498. }
  499. } elseif ($feed->id() == self::$current_get['feed']) {
  500. $found_current_get = true;
  501. } elseif ($feed->nbNotRead() > 0) {
  502. $another_unread_id = $feed->id();
  503. $sameCat = true;
  504. }
  505. }
  506. if ($found_current_get && $sameCat) {
  507. break;
  508. }
  509. }
  510. // If there is no more unread feed, show main stream
  511. self::$next_get = $another_unread_id == '' ? 'a' : 'f_' . $another_unread_id;
  512. break;
  513. case 'c':
  514. // We search the next category with at least one unread article.
  515. foreach (self::$categories as $cat) {
  516. if ($cat->id() == self::$current_get['category']) {
  517. // Here is our current category! Next one could be our
  518. // champion if it has unread articles.
  519. $found_current_get = true;
  520. continue;
  521. }
  522. if ($cat->nbNotRead(minPriority: FreshRSS_Feed::PRIORITY_CATEGORY) > 0) {
  523. $another_unread_id = $cat->id();
  524. if ($found_current_get) {
  525. // Unread articles and the current category has
  526. // already been found? Leave the loop!
  527. break;
  528. }
  529. }
  530. }
  531. // If there is no more unread category, show main stream
  532. self::$next_get = $another_unread_id == '' ? 'a' : 'c_' . $another_unread_id;
  533. break;
  534. case 't':
  535. // We can't know what the next unread tag is because entries can be in multiple tags
  536. // so marking all entries in a tag can indirectly mark all entries in multiple tags.
  537. // Default is to return to the current tag, so mark it as next_get = 'a' instead when
  538. // userconf -> onread_jump_next so the readAction knows to jump to the next unread
  539. // tag.
  540. self::$next_get = 'a';
  541. break;
  542. }
  543. }
  544. }
  545. /**
  546. * Determine if the auto remove is available in the current context.
  547. * This feature is available if:
  548. * - it is activated in the configuration
  549. * - the "read" state is not enable
  550. * - the "unread" state is enable
  551. */
  552. public static function isAutoRemoveAvailable(): bool {
  553. return FreshRSS_Context::userConf()->auto_remove_article && !self::isStateEnabled(FreshRSS_Entry::STATE_READ) &&
  554. (self::isStateEnabled(FreshRSS_Entry::STATE_NOT_READ) || self::isStateEnabled(FreshRSS_Entry::STATE_OR_NOT_READ));
  555. }
  556. /**
  557. * Determine if the "sticky post" option is enabled. It can be enable
  558. * by the user when it is selected in the configuration page or by the
  559. * application when the context allows to auto-remove articles when they
  560. * are read.
  561. */
  562. public static function isStickyPostEnabled(): bool {
  563. if (FreshRSS_Context::userConf()->sticky_post) {
  564. return true;
  565. }
  566. if (self::isAutoRemoveAvailable()) {
  567. return true;
  568. }
  569. return false;
  570. }
  571. public static function defaultTimeZone(): string {
  572. $timezone = ini_get('date.timezone');
  573. return $timezone != false ? $timezone : 'UTC';
  574. }
  575. }