configureController.php 11 KB

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