configureController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 = $this->view->feeds[$id];
  73. if (!$this->view->flux) {
  74. Error::error (
  75. 404,
  76. array ('error' => array (Translate::t ('page_not_found')))
  77. );
  78. } else {
  79. if (Request::isPost () && $this->view->flux) {
  80. $name = Request::param ('name', '');
  81. $description = Request::param('description', '');
  82. $website = Request::param('website', '');
  83. $url = Request::param('url', '');
  84. $hist = Request::param ('keep_history', 'no');
  85. $cat = Request::param ('category', 0);
  86. $path = Request::param ('path_entries', '');
  87. $priority = Request::param ('priority', 0);
  88. $user = Request::param ('http_user', '');
  89. $pass = 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' => Translate::t ('feed_updated')
  114. );
  115. } else {
  116. $notif = array (
  117. 'type' => 'bad',
  118. 'content' => Translate::t ('error_occurred_update')
  119. );
  120. }
  121. Session::_param ('notification', $notif);
  122. Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
  123. }
  124. View::prependTitle (Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - ');
  125. }
  126. } else {
  127. View::prependTitle (Translate::t ('rss_feed_management') . ' - ');
  128. }
  129. }
  130. public function displayAction () {
  131. if (Request::isPost ()) {
  132. $current_token = $this->view->conf->token ();
  133. $language = Request::param ('language', 'en');
  134. $nb = Request::param ('posts_per_page', 10);
  135. $mode = Request::param ('view_mode', 'normal');
  136. $view = Request::param ('default_view', 'all');
  137. $auto_load_more = Request::param ('auto_load_more', 'no');
  138. $display = Request::param ('display_posts', 'no');
  139. $onread_jump_next = Request::param ('onread_jump_next', 'no');
  140. $lazyload = Request::param ('lazyload', 'no');
  141. $sort = Request::param ('sort_order', 'low_to_high');
  142. $old = Request::param ('old_entries', 3);
  143. $mail = Request::param ('mail_login', false);
  144. $anon = Request::param ('anon_access', 'no');
  145. $token = Request::param ('token', $current_token);
  146. $openArticle = Request::param ('mark_open_article', 'no');
  147. $openSite = Request::param ('mark_open_site', 'no');
  148. $scroll = Request::param ('mark_scroll', 'no');
  149. $urlShaarli = Request::param ('shaarli', '');
  150. $theme = Request::param ('theme', 'default');
  151. $topline_read = Request::param ('topline_read', 'no');
  152. $topline_favorite = Request::param ('topline_favorite', 'no');
  153. $topline_date = Request::param ('topline_date', 'no');
  154. $topline_link = Request::param ('topline_link', 'no');
  155. $bottomline_read = Request::param ('bottomline_read', 'no');
  156. $bottomline_favorite = Request::param ('bottomline_favorite', 'no');
  157. $bottomline_sharing = Request::param ('bottomline_sharing', 'no');
  158. $bottomline_tags = Request::param ('bottomline_tags', 'no');
  159. $bottomline_date = Request::param ('bottomline_date', 'no');
  160. $bottomline_link = 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. ));
  179. $this->view->conf->_urlShaarli ($urlShaarli);
  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. 'url_shaarli' => $this->view->conf->urlShaarli (),
  207. 'theme' => $this->view->conf->theme (),
  208. 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no',
  209. 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no',
  210. 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no',
  211. 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no',
  212. 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no',
  213. 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no',
  214. 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no',
  215. 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no',
  216. 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no',
  217. 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no',
  218. );
  219. $confDAO = new RSSConfigurationDAO ();
  220. $confDAO->update ($values);
  221. Session::_param ('conf', $this->view->conf);
  222. Session::_param ('mail', $this->view->conf->mailLogin ());
  223. Session::_param ('language', $this->view->conf->language ());
  224. Translate::reset ();
  225. // notif
  226. $notif = array (
  227. 'type' => 'good',
  228. 'content' => Translate::t ('configuration_updated')
  229. );
  230. Session::_param ('notification', $notif);
  231. Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  232. }
  233. $this->view->themes = RSSThemes::get();
  234. View::prependTitle (Translate::t ('general_and_reading_management') . ' - ');
  235. $entryDAO = new EntryDAO ();
  236. $this->view->nb_total = $entryDAO->count ();
  237. }
  238. public function importExportAction () {
  239. $catDAO = new CategoryDAO ();
  240. $this->view->categories = $catDAO->listCategories ();
  241. $this->view->req = Request::param ('q');
  242. if ($this->view->req == 'export') {
  243. View::_title ('freshrss_feeds.opml');
  244. $this->view->_useLayout (false);
  245. header('Content-Type: application/xml; charset=utf-8');
  246. header('Content-disposition: attachment; filename=freshrss_feeds.opml');
  247. $feedDAO = new FeedDAO ();
  248. $catDAO = new CategoryDAO ();
  249. $list = array ();
  250. foreach ($catDAO->listCategories () as $key => $cat) {
  251. $list[$key]['name'] = $cat->name ();
  252. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  253. }
  254. $this->view->categories = $list;
  255. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  256. if ($_FILES['file']['error'] == 0) {
  257. // on parse le fichier OPML pour récupérer les catégories et les flux associés
  258. try {
  259. list ($categories, $feeds) = opml_import (
  260. file_get_contents ($_FILES['file']['tmp_name'])
  261. );
  262. // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
  263. // les flux sont mis au préalable dans des variables de Request
  264. Request::_param ('q', 'null');
  265. Request::_param ('categories', $categories);
  266. Request::_param ('feeds', $feeds);
  267. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  268. } catch (OpmlException $e) {
  269. Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
  270. $notif = array (
  271. 'type' => 'bad',
  272. 'content' => Translate::t ('bad_opml_file')
  273. );
  274. Session::_param ('notification', $notif);
  275. Request::forward (array (
  276. 'c' => 'configure',
  277. 'a' => 'importExport'
  278. ), true);
  279. }
  280. }
  281. }
  282. $feedDAO = new FeedDAO ();
  283. $this->view->feeds = $feedDAO->listFeeds ();
  284. // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
  285. $this->view->flux = false;
  286. View::prependTitle (Translate::t ('import_export_opml') . ' - ');
  287. }
  288. public function shortcutAction () {
  289. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  290. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  291. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  292. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  293. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  294. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  295. 'f10', 'f11', 'f12');
  296. $this->view->list_keys = $list_keys;
  297. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  298. 'prev_entry', 'next_page', 'prev_page', 'collapse_entry');
  299. if (Request::isPost ()) {
  300. $shortcuts = Request::param ('shortcuts');
  301. $shortcuts_ok = array ();
  302. foreach ($shortcuts as $key => $value) {
  303. if (in_array ($key, $list_names)
  304. && in_array ($value, $list_keys)) {
  305. $shortcuts_ok[$key] = $value;
  306. }
  307. }
  308. $this->view->conf->_shortcuts ($shortcuts_ok);
  309. $values = array (
  310. 'shortcuts' => $this->view->conf->shortcuts ()
  311. );
  312. $confDAO = new RSSConfigurationDAO ();
  313. $confDAO->update ($values);
  314. Session::_param ('conf', $this->view->conf);
  315. // notif
  316. $notif = array (
  317. 'type' => 'good',
  318. 'content' => Translate::t ('shortcuts_updated')
  319. );
  320. Session::_param ('notification', $notif);
  321. Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  322. }
  323. View::prependTitle (Translate::t ('shortcuts_management') . ' - ');
  324. }
  325. }