configureController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. $openArticle = Request::param ('mark_open_article', 'no');
  97. $openSite = Request::param ('mark_open_site', 'no');
  98. $openPage = Request::param ('mark_open_page', 'no');
  99. $this->view->conf->_postsPerPage (intval ($nb));
  100. $this->view->conf->_defaultView ($view);
  101. $this->view->conf->_displayPosts ($display);
  102. $this->view->conf->_sortOrder ($sort);
  103. $this->view->conf->_oldEntries ($old);
  104. $this->view->conf->_mailLogin ($mail);
  105. $this->view->conf->_markWhen (array (
  106. 'article' => $openArticle,
  107. 'site' => $openSite,
  108. 'page' => $openPage,
  109. ));
  110. $values = array (
  111. 'posts_per_page' => $this->view->conf->postsPerPage (),
  112. 'default_view' => $this->view->conf->defaultView (),
  113. 'display_posts' => $this->view->conf->displayPosts (),
  114. 'sort_order' => $this->view->conf->sortOrder (),
  115. 'old_entries' => $this->view->conf->oldEntries (),
  116. 'mail_login' => $this->view->conf->mailLogin (),
  117. 'mark_when' => $this->view->conf->markWhen (),
  118. );
  119. $confDAO = new RSSConfigurationDAO ();
  120. $confDAO->update ($values);
  121. Session::_param ('conf', $this->view->conf);
  122. Session::_param ('mail', $this->view->conf->mailLogin ());
  123. // notif
  124. $notif = array (
  125. 'type' => 'good',
  126. 'content' => 'La configuration a été mise à jour'
  127. );
  128. Session::_param ('notification', $notif);
  129. Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
  130. }
  131. View::prependTitle ('Gestion générale et affichage - ');
  132. }
  133. public function importExportAction () {
  134. $this->view->req = Request::param ('q');
  135. if ($this->view->req == 'export') {
  136. View::_title ('feeds_opml.xml');
  137. $this->view->_useLayout (false);
  138. header('Content-type: text/xml');
  139. $feedDAO = new FeedDAO ();
  140. $catDAO = new CategoryDAO ();
  141. $list = array ();
  142. foreach ($catDAO->listCategories () as $key => $cat) {
  143. $list[$key]['name'] = $cat->name ();
  144. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  145. }
  146. $this->view->categories = $list;
  147. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  148. if ($_FILES['file']['error'] == 0) {
  149. list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));
  150. Request::_param ('q', 'null');
  151. Request::_param ('categories', $categories);
  152. Request::_param ('feeds', $feeds);
  153. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  154. }
  155. }
  156. View::prependTitle ('Importation et exportation OPML - ');
  157. }
  158. public function shortcutAction () {
  159. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  160. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  161. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  162. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  163. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  164. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  165. 'f10', 'f11', 'f12');
  166. $this->view->list_keys = $list_keys;
  167. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  168. 'prev_entry', 'next_page', 'prev_page');
  169. if (Request::isPost ()) {
  170. $shortcuts = Request::param ('shortcuts');
  171. $shortcuts_ok = array ();
  172. foreach ($shortcuts as $key => $value) {
  173. if (in_array ($key, $list_names)
  174. && in_array ($value, $list_keys)) {
  175. $shortcuts_ok[$key] = $value;
  176. }
  177. }
  178. $this->view->conf->_shortcuts ($shortcuts_ok);
  179. $values = array (
  180. 'shortcuts' => $this->view->conf->shortcuts ()
  181. );
  182. $confDAO = new RSSConfigurationDAO ();
  183. $confDAO->update ($values);
  184. Session::_param ('conf', $this->view->conf);
  185. // notif
  186. $notif = array (
  187. 'type' => 'good',
  188. 'content' => 'Les raccourcis ont été mis à jour'
  189. );
  190. Session::_param ('notification', $notif);
  191. Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
  192. }
  193. View::prependTitle ('Gestion des raccourcis - ');
  194. }
  195. }