subscriptionController.php 4.5 KB

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