configureController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. $name = Minz_Request::param ('name', '');
  81. $description = sanitizeHTML(Minz_Request::param('description', '', true));
  82. $website = Minz_Request::param('website', '');
  83. $url = Minz_Request::param('url', '');
  84. $hist = Minz_Request::param ('keep_history', 'no');
  85. $cat = Minz_Request::param ('category', 0);
  86. $path = Minz_Request::param ('path_entries', '');
  87. $priority = Minz_Request::param ('priority', 0);
  88. $user = Minz_Request::param ('http_user', '');
  89. $pass = Minz_Request::param ('http_pass', '');
  90. $keep_history = false;
  91. if ($hist == 'yes') {
  92. $keep_history = true;
  93. }
  94. $httpAuth = '';
  95. if ($user != '' || $pass != '') {
  96. $httpAuth = $user . ':' . $pass;
  97. }
  98. $values = array (
  99. 'name' => $name,
  100. 'description' => $description,
  101. 'website' => $website,
  102. 'url' => $url,
  103. 'category' => $cat,
  104. 'pathEntries' => $path,
  105. 'priority' => $priority,
  106. 'httpAuth' => $httpAuth,
  107. 'keep_history' => $keep_history
  108. );
  109. if ($feedDAO->updateFeed ($id, $values)) {
  110. $this->view->flux->_category ($cat);
  111. $notif = array (
  112. 'type' => 'good',
  113. 'content' => Minz_Translate::t ('feed_updated')
  114. );
  115. } else {
  116. $notif = array (
  117. 'type' => 'bad',
  118. 'content' => Minz_Translate::t ('error_occurred_update')
  119. );
  120. }
  121. Minz_Session::_param ('notification', $notif);
  122. Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
  123. }
  124. Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - ');
  125. }
  126. } else {
  127. Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - ');
  128. }
  129. }
  130. public function displayAction () {
  131. if (Minz_Request::isPost ()) {
  132. $current_token = $this->view->conf->token ();
  133. $language = Minz_Request::param ('language', 'en');
  134. $nb = Minz_Request::param ('posts_per_page', 10);
  135. $mode = Minz_Request::param ('view_mode', 'normal');
  136. $view = Minz_Request::param ('default_view', 'a');
  137. $auto_load_more = Minz_Request::param ('auto_load_more', 'no');
  138. $display = Minz_Request::param ('display_posts', 'no');
  139. $onread_jump_next = Minz_Request::param ('onread_jump_next', 'no');
  140. $lazyload = Minz_Request::param ('lazyload', 'no');
  141. $sort = Minz_Request::param ('sort_order', 'DESC');
  142. $old = Minz_Request::param ('old_entries', 3);
  143. $mail = Minz_Request::param ('mail_login', false);
  144. $anon = Minz_Request::param ('anon_access', 'no');
  145. $token = Minz_Request::param ('token', $current_token);
  146. $openArticle = Minz_Request::param ('mark_open_article', 'no');
  147. $openSite = Minz_Request::param ('mark_open_site', 'no');
  148. $scroll = Minz_Request::param ('mark_scroll', 'no');
  149. $reception = Minz_Request::param ('mark_upon_reception', 'no');
  150. $theme = Minz_Request::param ('theme', 'default');
  151. $topline_read = Minz_Request::param ('topline_read', 'no');
  152. $topline_favorite = Minz_Request::param ('topline_favorite', 'no');
  153. $topline_date = Minz_Request::param ('topline_date', 'no');
  154. $topline_link = Minz_Request::param ('topline_link', 'no');
  155. $bottomline_read = Minz_Request::param ('bottomline_read', 'no');
  156. $bottomline_favorite = Minz_Request::param ('bottomline_favorite', 'no');
  157. $bottomline_sharing = Minz_Request::param ('bottomline_sharing', 'no');
  158. $bottomline_tags = Minz_Request::param ('bottomline_tags', 'no');
  159. $bottomline_date = Minz_Request::param ('bottomline_date', 'no');
  160. $bottomline_link = Minz_Request::param ('bottomline_link', 'no');
  161. $this->view->conf->_language ($language);
  162. $this->view->conf->_postsPerPage (intval ($nb));
  163. $this->view->conf->_viewMode ($mode);
  164. $this->view->conf->_defaultView ($view);
  165. $this->view->conf->_autoLoadMore ($auto_load_more);
  166. $this->view->conf->_displayPosts ($display);
  167. $this->view->conf->_onread_jump_next ($onread_jump_next);
  168. $this->view->conf->_lazyload ($lazyload);
  169. $this->view->conf->_sortOrder ($sort);
  170. $this->view->conf->_oldEntries ($old);
  171. $this->view->conf->_mailLogin ($mail);
  172. $this->view->conf->_anonAccess ($anon);
  173. $this->view->conf->_token ($token);
  174. $this->view->conf->_markWhen (array (
  175. 'article' => $openArticle,
  176. 'site' => $openSite,
  177. 'scroll' => $scroll,
  178. 'reception' => $reception,
  179. ));
  180. $this->view->conf->_theme ($theme);
  181. $this->view->conf->_topline_read ($topline_read);
  182. $this->view->conf->_topline_favorite ($topline_favorite);
  183. $this->view->conf->_topline_date ($topline_date);
  184. $this->view->conf->_topline_link ($topline_link);
  185. $this->view->conf->_bottomline_read ($bottomline_read);
  186. $this->view->conf->_bottomline_favorite ($bottomline_favorite);
  187. $this->view->conf->_bottomline_sharing ($bottomline_sharing);
  188. $this->view->conf->_bottomline_tags ($bottomline_tags);
  189. $this->view->conf->_bottomline_date ($bottomline_date);
  190. $this->view->conf->_bottomline_link ($bottomline_link);
  191. $values = array (
  192. 'language' => $this->view->conf->language (),
  193. 'posts_per_page' => $this->view->conf->postsPerPage (),
  194. 'view_mode' => $this->view->conf->viewMode (),
  195. 'default_view' => $this->view->conf->defaultView (),
  196. 'auto_load_more' => $this->view->conf->autoLoadMore (),
  197. 'display_posts' => $this->view->conf->displayPosts (),
  198. 'onread_jump_next' => $this->view->conf->onread_jump_next (),
  199. 'lazyload' => $this->view->conf->lazyload (),
  200. 'sort_order' => $this->view->conf->sortOrder (),
  201. 'old_entries' => $this->view->conf->oldEntries (),
  202. 'mail_login' => $this->view->conf->mailLogin (),
  203. 'anon_access' => $this->view->conf->anonAccess (),
  204. 'token' => $this->view->conf->token (),
  205. 'mark_when' => $this->view->conf->markWhen (),
  206. 'theme' => $this->view->conf->theme (),
  207. 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no',
  208. 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no',
  209. 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no',
  210. 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no',
  211. 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no',
  212. 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no',
  213. 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no',
  214. 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no',
  215. 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no',
  216. 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no',
  217. );
  218. $confDAO = new FreshRSS_ConfigurationDAO ();
  219. $confDAO->update ($values);
  220. Minz_Session::_param ('conf', $this->view->conf);
  221. Minz_Session::_param ('mail', $this->view->conf->mailLogin ());
  222. Minz_Session::_param ('language', $this->view->conf->language ());
  223. Minz_Translate::reset ();
  224. // notif
  225. $notif = array (
  226. 'type' => 'good',
  227. 'content' => Minz_Translate::t ('configuration_updated')
  228. );
  229. Minz_Session::_param ('notification', $notif);
  230. Minz_Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  231. }
  232. $this->view->themes = FreshRSS_Themes::get();
  233. Minz_View::prependTitle (Minz_Translate::t ('general_and_reading_management') . ' - ');
  234. $entryDAO = new FreshRSS_EntryDAO ();
  235. $this->view->nb_total = $entryDAO->count ();
  236. $this->view->size_total = $entryDAO->size ();
  237. }
  238. public function sharingAction () {
  239. if (Minz_Request::isPost ()) {
  240. $this->view->conf->_sharing (array (
  241. 'shaarli' => Minz_Request::param ('shaarli', ''),
  242. 'poche' => Minz_Request::param ('poche', ''),
  243. 'diaspora' => Minz_Request::param ('diaspora', ''),
  244. 'twitter' => Minz_Request::param ('twitter', 'no') === 'yes',
  245. 'g+' => Minz_Request::param ('g+', 'no') === 'yes',
  246. 'facebook' => Minz_Request::param ('facebook', 'no') === 'yes',
  247. 'email' => Minz_Request::param ('email', 'no') === 'yes',
  248. 'print' => Minz_Request::param ('print', 'no') === 'yes'
  249. ));
  250. $confDAO = new FreshRSS_ConfigurationDAO ();
  251. $confDAO->update ($this->view->conf->sharing ());
  252. Minz_Session::_param ('conf', $this->view->conf);
  253. // notif
  254. $notif = array (
  255. 'type' => 'good',
  256. 'content' => Minz_Translate::t ('configuration_updated')
  257. );
  258. Minz_Session::_param ('notification', $notif);
  259. Minz_Request::forward (array ('c' => 'configure', 'a' => 'sharing'), true);
  260. }
  261. Minz_View::prependTitle (Minz_Translate::t ('sharing_management') . ' - ');
  262. $entryDAO = new FreshRSS_EntryDAO ();
  263. $this->view->nb_total = $entryDAO->count ();
  264. }
  265. public function importExportAction () {
  266. $catDAO = new FreshRSS_CategoryDAO ();
  267. $this->view->categories = $catDAO->listCategories ();
  268. $this->view->req = Minz_Request::param ('q');
  269. if ($this->view->req == 'export') {
  270. Minz_View::_title ('freshrss_feeds.opml');
  271. $this->view->_useLayout (false);
  272. header('Content-Type: application/xml; charset=utf-8');
  273. header('Content-disposition: attachment; filename=freshrss_feeds.opml');
  274. $feedDAO = new FreshRSS_FeedDAO ();
  275. $catDAO = new FreshRSS_CategoryDAO ();
  276. $list = array ();
  277. foreach ($catDAO->listCategories () as $key => $cat) {
  278. $list[$key]['name'] = $cat->name ();
  279. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  280. }
  281. $this->view->categories = $list;
  282. } elseif ($this->view->req == 'import' && Minz_Request::isPost ()) {
  283. if ($_FILES['file']['error'] == 0) {
  284. // on parse le fichier OPML pour récupérer les catégories et les flux associés
  285. try {
  286. list ($categories, $feeds) = opml_import (
  287. file_get_contents ($_FILES['file']['tmp_name'])
  288. );
  289. // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
  290. // les flux sont mis au préalable dans des variables de Request
  291. Minz_Request::_param ('q', 'null');
  292. Minz_Request::_param ('categories', $categories);
  293. Minz_Request::_param ('feeds', $feeds);
  294. Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  295. } catch (FreshRSS_Opml_Exception $e) {
  296. Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
  297. $notif = array (
  298. 'type' => 'bad',
  299. 'content' => Minz_Translate::t ('bad_opml_file')
  300. );
  301. Minz_Session::_param ('notification', $notif);
  302. Minz_Request::forward (array (
  303. 'c' => 'configure',
  304. 'a' => 'importExport'
  305. ), true);
  306. }
  307. }
  308. }
  309. $feedDAO = new FreshRSS_FeedDAO ();
  310. $this->view->feeds = $feedDAO->listFeeds ();
  311. // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
  312. $this->view->flux = false;
  313. Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' - ');
  314. }
  315. public function shortcutAction () {
  316. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  317. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  318. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  319. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  320. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  321. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  322. 'f10', 'f11', 'f12');
  323. $this->view->list_keys = $list_keys;
  324. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  325. 'prev_entry', 'next_page', 'prev_page', 'collapse_entry',
  326. 'load_more');
  327. if (Minz_Request::isPost ()) {
  328. $shortcuts = Minz_Request::param ('shortcuts');
  329. $shortcuts_ok = array ();
  330. foreach ($shortcuts as $key => $value) {
  331. if (in_array ($key, $list_names)
  332. && in_array ($value, $list_keys)) {
  333. $shortcuts_ok[$key] = $value;
  334. }
  335. }
  336. $this->view->conf->_shortcuts ($shortcuts_ok);
  337. $values = array (
  338. 'shortcuts' => $this->view->conf->shortcuts ()
  339. );
  340. $confDAO = new FreshRSS_ConfigurationDAO ();
  341. $confDAO->update ($values);
  342. Minz_Session::_param ('conf', $this->view->conf);
  343. // notif
  344. $notif = array (
  345. 'type' => 'good',
  346. 'content' => Minz_Translate::t ('shortcuts_updated')
  347. );
  348. Minz_Session::_param ('notification', $notif);
  349. Minz_Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  350. }
  351. Minz_View::prependTitle (Minz_Translate::t ('shortcuts_management') . ' - ');
  352. }
  353. }