4
0

configureController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /**
  3. * Controller to handle every configuration options.
  4. */
  5. class FreshRSS_configure_Controller extends Minz_ActionController {
  6. /**
  7. * This action is called before every other action in that class. It is
  8. * the common boiler plate for every action. It is triggered by the
  9. * underlying framework.
  10. */
  11. public function firstAction() {
  12. if (!FreshRSS_Auth::hasAccess()) {
  13. Minz_Error::error(403);
  14. }
  15. }
  16. /**
  17. * This action handles the display configuration page.
  18. *
  19. * It displays the display configuration page.
  20. * If this action is reached through a POST request, it stores all new
  21. * configuration values then sends a notification to the user.
  22. *
  23. * The options available on the page are:
  24. * - language (default: en)
  25. * - theme (default: Origin)
  26. * - content width (default: thin)
  27. * - display of read action in header
  28. * - display of favorite action in header
  29. * - display of date in header
  30. * - display of open action in header
  31. * - display of read action in footer
  32. * - display of favorite action in footer
  33. * - display of sharing action in footer
  34. * - display of tags in footer
  35. * - display of date in footer
  36. * - display of open action in footer
  37. * - html5 notification timeout (default: 0)
  38. * Default values are false unless specified.
  39. */
  40. public function displayAction() {
  41. if (Minz_Request::isPost()) {
  42. FreshRSS_Context::$user_conf->language = Minz_Request::param('language', 'en');
  43. FreshRSS_Context::$user_conf->theme = Minz_Request::param('theme', FreshRSS_Themes::$defaultTheme);
  44. FreshRSS_Context::$user_conf->content_width = Minz_Request::param('content_width', 'thin');
  45. FreshRSS_Context::$user_conf->topline_read = Minz_Request::param('topline_read', false);
  46. FreshRSS_Context::$user_conf->topline_favorite = Minz_Request::param('topline_favorite', false);
  47. FreshRSS_Context::$user_conf->topline_date = Minz_Request::param('topline_date', false);
  48. FreshRSS_Context::$user_conf->topline_link = Minz_Request::param('topline_link', false);
  49. FreshRSS_Context::$user_conf->topline_display_authors = Minz_Request::param('topline_display_authors', false);
  50. FreshRSS_Context::$user_conf->bottomline_read = Minz_Request::param('bottomline_read', false);
  51. FreshRSS_Context::$user_conf->bottomline_favorite = Minz_Request::param('bottomline_favorite', false);
  52. FreshRSS_Context::$user_conf->bottomline_sharing = Minz_Request::param('bottomline_sharing', false);
  53. FreshRSS_Context::$user_conf->bottomline_tags = Minz_Request::param('bottomline_tags', false);
  54. FreshRSS_Context::$user_conf->bottomline_date = Minz_Request::param('bottomline_date', false);
  55. FreshRSS_Context::$user_conf->bottomline_link = Minz_Request::param('bottomline_link', false);
  56. FreshRSS_Context::$user_conf->html5_notif_timeout = Minz_Request::param('html5_notif_timeout', 0);
  57. FreshRSS_Context::$user_conf->show_nav_buttons = Minz_Request::param('show_nav_buttons', false);
  58. FreshRSS_Context::$user_conf->save();
  59. Minz_Session::_param('language', FreshRSS_Context::$user_conf->language);
  60. Minz_Translate::reset(FreshRSS_Context::$user_conf->language);
  61. invalidateHttpCache();
  62. Minz_Request::good(_t('feedback.conf.updated'),
  63. array('c' => 'configure', 'a' => 'display'));
  64. }
  65. $this->view->themes = FreshRSS_Themes::get();
  66. Minz_View::prependTitle(_t('conf.display.title') . ' · ');
  67. }
  68. /**
  69. * This action handles the reading configuration page.
  70. *
  71. * It displays the reading configuration page.
  72. * If this action is reached through a POST request, it stores all new
  73. * configuration values then sends a notification to the user.
  74. *
  75. * The options available on the page are:
  76. * - number of posts per page (default: 10)
  77. * - view mode (default: normal)
  78. * - default article view (default: all)
  79. * - load automatically articles
  80. * - display expanded articles
  81. * - display expanded categories
  82. * - hide categories and feeds without unread articles
  83. * - jump on next category or feed when marked as read
  84. * - image lazy loading
  85. * - stick open articles to the top
  86. * - display a confirmation when reading all articles
  87. * - auto remove article after reading
  88. * - article order (default: DESC)
  89. * - mark articles as read when:
  90. * - displayed
  91. * - opened on site
  92. * - scrolled
  93. * - received
  94. * Default values are false unless specified.
  95. */
  96. public function readingAction() {
  97. if (Minz_Request::isPost()) {
  98. FreshRSS_Context::$user_conf->posts_per_page = Minz_Request::param('posts_per_page', 10);
  99. FreshRSS_Context::$user_conf->view_mode = Minz_Request::param('view_mode', 'normal');
  100. FreshRSS_Context::$user_conf->default_view = Minz_Request::param('default_view', 'adaptive');
  101. FreshRSS_Context::$user_conf->auto_load_more = Minz_Request::param('auto_load_more', false);
  102. FreshRSS_Context::$user_conf->display_posts = Minz_Request::param('display_posts', false);
  103. FreshRSS_Context::$user_conf->display_categories = Minz_Request::param('display_categories', false);
  104. FreshRSS_Context::$user_conf->hide_read_feeds = Minz_Request::param('hide_read_feeds', false);
  105. FreshRSS_Context::$user_conf->onread_jump_next = Minz_Request::param('onread_jump_next', false);
  106. FreshRSS_Context::$user_conf->lazyload = Minz_Request::param('lazyload', false);
  107. FreshRSS_Context::$user_conf->sides_close_article = Minz_Request::param('sides_close_article', false);
  108. FreshRSS_Context::$user_conf->sticky_post = Minz_Request::param('sticky_post', false);
  109. FreshRSS_Context::$user_conf->reading_confirm = Minz_Request::param('reading_confirm', false);
  110. FreshRSS_Context::$user_conf->auto_remove_article = Minz_Request::param('auto_remove_article', false);
  111. FreshRSS_Context::$user_conf->mark_updated_article_unread = Minz_Request::param('mark_updated_article_unread', false);
  112. FreshRSS_Context::$user_conf->sort_order = Minz_Request::param('sort_order', 'DESC');
  113. FreshRSS_Context::$user_conf->mark_when = array(
  114. 'article' => Minz_Request::param('mark_open_article', false),
  115. 'site' => Minz_Request::param('mark_open_site', false),
  116. 'scroll' => Minz_Request::param('mark_scroll', false),
  117. 'reception' => Minz_Request::param('mark_upon_reception', false),
  118. );
  119. FreshRSS_Context::$user_conf->save();
  120. invalidateHttpCache();
  121. Minz_Request::good(_t('feedback.conf.updated'),
  122. array('c' => 'configure', 'a' => 'reading'));
  123. }
  124. Minz_View::prependTitle(_t('conf.reading.title') . ' · ');
  125. }
  126. /**
  127. * This action handles the sharing configuration page.
  128. *
  129. * It displays the sharing configuration page.
  130. * If this action is reached through a POST request, it stores all
  131. * configuration values then sends a notification to the user.
  132. */
  133. public function sharingAction() {
  134. if (Minz_Request::isPost()) {
  135. $params = Minz_Request::fetchPOST();
  136. FreshRSS_Context::$user_conf->sharing = $params['share'];
  137. FreshRSS_Context::$user_conf->save();
  138. invalidateHttpCache();
  139. Minz_Request::good(_t('feedback.conf.updated'),
  140. array('c' => 'configure', 'a' => 'sharing'));
  141. }
  142. Minz_View::prependTitle(_t('conf.sharing.title') . ' · ');
  143. }
  144. /**
  145. * This action handles the shortcut configuration page.
  146. *
  147. * It displays the shortcut configuration page.
  148. * If this action is reached through a POST request, it stores all new
  149. * configuration values then sends a notification to the user.
  150. *
  151. * The authorized values for shortcuts are letters (a to z), numbers (0
  152. * to 9), function keys (f1 to f12), backspace, delete, down, end, enter,
  153. * escape, home, insert, left, page down, page up, return, right, space,
  154. * tab and up.
  155. */
  156. public function shortcutAction() {
  157. $this->view->list_keys = SHORTCUT_KEYS;
  158. if (Minz_Request::isPost()) {
  159. FreshRSS_Context::$user_conf->shortcuts = validateShortcutList(Minz_Request::param('shortcuts'));
  160. FreshRSS_Context::$user_conf->save();
  161. invalidateHttpCache();
  162. Minz_Request::good(_t('feedback.conf.shortcuts_updated'), array('c' => 'configure', 'a' => 'shortcut'));
  163. } else {
  164. FreshRSS_Context::$user_conf->shortcuts = validateShortcutList(FreshRSS_Context::$user_conf->shortcuts);
  165. }
  166. Minz_View::prependTitle(_t('conf.shortcut.title') . ' · ');
  167. }
  168. /**
  169. * This action handles the archive configuration page.
  170. *
  171. * It displays the archive configuration page.
  172. * If this action is reached through a POST request, it stores all new
  173. * configuration values then sends a notification to the user.
  174. *
  175. * The options available on that page are:
  176. * - duration to retain old article (default: 3)
  177. * - number of article to retain per feed (default: 0)
  178. * - refresh frequency (default: 0)
  179. */
  180. public function archivingAction() {
  181. if (Minz_Request::isPost()) {
  182. FreshRSS_Context::$user_conf->old_entries = Minz_Request::param('old_entries', 3);
  183. FreshRSS_Context::$user_conf->keep_history_default = Minz_Request::param('keep_history_default', 0);
  184. FreshRSS_Context::$user_conf->ttl_default = Minz_Request::param('ttl_default', FreshRSS_Feed::TTL_DEFAULT);
  185. FreshRSS_Context::$user_conf->save();
  186. invalidateHttpCache();
  187. Minz_Request::good(_t('feedback.conf.updated'),
  188. array('c' => 'configure', 'a' => 'archiving'));
  189. }
  190. Minz_View::prependTitle(_t('conf.archiving.title') . ' · ');
  191. $entryDAO = FreshRSS_Factory::createEntryDao();
  192. $this->view->nb_total = $entryDAO->count();
  193. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  194. $this->view->size_user = $databaseDAO->size();
  195. if (FreshRSS_Auth::hasAccess('admin')) {
  196. $this->view->size_total = $databaseDAO->size(true);
  197. }
  198. }
  199. /**
  200. * This action handles the user queries configuration page.
  201. *
  202. * If this action is reached through a POST request, it stores all new
  203. * configuration values then sends a notification to the user then
  204. * redirect to the same page.
  205. * If this action is not reached through a POST request, it displays the
  206. * configuration page and verifies that every user query is runable by
  207. * checking if categories and feeds are still in use.
  208. */
  209. public function queriesAction() {
  210. $category_dao = FreshRSS_Factory::createCategoryDao();
  211. $feed_dao = FreshRSS_Factory::createFeedDao();
  212. $tag_dao = FreshRSS_Factory::createTagDao();
  213. if (Minz_Request::isPost()) {
  214. $params = Minz_Request::param('queries', array());
  215. foreach ($params as $key => $query) {
  216. if (!$query['name']) {
  217. $query['name'] = _t('conf.query.number', $key + 1);
  218. }
  219. $queries[] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
  220. }
  221. FreshRSS_Context::$user_conf->queries = $queries;
  222. FreshRSS_Context::$user_conf->save();
  223. Minz_Request::good(_t('feedback.conf.updated'),
  224. array('c' => 'configure', 'a' => 'queries'));
  225. } else {
  226. $this->view->queries = array();
  227. foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
  228. $this->view->queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
  229. }
  230. }
  231. Minz_View::prependTitle(_t('conf.query.title') . ' · ');
  232. }
  233. /**
  234. * This action handles the creation of a user query.
  235. *
  236. * It gets the GET parameters and stores them in the configuration query
  237. * storage. Before it is saved, the unwanted parameters are unset to keep
  238. * lean data.
  239. */
  240. public function addQueryAction() {
  241. $category_dao = FreshRSS_Factory::createCategoryDao();
  242. $feed_dao = FreshRSS_Factory::createFeedDao();
  243. $tag_dao = FreshRSS_Factory::createTagDao();
  244. $queries = array();
  245. foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
  246. $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao);
  247. }
  248. $params = Minz_Request::fetchGET();
  249. $params['url'] = Minz_Url::display(array('params' => $params));
  250. $params['name'] = _t('conf.query.number', count($queries) + 1);
  251. $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao);
  252. FreshRSS_Context::$user_conf->queries = $queries;
  253. FreshRSS_Context::$user_conf->save();
  254. Minz_Request::good(_t('feedback.conf.query_created', $query['name']),
  255. array('c' => 'configure', 'a' => 'queries'));
  256. }
  257. /**
  258. * This action handles the system configuration page.
  259. *
  260. * It displays the system configuration page.
  261. * If this action is reach through a POST request, it stores all new
  262. * configuration values then sends a notification to the user.
  263. *
  264. * The options available on the page are:
  265. * - instance name (default: FreshRSS)
  266. * - auto update URL (default: false)
  267. * - force emails validation (default: false)
  268. * - user limit (default: 1)
  269. * - user category limit (default: 16384)
  270. * - user feed limit (default: 16384)
  271. * - user login duration for form auth (default: 2592000)
  272. *
  273. * The `force-email-validation` is ignored with PHP < 5.5
  274. */
  275. public function systemAction() {
  276. if (!FreshRSS_Auth::hasAccess('admin')) {
  277. Minz_Error::error(403);
  278. }
  279. $can_enable_email_validation = version_compare(PHP_VERSION, '5.5') >= 0;
  280. $this->view->can_enable_email_validation = $can_enable_email_validation;
  281. if (Minz_Request::isPost()) {
  282. $limits = FreshRSS_Context::$system_conf->limits;
  283. $limits['max_registrations'] = Minz_Request::param('max-registrations', 1);
  284. $limits['max_feeds'] = Minz_Request::param('max-feeds', 16384);
  285. $limits['max_categories'] = Minz_Request::param('max-categories', 16384);
  286. $limits['cookie_duration'] = Minz_Request::param('cookie-duration', 2592000);
  287. FreshRSS_Context::$system_conf->limits = $limits;
  288. FreshRSS_Context::$system_conf->title = Minz_Request::param('instance-name', 'FreshRSS');
  289. FreshRSS_Context::$system_conf->auto_update_url = Minz_Request::param('auto-update-url', false);
  290. if ($can_enable_email_validation) {
  291. FreshRSS_Context::$system_conf->force_email_validation = Minz_Request::param('force-email-validation', false);
  292. }
  293. FreshRSS_Context::$system_conf->save();
  294. invalidateHttpCache();
  295. Minz_Session::_param('notification', array(
  296. 'type' => 'good',
  297. 'content' => _t('feedback.conf.updated')
  298. ));
  299. }
  300. }
  301. }