Context.php 20 KB

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