configureController.php 9.7 KB

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