configureController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Controller to handle every configuration options.
  5. */
  6. class FreshRSS_configure_Controller extends FreshRSS_ActionController {
  7. /**
  8. * This action is called before every other action in that class. It is
  9. * the common boilerplate for every action. It is triggered by the
  10. * underlying framework.
  11. */
  12. #[\Override]
  13. public function firstAction(): void {
  14. if (!FreshRSS_Auth::hasAccess()) {
  15. Minz_Error::error(403);
  16. }
  17. }
  18. /**
  19. * This action handles the display configuration page.
  20. *
  21. * It displays the display configuration page.
  22. * If this action is reached through a POST request, it stores all new
  23. * configuration values then sends a notification to the user.
  24. *
  25. * The options available on the page are:
  26. * - language (default: en)
  27. * - theme (default: Origin)
  28. * - darkMode (default: auto)
  29. * - content width (default: thin)
  30. * - display of read action in header
  31. * - display of favorite action in header
  32. * - display of date in header
  33. * - display of open action in header
  34. * - display of read action in footer
  35. * - display of favorite action in footer
  36. * - display of sharing action in footer
  37. * - display of article tags in footer
  38. * - display of my Labels in footer
  39. * - display of date in footer
  40. * - display of open action in footer
  41. * - html5 notification timeout (default: 0)
  42. * Default values are false unless specified.
  43. */
  44. public function displayAction(): void {
  45. if (Minz_Request::isPost()) {
  46. FreshRSS_Context::userConf()->language = Minz_Request::paramString('language') ?: 'en';
  47. FreshRSS_Context::userConf()->timezone = Minz_Request::paramString('timezone');
  48. $theme = Minz_Request::paramString('theme') ?: FreshRSS_Themes::$defaultTheme;
  49. if (FreshRSS_Themes::exists($theme)) {
  50. FreshRSS_Context::userConf()->theme = $theme;
  51. }
  52. FreshRSS_Context::userConf()->darkMode = Minz_Request::paramString('darkMode') ?: 'auto';
  53. FreshRSS_Context::userConf()->content_width = Minz_Request::paramString('content_width') ?: 'thin';
  54. FreshRSS_Context::userConf()->topline_read = Minz_Request::paramBoolean('topline_read');
  55. FreshRSS_Context::userConf()->topline_favorite = Minz_Request::paramBoolean('topline_favorite');
  56. FreshRSS_Context::userConf()->topline_myLabels = Minz_Request::paramBoolean('topline_myLabels');
  57. FreshRSS_Context::userConf()->topline_sharing = Minz_Request::paramBoolean('topline_sharing');
  58. FreshRSS_Context::userConf()->topline_date = Minz_Request::paramBoolean('topline_date');
  59. FreshRSS_Context::userConf()->topline_link = Minz_Request::paramBoolean('topline_link');
  60. FreshRSS_Context::userConf()->topline_website = Minz_Request::paramString('topline_website');
  61. FreshRSS_Context::userConf()->topline_thumbnail = Minz_Request::paramString('topline_thumbnail');
  62. FreshRSS_Context::userConf()->topline_summary = Minz_Request::paramBoolean('topline_summary');
  63. FreshRSS_Context::userConf()->topline_display_authors = Minz_Request::paramBoolean('topline_display_authors');
  64. FreshRSS_Context::userConf()->bottomline_read = Minz_Request::paramBoolean('bottomline_read');
  65. FreshRSS_Context::userConf()->bottomline_favorite = Minz_Request::paramBoolean('bottomline_favorite');
  66. FreshRSS_Context::userConf()->bottomline_sharing = Minz_Request::paramBoolean('bottomline_sharing');
  67. FreshRSS_Context::userConf()->bottomline_tags = Minz_Request::paramBoolean('bottomline_tags');
  68. FreshRSS_Context::userConf()->bottomline_myLabels = Minz_Request::paramBoolean('bottomline_myLabels');
  69. FreshRSS_Context::userConf()->bottomline_date = Minz_Request::paramBoolean('bottomline_date');
  70. FreshRSS_Context::userConf()->bottomline_link = Minz_Request::paramBoolean('bottomline_link');
  71. FreshRSS_Context::userConf()->show_nav_buttons = Minz_Request::paramBoolean('show_nav_buttons');
  72. FreshRSS_Context::userConf()->html5_notif_timeout = Minz_Request::paramInt('html5_notif_timeout');
  73. FreshRSS_Context::userConf()->save();
  74. Minz_Session::_param('language', FreshRSS_Context::userConf()->language);
  75. Minz_Translate::reset(FreshRSS_Context::userConf()->language);
  76. invalidateHttpCache();
  77. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'display' ], 'displayAction');
  78. }
  79. $this->view->themes = FreshRSS_Themes::get();
  80. FreshRSS_View::prependTitle(_t('conf.display.title') . ' · ');
  81. }
  82. /**
  83. * This action handles the reading configuration page.
  84. *
  85. * It displays the reading configuration page.
  86. * If this action is reached through a POST request, it stores all new
  87. * configuration values then sends a notification to the user.
  88. *
  89. * The options available on the page are:
  90. * - number of posts per page (default: 10)
  91. * - view mode (default: normal)
  92. * - default article view (default: all)
  93. * - load automatically articles
  94. * - display expanded articles
  95. * - display expanded categories
  96. * - hide categories and feeds without unread articles
  97. * - jump on next category or feed when marked as read
  98. * - image lazy loading
  99. * - stick open articles to the top
  100. * - display a confirmation when reading all articles
  101. * - auto remove article after reading
  102. * - article order (default: DESC)
  103. * - mark articles as read when:
  104. * - displayed
  105. * - opened on site
  106. * - scrolled
  107. * - received
  108. * - focus
  109. * Default values are false unless specified.
  110. */
  111. public function readingAction(): void {
  112. if (Minz_Request::isPost()) {
  113. FreshRSS_Context::userConf()->posts_per_page = Minz_Request::paramInt('posts_per_page') ?: 10;
  114. FreshRSS_Context::userConf()->view_mode = Minz_Request::paramStringNull('view_mode', true) ?? 'normal';
  115. FreshRSS_Context::userConf()->default_view = Minz_Request::paramStringNull('default_view') ?? 'adaptive';
  116. FreshRSS_Context::userConf()->show_fav_unread = Minz_Request::paramBoolean('show_fav_unread');
  117. FreshRSS_Context::userConf()->auto_load_more = Minz_Request::paramBoolean('auto_load_more');
  118. FreshRSS_Context::userConf()->display_posts = Minz_Request::paramBoolean('display_posts');
  119. FreshRSS_Context::userConf()->display_categories = Minz_Request::paramStringNull('display_categories') ?? 'active';
  120. FreshRSS_Context::userConf()->show_tags = Minz_Request::paramStringNull('show_tags') ?? '0';
  121. FreshRSS_Context::userConf()->show_tags_max = Minz_Request::paramInt('show_tags_max');
  122. FreshRSS_Context::userConf()->show_author_date = Minz_Request::paramStringNull('show_author_date') ?? '0';
  123. FreshRSS_Context::userConf()->show_feed_name = Minz_Request::paramStringNull('show_feed_name') ?? 't';
  124. FreshRSS_Context::userConf()->show_article_icons = Minz_Request::paramStringNull('show_article_icons') ?? 't';
  125. FreshRSS_Context::userConf()->hide_read_feeds = Minz_Request::paramBoolean('hide_read_feeds');
  126. FreshRSS_Context::userConf()->onread_jump_next = Minz_Request::paramBoolean('onread_jump_next');
  127. FreshRSS_Context::userConf()->lazyload = Minz_Request::paramBoolean('lazyload');
  128. FreshRSS_Context::userConf()->sides_close_article = Minz_Request::paramBoolean('sides_close_article');
  129. FreshRSS_Context::userConf()->sticky_post = Minz_Request::paramBoolean('sticky_post');
  130. $markReadButton = Minz_Request::paramStringNull('mark_read_button', plaintext: true);
  131. FreshRSS_Context::userConf()->mark_read_button = in_array($markReadButton, ['big', 'small', 'none'], true) ? $markReadButton : 'big';
  132. FreshRSS_Context::userConf()->reading_confirm = Minz_Request::paramBoolean('reading_confirm');
  133. FreshRSS_Context::userConf()->auto_remove_article = Minz_Request::paramBoolean('auto_remove_article');
  134. FreshRSS_Context::userConf()->mark_updated_article_unread = Minz_Request::paramBoolean('mark_updated_article_unread');
  135. if (in_array(Minz_Request::paramString('sort_order'), ['ASC', 'DESC'], true)) {
  136. FreshRSS_Context::userConf()->sort_order = Minz_Request::paramString('sort_order');
  137. } else {
  138. FreshRSS_Context::userConf()->sort_order = 'DESC';
  139. }
  140. FreshRSS_Context::userConf()->mark_when = [
  141. 'article' => Minz_Request::paramBoolean('mark_open_article'),
  142. 'gone' => Minz_Request::paramBoolean('read_upon_gone'),
  143. 'max_n_unread' => Minz_Request::paramBoolean('enable_keep_max_n_unread') ? Minz_Request::paramInt('keep_max_n_unread') : false,
  144. 'reception' => Minz_Request::paramBoolean('mark_upon_reception'),
  145. 'same_title_in_feed' => Minz_Request::paramBoolean('enable_read_when_same_title_in_feed') ?
  146. Minz_Request::paramInt('read_when_same_title_in_feed') : false,
  147. 'scroll' => Minz_Request::paramBoolean('mark_scroll'),
  148. 'site' => Minz_Request::paramBoolean('mark_open_site'),
  149. 'focus' => Minz_Request::paramBoolean('mark_focus'),
  150. ];
  151. FreshRSS_Context::userConf()->_filtersAction('read', Minz_Request::paramTextToArray('filteractions_read'));
  152. FreshRSS_Context::userConf()->_filtersAction('star', Minz_Request::paramTextToArray('filteractions_star'));
  153. FreshRSS_Context::userConf()->save();
  154. invalidateHttpCache();
  155. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'reading' ]);
  156. }
  157. $this->view->viewModes = FreshRSS_ViewMode::getAllModes();
  158. FreshRSS_View::prependTitle(_t('conf.reading.title') . ' · ');
  159. }
  160. /**
  161. * This action handles the integration configuration page.
  162. *
  163. * It displays the integration configuration page.
  164. * If this action is reached through a POST request, it stores all
  165. * configuration values then sends a notification to the user.
  166. *
  167. * Before v1.16, we used sharing instead of integration. This has
  168. * some unwanted behavior when the end-user was using an ad-blocker.
  169. */
  170. public function integrationAction(): void {
  171. FreshRSS_View::appendScript(Minz_Url::display('/scripts/integration.js?' . @filemtime(PUBLIC_PATH . '/scripts/integration.js')));
  172. FreshRSS_View::appendScript(Minz_Url::display('/scripts/draggable.js?' . @filemtime(PUBLIC_PATH . '/scripts/draggable.js')));
  173. if (Minz_Request::isPost()) {
  174. $share = $_POST['share'] ?? [];
  175. if (is_array($share)) {
  176. $share = array_filter($share, fn($value, $key): bool =>
  177. is_int($key) && is_array($value) &&
  178. is_array_values_string($value),
  179. ARRAY_FILTER_USE_BOTH);
  180. /** @var array<int,array<string,string>> $share */
  181. FreshRSS_Context::userConf()->sharing = $share;
  182. FreshRSS_Context::userConf()->save();
  183. invalidateHttpCache();
  184. }
  185. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'integration' ]);
  186. }
  187. FreshRSS_View::prependTitle(_t('conf.sharing.title') . ' · ');
  188. }
  189. /**
  190. * This action handles the shortcut configuration page.
  191. *
  192. * It displays the shortcut configuration page.
  193. * If this action is reached through a POST request, it stores all new
  194. * configuration values then sends a notification to the user.
  195. *
  196. * The authorized values for shortcuts are letters (a to z), numbers (0
  197. * to 9), function keys (f1 to f12), backspace, delete, down, end, enter,
  198. * escape, home, insert, left, page down, page up, return, right, space,
  199. * tab and up.
  200. */
  201. public function shortcutAction(): void {
  202. $this->view->list_keys = SHORTCUT_KEYS;
  203. if (Minz_Request::isPost()) {
  204. $shortcuts = Minz_Request::paramArray('shortcuts', plaintext: true);
  205. if (Minz_Request::paramBoolean('load_default_shortcuts')) {
  206. $default = Minz_Configuration::load(FRESHRSS_PATH . '/config-user.default.php');
  207. $shortcuts = $default['shortcuts'];
  208. }
  209. /** @var array<string,string> $shortcuts */
  210. FreshRSS_Context::userConf()->shortcuts = array_map('trim', $shortcuts);
  211. FreshRSS_Context::userConf()->save();
  212. invalidateHttpCache();
  213. Minz_Request::good(_t('feedback.conf.shortcuts_updated'), ['c' => 'configure', 'a' => 'shortcut']);
  214. }
  215. FreshRSS_View::prependTitle(_t('conf.shortcut.title') . ' · ');
  216. }
  217. /**
  218. * This action handles the archive configuration page.
  219. *
  220. * It displays the archive configuration page.
  221. * If this action is reached through a POST request, it stores all new
  222. * configuration values then sends a notification to the user.
  223. *
  224. * The options available on that page are:
  225. * - duration to retain old article (default: 3)
  226. * - number of article to retain per feed (default: 0)
  227. * - refresh frequency (default: 0)
  228. */
  229. public function archivingAction(): void {
  230. if (Minz_Request::isPost()) {
  231. if (Minz_Request::paramBoolean('enable_keep_max')) {
  232. $keepMax = Minz_Request::paramInt('keep_max') ?: FreshRSS_Feed::ARCHIVING_RETENTION_COUNT_LIMIT;
  233. } else {
  234. $keepMax = false;
  235. }
  236. if (Minz_Request::paramBoolean('enable_keep_period')) {
  237. $keepPeriod = FreshRSS_Feed::ARCHIVING_RETENTION_PERIOD;
  238. if (is_numeric(Minz_Request::paramString('keep_period_count')) && preg_match('/^PT?1[YMWDH]$/', Minz_Request::paramString('keep_period_unit'))) {
  239. $keepPeriod = str_replace('1', Minz_Request::paramString('keep_period_count'), Minz_Request::paramString('keep_period_unit'));
  240. }
  241. } else {
  242. $keepPeriod = false;
  243. }
  244. FreshRSS_Context::userConf()->ttl_default = Minz_Request::paramInt('ttl_default') ?: FreshRSS_Feed::TTL_DEFAULT;
  245. FreshRSS_Context::userConf()->archiving = [
  246. 'keep_period' => $keepPeriod,
  247. 'keep_max' => $keepMax,
  248. 'keep_min' => Minz_Request::paramInt('keep_min_default'),
  249. 'keep_favourites' => Minz_Request::paramBoolean('keep_favourites'),
  250. 'keep_labels' => Minz_Request::paramBoolean('keep_labels'),
  251. 'keep_unreads' => Minz_Request::paramBoolean('keep_unreads'),
  252. ];
  253. FreshRSS_Context::userConf()->keep_history_default = null; //Legacy < FreshRSS 1.15
  254. FreshRSS_Context::userConf()->old_entries = null; //Legacy < FreshRSS 1.15
  255. FreshRSS_Context::userConf()->save();
  256. invalidateHttpCache();
  257. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'archiving' ]);
  258. }
  259. $volatile = [
  260. 'enable_keep_period' => false,
  261. 'keep_period_count' => '3',
  262. 'keep_period_unit' => 'P1M',
  263. ];
  264. if (!empty(FreshRSS_Context::userConf()->archiving['keep_period'])) {
  265. $keepPeriod = FreshRSS_Context::userConf()->archiving['keep_period'];
  266. if (preg_match('/^PT?(?P<count>\d+)[YMWDH]$/', $keepPeriod, $matches)) {
  267. $volatile = [
  268. 'enable_keep_period' => true,
  269. 'keep_period_count' => $matches['count'],
  270. 'keep_period_unit' => str_replace($matches['count'], '1', $keepPeriod),
  271. ];
  272. }
  273. }
  274. FreshRSS_Context::userConf()->volatile = $volatile;
  275. $entryDAO = FreshRSS_Factory::createEntryDao();
  276. $this->view->nb_total = $entryDAO->count();
  277. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  278. $this->view->size_user = $databaseDAO->size();
  279. if (FreshRSS_Auth::hasAccess('admin')) {
  280. $this->view->size_total = $databaseDAO->size(true);
  281. }
  282. FreshRSS_View::prependTitle(_t('conf.archiving.title') . ' · ');
  283. }
  284. /**
  285. * This action handles the user queries configuration page.
  286. *
  287. * If this action is reached through a POST request, it stores all new
  288. * configuration values then sends a notification to the user then
  289. * redirect to the same page.
  290. * If this action is not reached through a POST request, it displays the
  291. * configuration page and verifies that every user query is runable by
  292. * checking if categories and feeds are still in use.
  293. */
  294. public function queriesAction(): void {
  295. FreshRSS_View::appendScript(Minz_Url::display('/scripts/draggable.js?' . @filemtime(PUBLIC_PATH . '/scripts/draggable.js')));
  296. if (Minz_Request::isPost()) {
  297. /** @var array<int,array{get?:string,name?:string,order?:string,search?:string,state?:int,url?:string,token?:string}> $params */
  298. $params = Minz_Request::paramArray('queries');
  299. $queries = [];
  300. foreach ($params as $key => $query) {
  301. $key = (int)$key;
  302. if (empty($query['name'])) {
  303. $query['name'] = _t('conf.query.number', $key + 1);
  304. }
  305. if (!empty($query['search'])) {
  306. $query['search'] = urldecode($query['search']);
  307. }
  308. $queries[$key] = (new FreshRSS_UserQuery($query, FreshRSS_Context::categories(), FreshRSS_Context::labels()))->toArray();
  309. }
  310. FreshRSS_Context::userConf()->queries = $queries;
  311. FreshRSS_Context::userConf()->save();
  312. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'queries' ]);
  313. } else {
  314. $this->view->queries = [];
  315. foreach (FreshRSS_Context::userConf()->queries as $key => $query) {
  316. $this->view->queries[intval($key)] = new FreshRSS_UserQuery($query, FreshRSS_Context::categories(), FreshRSS_Context::labels());
  317. }
  318. }
  319. $this->view->categories = FreshRSS_Context::categories();
  320. $this->view->feeds = FreshRSS_Context::feeds();
  321. $this->view->tags = FreshRSS_Context::labels();
  322. if (Minz_Request::paramTernary('id') !== null) {
  323. $id = Minz_Request::paramInt('id');
  324. $this->view->query = $this->view->queries[$id];
  325. $this->view->queryId = $id;
  326. $this->view->displaySlider = true;
  327. } else {
  328. $this->view->displaySlider = false;
  329. }
  330. FreshRSS_View::prependTitle(_t('conf.query.title') . ' · ');
  331. }
  332. /**
  333. * Handles query configuration.
  334. * It displays the query configuration page and handles modifications
  335. * applied to the selected query.
  336. */
  337. public function queryAction(): void {
  338. if (Minz_Request::paramBoolean('ajax')) {
  339. $this->view->_layout(null);
  340. }
  341. $id = Minz_Request::paramInt('id');
  342. if (Minz_Request::paramTernary('id') === null || empty(FreshRSS_Context::userConf()->queries[$id])) {
  343. Minz_Error::error(404);
  344. return;
  345. }
  346. $query = new FreshRSS_UserQuery(FreshRSS_Context::userConf()->queries[$id], FreshRSS_Context::categories(), FreshRSS_Context::labels());
  347. $this->view->query = $query;
  348. $this->view->queryId = $id;
  349. $this->view->categories = FreshRSS_Context::categories();
  350. $this->view->feeds = FreshRSS_Context::feeds();
  351. $this->view->tags = FreshRSS_Context::labels();
  352. if (Minz_Request::isPost()) {
  353. $params = Minz_Request::paramArray('query');
  354. $queryParams = [];
  355. $name = Minz_Request::paramString('name') ?: _t('conf.query.number', $id + 1);
  356. if ('' === $name) {
  357. $name = _t('conf.query.number', $id + 1);
  358. }
  359. if (!empty($params['get']) && is_string($params['get'])) {
  360. $queryParams['get'] = $params['get'];
  361. }
  362. if (!empty($params['order']) && is_string($params['order'])) {
  363. $queryParams['order'] = $params['order'];
  364. }
  365. if (!empty($params['search']) && is_string($params['search'])) {
  366. // Search must be as plain text to be XML-encoded or URL-encoded depending on the situation
  367. $queryParams['search'] = htmlspecialchars_decode($params['search'], ENT_QUOTES);
  368. }
  369. if (!empty($params['state']) && is_array($params['state'])) {
  370. $queryParams['state'] = (int)array_sum(array_map('intval', $params['state']));
  371. }
  372. if (empty($params['token']) || !is_string($params['token'])) {
  373. $queryParams['token'] = FreshRSS_UserQuery::generateToken($name);
  374. } else {
  375. $queryParams['token'] = $params['token'];
  376. }
  377. $queryParams['url'] = Minz_Url::display(['params' => $queryParams]);
  378. $queryParams['name'] = $name;
  379. if (!empty($params['description']) && is_string($params['description'])) {
  380. $queryParams['description'] = $params['description'];
  381. }
  382. if (!empty($params['imageUrl']) && is_string($params['imageUrl'])) {
  383. $queryParams['imageUrl'] = $params['imageUrl'];
  384. }
  385. if (!empty($params['shareOpml']) && ctype_digit($params['shareOpml'])) {
  386. $queryParams['shareOpml'] = (bool)$params['shareOpml'];
  387. }
  388. if (!empty($params['shareRss']) && ctype_digit($params['shareRss'])) {
  389. $queryParams['shareRss'] = (bool)$params['shareRss'];
  390. }
  391. $queries = FreshRSS_Context::userConf()->queries;
  392. $queries[$id] = (new FreshRSS_UserQuery($queryParams, FreshRSS_Context::categories(), FreshRSS_Context::labels()))->toArray();
  393. FreshRSS_Context::userConf()->queries = $queries;
  394. FreshRSS_Context::userConf()->save();
  395. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'queries', 'params' => ['id' => (string)$id] ]);
  396. }
  397. FreshRSS_View::prependTitle($query->getName() . ' · ' . _t('conf.query.title') . ' · ');
  398. }
  399. /**
  400. * Handles query deletion
  401. */
  402. public function deleteQueryAction(): void {
  403. $id = Minz_Request::paramInt('id');
  404. if (Minz_Request::paramTernary('id') === null || empty(FreshRSS_Context::userConf()->queries[$id])) {
  405. Minz_Error::error(404);
  406. return;
  407. }
  408. $queries = FreshRSS_Context::userConf()->queries;
  409. unset($queries[$id]);
  410. FreshRSS_Context::userConf()->queries = $queries;
  411. FreshRSS_Context::userConf()->save();
  412. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'queries' ]);
  413. }
  414. /**
  415. * This action handles the creation of a user query.
  416. *
  417. * It gets the GET parameters and stores them in the configuration query
  418. * storage. Before it is saved, the unwanted parameters are unset to keep
  419. * lean data.
  420. */
  421. public function bookmarkQueryAction(): void {
  422. $queries = [];
  423. foreach (FreshRSS_Context::userConf()->queries as $key => $query) {
  424. $queries[$key] = (new FreshRSS_UserQuery($query, FreshRSS_Context::categories(), FreshRSS_Context::labels()))->toArray();
  425. }
  426. $params = array_filter($_GET, 'is_string', ARRAY_FILTER_USE_KEY);
  427. unset($params['name']);
  428. unset($params['rid']);
  429. /** @var array{get?:string,name?:string,order?:string,search?:string,state?:int,url?:string,token?:string,shareRss?:bool,shareOpml?:bool,description?:string,imageUrl?:string} $params */
  430. $params['url'] = Minz_Url::display(['params' => $params]);
  431. $params['name'] = _t('conf.query.number', count($queries) + 1);
  432. $queries[] = (new FreshRSS_UserQuery($params, FreshRSS_Context::categories(), FreshRSS_Context::labels()))->toArray();
  433. FreshRSS_Context::userConf()->queries = $queries;
  434. FreshRSS_Context::userConf()->save();
  435. Minz_Request::good(_t('feedback.conf.query_created', $params['name']), [ 'c' => 'configure', 'a' => 'queries' ]);
  436. }
  437. /**
  438. * This action handles the system configuration page.
  439. *
  440. * It displays the system configuration page.
  441. * If this action is reach through a POST request, it stores all new
  442. * configuration values then sends a notification to the user.
  443. *
  444. * The options available on the page are:
  445. * - instance name (default: FreshRSS)
  446. * - auto update URL (default: false)
  447. * - force emails validation (default: false)
  448. * - user limit (default: 1)
  449. * - user category limit (default: 16384)
  450. * - user feed limit (default: 16384)
  451. * - user login duration for form auth (default: FreshRSS_Auth::DEFAULT_COOKIE_DURATION)
  452. */
  453. public function systemAction(): void {
  454. if (!FreshRSS_Auth::hasAccess('admin')) {
  455. Minz_Error::error(403);
  456. }
  457. if (Minz_Request::isPost()) {
  458. $limits = FreshRSS_Context::systemConf()->limits;
  459. $limits['max_registrations'] = Minz_Request::paramIntNull('max-registrations') ?? 1;
  460. $limits['max_feeds'] = Minz_Request::paramInt('max-feeds') ?: 16384;
  461. $limits['max_categories'] = Minz_Request::paramInt('max-categories') ?: 16384;
  462. $limits['cookie_duration'] = Minz_Request::paramInt('cookie-duration') ?: FreshRSS_Auth::DEFAULT_COOKIE_DURATION;
  463. FreshRSS_Context::systemConf()->limits = $limits;
  464. FreshRSS_Context::systemConf()->title = Minz_Request::paramString('instance-name') ?: 'FreshRSS';
  465. FreshRSS_Context::systemConf()->force_email_validation = Minz_Request::paramBoolean('force-email-validation');
  466. FreshRSS_Context::systemConf()->save();
  467. invalidateHttpCache();
  468. Minz_Request::good(_t('feedback.conf.updated'), [ 'c' => 'configure', 'a' => 'system' ]);
  469. }
  470. }
  471. public function privacyAction(): void {
  472. if (Minz_Request::isPost()) {
  473. FreshRSS_Context::userConf()->retrieve_extension_list = Minz_Request::paramBoolean('retrieve_extension_list');
  474. FreshRSS_Context::userConf()->save();
  475. invalidateHttpCache();
  476. Minz_Request::good(_t('feedback.conf.updated'), ['c' => 'configure', 'a' => 'privacy']);
  477. }
  478. FreshRSS_View::prependTitle(_t('conf.privacy') . ' · ');
  479. }
  480. }