feedController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * Controller to handle every feed actions.
  4. */
  5. class FreshRSS_feed_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. // Token is useful in the case that anonymous refresh is forbidden
  14. // and CRON task cannot be used with php command so the user can
  15. // set a CRON task to refresh his feeds by using token inside url
  16. $token = FreshRSS_Context::$user_conf->token;
  17. $token_param = Minz_Request::param('token', '');
  18. $token_is_ok = ($token != '' && $token == $token_param);
  19. $action = Minz_Request::actionName();
  20. $allow_anonymous_refresh = FreshRSS_Context::$system_conf->allow_anonymous_refresh;
  21. if ($action !== 'actualize' ||
  22. !($allow_anonymous_refresh || $token_is_ok)) {
  23. Minz_Error::error(403);
  24. }
  25. }
  26. }
  27. public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') {
  28. @set_time_limit(300);
  29. $catDAO = new FreshRSS_CategoryDAO();
  30. $cat = null;
  31. if ($cat_id > 0) {
  32. $cat = $catDAO->searchById($cat_id);
  33. }
  34. if ($cat == null && $new_cat_name != '') {
  35. $cat = $catDAO->addCategory(array('name' => $new_cat_name));
  36. }
  37. if ($cat == null) {
  38. $catDAO->checkDefault();
  39. }
  40. $cat_id = $cat == null ? FreshRSS_CategoryDAO::defaultCategoryId : $cat->id();
  41. $feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception
  42. $feed->_httpAuth($http_auth);
  43. $feed->load(true); //Throws FreshRSS_Feed_Exception, Minz_FileNotExistException
  44. $feed->_category($cat_id);
  45. $feedDAO = FreshRSS_Factory::createFeedDao();
  46. if ($feedDAO->searchByUrl($feed->url())) {
  47. throw new FreshRSS_AlreadySubscribed_Exception($url, $feed->name());
  48. }
  49. // Call the extension hook
  50. $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed);
  51. if ($feed === null) {
  52. throw new FreshRSS_FeedNotAdded_Exception($url, $feed->name());
  53. }
  54. $values = array(
  55. 'url' => $feed->url(),
  56. 'category' => $feed->category(),
  57. 'name' => $title != '' ? $title : $feed->name(),
  58. 'website' => $feed->website(),
  59. 'description' => $feed->description(),
  60. 'lastUpdate' => time(),
  61. 'httpAuth' => $feed->httpAuth(),
  62. );
  63. $id = $feedDAO->addFeed($values);
  64. if (!$id) {
  65. // There was an error in database... we cannot say what here.
  66. throw new FreshRSS_FeedNotAdded_Exception($url, $feed->name());
  67. }
  68. $feed->_id($id);
  69. // Ok, feed has been added in database. Now we have to refresh entries.
  70. self::actualizeFeed($id, $url, false, null, true);
  71. return $feed;
  72. }
  73. /**
  74. * This action subscribes to a feed.
  75. *
  76. * It can be reached by both GET and POST requests.
  77. *
  78. * GET request displays a form to add and configure a feed.
  79. * Request parameter is:
  80. * - url_rss (default: false)
  81. *
  82. * POST request adds a feed in database.
  83. * Parameters are:
  84. * - url_rss (default: false)
  85. * - category (default: false)
  86. * - new_category (required if category == 'nc')
  87. * - http_user (default: false)
  88. * - http_pass (default: false)
  89. * It tries to get website information from RSS feed.
  90. * If no category is given, feed is added to the default one.
  91. *
  92. * If url_rss is false, nothing happened.
  93. */
  94. public function addAction() {
  95. $url = Minz_Request::param('url_rss');
  96. if ($url === false) {
  97. // No url, do nothing
  98. Minz_Request::forward(array(
  99. 'c' => 'subscription',
  100. 'a' => 'index'
  101. ), true);
  102. }
  103. $feedDAO = FreshRSS_Factory::createFeedDao();
  104. $url_redirect = array(
  105. 'c' => 'subscription',
  106. 'a' => 'index',
  107. 'params' => array(),
  108. );
  109. $limits = FreshRSS_Context::$system_conf->limits;
  110. $this->view->feeds = $feedDAO->listFeeds();
  111. if (count($this->view->feeds) >= $limits['max_feeds']) {
  112. Minz_Request::bad(_t('feedback.sub.feed.over_max', $limits['max_feeds']),
  113. $url_redirect);
  114. }
  115. if (Minz_Request::isPost()) {
  116. $cat = Minz_Request::param('category');
  117. $new_cat_name = '';
  118. if ($cat === 'nc') {
  119. // User want to create a new category, new_category parameter
  120. // must exist
  121. $new_cat = Minz_Request::param('new_category');
  122. $new_cat_name = isset($new_cat['name']) ? $new_cat['name'] : '';
  123. }
  124. // HTTP information are useful if feed is protected behind a
  125. // HTTP authentication
  126. $user = trim(Minz_Request::param('http_user', ''));
  127. $pass = Minz_Request::param('http_pass', '');
  128. $http_auth = '';
  129. if ($user != '' && $pass != '') { //TODO: Sanitize
  130. $http_auth = $user . ':' . $pass;
  131. }
  132. try {
  133. $feed = self::addFeed($url, '', $cat, $new_cat_name, $http_auth);
  134. } catch (FreshRSS_BadUrl_Exception $e) {
  135. // Given url was not a valid url!
  136. Minz_Log::warning($e->getMessage());
  137. Minz_Request::bad(_t('feedback.sub.feed.invalid_url', $url), $url_redirect);
  138. } catch (FreshRSS_Feed_Exception $e) {
  139. // Something went bad (timeout, server not found, etc.)
  140. Minz_Log::warning($e->getMessage());
  141. Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
  142. } catch (Minz_FileNotExistException $e) {
  143. // Cache directory doesn't exist!
  144. Minz_Log::error($e->getMessage());
  145. Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
  146. } catch (FreshRSS_AlreadySubscribed_Exception $e) {
  147. Minz_Request::bad(_t('feedback.sub.feed.already_subscribed', $e->feedName()), $url_redirect);
  148. } catch (FreshRSS_FeedNotAdded_Exception $e) {
  149. Minz_Request::bad(_t('feedback.sub.feed.not_added', $e->feedName()), $url_redirect);
  150. }
  151. // Entries are in DB, we redirect to feed configuration page.
  152. $url_redirect['params']['id'] = $feed->id();
  153. Minz_Request::good(_t('feedback.sub.feed.added', $feed->name()), $url_redirect);
  154. } else {
  155. // GET request: we must ask confirmation to user before adding feed.
  156. Minz_View::prependTitle(_t('sub.feed.title_add') . ' · ');
  157. $this->catDAO = new FreshRSS_CategoryDAO();
  158. $this->view->categories = $this->catDAO->listCategories(false);
  159. $this->view->feed = new FreshRSS_Feed($url);
  160. try {
  161. // We try to get more information about the feed.
  162. $this->view->feed->load(true);
  163. $this->view->load_ok = true;
  164. } catch (Exception $e) {
  165. $this->view->load_ok = false;
  166. }
  167. $feed = $feedDAO->searchByUrl($this->view->feed->url());
  168. if ($feed) {
  169. // Already subscribe so we redirect to the feed configuration page.
  170. $url_redirect['params']['id'] = $feed->id();
  171. Minz_Request::good(_t('feedback.sub.feed.already_subscribed', $feed->name()), $url_redirect);
  172. }
  173. }
  174. }
  175. /**
  176. * This action remove entries from a given feed.
  177. *
  178. * It should be reached by a POST action.
  179. *
  180. * Parameter is:
  181. * - id (default: false)
  182. */
  183. public function truncateAction() {
  184. $id = Minz_Request::param('id');
  185. $url_redirect = array(
  186. 'c' => 'subscription',
  187. 'a' => 'index',
  188. 'params' => array('id' => $id)
  189. );
  190. if (!Minz_Request::isPost()) {
  191. Minz_Request::forward($url_redirect, true);
  192. }
  193. $feedDAO = FreshRSS_Factory::createFeedDao();
  194. $n = $feedDAO->truncate($id);
  195. invalidateHttpCache();
  196. if ($n === false) {
  197. Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
  198. } else {
  199. Minz_Request::good(_t('feedback.sub.feed.n_entries_deleted', $n), $url_redirect);
  200. }
  201. }
  202. public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush = null, $isNewFeed = false) {
  203. @set_time_limit(300);
  204. $feedDAO = FreshRSS_Factory::createFeedDao();
  205. $entryDAO = FreshRSS_Factory::createEntryDao();
  206. // Create a list of feeds to actualize.
  207. // If feed_id is set and valid, corresponding feed is added to the list but
  208. // alone in order to automatize further process.
  209. $feeds = array();
  210. if ($feed_id > 0 || $feed_url) {
  211. $feed = $feed_id > 0 ? $feedDAO->searchById($feed_id) : $feedDAO->searchByUrl($feed_url);
  212. if ($feed) {
  213. $feeds[] = $feed;
  214. }
  215. } else {
  216. $feeds = $feedDAO->listFeedsOrderUpdate(-1);
  217. }
  218. // Calculate date of oldest entries we accept in DB.
  219. $nb_month_old = max(FreshRSS_Context::$user_conf->old_entries, 1);
  220. $date_min = time() - (3600 * 24 * 30 * $nb_month_old);
  221. // PubSubHubbub support
  222. $pubsubhubbubEnabledGeneral = FreshRSS_Context::$system_conf->pubsubhubbub_enabled;
  223. $pshbMinAge = time() - (3600 * 24); //TODO: Make a configuration.
  224. $updated_feeds = 0;
  225. $is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
  226. foreach ($feeds as $feed) {
  227. $url = $feed->url(); //For detection of HTTP 301
  228. $pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled();
  229. if ((!$simplePiePush) && (!$feed_id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) {
  230. //$text = 'Skip pull of feed using PubSubHubbub: ' . $url;
  231. //Minz_Log::debug($text);
  232. //file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
  233. continue; //When PubSubHubbub is used, do not pull refresh so often
  234. }
  235. $mtime = 0;
  236. $ttl = $feed->ttl();
  237. if ($ttl == -1) {
  238. continue; //Feed refresh is disabled
  239. }
  240. if ((!$simplePiePush) && (!$feed_id) &&
  241. ($feed->lastUpdate() + 10 >= time() - ($ttl == -2 ? FreshRSS_Context::$user_conf->ttl_default : $ttl))) {
  242. //Too early to refresh from source, but check whether the feed was updated by another user
  243. $mtime = $feed->cacheModifiedTime();
  244. if ($feed->lastUpdate() + 10 >= $mtime) {
  245. continue; //Nothing newer from other users
  246. }
  247. //Minz_Log::debug($feed->url() . ' was updated at ' . date('c', $mtime) . ' by another user');
  248. //Will take advantage of the newer cache
  249. }
  250. if (!$feed->lock()) {
  251. Minz_Log::notice('Feed already being actualized: ' . $feed->url());
  252. continue;
  253. }
  254. try {
  255. if ($simplePiePush) {
  256. $feed->loadEntries($simplePiePush); //Used by PubSubHubbub
  257. } else {
  258. $feed->load(false, $isNewFeed);
  259. }
  260. } catch (FreshRSS_Feed_Exception $e) {
  261. Minz_Log::warning($e->getMessage());
  262. $feedDAO->updateLastUpdate($feed->id(), true);
  263. $feed->unlock();
  264. continue;
  265. }
  266. $feed_history = $feed->keepHistory();
  267. if ($isNewFeed) {
  268. $feed_history = -1; //∞
  269. } elseif ($feed_history == -2) {
  270. // TODO: -2 must be a constant!
  271. // -2 means we take the default value from configuration
  272. $feed_history = FreshRSS_Context::$user_conf->keep_history_default;
  273. }
  274. // We want chronological order and SimplePie uses reverse order.
  275. $entries = array_reverse($feed->entries());
  276. if (count($entries) > 0) {
  277. $newGuids = array();
  278. foreach ($entries as $entry) {
  279. $newGuids[] = safe_ascii($entry->guid());
  280. }
  281. // For this feed, check existing GUIDs already in database.
  282. $existingHashForGuids = $entryDAO->listHashForFeedGuids($feed->id(), $newGuids);
  283. unset($newGuids);
  284. $oldGuids = array();
  285. // Add entries in database if possible.
  286. foreach ($entries as $entry) {
  287. $entry_date = $entry->date(true);
  288. if (isset($existingHashForGuids[$entry->guid()])) {
  289. $existingHash = $existingHashForGuids[$entry->guid()];
  290. if (strcasecmp($existingHash, $entry->hash()) === 0 || trim($existingHash, '0') == '') {
  291. //This entry already exists and is unchanged. TODO: Remove the test with the zero'ed hash in FreshRSS v1.3
  292. $oldGuids[] = $entry->guid();
  293. } else { //This entry already exists but has been updated
  294. //Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->id() .
  295. //', old hash ' . $existingHash . ', new hash ' . $entry->hash());
  296. //TODO: Make an updated/is_read policy by feed, in addition to the global one.
  297. $entry->_isRead(FreshRSS_Context::$user_conf->mark_updated_article_unread ? false : null); //Change is_read according to policy.
  298. if (!$entryDAO->inTransaction()) {
  299. $entryDAO->beginTransaction();
  300. }
  301. $entryDAO->updateEntry($entry->toArray());
  302. }
  303. } elseif ($feed_history == 0 && $entry_date < $date_min) {
  304. // This entry should not be added considering configuration and date.
  305. $oldGuids[] = $entry->guid();
  306. } else {
  307. if ($isNewFeed) {
  308. $id = min(time(), $entry_date) . uSecString();
  309. } elseif ($entry_date < $date_min) {
  310. $id = min(time(), $entry_date) . uSecString();
  311. $entry->_isRead(true); //Old article that was not in database. Probably an error, so mark as read
  312. } else {
  313. $id = uTimeString();
  314. $entry->_isRead($is_read);
  315. }
  316. $entry->_id($id);
  317. $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
  318. if ($entry === null) {
  319. // An extension has returned a null value, there is nothing to insert.
  320. continue;
  321. }
  322. if ($pubSubHubbubEnabled && !$simplePiePush) { //We use push, but have discovered an article by pull!
  323. $text = 'An article was discovered by pull although we use PubSubHubbub!: Feed ' . $url . ' GUID ' . $entry->guid();
  324. file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
  325. Minz_Log::warning($text);
  326. $pubSubHubbubEnabled = false;
  327. $feed->pubSubHubbubError(true);
  328. }
  329. if (!$entryDAO->inTransaction()) {
  330. $entryDAO->beginTransaction();
  331. }
  332. $entryDAO->addEntry($entry->toArray());
  333. }
  334. }
  335. $entryDAO->updateLastSeen($feed->id(), $oldGuids, $mtime);
  336. }
  337. if ($feed_history >= 0 && rand(0, 30) === 1) {
  338. // TODO: move this function in web cron when available (see entry::purge)
  339. // Remove old entries once in 30.
  340. if (!$entryDAO->inTransaction()) {
  341. $entryDAO->beginTransaction();
  342. }
  343. $nb = $feedDAO->cleanOldEntries($feed->id(),
  344. $date_min,
  345. max($feed_history, count($entries) + 10));
  346. if ($nb > 0) {
  347. Minz_Log::debug($nb . ' old entries cleaned in feed [' .
  348. $feed->url() . ']');
  349. }
  350. }
  351. $feedDAO->updateLastUpdate($feed->id(), false, $entryDAO->inTransaction(), $mtime);
  352. if ($entryDAO->inTransaction()) {
  353. $entryDAO->commit();
  354. }
  355. if ($feed->hubUrl() && $feed->selfUrl()) { //selfUrl has priority for PubSubHubbub
  356. if ($feed->selfUrl() !== $url) { //https://code.google.com/p/pubsubhubbub/wiki/MovingFeedsOrChangingHubs
  357. $selfUrl = checkUrl($feed->selfUrl());
  358. if ($selfUrl) {
  359. Minz_Log::debug('PubSubHubbub unsubscribe ' . $feed->url());
  360. if (!$feed->pubSubHubbubSubscribe(false)) { //Unsubscribe
  361. Minz_Log::warning('Error while PubSubHubbub unsubscribing from ' . $feed->url());
  362. }
  363. $feed->_url($selfUrl, false);
  364. Minz_Log::notice('Feed ' . $url . ' canonical address moved to ' . $feed->url());
  365. $feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
  366. }
  367. }
  368. }
  369. elseif ($feed->url() !== $url) { // HTTP 301 Moved Permanently
  370. Minz_Log::notice('Feed ' . $url . ' moved permanently to ' . $feed->url());
  371. $feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
  372. }
  373. $feed->faviconPrepare();
  374. if ($pubsubhubbubEnabledGeneral && $feed->pubSubHubbubPrepare()) {
  375. Minz_Log::notice('PubSubHubbub subscribe ' . $feed->url());
  376. if (!$feed->pubSubHubbubSubscribe(true)) { //Subscribe
  377. Minz_Log::warning('Error while PubSubHubbub subscribing to ' . $feed->url());
  378. }
  379. }
  380. $feed->unlock();
  381. $updated_feeds++;
  382. unset($feed);
  383. // No more than 10 feeds unless $force is true to avoid overloading
  384. // the server.
  385. if ($updated_feeds >= 10 && !$force) {
  386. break;
  387. }
  388. }
  389. return array($updated_feeds, reset($feeds));
  390. }
  391. /**
  392. * This action actualizes entries from one or several feeds.
  393. *
  394. * Parameters are:
  395. * - id (default: false): Feed ID
  396. * - url (default: false): Feed URL
  397. * - force (default: false)
  398. * If id and url are not specified, all the feeds are actualized. But if force is
  399. * false, process stops at 10 feeds to avoid time execution problem.
  400. */
  401. public function actualizeAction() {
  402. Minz_Session::_param('actualize_feeds', false);
  403. $id = Minz_Request::param('id');
  404. $url = Minz_Request::param('url');
  405. $force = Minz_Request::param('force');
  406. list($updated_feeds, $feed) = self::actualizeFeed($id, $url, $force);
  407. if (Minz_Request::param('ajax')) {
  408. // Most of the time, ajax request is for only one feed. But since
  409. // there are several parallel requests, we should return that there
  410. // are several updated feeds.
  411. $notif = array(
  412. 'type' => 'good',
  413. 'content' => _t('feedback.sub.feed.actualizeds')
  414. );
  415. Minz_Session::_param('notification', $notif);
  416. // No layout in ajax request.
  417. $this->view->_useLayout(false);
  418. } else {
  419. // Redirect to the main page with correct notification.
  420. if ($updated_feeds === 1) {
  421. Minz_Request::good(_t('feedback.sub.feed.actualized', $feed->name()), array(
  422. 'params' => array('get' => 'f_' . $feed->id())
  423. ));
  424. } elseif ($updated_feeds > 1) {
  425. Minz_Request::good(_t('feedback.sub.feed.n_actualized', $updated_feeds), array());
  426. } else {
  427. Minz_Request::good(_t('feedback.sub.feed.no_refresh'), array());
  428. }
  429. }
  430. return $updated_feeds;
  431. }
  432. public static function renameFeed($feed_id, $feed_name) {
  433. if ($feed_id <= 0 || $feed_name == '') {
  434. return false;
  435. }
  436. $feedDAO = FreshRSS_Factory::createFeedDao();
  437. return $feedDAO->updateFeed($feed_id, array('name' => $feed_name));
  438. }
  439. public static function moveFeed($feed_id, $cat_id, $new_cat_name = '') {
  440. if ($feed_id <= 0 || ($cat_id <= 0 && $new_cat_name == '')) {
  441. return false;
  442. }
  443. $catDAO = new FreshRSS_CategoryDAO();
  444. if ($cat_id > 0) {
  445. $cat = $catDAO->searchById($cat_id);
  446. $cat_id = $cat == null ? 0 : $cat->id();
  447. }
  448. if ($cat_id <= 1 && $new_cat_name != '') {
  449. $cat_id = $catDAO->addCategory(array('name' => $new_cat_name));
  450. }
  451. if ($cat_id <= 1) {
  452. $catDAO->checkDefault();
  453. $cat_id = FreshRSS_CategoryDAO::defaultCategoryId;
  454. }
  455. $feedDAO = FreshRSS_Factory::createFeedDao();
  456. return $feedDAO->updateFeed($feed_id, array('category' => $cat_id));
  457. }
  458. /**
  459. * This action changes the category of a feed.
  460. *
  461. * This page must be reached by a POST request.
  462. *
  463. * Parameters are:
  464. * - f_id (default: false)
  465. * - c_id (default: false)
  466. * If c_id is false, default category is used.
  467. *
  468. * @todo should handle order of the feed inside the category.
  469. */
  470. public function moveAction() {
  471. if (!Minz_Request::isPost()) {
  472. Minz_Request::forward(array('c' => 'subscription'), true);
  473. }
  474. $feed_id = Minz_Request::param('f_id');
  475. $cat_id = Minz_Request::param('c_id');
  476. if (self::moveFeed($feed_id, $cat_id)) {
  477. // TODO: return something useful
  478. } else {
  479. Minz_Log::warning('Cannot move feed `' . $feed_id . '` ' .
  480. 'in the category `' . $cat_id . '`');
  481. Minz_Error::error(404);
  482. }
  483. }
  484. public static function deleteFeed($feed_id) {
  485. $feedDAO = FreshRSS_Factory::createFeedDao();
  486. if ($feedDAO->deleteFeed($feed_id)) {
  487. // TODO: Delete old favicon
  488. // Remove related queries
  489. FreshRSS_Context::$user_conf->queries = remove_query_by_get(
  490. 'f_' . $feed_id, FreshRSS_Context::$user_conf->queries);
  491. FreshRSS_Context::$user_conf->save();
  492. return true;
  493. }
  494. return false;
  495. }
  496. /**
  497. * This action deletes a feed.
  498. *
  499. * This page must be reached by a POST request.
  500. * If there are related queries, they are deleted too.
  501. *
  502. * Parameters are:
  503. * - id (default: false)
  504. * - r (default: false)
  505. * r permits to redirect to a given page at the end of this action.
  506. *
  507. * @todo handle "r" redirection in Minz_Request::forward()?
  508. */
  509. public function deleteAction() {
  510. $redirect_url = Minz_Request::param('r', false, true);
  511. if (!$redirect_url) {
  512. $redirect_url = array('c' => 'subscription', 'a' => 'index');
  513. }
  514. if (!Minz_Request::isPost()) {
  515. Minz_Request::forward($redirect_url, true);
  516. }
  517. $id = Minz_Request::param('id');
  518. if (self::deleteFeed($id)) {
  519. Minz_Request::good(_t('feedback.sub.feed.deleted'), $redirect_url);
  520. } else {
  521. Minz_Request::bad(_t('feedback.sub.feed.error'), $redirect_url);
  522. }
  523. }
  524. }