configureController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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->bottomline_read = Minz_Request::param('bottomline_read', false);
  50. FreshRSS_Context::$user_conf->bottomline_favorite = Minz_Request::param('bottomline_favorite', false);
  51. FreshRSS_Context::$user_conf->bottomline_sharing = Minz_Request::param('bottomline_sharing', false);
  52. FreshRSS_Context::$user_conf->bottomline_tags = Minz_Request::param('bottomline_tags', false);
  53. FreshRSS_Context::$user_conf->bottomline_date = Minz_Request::param('bottomline_date', false);
  54. FreshRSS_Context::$user_conf->bottomline_link = Minz_Request::param('bottomline_link', false);
  55. FreshRSS_Context::$user_conf->html5_notif_timeout = Minz_Request::param('html5_notif_timeout', 0);
  56. FreshRSS_Context::$user_conf->save();
  57. Minz_Session::_param('language', FreshRSS_Context::$user_conf->language);
  58. Minz_Translate::reset(FreshRSS_Context::$user_conf->language);
  59. invalidateHttpCache();
  60. Minz_Request::good(_t('feedback.conf.updated'),
  61. array('c' => 'configure', 'a' => 'display'));
  62. }
  63. $this->view->themes = FreshRSS_Themes::get();
  64. Minz_View::prependTitle(_t('conf.display.title') . ' · ');
  65. }
  66. /**
  67. * This action handles the reading configuration page.
  68. *
  69. * It displays the reading configuration page.
  70. * If this action is reached through a POST request, it stores all new
  71. * configuration values then sends a notification to the user.
  72. *
  73. * The options available on the page are:
  74. * - number of posts per page (default: 10)
  75. * - view mode (default: normal)
  76. * - default article view (default: all)
  77. * - load automatically articles
  78. * - display expanded articles
  79. * - display expanded categories
  80. * - hide categories and feeds without unread articles
  81. * - jump on next category or feed when marked as read
  82. * - image lazy loading
  83. * - stick open articles to the top
  84. * - display a confirmation when reading all articles
  85. * - auto remove article after reading
  86. * - article order (default: DESC)
  87. * - mark articles as read when:
  88. * - displayed
  89. * - opened on site
  90. * - scrolled
  91. * - received
  92. * Default values are false unless specified.
  93. */
  94. public function readingAction() {
  95. if (Minz_Request::isPost()) {
  96. FreshRSS_Context::$user_conf->posts_per_page = Minz_Request::param('posts_per_page', 10);
  97. FreshRSS_Context::$user_conf->view_mode = Minz_Request::param('view_mode', 'normal');
  98. FreshRSS_Context::$user_conf->default_view = Minz_Request::param('default_view', 'adaptive');
  99. FreshRSS_Context::$user_conf->auto_load_more = Minz_Request::param('auto_load_more', false);
  100. FreshRSS_Context::$user_conf->display_posts = Minz_Request::param('display_posts', false);
  101. FreshRSS_Context::$user_conf->display_categories = Minz_Request::param('display_categories', false);
  102. FreshRSS_Context::$user_conf->hide_read_feeds = Minz_Request::param('hide_read_feeds', false);
  103. FreshRSS_Context::$user_conf->onread_jump_next = Minz_Request::param('onread_jump_next', false);
  104. FreshRSS_Context::$user_conf->lazyload = Minz_Request::param('lazyload', false);
  105. FreshRSS_Context::$user_conf->sticky_post = Minz_Request::param('sticky_post', false);
  106. FreshRSS_Context::$user_conf->reading_confirm = Minz_Request::param('reading_confirm', false);
  107. FreshRSS_Context::$user_conf->auto_remove_article = Minz_Request::param('auto_remove_article', false);
  108. FreshRSS_Context::$user_conf->sort_order = Minz_Request::param('sort_order', 'DESC');
  109. FreshRSS_Context::$user_conf->mark_when = array(
  110. 'article' => Minz_Request::param('mark_open_article', false),
  111. 'site' => Minz_Request::param('mark_open_site', false),
  112. 'scroll' => Minz_Request::param('mark_scroll', false),
  113. 'reception' => Minz_Request::param('mark_upon_reception', false),
  114. );
  115. FreshRSS_Context::$user_conf->save();
  116. invalidateHttpCache();
  117. Minz_Request::good(_t('feedback.conf.updated'),
  118. array('c' => 'configure', 'a' => 'reading'));
  119. }
  120. Minz_View::prependTitle(_t('conf.reading.title') . ' · ');
  121. }
  122. /**
  123. * This action handles the sharing configuration page.
  124. *
  125. * It displays the sharing configuration page.
  126. * If this action is reached through a POST request, it stores all
  127. * configuration values then sends a notification to the user.
  128. */
  129. public function sharingAction() {
  130. if (Minz_Request::isPost()) {
  131. $params = Minz_Request::params();
  132. FreshRSS_Context::$user_conf->sharing = $params['share'];
  133. FreshRSS_Context::$user_conf->save();
  134. invalidateHttpCache();
  135. Minz_Request::good(_t('feedback.conf.updated'),
  136. array('c' => 'configure', 'a' => 'sharing'));
  137. }
  138. Minz_View::prependTitle(_t('conf.sharing.title') . ' · ');
  139. }
  140. /**
  141. * This action handles the shortcut configuration page.
  142. *
  143. * It displays the shortcut configuration page.
  144. * If this action is reached through a POST request, it stores all new
  145. * configuration values then sends a notification to the user.
  146. *
  147. * The authorized values for shortcuts are letters (a to z), numbers (0
  148. * to 9), function keys (f1 to f12), backspace, delete, down, end, enter,
  149. * escape, home, insert, left, page down, page up, return, right, space,
  150. * tab and up.
  151. */
  152. public function shortcutAction() {
  153. $list_keys = array('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  154. 'escape', 'f', 'g', 'h', 'home', 'i', 'insert', 'j', 'k', 'l', 'left',
  155. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  156. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  157. 'z', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  158. 'f10', 'f11', 'f12');
  159. $this->view->list_keys = $list_keys;
  160. if (Minz_Request::isPost()) {
  161. $shortcuts = Minz_Request::param('shortcuts');
  162. $shortcuts_ok = array();
  163. foreach ($shortcuts as $key => $value) {
  164. if (in_array($value, $list_keys)) {
  165. $shortcuts_ok[$key] = $value;
  166. }
  167. }
  168. FreshRSS_Context::$user_conf->shortcuts = $shortcuts_ok;
  169. FreshRSS_Context::$user_conf->save();
  170. invalidateHttpCache();
  171. Minz_Request::good(_t('feedback.conf.shortcuts_updated'),
  172. array('c' => 'configure', 'a' => 'shortcut'));
  173. }
  174. Minz_View::prependTitle(_t('conf.shortcut.title') . ' · ');
  175. }
  176. /**
  177. * This action handles the archive configuration page.
  178. *
  179. * It displays the archive configuration page.
  180. * If this action is reached through a POST request, it stores all new
  181. * configuration values then sends a notification to the user.
  182. *
  183. * The options available on that page are:
  184. * - duration to retain old article (default: 3)
  185. * - number of article to retain per feed (default: 0)
  186. * - refresh frequency (default: -2)
  187. *
  188. * @todo explain why the default value is -2 but this value does not
  189. * exist in the drop-down list
  190. */
  191. public function archivingAction() {
  192. if (Minz_Request::isPost()) {
  193. FreshRSS_Context::$user_conf->old_entries = Minz_Request::param('old_entries', 3);
  194. FreshRSS_Context::$user_conf->keep_history_default = Minz_Request::param('keep_history_default', 0);
  195. FreshRSS_Context::$user_conf->ttl_default = Minz_Request::param('ttl_default', -2);
  196. FreshRSS_Context::$user_conf->save();
  197. invalidateHttpCache();
  198. Minz_Request::good(_t('feedback.conf.updated'),
  199. array('c' => 'configure', 'a' => 'archiving'));
  200. }
  201. Minz_View::prependTitle(_t('conf.archiving.title') . ' · ');
  202. $entryDAO = FreshRSS_Factory::createEntryDao();
  203. $this->view->nb_total = $entryDAO->count();
  204. $this->view->size_user = $entryDAO->size();
  205. if (FreshRSS_Auth::hasAccess('admin')) {
  206. $this->view->size_total = $entryDAO->size(true);
  207. }
  208. }
  209. /**
  210. * This action handles the user queries configuration page.
  211. *
  212. * If this action is reached through a POST request, it stores all new
  213. * configuration values then sends a notification to the user then
  214. * redirect to the same page.
  215. * If this action is not reached through a POST request, it displays the
  216. * configuration page and verifies that every user query is runable by
  217. * checking if categories and feeds are still in use.
  218. */
  219. public function queriesAction() {
  220. if (Minz_Request::isPost()) {
  221. $queries = Minz_Request::param('queries', array());
  222. foreach ($queries as $key => $query) {
  223. if (!$query['name']) {
  224. $query['name'] = _t('conf.query.number', $key + 1);
  225. }
  226. }
  227. FreshRSS_Context::$user_conf->queries = $queries;
  228. FreshRSS_Context::$user_conf->save();
  229. Minz_Request::good(_t('feedback.conf.updated'),
  230. array('c' => 'configure', 'a' => 'queries'));
  231. } else {
  232. $this->view->query_get = array();
  233. $cat_dao = new FreshRSS_CategoryDAO();
  234. $feed_dao = FreshRSS_Factory::createFeedDao();
  235. foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
  236. if (!isset($query['get'])) {
  237. continue;
  238. }
  239. switch ($query['get'][0]) {
  240. case 'c':
  241. $category = $cat_dao->searchById(substr($query['get'], 2));
  242. $deprecated = true;
  243. $cat_name = '';
  244. if ($category) {
  245. $cat_name = $category->name();
  246. $deprecated = false;
  247. }
  248. $this->view->query_get[$key] = array(
  249. 'type' => 'category',
  250. 'name' => $cat_name,
  251. 'deprecated' => $deprecated,
  252. );
  253. break;
  254. case 'f':
  255. $feed = $feed_dao->searchById(substr($query['get'], 2));
  256. $deprecated = true;
  257. $feed_name = '';
  258. if ($feed) {
  259. $feed_name = $feed->name();
  260. $deprecated = false;
  261. }
  262. $this->view->query_get[$key] = array(
  263. 'type' => 'feed',
  264. 'name' => $feed_name,
  265. 'deprecated' => $deprecated,
  266. );
  267. break;
  268. case 's':
  269. $this->view->query_get[$key] = array(
  270. 'type' => 'favorite',
  271. 'name' => 'favorite',
  272. 'deprecated' => false,
  273. );
  274. break;
  275. case 'a':
  276. $this->view->query_get[$key] = array(
  277. 'type' => 'all',
  278. 'name' => 'all',
  279. 'deprecated' => false,
  280. );
  281. break;
  282. }
  283. }
  284. }
  285. Minz_View::prependTitle(_t('conf.query.title') . ' · ');
  286. }
  287. /**
  288. * This action handles the creation of a user query.
  289. *
  290. * It gets the GET parameters and stores them in the configuration query
  291. * storage. Before it is saved, the unwanted parameters are unset to keep
  292. * lean data.
  293. */
  294. public function addQueryAction() {
  295. $whitelist = array('get', 'order', 'name', 'search', 'state');
  296. $queries = FreshRSS_Context::$user_conf->queries;
  297. $query = Minz_Request::params();
  298. $query['name'] = _t('conf.query.number', count($queries) + 1);
  299. foreach ($query as $key => $value) {
  300. if (!in_array($key, $whitelist)) {
  301. unset($query[$key]);
  302. }
  303. }
  304. $queries[] = $query;
  305. FreshRSS_Context::$user_conf->queries = $queries;
  306. FreshRSS_Context::$user_conf->save();
  307. Minz_Request::good(_t('feedback.conf.query_created', $query['name']),
  308. array('c' => 'configure', 'a' => 'queries'));
  309. }
  310. }