configureController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. // notif
  39. $notif = array (
  40. 'type' => 'good',
  41. 'content' => 'Les catégories ont été mises à jour'
  42. );
  43. Session::_param ('notification', $notif);
  44. Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
  45. }
  46. $this->view->categories = $catDAO->listCategories ();
  47. View::prependTitle ('Gestion des catégories - ');
  48. }
  49. public function feedAction () {
  50. $feedDAO = new FeedDAO ();
  51. $this->view->feeds = $feedDAO->listFeeds ();
  52. $id = Request::param ('id');
  53. if ($id == false && !empty ($this->view->feeds)) {
  54. $id = current ($this->view->feeds)->id ();
  55. }
  56. $this->view->flux = false;
  57. if ($id != false) {
  58. $this->view->flux = $feedDAO->searchById ($id);
  59. if (!$this->view->flux) {
  60. Error::error (
  61. 404,
  62. array ('error' => array ('La page que vous cherchez n\'existe pas'))
  63. );
  64. } else {
  65. $catDAO = new CategoryDAO ();
  66. $this->view->categories = $catDAO->listCategories ();
  67. if (Request::isPost () && $this->view->flux) {
  68. $cat = Request::param ('category');
  69. $values = array (
  70. 'category' => $cat
  71. );
  72. $feedDAO->updateFeed ($id, $values);
  73. $this->view->flux->_category ($cat);
  74. // notif
  75. $notif = array (
  76. 'type' => 'good',
  77. 'content' => 'Le flux a été mis à jour'
  78. );
  79. Session::_param ('notification', $notif);
  80. Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
  81. }
  82. View::prependTitle ('Gestion des flux RSS - ' . $this->view->flux->name () . ' - ');
  83. }
  84. } else {
  85. View::prependTitle ('Gestion des flux RSS - ');
  86. }
  87. }
  88. public function displayAction () {
  89. if (Request::isPost ()) {
  90. $nb = Request::param ('posts_per_page', 10);
  91. $view = Request::param ('default_view', 'all');
  92. $display = Request::param ('display_posts', 'no');
  93. $sort = Request::param ('sort_order', 'low_to_high');
  94. $old = Request::param ('old_entries', 3);
  95. $mail = Request::param ('mail_login', false);
  96. $this->view->conf->_postsPerPage (intval ($nb));
  97. $this->view->conf->_defaultView ($view);
  98. $this->view->conf->_displayPosts ($display);
  99. $this->view->conf->_sortOrder ($sort);
  100. $this->view->conf->_oldEntries ($old);
  101. $this->view->conf->_mailLogin ($mail);
  102. $values = array (
  103. 'posts_per_page' => $this->view->conf->postsPerPage (),
  104. 'default_view' => $this->view->conf->defaultView (),
  105. 'display_posts' => $this->view->conf->displayPosts (),
  106. 'sort_order' => $this->view->conf->sortOrder (),
  107. 'old_entries' => $this->view->conf->oldEntries (),
  108. 'mail_login' => $this->view->conf->mailLogin (),
  109. );
  110. $confDAO = new RSSConfigurationDAO ();
  111. $confDAO->update ($values);
  112. Session::_param ('conf', $this->view->conf);
  113. Session::_param ('mail', $this->view->conf->mailLogin ());
  114. // notif
  115. $notif = array (
  116. 'type' => 'good',
  117. 'content' => 'La configuration a été mise à jour'
  118. );
  119. Session::_param ('notification', $notif);
  120. Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  121. }
  122. View::prependTitle ('Gestion générale et affichage - ');
  123. }
  124. public function importExportAction () {
  125. $this->view->req = Request::param ('q');
  126. if ($this->view->req == 'export') {
  127. View::_title ('feeds_opml.xml');
  128. $this->view->_useLayout (false);
  129. header('Content-type: text/xml');
  130. $feedDAO = new FeedDAO ();
  131. $catDAO = new CategoryDAO ();
  132. $list = array ();
  133. foreach ($catDAO->listCategories () as $key => $cat) {
  134. $list[$key]['name'] = $cat->name ();
  135. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  136. }
  137. $this->view->categories = $list;
  138. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  139. if ($_FILES['file']['error'] == 0) {
  140. list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));
  141. Request::_param ('q', 'null');
  142. Request::_param ('categories', $categories);
  143. Request::_param ('feeds', $feeds);
  144. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  145. }
  146. }
  147. View::prependTitle ('Importation et exportation OPML - ');
  148. }
  149. public function shortcutAction () {
  150. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  151. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  152. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  153. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  154. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  155. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  156. 'f10', 'f11', 'f12');
  157. $this->view->list_keys = $list_keys;
  158. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  159. 'prev_entry', 'next_page', 'prev_page');
  160. if (Request::isPost ()) {
  161. $shortcuts = Request::param ('shortcuts');
  162. $shortcuts_ok = array ();
  163. foreach ($shortcuts as $key => $value) {
  164. if (in_array ($key, $list_names)
  165. && in_array ($value, $list_keys)) {
  166. $shortcuts_ok[$key] = $value;
  167. }
  168. }
  169. $this->view->conf->_shortcuts ($shortcuts_ok);
  170. $values = array (
  171. 'shortcuts' => $this->view->conf->shortcuts ()
  172. );
  173. $confDAO = new RSSConfigurationDAO ();
  174. $confDAO->update ($values);
  175. Session::_param ('conf', $this->view->conf);
  176. // notif
  177. $notif = array (
  178. 'type' => 'good',
  179. 'content' => 'Les raccourcis ont été mis à jour'
  180. );
  181. Session::_param ('notification', $notif);
  182. Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  183. }
  184. View::prependTitle ('Gestion des raccourcis - ');
  185. }
  186. }