configureController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. $catDAO->save ();
  31. }
  32. $this->view->categories = $catDAO->listCategories ();
  33. }
  34. public function fluxAction () {
  35. $feedDAO = new FeedDAO ();
  36. $this->view->feeds = $feedDAO->listFeeds ();
  37. $id = Request::param ('id');
  38. $this->view->flux = false;
  39. if ($id != false) {
  40. $this->view->flux = $feedDAO->searchById ($id);
  41. $catDAO = new CategoryDAO ();
  42. $this->view->categories = $catDAO->listCategories ();
  43. if (Request::isPost () && $this->view->flux) {
  44. $cat = Request::param ('category');
  45. $values = array (
  46. 'category' => $cat
  47. );
  48. $feedDAO->updateFeed ($id, $values);
  49. $this->view->flux->_category ($cat);
  50. }
  51. }
  52. }
  53. public function displayAction () {
  54. if (Request::isPost ()) {
  55. $nb = Request::param ('posts_per_page', 10);
  56. $view = Request::param ('default_view', 'all');
  57. $display = Request::param ('display_posts', 'no');
  58. $sort = Request::param ('sort_order', 'low_to_high');
  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. $values = array (
  64. 'posts_per_page' => $this->view->conf->postsPerPage (),
  65. 'default_view' => $this->view->conf->defaultView (),
  66. 'display_posts' => $this->view->conf->displayPosts (),
  67. 'sort_order' => $this->view->conf->sortOrder ()
  68. );
  69. $confDAO = new RSSConfigurationDAO ();
  70. $confDAO->save ($values);
  71. Session::_param ('conf', $this->view->conf);
  72. }
  73. }
  74. public function importExportAction () {
  75. $this->view->req = Request::param ('q');
  76. if ($this->view->req == 'export') {
  77. View::_title ('feeds_opml.xml');
  78. $this->view->_useLayout (false);
  79. header('Content-type: text/xml');
  80. $feedDAO = new FeedDAO ();
  81. $catDAO = new CategoryDAO ();
  82. $list = array ();
  83. foreach ($catDAO->listCategories () as $key => $cat) {
  84. $list[$key]['name'] = $cat->name ();
  85. $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
  86. }
  87. $this->view->categories = $list;
  88. } elseif ($this->view->req == 'import' && Request::isPost ()) {
  89. if ($_FILES['file']['error'] == 0) {
  90. $content = file_get_contents ($_FILES['file']['tmp_name']);
  91. $feeds = opml_import ($content);
  92. Request::_param ('q');
  93. Request::_param ('feeds', $feeds);
  94. Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
  95. }
  96. }
  97. }
  98. }