subscriptionController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $catDAO = new FreshRSS_CategoryDAO();
  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::prependTitle(_t('subscription_management') . ' · ');
  29. $id = Minz_Request::param('id');
  30. if ($id !== false) {
  31. $feedDAO = FreshRSS_Factory::createFeedDao();
  32. $this->view->feed = $feedDAO->searchById($id);
  33. }
  34. }
  35. /**
  36. * This action handles the feed configuration page.
  37. *
  38. * It displays the feed configuration page.
  39. * If this action is reached through a POST request, it stores all new
  40. * configuraiton values then sends a notification to the user.
  41. *
  42. * The options available on the page are:
  43. * - name
  44. * - description
  45. * - website URL
  46. * - feed URL
  47. * - category id (default: default category id)
  48. * - CSS path to article on website
  49. * - display in main stream (default: 0)
  50. * - HTTP authentication
  51. * - number of article to retain (default: -2)
  52. * - refresh frequency (default: -2)
  53. * Default values are empty strings unless specified.
  54. */
  55. public function feedAction() {
  56. if (Minz_Request::param('ajax')) {
  57. $this->view->_useLayout(false);
  58. }
  59. $feedDAO = FreshRSS_Factory::createFeedDao();
  60. $this->view->feeds = $feedDAO->listFeeds();
  61. $id = Minz_Request::param('id');
  62. if ($id === false || !isset($this->view->feeds[$id])) {
  63. Minz_Error::error(
  64. 404,
  65. array('error' => array(_t('page_not_found')))
  66. );
  67. return;
  68. }
  69. $this->view->feed = $this->view->feeds[$id];
  70. Minz_View::prependTitle(_t('rss_feed_management') . ' · ' . $this->view->feed->name() . ' · ');
  71. if (Minz_Request::isPost()) {
  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. invalidateHttpCache();
  92. if ($feedDAO->updateFeed($id, $values)) {
  93. $this->view->feed->_category($cat);
  94. $this->view->feed->faviconPrepare();
  95. Minz_Request::good(_t('feed_updated'), array('c' => 'subscription', 'params' => array('id' => $id)));
  96. } else {
  97. Minz_Request::bad(_t('error_occurred_update'), array('c' => 'subscription'));
  98. }
  99. }
  100. }
  101. }