configureController.php 8.9 KB

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