configureController.php 14 KB

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