configureController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 (!$this->view->loginOk) {
  13. Minz_Error::error(
  14. 403,
  15. array('error' => array(_t('access_denied')))
  16. );
  17. }
  18. }
  19. /**
  20. * This action handles the display configuration page.
  21. *
  22. * It displays the display configuration page.
  23. * If this action is reached through a POST request, it stores all new
  24. * configuration values then sends a notification to the user.
  25. *
  26. * The options available on the page are:
  27. * - language (default: en)
  28. * - theme (default: Origin)
  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 tags in footer
  38. * - display of date in footer
  39. * - display of open action in footer
  40. * - html5 notification timeout (default: 0)
  41. * Default values are false unless specified.
  42. */
  43. public function displayAction() {
  44. if (Minz_Request::isPost()) {
  45. $this->view->conf->_language(Minz_Request::param('language', 'en'));
  46. $this->view->conf->_theme(Minz_Request::param('theme', FreshRSS_Themes::$defaultTheme));
  47. $this->view->conf->_content_width(Minz_Request::param('content_width', 'thin'));
  48. $this->view->conf->_topline_read(Minz_Request::param('topline_read', false));
  49. $this->view->conf->_topline_favorite(Minz_Request::param('topline_favorite', false));
  50. $this->view->conf->_topline_date(Minz_Request::param('topline_date', false));
  51. $this->view->conf->_topline_link(Minz_Request::param('topline_link', false));
  52. $this->view->conf->_bottomline_read(Minz_Request::param('bottomline_read', false));
  53. $this->view->conf->_bottomline_favorite(Minz_Request::param('bottomline_favorite', false));
  54. $this->view->conf->_bottomline_sharing(Minz_Request::param('bottomline_sharing', false));
  55. $this->view->conf->_bottomline_tags(Minz_Request::param('bottomline_tags', false));
  56. $this->view->conf->_bottomline_date(Minz_Request::param('bottomline_date', false));
  57. $this->view->conf->_bottomline_link(Minz_Request::param('bottomline_link', false));
  58. $this->view->conf->_html5_notif_timeout(Minz_Request::param('html5_notif_timeout', 0));
  59. $this->view->conf->save();
  60. Minz_Session::_param('language', $this->view->conf->language);
  61. Minz_Translate::reset();
  62. invalidateHttpCache();
  63. Minz_Request::good(_t('configuration_updated'),
  64. array('c' => 'configure', 'a' => 'display'));
  65. }
  66. $this->view->themes = FreshRSS_Themes::get();
  67. Minz_View::prependTitle(_t('display_configuration') . ' · ');
  68. }
  69. /**
  70. * This action handles the reading configuration page.
  71. *
  72. * It displays the reading configuration page.
  73. * If this action is reached through a POST request, it stores all new
  74. * configuration values then sends a notification to the user.
  75. *
  76. * The options available on the page are:
  77. * - number of posts per page (default: 10)
  78. * - view mode (default: normal)
  79. * - default article view (default: all)
  80. * - load automatically articles
  81. * - display expanded articles
  82. * - display expanded categories
  83. * - hide categories and feeds without unread articles
  84. * - jump on next category or feed when marked as read
  85. * - image lazy loading
  86. * - stick open articles to the top
  87. * - display a confirmation when reading all articles
  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. $this->view->conf->_posts_per_page(Minz_Request::param('posts_per_page', 10));
  99. $this->view->conf->_view_mode(Minz_Request::param('view_mode', 'normal'));
  100. $this->view->conf->_default_view((int)Minz_Request::param('default_view', FreshRSS_Entry::STATE_ALL));
  101. $this->view->conf->_auto_load_more(Minz_Request::param('auto_load_more', false));
  102. $this->view->conf->_display_posts(Minz_Request::param('display_posts', false));
  103. $this->view->conf->_display_categories(Minz_Request::param('display_categories', false));
  104. $this->view->conf->_hide_read_feeds(Minz_Request::param('hide_read_feeds', false));
  105. $this->view->conf->_onread_jump_next(Minz_Request::param('onread_jump_next', false));
  106. $this->view->conf->_lazyload(Minz_Request::param('lazyload', false));
  107. $this->view->conf->_sticky_post(Minz_Request::param('sticky_post', false));
  108. $this->view->conf->_reading_confirm(Minz_Request::param('reading_confirm', false));
  109. $this->view->conf->_sort_order(Minz_Request::param('sort_order', 'DESC'));
  110. $this->view->conf->_mark_when(array(
  111. 'article' => Minz_Request::param('mark_open_article', false),
  112. 'site' => Minz_Request::param('mark_open_site', false),
  113. 'scroll' => Minz_Request::param('mark_scroll', false),
  114. 'reception' => Minz_Request::param('mark_upon_reception', false),
  115. ));
  116. $this->view->conf->save();
  117. Minz_Session::_param('language', $this->view->conf->language);
  118. Minz_Translate::reset();
  119. invalidateHttpCache();
  120. Minz_Request::good(_t('configuration_updated'),
  121. array('c' => 'configure', 'a' => 'reading'));
  122. }
  123. Minz_View::prependTitle(_t('reading_configuration') . ' · ');
  124. }
  125. /**
  126. * This action handles the sharing configuration page.
  127. *
  128. * It displays the sharing configuration page.
  129. * If this action is reached through a POST request, it stores all
  130. * configuration values then sends a notification to the user.
  131. */
  132. public function sharingAction() {
  133. if (Minz_Request::isPost()) {
  134. $params = Minz_Request::params();
  135. $this->view->conf->_sharing($params['share']);
  136. $this->view->conf->save();
  137. invalidateHttpCache();
  138. Minz_Request::good(_t('configuration_updated'),
  139. array('c' => 'configure', 'a' => 'sharing'));
  140. }
  141. Minz_View::prependTitle(_t('sharing') . ' · ');
  142. }
  143. /**
  144. * This action handles the shortcut configuration page.
  145. *
  146. * It displays the shortcut configuration page.
  147. * If this action is reached through a POST request, it stores all new
  148. * configuration values then sends a notification to the user.
  149. *
  150. * The authorized values for shortcuts are letters (a to z), numbers (0
  151. * to 9), function keys (f1 to f12), backspace, delete, down, end, enter,
  152. * escape, home, insert, left, page down, page up, return, right, space,
  153. * tab and up.
  154. */
  155. public function shortcutAction() {
  156. $list_keys = array('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  157. 'escape', 'f', 'g', 'h', 'home', 'i', 'insert', 'j', 'k', 'l', 'left',
  158. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  159. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  160. 'z', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  161. 'f10', 'f11', 'f12');
  162. $this->view->list_keys = $list_keys;
  163. if (Minz_Request::isPost()) {
  164. $shortcuts = Minz_Request::param('shortcuts');
  165. $shortcuts_ok = array();
  166. foreach ($shortcuts as $key => $value) {
  167. if (in_array($value, $list_keys)) {
  168. $shortcuts_ok[$key] = $value;
  169. }
  170. }
  171. $this->view->conf->_shortcuts($shortcuts_ok);
  172. $this->view->conf->save();
  173. invalidateHttpCache();
  174. Minz_Request::good(_t('shortcuts_updated'),
  175. array('c' => 'configure', 'a' => 'shortcut'));
  176. }
  177. Minz_View::prependTitle(_t('shortcuts') . ' · ');
  178. }
  179. /**
  180. * This action display the user configuration page
  181. *
  182. * @todo move that action in the user controller
  183. */
  184. public function usersAction() {
  185. Minz_View::prependTitle(_t('users') . ' · ');
  186. }
  187. /**
  188. * This action handles the archive configuration page.
  189. *
  190. * It displays the archive configuration page.
  191. * If this action is reached through a POST request, it stores all new
  192. * configuration values then sends a notification to the user.
  193. *
  194. * The options available on that page are:
  195. * - duration to retain old article (default: 3)
  196. * - number of article to retain per feed (default: 0)
  197. * - refresh frequency (default: -2)
  198. *
  199. * @todo explain why the default value is -2 but this value does not
  200. * exist in the drop-down list
  201. */
  202. public function archivingAction() {
  203. if (Minz_Request::isPost()) {
  204. $this->view->conf->_old_entries(Minz_Request::param('old_entries', 3));
  205. $this->view->conf->_keep_history_default(Minz_Request::param('keep_history_default', 0));
  206. $this->view->conf->_ttl_default(Minz_Request::param('ttl_default', -2));
  207. $this->view->conf->save();
  208. invalidateHttpCache();
  209. Minz_Request::good(_t('configuration_updated'),
  210. array('c' => 'configure', 'a' => 'archiving'));
  211. }
  212. Minz_View::prependTitle(_t('archiving_configuration') . ' · ');
  213. $entryDAO = FreshRSS_Factory::createEntryDao();
  214. $this->view->nb_total = $entryDAO->count();
  215. $this->view->size_user = $entryDAO->size();
  216. if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
  217. $this->view->size_total = $entryDAO->size(true);
  218. }
  219. }
  220. /**
  221. * This action handles the user queries configuration page.
  222. *
  223. * If this action is reached through a POST request, it stores all new
  224. * configuration values then sends a notification to the user then
  225. * redirect to the same page.
  226. * If this action is not reached through a POST request, it displays the
  227. * configuration page and verifies that every user query is runable by
  228. * checking if categories and feeds are still in use.
  229. */
  230. public function queriesAction() {
  231. if (Minz_Request::isPost()) {
  232. $queries = Minz_Request::param('queries', array());
  233. foreach ($queries as $key => $query) {
  234. if (!$query['name']) {
  235. $query['name'] = _t('query_number', $key + 1);
  236. }
  237. }
  238. $this->view->conf->_queries($queries);
  239. $this->view->conf->save();
  240. Minz_Request::good(_t('configuration_updated'),
  241. array('c' => 'configure', 'a' => 'queries'));
  242. } else {
  243. $this->view->query_get = array();
  244. $cat_dao = new FreshRSS_CategoryDAO();
  245. $feed_dao = FreshRSS_Factory::createFeedDao();
  246. foreach ($this->view->conf->queries as $key => $query) {
  247. if (!isset($query['get'])) {
  248. continue;
  249. }
  250. switch ($query['get'][0]) {
  251. case 'c':
  252. $category = $cat_dao->searchById(substr($query['get'], 2));
  253. $deprecated = true;
  254. $cat_name = '';
  255. if ($category) {
  256. $cat_name = $category->name();
  257. $deprecated = false;
  258. }
  259. $this->view->query_get[$key] = array(
  260. 'type' => 'category',
  261. 'name' => $cat_name,
  262. 'deprecated' => $deprecated,
  263. );
  264. break;
  265. case 'f':
  266. $feed = $feed_dao->searchById(substr($query['get'], 2));
  267. $deprecated = true;
  268. $feed_name = '';
  269. if ($feed) {
  270. $feed_name = $feed->name();
  271. $deprecated = false;
  272. }
  273. $this->view->query_get[$key] = array(
  274. 'type' => 'feed',
  275. 'name' => $feed_name,
  276. 'deprecated' => $deprecated,
  277. );
  278. break;
  279. case 's':
  280. $this->view->query_get[$key] = array(
  281. 'type' => 'favorite',
  282. 'name' => 'favorite',
  283. 'deprecated' => false,
  284. );
  285. break;
  286. case 'a':
  287. $this->view->query_get[$key] = array(
  288. 'type' => 'all',
  289. 'name' => 'all',
  290. 'deprecated' => false,
  291. );
  292. break;
  293. }
  294. }
  295. }
  296. Minz_View::prependTitle(_t('queries') . ' · ');
  297. }
  298. /**
  299. * This action handles the creation of a user query.
  300. *
  301. * It gets the GET parameters and stores them in the configuration query
  302. * storage. Before it is saved, the unwanted parameters are unset to keep
  303. * lean data.
  304. */
  305. public function addQueryAction() {
  306. $whitelist = array('get', 'order', 'name', 'search', 'state');
  307. $queries = $this->view->conf->queries;
  308. $query = Minz_Request::params();
  309. $query['name'] = _t('query_number', count($queries) + 1);
  310. foreach ($query as $key => $value) {
  311. if (!in_array($key, $whitelist)) {
  312. unset($query[$key]);
  313. }
  314. }
  315. if (!empty($query['state']) && $query['state'] & FreshRSS_Entry::STATE_STRICT) {
  316. $query['state'] -= FreshRSS_Entry::STATE_STRICT;
  317. }
  318. $queries[] = $query;
  319. $this->view->conf->_queries($queries);
  320. $this->view->conf->save();
  321. Minz_Request::good(_t('query_created', $query['name']),
  322. array('c' => 'configure', 'a' => 'queries'));
  323. }
  324. }