configureController.php 10.0 KB

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