configureController.php 11 KB

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