subscriptionController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 (!$this->view->loginOk) {
  13. Minz_Error::error(
  14. 403,
  15. array('error' => array(_t('access_denied')))
  16. );
  17. }
  18. }
  19. /**
  20. * This action handles the main subscription page
  21. *
  22. * It displays categories and associated feeds.
  23. */
  24. public function indexAction() {
  25. $catDAO = new FreshRSS_CategoryDAO();
  26. $this->view->categories = $catDAO->listCategories(false);
  27. $this->view->default_category = $catDAO->getDefault();
  28. Minz_View::prependTitle(_t('subscription_management') . ' · ');
  29. }
  30. /**
  31. * This action handles the feed configuration page.
  32. *
  33. * It displays the feed configuration page.
  34. * If this action is reached through a POST request, it stores all new
  35. * configuraiton values then sends a notification to the user.
  36. *
  37. * The options available on the page are:
  38. * - name
  39. * - description
  40. * - website URL
  41. * - feed URL
  42. * - category id (default: default category id)
  43. * - CSS path to article on website
  44. * - display in main stream (default: 0)
  45. * - HTTP authentication
  46. * - number of article to retain (default: -2)
  47. * - refresh frequency (default: -2)
  48. * Default values are empty strings unless specified.
  49. */
  50. public function feedAction() {
  51. if (Minz_Request::param('ajax')) {
  52. $this->view->_useLayout(false);
  53. }
  54. $catDAO = new FreshRSS_CategoryDAO();
  55. $this->view->categories = $catDAO->listCategories(false);
  56. $feedDAO = FreshRSS_Factory::createFeedDao();
  57. $this->view->feeds = $feedDAO->listFeeds();
  58. $id = Minz_Request::param('id');
  59. if ($id == false && !empty($this->view->feeds)) {
  60. $id = current($this->view->feeds)->id();
  61. }
  62. $this->view->flux = false;
  63. if ($id != false) {
  64. $this->view->flux = $this->view->feeds[$id];
  65. if (!$this->view->flux) {
  66. Minz_Error::error(
  67. 404,
  68. array('error' => array(_t('page_not_found')))
  69. );
  70. } else {
  71. if (Minz_Request::isPost() && $this->view->flux) {
  72. $user = Minz_Request::param('http_user', '');
  73. $pass = Minz_Request::param('http_pass', '');
  74. $httpAuth = '';
  75. if ($user != '' || $pass != '') {
  76. $httpAuth = $user . ':' . $pass;
  77. }
  78. $cat = intval(Minz_Request::param('category', 0));
  79. $values = array(
  80. 'name' => Minz_Request::param('name', ''),
  81. 'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
  82. 'website' => Minz_Request::param('website', ''),
  83. 'url' => Minz_Request::param('url', ''),
  84. 'category' => $cat,
  85. 'pathEntries' => Minz_Request::param('path_entries', ''),
  86. 'priority' => intval(Minz_Request::param('priority', 0)),
  87. 'httpAuth' => $httpAuth,
  88. 'keep_history' => intval(Minz_Request::param('keep_history', -2)),
  89. 'ttl' => intval(Minz_Request::param('ttl', -2)),
  90. );
  91. if ($feedDAO->updateFeed($id, $values)) {
  92. $this->view->flux->_category($cat);
  93. $this->view->flux->faviconPrepare();
  94. $notif = array(
  95. 'type' => 'good',
  96. 'content' => _t('feed_updated')
  97. );
  98. } else {
  99. $notif = array(
  100. 'type' => 'bad',
  101. 'content' => _t('error_occurred_update')
  102. );
  103. }
  104. invalidateHttpCache();
  105. Minz_Session::_param('notification', $notif);
  106. Minz_Request::forward(array('c' => 'subscription'), true);
  107. }
  108. Minz_View::prependTitle(_t('rss_feed_management') . ' · ' . $this->view->flux->name() . ' · ');
  109. }
  110. } else {
  111. Minz_View::prependTitle(_t('rss_feed_management') . ' · ');
  112. }
  113. }
  114. }