configureController.php 26 KB

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