subscriptionController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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?' . @filemtime(PUBLIC_PATH . '/scripts/category.js')));
  29. Minz_View::prependTitle(_t('sub.title') . ' · ');
  30. $this->view->onlyFeedsWithError = Minz_Request::paramTernary('error');
  31. $id = Minz_Request::param('id');
  32. $this->view->displaySlider = false;
  33. if (false !== $id) {
  34. $type = Minz_Request::param('type');
  35. $this->view->displaySlider = true;
  36. switch ($type) {
  37. case 'category':
  38. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  39. $this->view->category = $categoryDAO->searchById($id);
  40. break;
  41. default:
  42. $feedDAO = FreshRSS_Factory::createFeedDao();
  43. $this->view->feed = $feedDAO->searchById($id);
  44. break;
  45. }
  46. }
  47. }
  48. /**
  49. * This action handles the feed configuration page.
  50. *
  51. * It displays the feed configuration page.
  52. * If this action is reached through a POST request, it stores all new
  53. * configuraiton values then sends a notification to the user.
  54. *
  55. * The options available on the page are:
  56. * - name
  57. * - description
  58. * - website URL
  59. * - feed URL
  60. * - category id (default: default category id)
  61. * - CSS path to article on website
  62. * - display in main stream (default: 0)
  63. * - HTTP authentication
  64. * - number of article to retain (default: -2)
  65. * - refresh frequency (default: 0)
  66. * Default values are empty strings unless specified.
  67. */
  68. public function feedAction() {
  69. if (Minz_Request::param('ajax')) {
  70. $this->view->_useLayout(false);
  71. }
  72. $feedDAO = FreshRSS_Factory::createFeedDao();
  73. $this->view->feeds = $feedDAO->listFeeds();
  74. $id = Minz_Request::param('id');
  75. if ($id === false || !isset($this->view->feeds[$id])) {
  76. Minz_Error::error(404);
  77. return;
  78. }
  79. $feed = $this->view->feeds[$id];
  80. $this->view->feed = $feed;
  81. Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $feed->name() . ' · ');
  82. if (Minz_Request::isPost()) {
  83. $user = trim(Minz_Request::param('http_user_feed' . $id, ''));
  84. $pass = Minz_Request::param('http_pass_feed' . $id, '');
  85. $httpAuth = '';
  86. if ($user != '' && $pass != '') { //TODO: Sanitize
  87. $httpAuth = $user . ':' . $pass;
  88. }
  89. $cat = intval(Minz_Request::param('category', 0));
  90. $mute = Minz_Request::param('mute', false);
  91. $ttl = intval(Minz_Request::param('ttl', FreshRSS_Feed::TTL_DEFAULT));
  92. if ($mute && FreshRSS_Feed::TTL_DEFAULT === $ttl) {
  93. $ttl = FreshRSS_Context::$user_conf->ttl_default;
  94. }
  95. $feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
  96. $feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
  97. $feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache'));
  98. if (FreshRSS_Auth::hasAccess('admin')) {
  99. $feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));
  100. $timeout = intval(Minz_Request::param('timeout', 0));
  101. $feed->_attributes('timeout', $timeout > 0 ? $timeout : null);
  102. } else {
  103. $feed->_attributes('ssl_verify', null);
  104. $feed->_attributes('timeout', null);
  105. }
  106. $feed->_filtersAction('read', preg_split('/[\n\r]+/', Minz_Request::param('filteractions_read', '')));
  107. $values = array(
  108. 'name' => Minz_Request::param('name', ''),
  109. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  110. 'website' => checkUrl(Minz_Request::param('website', '')),
  111. 'url' => checkUrl(Minz_Request::param('url', '')),
  112. 'category' => $cat,
  113. 'pathEntries' => Minz_Request::param('path_entries', ''),
  114. 'priority' => intval(Minz_Request::param('priority', FreshRSS_Feed::PRIORITY_MAIN_STREAM)),
  115. 'httpAuth' => $httpAuth,
  116. 'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)),
  117. 'ttl' => $ttl * ($mute ? -1 : 1),
  118. 'attributes' => $feed->attributes(),
  119. );
  120. invalidateHttpCache();
  121. $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
  122. if ($feedDAO->updateFeed($id, $values) !== false) {
  123. $feed->_category($cat);
  124. $feed->faviconPrepare();
  125. Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
  126. } else {
  127. Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
  128. }
  129. }
  130. }
  131. public function categoryAction() {
  132. $this->view->_useLayout(false);
  133. $categoryDAO = FreshRSS_Factory::createCategoryDao();
  134. $id = Minz_Request::param('id');
  135. $category = $categoryDAO->searchById($id);
  136. if ($id === false || null === $category) {
  137. Minz_Error::error(404);
  138. return;
  139. }
  140. $this->view->category = $category;
  141. if (Minz_Request::isPost()) {
  142. $values = array(
  143. 'name' => Minz_Request::param('name', ''),
  144. );
  145. invalidateHttpCache();
  146. $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id, 'type' => 'category'));
  147. if (false !== $categoryDAO->updateCategory($id, $values)) {
  148. Minz_Request::good(_t('feedback.sub.category.updated'), $url_redirect);
  149. } else {
  150. Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect);
  151. }
  152. }
  153. }
  154. /**
  155. * This action displays the bookmarklet page.
  156. */
  157. public function bookmarkletAction() {
  158. Minz_View::prependTitle(_t('sub.title.subscription_tools') . ' . ');
  159. }
  160. }