configureController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. class configureController extends ActionController {
  3. public function categorizeAction () {
  4. $catDAO = new CategoryDAO ();
  5. if (Request::isPost ()) {
  6. $cats = Request::param ('categories', array ());
  7. $ids = Request::param ('ids', array ());
  8. $newCat = Request::param ('new_category');
  9. foreach ($cats as $key => $name) {
  10. if (strlen ($name) > 0) {
  11. $cat = new Category ($name);
  12. $values = array (
  13. 'name' => $cat->name (),
  14. 'color' => $cat->color ()
  15. );
  16. $catDAO->updateCategory ($ids[$key], $values);
  17. } else {
  18. $catDAO->deleteCategory ($ids[$key]);
  19. }
  20. }
  21. if ($newCat != false) {
  22. $cat = new Category ($newCat);
  23. $values = array (
  24. 'id' => $cat->id (),
  25. 'name' => $cat->name (),
  26. 'color' => $cat->color ()
  27. );
  28. $catDAO->addCategory ($values);
  29. }
  30. }
  31. $this->view->categories = $catDAO->listCategories ();
  32. }
  33. public function fluxAction () {
  34. $feedDAO = new FeedDAO ();
  35. $this->view->feeds = $feedDAO->listFeeds ();
  36. $id = Request::param ('id');
  37. $this->view->flux = false;
  38. if ($id != false) {
  39. $this->view->flux = $feedDAO->searchById ($id);
  40. $catDAO = new CategoryDAO ();
  41. $this->view->categories = $catDAO->listCategories ();
  42. if (Request::isPost () && $this->view->flux) {
  43. $cat = Request::param ('category');
  44. $values = array (
  45. 'category' => $cat
  46. );
  47. $feedDAO->updateFeed ($id, $values);
  48. $this->view->flux->_category ($cat);
  49. }
  50. }
  51. }
  52. public function displayAction () {
  53. if (Request::isPost ()) {
  54. $nb = Request::param ('posts_per_page', 10);
  55. $view = Request::param ('default_view', 'all');
  56. $display = Request::param ('display_posts', 'no');
  57. $sort = Request::param ('sort_order', 'low_to_high');
  58. $old = Request::param ('old_entries', 3);
  59. $this->view->conf->_postsPerPage (intval ($nb));
  60. $this->view->conf->_defaultView ($view);
  61. $this->view->conf->_displayPosts ($display);
  62. $this->view->conf->_sortOrder ($sort);
  63. $this->view->conf->_oldEntries ($old);
  64. $values = array (
  65. 'posts_per_page' => $this->view->conf->postsPerPage (),
  66. 'default_view' => $this->view->conf->defaultView (),
  67. 'display_posts' => $this->view->conf->displayPosts (),
  68. 'sort_order' => $this->view->conf->sortOrder (),
  69. 'old_entries' => $this->view->conf->oldEntries (),
  70. );
  71. $confDAO = new RSSConfigurationDAO ();
  72. $confDAO->update ($values);
  73. Session::_param ('conf', $this->view->conf);
  74. }
  75. }
  76. public function importExportAction () {
  77. $this->view->req = Request::param ('q');
  78. if ($this->view->req == 'export') {
  79. View::_title ('feeds_opml.xml');
  80. $this->view->_useLayout (false);
  81. header('Content-type: text/xml');
  82. $feedDAO = new FeedDAO ();
  83. $catDAO = new CategoryDAO ();
  84. $list = array ();
  85. foreach ($catDAO->listCategories () as $key => $cat) {
  86. $list[$key]['name'] = $cat->name ();
  87. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  88. }
  89. $this->view->categories = $list;
  90. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  91. if ($_FILES['file']['error'] == 0) {
  92. list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));
  93. Request::_param ('q', 'null');
  94. Request::_param ('categories', $categories);
  95. Request::_param ('feeds', $feeds);
  96. Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
  97. }
  98. }
  99. }
  100. public function shortcutAction () {
  101. $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
  102. 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
  103. 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
  104. 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
  105. 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  106. '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
  107. 'f10', 'f11', 'f12');
  108. $this->view->list_keys = $list_keys;
  109. $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
  110. 'prev_entry', 'next_page', 'prev_page');
  111. if (Request::isPost ()) {
  112. $shortcuts = Request::param ('shortcuts');
  113. $shortcuts_ok = array ();
  114. foreach ($shortcuts as $key => $value) {
  115. if (in_array ($key, $list_names)
  116. && in_array ($value, $list_keys)) {
  117. $shortcuts_ok[$key] = $value;
  118. }
  119. }
  120. $this->view->conf->_shortcuts ($shortcuts_ok);
  121. $values = array (
  122. 'shortcuts' => $this->view->conf->shortcuts ()
  123. );
  124. $confDAO = new RSSConfigurationDAO ();
  125. $confDAO->update ($values);
  126. Session::_param ('conf', $this->view->conf);
  127. }
  128. }
  129. }