configureController.php 7.5 KB

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