configureController.php 7.4 KB

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