Context.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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' */
  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. }
  146. /**
  147. * @throws FreshRSS_Context_Exception
  148. */
  149. public static function &userConf(): FreshRSS_UserConfiguration {
  150. if (FreshRSS_Context::$user_conf === null) {
  151. throw new FreshRSS_Context_Exception('User configuration not initialised!');
  152. }
  153. return FreshRSS_Context::$user_conf;
  154. }
  155. public static function hasUserConf(): bool {
  156. return FreshRSS_Context::$user_conf !== null;
  157. }
  158. public static function clearUserConf(): void {
  159. FreshRSS_Context::$user_conf = null;
  160. }
  161. /** @return array<int,FreshRSS_Category> where the key is the category ID */
  162. public static function categories(): array {
  163. if (empty(self::$categories)) {
  164. $catDAO = FreshRSS_Factory::createCategoryDao();
  165. self::$categories = $catDAO->listSortedCategories(prePopulateFeeds: true, details: false);
  166. }
  167. return self::$categories;
  168. }
  169. /** @return array<int,FreshRSS_Feed> where the key is the feed ID */
  170. public static function feeds(): array {
  171. return FreshRSS_Category::findFeeds(self::categories());
  172. }
  173. /** @return array<int,FreshRSS_Tag> where the key is the label ID */
  174. public static function labels(bool $precounts = false): array {
  175. if (empty(self::$tags) || $precounts) {
  176. $tagDAO = FreshRSS_Factory::createTagDao();
  177. self::$tags = $tagDAO->listTags($precounts);
  178. }
  179. return self::$tags;
  180. }
  181. /**
  182. * This action updates the Context object by using request parameters.
  183. *
  184. * HTTP GET request parameters are:
  185. * - state (default: conf->default_view)
  186. * - search (default: empty string)
  187. * - order (default: conf->sort_order)
  188. * - nb (default: conf->posts_per_page)
  189. * - next (default: empty string)
  190. * - hours (default: 0)
  191. * @throws FreshRSS_Context_Exception
  192. * @throws Minz_ConfigurationNamespaceException
  193. * @throws Minz_PDOConnectionException
  194. */
  195. public static function updateUsingRequest(bool $computeStatistics): void {
  196. if ($computeStatistics && self::$total_unread === 0) {
  197. // Update number of read / unread variables.
  198. $entryDAO = FreshRSS_Factory::createEntryDao();
  199. self::$total_starred = $entryDAO->countUnreadReadFavorites();
  200. self::$total_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_MAIN_STREAM);
  201. self::$total_important_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_IMPORTANT);
  202. }
  203. self::_get(Minz_Request::paramString('get') ?: 'a');
  204. self::$state = Minz_Request::paramInt('state') ?: FreshRSS_Context::userConf()->default_state;
  205. $state_forced_by_user = Minz_Request::paramString('state', true) !== '';
  206. if (!$state_forced_by_user) {
  207. if (FreshRSS_Context::userConf()->show_fav_unread && (self::isCurrentGet('s') || self::isCurrentGet('T') || self::isTag())) {
  208. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  209. } elseif (FreshRSS_Context::userConf()->default_view === 'all') {
  210. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  211. } elseif (FreshRSS_Context::userConf()->default_view === 'unread_or_favorite') {
  212. self::$state = FreshRSS_Entry::STATE_OR_NOT_READ | FreshRSS_Entry::STATE_OR_FAVORITE;
  213. } elseif (FreshRSS_Context::userConf()->default_view === 'adaptive' && self::$get_unread <= 0) {
  214. self::$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_READ;
  215. }
  216. }
  217. self::$search = new FreshRSS_BooleanSearch(Minz_Request::paramString('search'));
  218. $order = Minz_Request::paramString('order', true) ?: FreshRSS_Context::userConf()->sort_order;
  219. self::$order = in_array($order, ['ASC', 'DESC'], true) ? $order : 'DESC';
  220. $sort = Minz_Request::paramString('sort', true) ?: FreshRSS_Context::userConf()->sort;
  221. self::$sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand'], true) ? $sort : 'id';
  222. self::$number = Minz_Request::paramInt('nb') ?: FreshRSS_Context::userConf()->posts_per_page;
  223. if (self::$number > FreshRSS_Context::userConf()->max_posts_per_rss) {
  224. self::$number = max(
  225. FreshRSS_Context::userConf()->max_posts_per_rss,
  226. FreshRSS_Context::userConf()->posts_per_page);
  227. }
  228. self::$offset = Minz_Request::paramInt('offset');
  229. $id_max = Minz_Request::paramString('idMax', true);
  230. self::$id_max = ctype_digit($id_max) ? $id_max : '0';
  231. $continuation_id = Minz_Request::paramString('cid', true);
  232. self::$continuation_id = ctype_digit($continuation_id) ? $continuation_id : '0';
  233. self::$sinceHours = Minz_Request::paramInt('hours');
  234. }
  235. /**
  236. * Returns if the current state includes $state parameter.
  237. */
  238. public static function isStateEnabled(int $state): int {
  239. return self::$state & $state;
  240. }
  241. /**
  242. * Returns the current state with or without $state parameter.
  243. */
  244. public static function getRevertState(int $state): int {
  245. if (self::$state & $state) {
  246. return self::$state & ~$state;
  247. }
  248. return self::$state | $state;
  249. }
  250. /**
  251. * Return the current get as a string or an array.
  252. *
  253. * If $array is true, the first item of the returned value is 'f' or 'c' or 't' and the second is the id.
  254. * @phpstan-return ($asArray is true ? array{'a'|'A'|'c'|'f'|'i'|'s'|'t'|'T'|'Z',bool|int} : string)
  255. * @return string|array{string,bool|int}
  256. */
  257. public static function currentGet(bool $asArray = false): string|array {
  258. if (self::$current_get['all']) {
  259. return $asArray ? ['a', true] : 'a';
  260. } elseif (self::$current_get['A']) {
  261. return $asArray ? ['A', true] : 'A';
  262. } elseif (self::$current_get['important']) {
  263. return $asArray ? ['i', true] : 'i';
  264. } elseif (self::$current_get['starred']) {
  265. return $asArray ? ['s', true] : 's';
  266. } elseif (self::$current_get['feed']) {
  267. if ($asArray) {
  268. return ['f', self::$current_get['feed']];
  269. } else {
  270. return 'f_' . self::$current_get['feed'];
  271. }
  272. } elseif (self::$current_get['category']) {
  273. if ($asArray) {
  274. return ['c', self::$current_get['category']];
  275. } else {
  276. return 'c_' . self::$current_get['category'];
  277. }
  278. } elseif (self::$current_get['tag']) {
  279. if ($asArray) {
  280. return ['t', self::$current_get['tag']];
  281. } else {
  282. return 't_' . self::$current_get['tag'];
  283. }
  284. } elseif (self::$current_get['tags']) {
  285. return $asArray ? ['T', true] : 'T';
  286. } elseif (self::$current_get['Z']) {
  287. return $asArray ? ['Z', true] : 'Z';
  288. }
  289. return '';
  290. }
  291. /**
  292. * @return bool true if the current request targets all feeds (main view), false otherwise.
  293. */
  294. public static function isAll(): bool {
  295. return self::$current_get['all'] != false;
  296. }
  297. public static function isAllAndCategories(): bool {
  298. return self::$current_get['A'] != false;
  299. }
  300. public static function isAllAndArchived(): bool {
  301. return self::$current_get['Z'] != false;
  302. }
  303. /**
  304. * @return bool true if the current request targets important feeds, false otherwise.
  305. */
  306. public static function isImportant(): bool {
  307. return self::$current_get['important'] != false;
  308. }
  309. /**
  310. * @return bool true if the current request targets a category, false otherwise.
  311. */
  312. public static function isCategory(): bool {
  313. return self::$current_get['category'] != false;
  314. }
  315. /**
  316. * @return bool true if the current request targets a feed (and not a category or all articles), false otherwise.
  317. */
  318. public static function isFeed(): bool {
  319. return self::$current_get['feed'] != false;
  320. }
  321. /**
  322. * @return bool true if the current request targets a tag (though not all tags), false otherwise.
  323. */
  324. public static function isTag(): bool {
  325. return self::$current_get['tag'] != false;
  326. }
  327. /**
  328. * @return bool whether $get parameter corresponds to the $current_get attribute.
  329. */
  330. public static function isCurrentGet(string $get): bool {
  331. $type = substr($get, 0, 1);
  332. $id = substr($get, 2);
  333. return match ($type) {
  334. 'a' => self::$current_get['all'],
  335. 'A' => self::$current_get['A'],
  336. 'i' => self::$current_get['important'],
  337. 's' => self::$current_get['starred'],
  338. 'f' => self::$current_get['feed'] == $id,
  339. 'c' => self::$current_get['category'] == $id,
  340. 't' => self::$current_get['tag'] == $id,
  341. 'T' => self::$current_get['tags'] || self::$current_get['tag'],
  342. 'Z' => self::$current_get['Z'],
  343. default => false,
  344. };
  345. }
  346. /**
  347. * Set the current $get attribute.
  348. *
  349. * Valid $get parameter are:
  350. * - a
  351. * - s
  352. * - f_<feed id>
  353. * - c_<category id>
  354. * - t_<tag id>
  355. *
  356. * $name and $get_unread attributes are also updated as $next_get
  357. * Raise an exception if id or $get is invalid.
  358. * @throws FreshRSS_Context_Exception
  359. * @throws Minz_ConfigurationNamespaceException
  360. * @throws Minz_PDOConnectionException
  361. */
  362. public static function _get(string $get): void {
  363. $type = $get[0];
  364. $id = (int)substr($get, 2);
  365. if (empty(self::$categories)) {
  366. $catDAO = FreshRSS_Factory::createCategoryDao();
  367. $details = $type === 'f'; // Load additional feed details in the case of feed view
  368. self::$categories = $catDAO->listCategories(prePopulateFeeds: true, details: $details);
  369. }
  370. switch ($type) {
  371. case 'a': // All PRIORITY_MAIN_STREAM
  372. self::$current_get['all'] = true;
  373. self::$description = FreshRSS_Context::systemConf()->meta_description;
  374. self::$get_unread = self::$total_unread;
  375. break;
  376. case 'A': // All except PRIORITY_HIDDEN
  377. self::$current_get['A'] = true;
  378. self::$description = FreshRSS_Context::systemConf()->meta_description;
  379. self::$get_unread = self::$total_unread;
  380. break;
  381. case 'Z': // All including PRIORITY_HIDDEN
  382. self::$current_get['Z'] = true;
  383. self::$name = _t('index.feed.title');
  384. self::$description = FreshRSS_Context::systemConf()->meta_description;
  385. self::$get_unread = self::$total_unread;
  386. break;
  387. case 'i': // Priority important feeds
  388. self::$current_get['important'] = true;
  389. self::$name = _t('index.menu.important');
  390. self::$description = FreshRSS_Context::systemConf()->meta_description;
  391. self::$get_unread = self::$total_unread;
  392. break;
  393. case 's':
  394. self::$current_get['starred'] = true;
  395. self::$name = _t('index.feed.title_fav');
  396. self::$description = FreshRSS_Context::systemConf()->meta_description;
  397. self::$get_unread = self::$total_starred['unread'];
  398. // Update state if favorite is not yet enabled.
  399. self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE;
  400. break;
  401. case 'f':
  402. // We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description
  403. $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id);
  404. if ($feed === null) {
  405. throw new FreshRSS_Context_Exception('Invalid feed: ' . $id);
  406. }
  407. self::$current_get['feed'] = $id;
  408. self::$current_get['category'] = $feed->categoryId();
  409. self::$name = $feed->name();
  410. self::$description = $feed->description();
  411. self::$get_unread = $feed->nbNotRead();
  412. break;
  413. case 'c':
  414. // We try to find the corresponding category.
  415. self::$current_get['category'] = $id;
  416. $cat = null;
  417. foreach (self::$categories as $category) {
  418. if ($category->id() === $id) {
  419. $cat = $category;
  420. break;
  421. }
  422. }
  423. if ($cat === null) {
  424. throw new FreshRSS_Context_Exception('Invalid category: ' . $id);
  425. }
  426. self::$name = $cat->name();
  427. self::$get_unread = $cat->nbNotRead();
  428. break;
  429. case 't':
  430. // We try to find the corresponding tag.
  431. self::$current_get['tag'] = $id;
  432. $tag = null;
  433. foreach (self::$tags as $t) {
  434. if ($t->id() === $id) {
  435. $tag = $t;
  436. break;
  437. }
  438. }
  439. if ($tag === null) {
  440. $tagDAO = FreshRSS_Factory::createTagDao();
  441. $tag = $tagDAO->searchById($id);
  442. if ($tag === null) {
  443. throw new FreshRSS_Context_Exception('Invalid tag: ' . $id);
  444. }
  445. }
  446. self::$name = $tag->name();
  447. self::$get_unread = $tag->nbUnread();
  448. break;
  449. case 'T':
  450. $tagDAO = FreshRSS_Factory::createTagDao();
  451. self::$current_get['tags'] = true;
  452. self::$name = _t('index.menu.mylabels');
  453. self::$get_unread = $tagDAO->countNotRead();
  454. break;
  455. default:
  456. throw new FreshRSS_Context_Exception('Invalid getter: ' . $get);
  457. }
  458. self::_nextGet();
  459. }
  460. /**
  461. * Set the value of $next_get attribute.
  462. */
  463. private static function _nextGet(): void {
  464. $get = self::currentGet();
  465. // By default, $next_get == $get
  466. self::$next_get = $get;
  467. if (empty(self::$categories)) {
  468. $catDAO = FreshRSS_Factory::createCategoryDao();
  469. self::$categories = $catDAO->listCategories(prePopulateFeeds: true);
  470. }
  471. if (FreshRSS_Context::userConf()->onread_jump_next && strlen($get) > 2) {
  472. $another_unread_id = '';
  473. $found_current_get = false;
  474. switch ($get[0]) {
  475. case 'f':
  476. // We search the next unread feed with the following priorities: next in same category, or previous in same category, or next, or previous.
  477. foreach (self::$categories as $cat) {
  478. $sameCat = false;
  479. foreach ($cat->feeds() as $feed) {
  480. if ($found_current_get) {
  481. if ($feed->nbNotRead() > 0) {
  482. $another_unread_id = $feed->id();
  483. break 2;
  484. }
  485. } elseif ($feed->id() == self::$current_get['feed']) {
  486. $found_current_get = true;
  487. } elseif ($feed->nbNotRead() > 0) {
  488. $another_unread_id = $feed->id();
  489. $sameCat = true;
  490. }
  491. }
  492. if ($found_current_get && $sameCat) {
  493. break;
  494. }
  495. }
  496. // If there is no more unread feed, show main stream
  497. self::$next_get = $another_unread_id == '' ? 'a' : 'f_' . $another_unread_id;
  498. break;
  499. case 'c':
  500. // We search the next category with at least one unread article.
  501. foreach (self::$categories as $cat) {
  502. if ($cat->id() == self::$current_get['category']) {
  503. // Here is our current category! Next one could be our
  504. // champion if it has unread articles.
  505. $found_current_get = true;
  506. continue;
  507. }
  508. if ($cat->nbNotRead() > 0) {
  509. $another_unread_id = $cat->id();
  510. if ($found_current_get) {
  511. // Unread articles and the current category has
  512. // already been found? Leave the loop!
  513. break;
  514. }
  515. }
  516. }
  517. // If there is no more unread category, show main stream
  518. self::$next_get = $another_unread_id == '' ? 'a' : 'c_' . $another_unread_id;
  519. break;
  520. case 't':
  521. // We can't know what the next unread tag is because entries can be in multiple tags
  522. // so marking all entries in a tag can indirectly mark all entries in multiple tags.
  523. // Default is to return to the current tag, so mark it as next_get = 'a' instead when
  524. // userconf -> onread_jump_next so the readAction knows to jump to the next unread
  525. // tag.
  526. self::$next_get = 'a';
  527. break;
  528. }
  529. }
  530. }
  531. /**
  532. * Determine if the auto remove is available in the current context.
  533. * This feature is available if:
  534. * - it is activated in the configuration
  535. * - the "read" state is not enable
  536. * - the "unread" state is enable
  537. */
  538. public static function isAutoRemoveAvailable(): bool {
  539. return FreshRSS_Context::userConf()->auto_remove_article && !self::isStateEnabled(FreshRSS_Entry::STATE_READ) &&
  540. (self::isStateEnabled(FreshRSS_Entry::STATE_NOT_READ) || self::isStateEnabled(FreshRSS_Entry::STATE_OR_NOT_READ));
  541. }
  542. /**
  543. * Determine if the "sticky post" option is enabled. It can be enable
  544. * by the user when it is selected in the configuration page or by the
  545. * application when the context allows to auto-remove articles when they
  546. * are read.
  547. */
  548. public static function isStickyPostEnabled(): bool {
  549. if (FreshRSS_Context::userConf()->sticky_post) {
  550. return true;
  551. }
  552. if (self::isAutoRemoveAvailable()) {
  553. return true;
  554. }
  555. return false;
  556. }
  557. public static function defaultTimeZone(): string {
  558. $timezone = ini_get('date.timezone');
  559. return $timezone != false ? $timezone : 'UTC';
  560. }
  561. }