subscriptionController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = FreshRSS_Factory::createCategoryDao();
  16. $feedDAO = FreshRSS_Factory::createFeedDao();
  17. $catDAO->checkDefault();
  18. $feedDAO->updateTTL();
  19. $this->view->categories = $catDAO->listCategories(false);
  20. $this->view->default_category = $catDAO->getDefault();
  21. }
  22. /**
  23. * This action handles the main subscription page
  24. *
  25. * It displays categories and associated feeds.
  26. */
  27. public function indexAction() {
  28. Minz_View::appendScript(Minz_Url::display('/scripts/category.js?' .
  29. @filemtime(PUBLIC_PATH . '/scripts/category.js')));
  30. Minz_View::prependTitle(_t('sub.title') . ' · ');
  31. $this->view->onlyFeedsWithError = Minz_Request::paramTernary('error');
  32. $id = Minz_Request::param('id');
  33. if ($id !== false) {
  34. $feedDAO = FreshRSS_Factory::createFeedDao();
  35. $this->view->feed = $feedDAO->searchById($id);
  36. }
  37. }
  38. /**
  39. * This action handles the feed configuration page.
  40. *
  41. * It displays the feed configuration page.
  42. * If this action is reached through a POST request, it stores all new
  43. * configuraiton values then sends a notification to the user.
  44. *
  45. * The options available on the page are:
  46. * - name
  47. * - description
  48. * - website URL
  49. * - feed URL
  50. * - category id (default: default category id)
  51. * - CSS path to article on website
  52. * - display in main stream (default: 0)
  53. * - HTTP authentication
  54. * - number of article to retain (default: -2)
  55. * - refresh frequency (default: 0)
  56. * Default values are empty strings unless specified.
  57. */
  58. public function feedAction() {
  59. if (Minz_Request::param('ajax')) {
  60. $this->view->_useLayout(false);
  61. }
  62. $feedDAO = FreshRSS_Factory::createFeedDao();
  63. $this->view->feeds = $feedDAO->listFeeds();
  64. $id = Minz_Request::param('id');
  65. if ($id === false || !isset($this->view->feeds[$id])) {
  66. Minz_Error::error(404);
  67. return;
  68. }
  69. $feed = $this->view->feeds[$id];
  70. $this->view->feed = $feed;
  71. Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $feed->name() . ' · ');
  72. if (Minz_Request::isPost()) {
  73. $user = trim(Minz_Request::param('http_user_feed' . $id, ''));
  74. $pass = Minz_Request::param('http_pass_feed' . $id, '');
  75. $httpAuth = '';
  76. if ($user != '' && $pass != '') { //TODO: Sanitize
  77. $httpAuth = $user . ':' . $pass;
  78. }
  79. $cat = intval(Minz_Request::param('category', 0));
  80. $mute = Minz_Request::param('mute', false);
  81. $ttl = intval(Minz_Request::param('ttl', FreshRSS_Feed::TTL_DEFAULT));
  82. if ($mute && FreshRSS_Feed::TTL_DEFAULT === $ttl) {
  83. $ttl = FreshRSS_Context::$user_conf->ttl_default;
  84. }
  85. $feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
  86. $feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
  87. $feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache'));
  88. if (FreshRSS_Auth::hasAccess('admin')) {
  89. $feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));
  90. $timeout = intval(Minz_Request::param('timeout', 0));
  91. $feed->_attributes('timeout', $timeout > 0 ? $timeout : null);
  92. } else {
  93. $feed->_attributes('ssl_verify', null);
  94. $feed->_attributes('timeout', null);
  95. }
  96. $values = array(
  97. 'name' => Minz_Request::param('name', ''),
  98. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  99. 'website' => checkUrl(Minz_Request::param('website', '')),
  100. 'url' => checkUrl(Minz_Request::param('url', '')),
  101. 'category' => $cat,
  102. 'pathEntries' => Minz_Request::param('path_entries', ''),
  103. 'priority' => intval(Minz_Request::param('priority', FreshRSS_Feed::PRIORITY_MAIN_STREAM)),
  104. 'httpAuth' => $httpAuth,
  105. 'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)),
  106. 'ttl' => $ttl * ($mute ? -1 : 1),
  107. 'attributes' => $feed->attributes()
  108. );
  109. invalidateHttpCache();
  110. $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
  111. if ($feedDAO->updateFeed($id, $values) !== false) {
  112. $feed->_category($cat);
  113. $feed->faviconPrepare();
  114. Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
  115. } else {
  116. Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
  117. }
  118. }
  119. }
  120. /**
  121. * This action displays the bookmarklet page.
  122. */
  123. public function bookmarkletAction() {
  124. Minz_View::prependTitle(_t('sub.title.subscription_tools') . ' . ');
  125. }
  126. }