configureController.php 7.7 KB

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