subscriptionController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Controller to handle subscription actions.
  4. */
  5. class FreshRSS_subscription_Controller extends Minz_ActionController {
  6. /**
  7. * This action is called before every other action in that class. It is
  8. * the common boiler plate for every action. It is triggered by the
  9. * underlying framework.
  10. */
  11. public function firstAction() {
  12. if (!FreshRSS_Auth::hasAccess()) {
  13. Minz_Error::error(403);
  14. }
  15. $catDAO = new FreshRSS_CategoryDAO();
  16. $catDAO->checkDefault();
  17. $this->view->categories = $catDAO->listCategories(false);
  18. $this->view->default_category = $catDAO->getDefault();
  19. }
  20. /**
  21. * This action handles the main subscription page
  22. *
  23. * It displays categories and associated feeds.
  24. */
  25. public function indexAction() {
  26. Minz_View::appendScript(Minz_Url::display('/scripts/category.js?' .
  27. @filemtime(PUBLIC_PATH . '/scripts/category.js')));
  28. Minz_View::prependTitle(_t('sub.title') . ' · ');
  29. $id = Minz_Request::param('id');
  30. if ($id !== false) {
  31. $feedDAO = FreshRSS_Factory::createFeedDao();
  32. $this->view->feed = $feedDAO->searchById($id);
  33. }
  34. }
  35. /**
  36. * This action handles the feed configuration page.
  37. *
  38. * It displays the feed configuration page.
  39. * If this action is reached through a POST request, it stores all new
  40. * configuraiton values then sends a notification to the user.
  41. *
  42. * The options available on the page are:
  43. * - name
  44. * - description
  45. * - website URL
  46. * - feed URL
  47. * - category id (default: default category id)
  48. * - CSS path to article on website
  49. * - display in main stream (default: 0)
  50. * - HTTP authentication
  51. * - number of article to retain (default: -2)
  52. * - refresh frequency (default: -2)
  53. * Default values are empty strings unless specified.
  54. */
  55. public function feedAction() {
  56. if (Minz_Request::param('ajax')) {
  57. $this->view->_useLayout(false);
  58. }
  59. $feedDAO = FreshRSS_Factory::createFeedDao();
  60. $this->view->feeds = $feedDAO->listFeeds();
  61. $id = Minz_Request::param('id');
  62. if ($id === false || !isset($this->view->feeds[$id])) {
  63. Minz_Error::error(404);
  64. return;
  65. }
  66. $this->view->feed = $this->view->feeds[$id];
  67. Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $this->view->feed->name() . ' · ');
  68. if (Minz_Request::isPost()) {
  69. $user = Minz_Request::param('http_user', '');
  70. $pass = Minz_Request::param('http_pass', '');
  71. $httpAuth = '';
  72. if ($user != '' || $pass != '') {
  73. $httpAuth = $user . ':' . $pass;
  74. }
  75. $cat = intval(Minz_Request::param('category', 0));
  76. $values = array(
  77. 'name' => Minz_Request::param('name', ''),
  78. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  79. 'website' => Minz_Request::param('website', ''),
  80. 'url' => Minz_Request::param('url', ''),
  81. 'category' => $cat,
  82. 'pathEntries' => Minz_Request::param('path_entries', ''),
  83. 'priority' => intval(Minz_Request::param('priority', 0)),
  84. 'httpAuth' => $httpAuth,
  85. 'keep_history' => intval(Minz_Request::param('keep_history', -2)),
  86. 'ttl' => intval(Minz_Request::param('ttl', -2)),
  87. );
  88. invalidateHttpCache();
  89. if ($feedDAO->updateFeed($id, $values)) {
  90. $this->view->feed->_category($cat);
  91. $this->view->feed->faviconPrepare();
  92. Minz_Request::good(_t('feedback.sub.feed.updated'), array('c' => 'subscription', 'params' => array('id' => $id)));
  93. } else {
  94. Minz_Request::bad(_t('feedback.sub.feed.error'), array('c' => 'subscription'));
  95. }
  96. }
  97. }
  98. }