4
0

subscriptionController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 = new FreshRSS_FeedDAO();
  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. $this->view->feed = $this->view->feeds[$id];
  69. Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $this->view->feed->name() . ' · ');
  70. if (Minz_Request::isPost()) {
  71. $user = trim(Minz_Request::param('http_user_feed' . $id, ''));
  72. $pass = Minz_Request::param('http_pass_feed' . $id, '');
  73. $httpAuth = '';
  74. if ($user != '' && $pass != '') { //TODO: Sanitize
  75. $httpAuth = $user . ':' . $pass;
  76. }
  77. $cat = intval(Minz_Request::param('category', 0));
  78. $mute = Minz_Request::param('mute', false);
  79. $ttl = intval(Minz_Request::param('ttl', FreshRSS_Feed::TTL_DEFAULT));
  80. if ($mute && FreshRSS_Feed::TTL_DEFAULT === $ttl) {
  81. $ttl = FreshRSS_Context::$user_conf->ttl_default;
  82. }
  83. $values = array(
  84. 'name' => Minz_Request::param('name', ''),
  85. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  86. 'website' => checkUrl(Minz_Request::param('website', '')),
  87. 'url' => checkUrl(Minz_Request::param('url', '')),
  88. 'category' => $cat,
  89. 'pathEntries' => Minz_Request::param('path_entries', ''),
  90. 'priority' => intval(Minz_Request::param('priority', FreshRSS_Feed::PRIORITY_MAIN_STREAM)),
  91. 'httpAuth' => $httpAuth,
  92. 'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)),
  93. 'ttl' => $ttl * ($mute ? -1 : 1),
  94. );
  95. invalidateHttpCache();
  96. $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
  97. if ($feedDAO->updateFeed($id, $values) !== false) {
  98. $this->view->feed->_category($cat);
  99. $this->view->feed->faviconPrepare();
  100. Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
  101. } else {
  102. Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
  103. }
  104. }
  105. }
  106. /**
  107. * This action displays the bookmarklet page.
  108. */
  109. public function bookmarkletAction() {
  110. Minz_View::prependTitle(_t('sub.title.subscription_tools') . ' . ');
  111. }
  112. }