configureController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 ('Vous n\'avez pas le droit d\'accéder à cette page'))
  8. );
  9. }
  10. }
  11. public function categorizeAction () {
  12. $catDAO = new CategoryDAO ();
  13. if (Request::isPost ()) {
  14. $cats = Request::param ('categories', array ());
  15. $ids = Request::param ('ids', array ());
  16. $newCat = Request::param ('new_category');
  17. foreach ($cats as $key => $name) {
  18. if (strlen ($name) > 0) {
  19. $cat = new Category ($name);
  20. $values = array (
  21. 'name' => $cat->name (),
  22. 'color' => $cat->color ()
  23. );
  24. $catDAO->updateCategory ($ids[$key], $values);
  25. } else {
  26. $catDAO->deleteCategory ($ids[$key]);
  27. }
  28. }
  29. if ($newCat != false) {
  30. $cat = new Category ($newCat);
  31. $values = array (
  32. 'id' => $cat->id (),
  33. 'name' => $cat->name (),
  34. 'color' => $cat->color ()
  35. );
  36. $catDAO->addCategory ($values);
  37. }
  38. }
  39. $this->view->categories = $catDAO->listCategories ();
  40. }
  41. public function feedAction () {
  42. $feedDAO = new FeedDAO ();
  43. $this->view->feeds = $feedDAO->listFeeds ();
  44. $id = Request::param ('id');
  45. $this->view->flux = false;
  46. if ($id != false) {
  47. $this->view->flux = $feedDAO->searchById ($id);
  48. $catDAO = new CategoryDAO ();
  49. $this->view->categories = $catDAO->listCategories ();
  50. if (Request::isPost () && $this->view->flux) {
  51. $cat = Request::param ('category');
  52. $values = array (
  53. 'category' => $cat
  54. );
  55. $feedDAO->updateFeed ($id, $values);
  56. $this->view->flux->_category ($cat);
  57. }
  58. }
  59. }
  60. public function displayAction () {
  61. if (Request::isPost ()) {
  62. $nb = Request::param ('posts_per_page', 10);
  63. $view = Request::param ('default_view', 'all');
  64. $display = Request::param ('display_posts', 'no');
  65. $sort = Request::param ('sort_order', 'low_to_high');
  66. $old = Request::param ('old_entries', 3);
  67. $mail = Request::param ('mail_login', false);
  68. $this->view->conf->_postsPerPage (intval ($nb));
  69. $this->view->conf->_defaultView ($view);
  70. $this->view->conf->_displayPosts ($display);
  71. $this->view->conf->_sortOrder ($sort);
  72. $this->view->conf->_oldEntries ($old);
  73. $this->view->conf->_mailLogin ($mail);
  74. $values = array (
  75. 'posts_per_page' => $this->view->conf->postsPerPage (),
  76. 'default_view' => $this->view->conf->defaultView (),
  77. 'display_posts' => $this->view->conf->displayPosts (),
  78. 'sort_order' => $this->view->conf->sortOrder (),
  79. 'old_entries' => $this->view->conf->oldEntries (),
  80. 'mail_login' => $this->view->conf->mailLogin (),
  81. );
  82. $confDAO = new RSSConfigurationDAO ();
  83. $confDAO->update ($values);
  84. Session::_param ('conf', $this->view->conf);
  85. Session::_param ('mail', $this->view->conf->mailLogin ());
  86. }
  87. }
  88. public function importExportAction () {
  89. $this->view->req = Request::param ('q');
  90. if ($this->view->req == 'export') {
  91. View::_title ('feeds_opml.xml');
  92. $this->view->_useLayout (false);
  93. header('Content-type: text/xml');
  94. $feedDAO = new FeedDAO ();
  95. $catDAO = new CategoryDAO ();
  96. $list = array ();
  97. foreach ($catDAO->listCategories () as $key => $cat) {
  98. $list[$key]['name'] = $cat->name ();
  99. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  100. }
  101. $this->view->categories = $list;
  102. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  103. if ($_FILES['file']['error'] == 0) {
  104. list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));
  105. Request::_param ('q', 'null');
  106. Request::_param ('categories', $categories);
  107. Request::_param ('feeds', $feeds);
  108. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  109. }
  110. }
  111. }
  112. public function shortcutAction () {
  113. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  114. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  115. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  116. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  117. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  118. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  119. 'f10', 'f11', 'f12');
  120. $this->view->list_keys = $list_keys;
  121. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  122. 'prev_entry', 'next_page', 'prev_page');
  123. if (Request::isPost ()) {
  124. $shortcuts = Request::param ('shortcuts');
  125. $shortcuts_ok = array ();
  126. foreach ($shortcuts as $key => $value) {
  127. if (in_array ($key, $list_names)
  128. && in_array ($value, $list_keys)) {
  129. $shortcuts_ok[$key] = $value;
  130. }
  131. }
  132. $this->view->conf->_shortcuts ($shortcuts_ok);
  133. $values = array (
  134. 'shortcuts' => $this->view->conf->shortcuts ()
  135. );
  136. $confDAO = new RSSConfigurationDAO ();
  137. $confDAO->update ($values);
  138. Session::_param ('conf', $this->view->conf);
  139. }
  140. }
  141. }