subscriptionController.php 3.5 KB

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