configureController.php 6.7 KB

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