configureController.php 16 KB

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