4
0

configureController.php 7.9 KB

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