configureController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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(
  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 handles the archive configuration page.
  181. *
  182. * It displays the archive configuration page.
  183. * If this action is reached through a POST request, it stores all new
  184. * configuration values then sends a notification to the user.
  185. *
  186. * The options available on that page are:
  187. * - duration to retain old article (default: 3)
  188. * - number of article to retain per feed (default: 0)
  189. * - refresh frequency (default: -2)
  190. *
  191. * @todo explain why the default value is -2 but this value does not
  192. * exist in the drop-down list
  193. */
  194. public function archivingAction() {
  195. if (Minz_Request::isPost()) {
  196. $this->view->conf->_old_entries(Minz_Request::param('old_entries', 3));
  197. $this->view->conf->_keep_history_default(Minz_Request::param('keep_history_default', 0));
  198. $this->view->conf->_ttl_default(Minz_Request::param('ttl_default', -2));
  199. $this->view->conf->save();
  200. invalidateHttpCache();
  201. Minz_Request::good(_t('configuration_updated'),
  202. array('c' => 'configure', 'a' => 'archiving'));
  203. }
  204. Minz_View::prependTitle(_t('archiving_configuration') . ' · ');
  205. $entryDAO = FreshRSS_Factory::createEntryDao();
  206. $this->view->nb_total = $entryDAO->count();
  207. $this->view->size_user = $entryDAO->size();
  208. if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
  209. $this->view->size_total = $entryDAO->size(true);
  210. }
  211. }
  212. /**
  213. * This action handles the user queries configuration page.
  214. *
  215. * If this action is reached through a POST request, it stores all new
  216. * configuration values then sends a notification to the user then
  217. * redirect to the same page.
  218. * If this action is not reached through a POST request, it displays the
  219. * configuration page and verifies that every user query is runable by
  220. * checking if categories and feeds are still in use.
  221. */
  222. public function queriesAction() {
  223. if (Minz_Request::isPost()) {
  224. $queries = Minz_Request::param('queries', array());
  225. foreach ($queries as $key => $query) {
  226. if (!$query['name']) {
  227. $query['name'] = _t('query_number', $key + 1);
  228. }
  229. }
  230. $this->view->conf->_queries($queries);
  231. $this->view->conf->save();
  232. Minz_Request::good(_t('configuration_updated'),
  233. array('c' => 'configure', 'a' => 'queries'));
  234. } else {
  235. $this->view->query_get = array();
  236. $cat_dao = new FreshRSS_CategoryDAO();
  237. $feed_dao = FreshRSS_Factory::createFeedDao();
  238. foreach ($this->view->conf->queries as $key => $query) {
  239. if (!isset($query['get'])) {
  240. continue;
  241. }
  242. switch ($query['get'][0]) {
  243. case 'c':
  244. $category = $cat_dao->searchById(substr($query['get'], 2));
  245. $deprecated = true;
  246. $cat_name = '';
  247. if ($category) {
  248. $cat_name = $category->name();
  249. $deprecated = false;
  250. }
  251. $this->view->query_get[$key] = array(
  252. 'type' => 'category',
  253. 'name' => $cat_name,
  254. 'deprecated' => $deprecated,
  255. );
  256. break;
  257. case 'f':
  258. $feed = $feed_dao->searchById(substr($query['get'], 2));
  259. $deprecated = true;
  260. $feed_name = '';
  261. if ($feed) {
  262. $feed_name = $feed->name();
  263. $deprecated = false;
  264. }
  265. $this->view->query_get[$key] = array(
  266. 'type' => 'feed',
  267. 'name' => $feed_name,
  268. 'deprecated' => $deprecated,
  269. );
  270. break;
  271. case 's':
  272. $this->view->query_get[$key] = array(
  273. 'type' => 'favorite',
  274. 'name' => 'favorite',
  275. 'deprecated' => false,
  276. );
  277. break;
  278. case 'a':
  279. $this->view->query_get[$key] = array(
  280. 'type' => 'all',
  281. 'name' => 'all',
  282. 'deprecated' => false,
  283. );
  284. break;
  285. }
  286. }
  287. }
  288. Minz_View::prependTitle(_t('queries') . ' · ');
  289. }
  290. /**
  291. * This action handles the creation of a user query.
  292. *
  293. * It gets the GET parameters and stores them in the configuration query
  294. * storage. Before it is saved, the unwanted parameters are unset to keep
  295. * lean data.
  296. */
  297. public function addQueryAction() {
  298. $whitelist = array('get', 'order', 'name', 'search', 'state');
  299. $queries = $this->view->conf->queries;
  300. $query = Minz_Request::params();
  301. $query['name'] = _t('query_number', count($queries) + 1);
  302. foreach ($query as $key => $value) {
  303. if (!in_array($key, $whitelist)) {
  304. unset($query[$key]);
  305. }
  306. }
  307. if (!empty($query['state']) && $query['state'] & FreshRSS_Entry::STATE_STRICT) {
  308. $query['state'] -= FreshRSS_Entry::STATE_STRICT;
  309. }
  310. $queries[] = $query;
  311. $this->view->conf->_queries($queries);
  312. $this->view->conf->save();
  313. Minz_Request::good(_t('query_created', $query['name']),
  314. array('c' => 'configure', 'a' => 'queries'));
  315. }
  316. }