configureController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  2. class FreshRSS_configure_Controller extends Minz_ActionController {
  3. public function firstAction () {
  4. if (login_is_conf ($this->view->conf) && !is_logged ()) {
  5. Minz_Error::error (
  6. 403,
  7. array ('error' => array (Minz_Translate::t ('access_denied')))
  8. );
  9. }
  10. $catDAO = new FreshRSS_CategoryDAO ();
  11. $catDAO->checkDefault ();
  12. }
  13. public function categorizeAction () {
  14. $feedDAO = new FreshRSS_FeedDAO ();
  15. $catDAO = new FreshRSS_CategoryDAO ();
  16. $catDAO->checkDefault ();
  17. $defaultCategory = $catDAO->getDefault ();
  18. $defaultId = $defaultCategory->id ();
  19. if (Minz_Request::isPost ()) {
  20. $cats = Minz_Request::param ('categories', array ());
  21. $ids = Minz_Request::param ('ids', array ());
  22. $newCat = trim (Minz_Request::param ('new_category', ''));
  23. foreach ($cats as $key => $name) {
  24. if (strlen ($name) > 0) {
  25. $cat = new FreshRSS_Category ($name);
  26. $values = array (
  27. 'name' => $cat->name (),
  28. 'color' => $cat->color ()
  29. );
  30. $catDAO->updateCategory ($ids[$key], $values);
  31. } elseif ($ids[$key] != $defaultId) {
  32. $feedDAO->changeCategory ($ids[$key], $defaultId);
  33. $catDAO->deleteCategory ($ids[$key]);
  34. }
  35. }
  36. if ($newCat != '') {
  37. $cat = new FreshRSS_Category ($newCat);
  38. $values = array (
  39. 'id' => $cat->id (),
  40. 'name' => $cat->name (),
  41. 'color' => $cat->color ()
  42. );
  43. if ($catDAO->searchByName ($newCat) == false) {
  44. $catDAO->addCategory ($values);
  45. }
  46. }
  47. // notif
  48. $notif = array (
  49. 'type' => 'good',
  50. 'content' => Minz_Translate::t ('categories_updated')
  51. );
  52. Minz_Session::_param ('notification', $notif);
  53. Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
  54. }
  55. $this->view->categories = $catDAO->listCategories (false);
  56. $this->view->defaultCategory = $catDAO->getDefault ();
  57. $this->view->feeds = $feedDAO->listFeeds ();
  58. $this->view->flux = false;
  59. Minz_View::prependTitle (Minz_Translate::t ('categories_management') . ' - ');
  60. }
  61. public function feedAction () {
  62. $catDAO = new FreshRSS_CategoryDAO ();
  63. $this->view->categories = $catDAO->listCategories (false);
  64. $feedDAO = new FreshRSS_FeedDAO ();
  65. $this->view->feeds = $feedDAO->listFeeds ();
  66. $id = Minz_Request::param ('id');
  67. if ($id == false && !empty ($this->view->feeds)) {
  68. $id = current ($this->view->feeds)->id ();
  69. }
  70. $this->view->flux = false;
  71. if ($id != false) {
  72. $this->view->flux = $this->view->feeds[$id];
  73. if (!$this->view->flux) {
  74. Minz_Error::error (
  75. 404,
  76. array ('error' => array (Minz_Translate::t ('page_not_found')))
  77. );
  78. } else {
  79. if (Minz_Request::isPost () && $this->view->flux) {
  80. $user = Minz_Request::param ('http_user', '');
  81. $pass = Minz_Request::param ('http_pass', '');
  82. $httpAuth = '';
  83. if ($user != '' || $pass != '') {
  84. $httpAuth = $user . ':' . $pass;
  85. }
  86. $values = array (
  87. 'name' => Minz_Request::param ('name', ''),
  88. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  89. 'website' => Minz_Request::param('website', ''),
  90. 'url' => Minz_Request::param('url', ''),
  91. 'category' => intval(Minz_Request::param ('category', 0)),
  92. 'pathEntries' => Minz_Request::param ('path_entries', ''),
  93. 'priority' => intval(Minz_Request::param ('priority', 0)),
  94. 'httpAuth' => $httpAuth,
  95. 'keep_history' => intval(Minz_Request::param ('keep_history', -2)),
  96. );
  97. if ($feedDAO->updateFeed ($id, $values)) {
  98. $this->view->flux->_category ($cat);
  99. $notif = array (
  100. 'type' => 'good',
  101. 'content' => Minz_Translate::t ('feed_updated')
  102. );
  103. } else {
  104. $notif = array (
  105. 'type' => 'bad',
  106. 'content' => Minz_Translate::t ('error_occurred_update')
  107. );
  108. }
  109. Minz_Session::_param ('notification', $notif);
  110. Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
  111. }
  112. Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - ');
  113. }
  114. } else {
  115. Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - ');
  116. }
  117. }
  118. public function displayAction () {
  119. if (Minz_Request::isPost ()) {
  120. $current_token = $this->view->conf->token ();
  121. $language = Minz_Request::param ('language', 'en');
  122. $nb = Minz_Request::param ('posts_per_page', 10);
  123. $mode = Minz_Request::param ('view_mode', 'normal');
  124. $view = Minz_Request::param ('default_view', 'a');
  125. $auto_load_more = Minz_Request::param ('auto_load_more', 'no');
  126. $display = Minz_Request::param ('display_posts', 'no');
  127. $onread_jump_next = Minz_Request::param ('onread_jump_next', 'no');
  128. $lazyload = Minz_Request::param ('lazyload', 'no');
  129. $sort = Minz_Request::param ('sort_order', 'DESC');
  130. $openArticle = Minz_Request::param ('mark_open_article', 'no');
  131. $openSite = Minz_Request::param ('mark_open_site', 'no');
  132. $scroll = Minz_Request::param ('mark_scroll', 'no');
  133. $reception = Minz_Request::param ('mark_upon_reception', 'no');
  134. $theme = Minz_Request::param ('theme', 'default');
  135. $topline_read = Minz_Request::param ('topline_read', 'no');
  136. $topline_favorite = Minz_Request::param ('topline_favorite', 'no');
  137. $topline_date = Minz_Request::param ('topline_date', 'no');
  138. $topline_link = Minz_Request::param ('topline_link', 'no');
  139. $bottomline_read = Minz_Request::param ('bottomline_read', 'no');
  140. $bottomline_favorite = Minz_Request::param ('bottomline_favorite', 'no');
  141. $bottomline_sharing = Minz_Request::param ('bottomline_sharing', 'no');
  142. $bottomline_tags = Minz_Request::param ('bottomline_tags', 'no');
  143. $bottomline_date = Minz_Request::param ('bottomline_date', 'no');
  144. $bottomline_link = Minz_Request::param ('bottomline_link', 'no');
  145. $this->view->conf->_language ($language);
  146. $this->view->conf->_postsPerPage ($nb);
  147. $this->view->conf->_viewMode ($mode);
  148. $this->view->conf->_defaultView ($view);
  149. $this->view->conf->_autoLoadMore ($auto_load_more);
  150. $this->view->conf->_displayPosts ($display);
  151. $this->view->conf->_onread_jump_next ($onread_jump_next);
  152. $this->view->conf->_lazyload ($lazyload);
  153. $this->view->conf->_sortOrder ($sort);
  154. $this->view->conf->_markWhen (array (
  155. 'article' => $openArticle,
  156. 'site' => $openSite,
  157. 'scroll' => $scroll,
  158. 'reception' => $reception,
  159. ));
  160. $this->view->conf->_theme ($theme);
  161. $this->view->conf->_topline_read ($topline_read);
  162. $this->view->conf->_topline_favorite ($topline_favorite);
  163. $this->view->conf->_topline_date ($topline_date);
  164. $this->view->conf->_topline_link ($topline_link);
  165. $this->view->conf->_bottomline_read ($bottomline_read);
  166. $this->view->conf->_bottomline_favorite ($bottomline_favorite);
  167. $this->view->conf->_bottomline_sharing ($bottomline_sharing);
  168. $this->view->conf->_bottomline_tags ($bottomline_tags);
  169. $this->view->conf->_bottomline_date ($bottomline_date);
  170. $this->view->conf->_bottomline_link ($bottomline_link);
  171. $values = array (
  172. 'language' => $this->view->conf->language (),
  173. 'posts_per_page' => $this->view->conf->postsPerPage (),
  174. 'view_mode' => $this->view->conf->viewMode (),
  175. 'default_view' => $this->view->conf->defaultView (),
  176. 'auto_load_more' => $this->view->conf->autoLoadMore (),
  177. 'display_posts' => $this->view->conf->displayPosts (),
  178. 'onread_jump_next' => $this->view->conf->onread_jump_next (),
  179. 'lazyload' => $this->view->conf->lazyload (),
  180. 'sort_order' => $this->view->conf->sortOrder (),
  181. 'mark_when' => $this->view->conf->markWhen (),
  182. 'theme' => $this->view->conf->theme (),
  183. 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no',
  184. 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no',
  185. 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no',
  186. 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no',
  187. 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no',
  188. 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no',
  189. 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no',
  190. 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no',
  191. 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no',
  192. 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no',
  193. );
  194. $confDAO = new FreshRSS_ConfigurationDAO ();
  195. $confDAO->update ($values);
  196. Minz_Session::_param ('conf', $this->view->conf);
  197. Minz_Session::_param ('mail', $this->view->conf->mailLogin ());
  198. Minz_Session::_param ('language', $this->view->conf->language ());
  199. Minz_Translate::reset ();
  200. // notif
  201. $notif = array (
  202. 'type' => 'good',
  203. 'content' => Minz_Translate::t ('configuration_updated')
  204. );
  205. Minz_Session::_param ('notification', $notif);
  206. Minz_Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  207. }
  208. $this->view->themes = FreshRSS_Themes::get();
  209. Minz_View::prependTitle (Minz_Translate::t ('reading_configuration') . ' - ');
  210. }
  211. public function sharingAction () {
  212. if (Minz_Request::isPost ()) {
  213. $this->view->conf->_sharing (array (
  214. 'shaarli' => Minz_Request::param ('shaarli', ''),
  215. 'poche' => Minz_Request::param ('poche', ''),
  216. 'diaspora' => Minz_Request::param ('diaspora', ''),
  217. 'twitter' => Minz_Request::param ('twitter', 'no') === 'yes',
  218. 'g+' => Minz_Request::param ('g+', 'no') === 'yes',
  219. 'facebook' => Minz_Request::param ('facebook', 'no') === 'yes',
  220. 'email' => Minz_Request::param ('email', 'no') === 'yes',
  221. 'print' => Minz_Request::param ('print', 'no') === 'yes'
  222. ));
  223. $confDAO = new FreshRSS_ConfigurationDAO ();
  224. $confDAO->update ($this->view->conf->sharing ());
  225. Minz_Session::_param ('conf', $this->view->conf);
  226. // notif
  227. $notif = array (
  228. 'type' => 'good',
  229. 'content' => Minz_Translate::t ('configuration_updated')
  230. );
  231. Minz_Session::_param ('notification', $notif);
  232. Minz_Request::forward (array ('c' => 'configure', 'a' => 'sharing'), true);
  233. }
  234. Minz_View::prependTitle (Minz_Translate::t ('sharing_management') . ' - ');
  235. $entryDAO = new FreshRSS_EntryDAO ();
  236. $this->view->nb_total = $entryDAO->count ();
  237. }
  238. public function importExportAction () {
  239. require_once(LIB_PATH . '/lib_opml.php');
  240. $catDAO = new FreshRSS_CategoryDAO ();
  241. $this->view->categories = $catDAO->listCategories ();
  242. $this->view->req = Minz_Request::param ('q');
  243. if ($this->view->req == 'export') {
  244. Minz_View::_title ('freshrss_feeds.opml');
  245. $this->view->_useLayout (false);
  246. header('Content-Type: application/xml; charset=utf-8');
  247. header('Content-disposition: attachment; filename=freshrss_feeds.opml');
  248. $feedDAO = new FreshRSS_FeedDAO ();
  249. $catDAO = new FreshRSS_CategoryDAO ();
  250. $list = array ();
  251. foreach ($catDAO->listCategories () as $key => $cat) {
  252. $list[$key]['name'] = $cat->name ();
  253. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  254. }
  255. $this->view->categories = $list;
  256. } elseif ($this->view->req == 'import' && Minz_Request::isPost ()) {
  257. if ($_FILES['file']['error'] == 0) {
  258. // on parse le fichier OPML pour récupérer les catégories et les flux associés
  259. try {
  260. list ($categories, $feeds) = opml_import (
  261. file_get_contents ($_FILES['file']['tmp_name'])
  262. );
  263. // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
  264. // les flux sont mis au préalable dans des variables de Request
  265. Minz_Request::_param ('q', 'null');
  266. Minz_Request::_param ('categories', $categories);
  267. Minz_Request::_param ('feeds', $feeds);
  268. Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  269. } catch (FreshRSS_Opml_Exception $e) {
  270. Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
  271. $notif = array (
  272. 'type' => 'bad',
  273. 'content' => Minz_Translate::t ('bad_opml_file')
  274. );
  275. Minz_Session::_param ('notification', $notif);
  276. Minz_Request::forward (array (
  277. 'c' => 'configure',
  278. 'a' => 'importExport'
  279. ), true);
  280. }
  281. }
  282. }
  283. $feedDAO = new FreshRSS_FeedDAO ();
  284. $this->view->feeds = $feedDAO->listFeeds ();
  285. // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
  286. $this->view->flux = false;
  287. Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' - ');
  288. }
  289. public function shortcutAction () {
  290. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  291. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  292. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  293. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  294. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  295. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  296. 'f10', 'f11', 'f12');
  297. $this->view->list_keys = $list_keys;
  298. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  299. 'prev_entry', 'next_page', 'prev_page', 'collapse_entry',
  300. 'load_more');
  301. if (Minz_Request::isPost ()) {
  302. $shortcuts = Minz_Request::param ('shortcuts');
  303. $shortcuts_ok = array ();
  304. foreach ($shortcuts as $key => $value) {
  305. if (in_array ($key, $list_names)
  306. && in_array ($value, $list_keys)) {
  307. $shortcuts_ok[$key] = $value;
  308. }
  309. }
  310. $this->view->conf->_shortcuts ($shortcuts_ok);
  311. $values = array (
  312. 'shortcuts' => $this->view->conf->shortcuts ()
  313. );
  314. $confDAO = new FreshRSS_ConfigurationDAO ();
  315. $confDAO->update ($values);
  316. Minz_Session::_param ('conf', $this->view->conf);
  317. // notif
  318. $notif = array (
  319. 'type' => 'good',
  320. 'content' => Minz_Translate::t ('shortcuts_updated')
  321. );
  322. Minz_Session::_param ('notification', $notif);
  323. Minz_Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  324. }
  325. Minz_View::prependTitle (Minz_Translate::t ('shortcuts_management') . ' - ');
  326. }
  327. public function usersAction() {
  328. if (Minz_Request::isPost()) {
  329. $ok = true;
  330. $current_token = $this->view->conf->token();
  331. $mail = Minz_Request::param('mail_login', false);
  332. $token = Minz_Request::param('token', $current_token);
  333. $this->view->conf->_mailLogin($mail);
  334. $this->view->conf->_token($token);
  335. $values = array(
  336. 'mail_login' => $this->view->conf->mailLogin(),
  337. 'token' => $this->view->conf->token(),
  338. );
  339. $confDAO = new FreshRSS_ConfigurationDAO();
  340. $ok &= $confDAO->update($values);
  341. Minz_Session::_param('conf', $this->view->conf);
  342. Minz_Session::_param('mail', $this->view->conf->mailLogin());
  343. if (Minz_Configuration::isAdmin()) {
  344. $anon = (bool)(Minz_Request::param('anon_access', false));
  345. if ($anon != Minz_Configuration::allowAnonymous()) {
  346. Minz_Configuration::_allowAnonymous($anon);
  347. $ok &= Minz_Configuration::writeFile();
  348. }
  349. }
  350. //TODO: use $ok
  351. $notif = array(
  352. 'type' => 'good',
  353. 'content' => Minz_Translate::t('configuration_updated')
  354. );
  355. Minz_Session::_param('notification', $notif);
  356. Minz_Request::forward(array('c' => 'configure', 'a' => 'users'), true);
  357. }
  358. Minz_View::prependTitle(Minz_Translate::t ('users') . ' - ');
  359. }
  360. public function archivingAction () {
  361. if (Minz_Request::isPost()) {
  362. $old = Minz_Request::param('old_entries', 3);
  363. $keepHistoryDefault = Minz_Request::param('keep_history_default', 0);
  364. $this->view->conf->_oldEntries($old);
  365. $this->view->conf->_keepHistoryDefault($keepHistoryDefault);
  366. $values = array(
  367. 'old_entries' => $this->view->conf->oldEntries(),
  368. 'keep_history_default' => $this->view->conf->keepHistoryDefault(),
  369. );
  370. $confDAO = new FreshRSS_ConfigurationDAO();
  371. $confDAO->update($values);
  372. Minz_Session::_param('conf', $this->view->conf);
  373. Minz_Session::_param('mail', $this->view->conf->mailLogin ());
  374. // notif
  375. $notif = array(
  376. 'type' => 'good',
  377. 'content' => Minz_Translate::t('configuration_updated')
  378. );
  379. Minz_Session::_param('notification', $notif);
  380. Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true);
  381. }
  382. Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' - ');
  383. $entryDAO = new FreshRSS_EntryDAO();
  384. $this->view->nb_total = $entryDAO->count();
  385. $this->view->size_total = $entryDAO->size();
  386. }
  387. }