configureController.php 6.7 KB

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