configureController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. $onread_jump_next = Request::param ('onread_jump_next', 'yes');
  135. $lazyload = Request::param ('lazyload', 'no');
  136. $sort = Request::param ('sort_order', 'low_to_high');
  137. $old = Request::param ('old_entries', 3);
  138. $mail = Request::param ('mail_login', false);
  139. $anon = Request::param ('anon_access', 'no');
  140. $token = Request::param ('token', $current_token);
  141. $openArticle = Request::param ('mark_open_article', 'no');
  142. $openSite = Request::param ('mark_open_site', 'no');
  143. $scroll = Request::param ('mark_scroll', 'no');
  144. $urlShaarli = Request::param ('shaarli', '');
  145. $theme = Request::param ('theme', 'default');
  146. $this->view->conf->_language ($language);
  147. $this->view->conf->_postsPerPage (intval ($nb));
  148. $this->view->conf->_viewMode ($mode);
  149. $this->view->conf->_defaultView ($view);
  150. $this->view->conf->_autoLoadMore ($auto_load_more);
  151. $this->view->conf->_displayPosts ($display);
  152. $this->view->conf->_onread_jump_next ($onread_jump_next);
  153. $this->view->conf->_lazyload ($lazyload);
  154. $this->view->conf->_sortOrder ($sort);
  155. $this->view->conf->_oldEntries ($old);
  156. $this->view->conf->_mailLogin ($mail);
  157. $this->view->conf->_anonAccess ($anon);
  158. $this->view->conf->_token ($token);
  159. $this->view->conf->_markWhen (array (
  160. 'article' => $openArticle,
  161. 'site' => $openSite,
  162. 'scroll' => $scroll,
  163. ));
  164. $this->view->conf->_urlShaarli ($urlShaarli);
  165. $this->view->conf->_theme ($theme);
  166. $values = array (
  167. 'language' => $this->view->conf->language (),
  168. 'posts_per_page' => $this->view->conf->postsPerPage (),
  169. 'view_mode' => $this->view->conf->viewMode (),
  170. 'default_view' => $this->view->conf->defaultView (),
  171. 'auto_load_more' => $this->view->conf->autoLoadMore (),
  172. 'display_posts' => $this->view->conf->displayPosts (),
  173. 'onread_jump_next' => $this->view->conf->onread_jump_next (),
  174. 'lazyload' => $this->view->conf->lazyload (),
  175. 'sort_order' => $this->view->conf->sortOrder (),
  176. 'old_entries' => $this->view->conf->oldEntries (),
  177. 'mail_login' => $this->view->conf->mailLogin (),
  178. 'anon_access' => $this->view->conf->anonAccess (),
  179. 'token' => $this->view->conf->token (),
  180. 'mark_when' => $this->view->conf->markWhen (),
  181. 'url_shaarli' => $this->view->conf->urlShaarli (),
  182. 'theme' => $this->view->conf->theme ()
  183. );
  184. $confDAO = new RSSConfigurationDAO ();
  185. $confDAO->update ($values);
  186. Session::_param ('conf', $this->view->conf);
  187. Session::_param ('mail', $this->view->conf->mailLogin ());
  188. Session::_param ('language', $this->view->conf->language ());
  189. Translate::reset ();
  190. // notif
  191. $notif = array (
  192. 'type' => 'good',
  193. 'content' => Translate::t ('configuration_updated')
  194. );
  195. Session::_param ('notification', $notif);
  196. Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  197. }
  198. $this->view->themes = RSSThemes::get();
  199. View::prependTitle (Translate::t ('general_and_reading_management') . ' - ');
  200. }
  201. public function importExportAction () {
  202. $catDAO = new CategoryDAO ();
  203. $this->view->categories = $catDAO->listCategories ();
  204. $this->view->req = Request::param ('q');
  205. if ($this->view->req == 'export') {
  206. View::_title ('freshrss_feeds.opml');
  207. $this->view->_useLayout (false);
  208. header('Content-Type: text/xml; charset=utf-8');
  209. header('Content-disposition: attachment; filename=freshrss_feeds.opml');
  210. $feedDAO = new FeedDAO ();
  211. $catDAO = new CategoryDAO ();
  212. $list = array ();
  213. foreach ($catDAO->listCategories () as $key => $cat) {
  214. $list[$key]['name'] = $cat->name ();
  215. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  216. }
  217. $this->view->categories = $list;
  218. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  219. if ($_FILES['file']['error'] == 0) {
  220. // on parse le fichier OPML pour récupérer les catégories et les flux associés
  221. try {
  222. list ($categories, $feeds) = opml_import (
  223. file_get_contents ($_FILES['file']['tmp_name'])
  224. );
  225. // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
  226. // les flux sont mis au préalable dans des variables de Request
  227. Request::_param ('q', 'null');
  228. Request::_param ('categories', $categories);
  229. Request::_param ('feeds', $feeds);
  230. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  231. } catch (OpmlException $e) {
  232. Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
  233. $notif = array (
  234. 'type' => 'bad',
  235. 'content' => Translate::t ('bad_opml_file')
  236. );
  237. Session::_param ('notification', $notif);
  238. Request::forward (array (
  239. 'c' => 'configure',
  240. 'a' => 'importExport'
  241. ), true);
  242. }
  243. }
  244. }
  245. $feedDAO = new FeedDAO ();
  246. $this->view->feeds = $feedDAO->listFeeds ();
  247. // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
  248. $this->view->flux = false;
  249. View::prependTitle (Translate::t ('import_export_opml') . ' - ');
  250. }
  251. public function shortcutAction () {
  252. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  253. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  254. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  255. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  256. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  257. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  258. 'f10', 'f11', 'f12');
  259. $this->view->list_keys = $list_keys;
  260. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  261. 'prev_entry', 'next_page', 'prev_page');
  262. if (Request::isPost ()) {
  263. $shortcuts = Request::param ('shortcuts');
  264. $shortcuts_ok = array ();
  265. foreach ($shortcuts as $key => $value) {
  266. if (in_array ($key, $list_names)
  267. && in_array ($value, $list_keys)) {
  268. $shortcuts_ok[$key] = $value;
  269. }
  270. }
  271. $this->view->conf->_shortcuts ($shortcuts_ok);
  272. $values = array (
  273. 'shortcuts' => $this->view->conf->shortcuts ()
  274. );
  275. $confDAO = new RSSConfigurationDAO ();
  276. $confDAO->update ($values);
  277. Session::_param ('conf', $this->view->conf);
  278. // notif
  279. $notif = array (
  280. 'type' => 'good',
  281. 'content' => Translate::t ('shortcuts_updated')
  282. );
  283. Session::_param ('notification', $notif);
  284. Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  285. }
  286. View::prependTitle (Translate::t ('shortcuts_management') . ' - ');
  287. }
  288. }