Context.php 20 KB

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