configureController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. class configureController extends ActionController {
  3. public function firstAction () {
  4. if (login_is_conf ($this->view->conf) && !is_logged ()) {
  5. Error::error (
  6. 403,
  7. array ('error' => array (Translate::t ('access_denied')))
  8. );
  9. }
  10. $catDAO = new CategoryDAO ();
  11. $catDAO->checkDefault ();
  12. }
  13. public function categorizeAction () {
  14. $feedDAO = new FeedDAO ();
  15. $catDAO = new CategoryDAO ();
  16. $catDAO->checkDefault ();
  17. $defaultCategory = $catDAO->getDefault ();
  18. $defaultId = $defaultCategory->id ();
  19. if (Request::isPost ()) {
  20. $cats = Request::param ('categories', array ());
  21. $ids = Request::param ('ids', array ());
  22. $newCat = trim (Request::param ('new_category', ''));
  23. foreach ($cats as $key => $name) {
  24. if (strlen ($name) > 0) {
  25. $cat = new 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 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' => Translate::t ('categories_updated')
  51. );
  52. Session::_param ('notification', $notif);
  53. 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. View::prependTitle (Translate::t ('categories_management') . ' - ');
  60. }
  61. public function feedAction () {
  62. $catDAO = new CategoryDAO ();
  63. $this->view->categories = $catDAO->listCategories (false);
  64. $feedDAO = new FeedDAO ();
  65. $this->view->feeds = $feedDAO->listFeeds ();
  66. $id = 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 = $feedDAO->searchById ($id);
  73. if (!$this->view->flux) {
  74. Error::error (
  75. 404,
  76. array ('error' => array (Translate::t ('page_not_found')))
  77. );
  78. } else {
  79. $catDAO = new CategoryDAO ();
  80. $this->view->categories = $catDAO->listCategories (false);
  81. if (Request::isPost () && $this->view->flux) {
  82. $name = Request::param ('name', '');
  83. $hist = Request::param ('keep_history', 'no');
  84. $cat = Request::param ('category', 0);
  85. $path = Request::param ('path_entries', '');
  86. $priority = Request::param ('priority', 0);
  87. $user = Request::param ('http_user', '');
  88. $pass = Request::param ('http_pass', '');
  89. $keep_history = false;
  90. if ($hist == 'yes') {
  91. $keep_history = true;
  92. }
  93. $httpAuth = '';
  94. if ($user != '' || $pass != '') {
  95. $httpAuth = $user . ':' . $pass;
  96. }
  97. $values = array (
  98. 'name' => $name,
  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' => Translate::t ('feed_updated')
  110. );
  111. } else {
  112. $notif = array (
  113. 'type' => 'bad',
  114. 'content' => Translate::t ('error_occurred_update')
  115. );
  116. }
  117. Session::_param ('notification', $notif);
  118. Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
  119. }
  120. View::prependTitle (Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - ');
  121. }
  122. } else {
  123. View::prependTitle (Translate::t ('rss_feed_management') . ' - ');
  124. }
  125. }
  126. public function displayAction () {
  127. if (Request::isPost ()) {
  128. $current_token = $this->view->conf->token ();
  129. $language = Request::param ('language', 'en');
  130. $nb = Request::param ('posts_per_page', 10);
  131. $mode = Request::param ('view_mode', 'normal');
  132. $view = Request::param ('default_view', 'all');
  133. $auto_load_more = Request::param ('auto_load_more', 'no');
  134. $display = Request::param ('display_posts', 'no');
  135. $onread_jump_next = Request::param ('onread_jump_next', 'no');
  136. $lazyload = Request::param ('lazyload', 'no');
  137. $sort = Request::param ('sort_order', 'low_to_high');
  138. $old = Request::param ('old_entries', 3);
  139. $mail = Request::param ('mail_login', false);
  140. $anon = Request::param ('anon_access', 'no');
  141. $token = Request::param ('token', $current_token);
  142. $openArticle = Request::param ('mark_open_article', 'no');
  143. $openSite = Request::param ('mark_open_site', 'no');
  144. $scroll = Request::param ('mark_scroll', 'no');
  145. $urlShaarli = Request::param ('shaarli', '');
  146. $theme = Request::param ('theme', 'default');
  147. $topline_read = Request::param ('topline_read', 'no');
  148. $topline_favorite = Request::param ('topline_favorite', 'no');
  149. $topline_date = Request::param ('topline_date', 'no');
  150. $topline_link = Request::param ('topline_link', 'no');
  151. $bottomline_read = Request::param ('bottomline_read', 'no');
  152. $bottomline_favorite = Request::param ('bottomline_favorite', 'no');
  153. $bottomline_sharing = Request::param ('bottomline_sharing', 'no');
  154. $bottomline_tags = Request::param ('bottomline_tags', 'no');
  155. $bottomline_date = Request::param ('bottomline_date', 'no');
  156. $bottomline_link = Request::param ('bottomline_link', 'no');
  157. $this->view->conf->_language ($language);
  158. $this->view->conf->_postsPerPage (intval ($nb));
  159. $this->view->conf->_viewMode ($mode);
  160. $this->view->conf->_defaultView ($view);
  161. $this->view->conf->_autoLoadMore ($auto_load_more);
  162. $this->view->conf->_displayPosts ($display);
  163. $this->view->conf->_onread_jump_next ($onread_jump_next);
  164. $this->view->conf->_lazyload ($lazyload);
  165. $this->view->conf->_sortOrder ($sort);
  166. $this->view->conf->_oldEntries ($old);
  167. $this->view->conf->_mailLogin ($mail);
  168. $this->view->conf->_anonAccess ($anon);
  169. $this->view->conf->_token ($token);
  170. $this->view->conf->_markWhen (array (
  171. 'article' => $openArticle,
  172. 'site' => $openSite,
  173. 'scroll' => $scroll,
  174. ));
  175. $this->view->conf->_urlShaarli ($urlShaarli);
  176. $this->view->conf->_theme ($theme);
  177. $this->view->conf->_topline_read ($topline_read);
  178. $this->view->conf->_topline_favorite ($topline_favorite);
  179. $this->view->conf->_topline_date ($topline_date);
  180. $this->view->conf->_topline_link ($topline_link);
  181. $this->view->conf->_bottomline_read ($bottomline_read);
  182. $this->view->conf->_bottomline_favorite ($bottomline_favorite);
  183. $this->view->conf->_bottomline_sharing ($bottomline_sharing);
  184. $this->view->conf->_bottomline_tags ($bottomline_tags);
  185. $this->view->conf->_bottomline_date ($bottomline_date);
  186. $this->view->conf->_bottomline_link ($bottomline_link);
  187. $values = array (
  188. 'language' => $this->view->conf->language (),
  189. 'posts_per_page' => $this->view->conf->postsPerPage (),
  190. 'view_mode' => $this->view->conf->viewMode (),
  191. 'default_view' => $this->view->conf->defaultView (),
  192. 'auto_load_more' => $this->view->conf->autoLoadMore (),
  193. 'display_posts' => $this->view->conf->displayPosts (),
  194. 'onread_jump_next' => $this->view->conf->onread_jump_next (),
  195. 'lazyload' => $this->view->conf->lazyload (),
  196. 'sort_order' => $this->view->conf->sortOrder (),
  197. 'old_entries' => $this->view->conf->oldEntries (),
  198. 'mail_login' => $this->view->conf->mailLogin (),
  199. 'anon_access' => $this->view->conf->anonAccess (),
  200. 'token' => $this->view->conf->token (),
  201. 'mark_when' => $this->view->conf->markWhen (),
  202. 'url_shaarli' => $this->view->conf->urlShaarli (),
  203. 'theme' => $this->view->conf->theme (),
  204. 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no',
  205. 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no',
  206. 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no',
  207. 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no',
  208. 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no',
  209. 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no',
  210. 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no',
  211. 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no',
  212. 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no',
  213. 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no',
  214. );
  215. $confDAO = new RSSConfigurationDAO ();
  216. $confDAO->update ($values);
  217. Session::_param ('conf', $this->view->conf);
  218. Session::_param ('mail', $this->view->conf->mailLogin ());
  219. Session::_param ('language', $this->view->conf->language ());
  220. Translate::reset ();
  221. // notif
  222. $notif = array (
  223. 'type' => 'good',
  224. 'content' => Translate::t ('configuration_updated')
  225. );
  226. Session::_param ('notification', $notif);
  227. Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  228. }
  229. $this->view->themes = RSSThemes::get();
  230. View::prependTitle (Translate::t ('general_and_reading_management') . ' - ');
  231. }
  232. public function importExportAction () {
  233. $catDAO = new CategoryDAO ();
  234. $this->view->categories = $catDAO->listCategories ();
  235. $this->view->req = Request::param ('q');
  236. if ($this->view->req == 'export') {
  237. View::_title ('freshrss_feeds.opml');
  238. $this->view->_useLayout (false);
  239. header('Content-Type: text/xml; charset=utf-8');
  240. header('Content-disposition: attachment; filename=freshrss_feeds.opml');
  241. $feedDAO = new FeedDAO ();
  242. $catDAO = new CategoryDAO ();
  243. $list = array ();
  244. foreach ($catDAO->listCategories () as $key => $cat) {
  245. $list[$key]['name'] = $cat->name ();
  246. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  247. }
  248. $this->view->categories = $list;
  249. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  250. if ($_FILES['file']['error'] == 0) {
  251. // on parse le fichier OPML pour récupérer les catégories et les flux associés
  252. try {
  253. list ($categories, $feeds) = opml_import (
  254. file_get_contents ($_FILES['file']['tmp_name'])
  255. );
  256. // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
  257. // les flux sont mis au préalable dans des variables de Request
  258. Request::_param ('q', 'null');
  259. Request::_param ('categories', $categories);
  260. Request::_param ('feeds', $feeds);
  261. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  262. } catch (OpmlException $e) {
  263. Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
  264. $notif = array (
  265. 'type' => 'bad',
  266. 'content' => Translate::t ('bad_opml_file')
  267. );
  268. Session::_param ('notification', $notif);
  269. Request::forward (array (
  270. 'c' => 'configure',
  271. 'a' => 'importExport'
  272. ), true);
  273. }
  274. }
  275. }
  276. $feedDAO = new FeedDAO ();
  277. $this->view->feeds = $feedDAO->listFeeds ();
  278. // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
  279. $this->view->flux = false;
  280. View::prependTitle (Translate::t ('import_export_opml') . ' - ');
  281. }
  282. public function shortcutAction () {
  283. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  284. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  285. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  286. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  287. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  288. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  289. 'f10', 'f11', 'f12');
  290. $this->view->list_keys = $list_keys;
  291. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  292. 'prev_entry', 'next_page', 'prev_page');
  293. if (Request::isPost ()) {
  294. $shortcuts = Request::param ('shortcuts');
  295. $shortcuts_ok = array ();
  296. foreach ($shortcuts as $key => $value) {
  297. if (in_array ($key, $list_names)
  298. && in_array ($value, $list_keys)) {
  299. $shortcuts_ok[$key] = $value;
  300. }
  301. }
  302. $this->view->conf->_shortcuts ($shortcuts_ok);
  303. $values = array (
  304. 'shortcuts' => $this->view->conf->shortcuts ()
  305. );
  306. $confDAO = new RSSConfigurationDAO ();
  307. $confDAO->update ($values);
  308. Session::_param ('conf', $this->view->conf);
  309. // notif
  310. $notif = array (
  311. 'type' => 'good',
  312. 'content' => Translate::t ('shortcuts_updated')
  313. );
  314. Session::_param ('notification', $notif);
  315. Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  316. }
  317. View::prependTitle (Translate::t ('shortcuts_management') . ' - ');
  318. }
  319. }