4
0

Context.php 21 KB

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