feedController.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Controller to handle every feed actions.
  5. */
  6. class FreshRSS_feed_Controller extends FreshRSS_ActionController {
  7. /**
  8. * This action is called before every other action in that class. It is
  9. * the common boiler plate for every action. It is triggered by the
  10. * underlying framework.
  11. */
  12. public function firstAction(): void {
  13. if (!FreshRSS_Auth::hasAccess()) {
  14. // Token is useful in the case that anonymous refresh is forbidden
  15. // and CRON task cannot be used with php command so the user can
  16. // set a CRON task to refresh his feeds by using token inside url
  17. $token = FreshRSS_Context::userConf()->token;
  18. $token_param = Minz_Request::paramString('token');
  19. $token_is_ok = ($token != '' && $token == $token_param);
  20. $action = Minz_Request::actionName();
  21. $allow_anonymous_refresh = FreshRSS_Context::systemConf()->allow_anonymous_refresh;
  22. if ($action !== 'actualize' ||
  23. !($allow_anonymous_refresh || $token_is_ok)) {
  24. Minz_Error::error(403);
  25. }
  26. }
  27. }
  28. /**
  29. * @param array<string,mixed> $attributes
  30. * @throws FreshRSS_AlreadySubscribed_Exception
  31. * @throws FreshRSS_FeedNotAdded_Exception
  32. * @throws FreshRSS_Feed_Exception
  33. * @throws Minz_FileNotExistException
  34. */
  35. public static function addFeed(string $url, string $title = '', int $cat_id = 0, string $new_cat_name = '',
  36. string $http_auth = '', array $attributes = [], int $kind = FreshRSS_Feed::KIND_RSS): FreshRSS_Feed {
  37. FreshRSS_UserDAO::touch();
  38. if (function_exists('set_time_limit')) {
  39. @set_time_limit(300);
  40. }
  41. $catDAO = FreshRSS_Factory::createCategoryDao();
  42. $url = trim($url);
  43. /** @var string|null $urlHooked */
  44. $urlHooked = Minz_ExtensionManager::callHook('check_url_before_add', $url);
  45. if ($urlHooked === null) {
  46. throw new FreshRSS_FeedNotAdded_Exception($url);
  47. }
  48. $url = $urlHooked;
  49. $cat = null;
  50. if ($cat_id > 0) {
  51. $cat = $catDAO->searchById($cat_id);
  52. }
  53. if ($cat === null && $new_cat_name != '') {
  54. $new_cat_id = $catDAO->addCategory(['name' => $new_cat_name]);
  55. $cat_id = $new_cat_id > 0 ? $new_cat_id : $cat_id;
  56. $cat = $catDAO->searchById($cat_id);
  57. }
  58. if ($cat === null) {
  59. $catDAO->checkDefault();
  60. }
  61. $feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception
  62. $title = trim($title);
  63. if ($title !== '') {
  64. $feed->_name($title);
  65. }
  66. $feed->_kind($kind);
  67. $feed->_attributes($attributes);
  68. $feed->_httpAuth($http_auth);
  69. if ($cat === null) {
  70. $feed->_categoryId(FreshRSS_CategoryDAO::DEFAULTCATEGORYID);
  71. } else {
  72. $feed->_category($cat);
  73. }
  74. switch ($kind) {
  75. case FreshRSS_Feed::KIND_RSS:
  76. case FreshRSS_Feed::KIND_RSS_FORCED:
  77. $feed->load(true); //Throws FreshRSS_Feed_Exception, Minz_FileNotExistException
  78. break;
  79. case FreshRSS_Feed::KIND_HTML_XPATH:
  80. case FreshRSS_Feed::KIND_XML_XPATH:
  81. $feed->_website($url);
  82. break;
  83. }
  84. $feedDAO = FreshRSS_Factory::createFeedDao();
  85. if ($feedDAO->searchByUrl($feed->url())) {
  86. throw new FreshRSS_AlreadySubscribed_Exception($url, $feed->name());
  87. }
  88. /** @var FreshRSS_Feed|null $feed */
  89. $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed);
  90. if ($feed === null) {
  91. throw new FreshRSS_FeedNotAdded_Exception($url);
  92. }
  93. $id = $feedDAO->addFeedObject($feed);
  94. if (!$id) {
  95. // There was an error in database… we cannot say what here.
  96. throw new FreshRSS_FeedNotAdded_Exception($url);
  97. }
  98. $feed->_id($id);
  99. // Ok, feed has been added in database. Now we have to refresh entries.
  100. [, , $nb_new_articles] = self::actualizeFeeds($id, $url);
  101. if ($nb_new_articles > 0) {
  102. self::commitNewEntries();
  103. }
  104. return $feed;
  105. }
  106. /**
  107. * This action subscribes to a feed.
  108. *
  109. * It can be reached by both GET and POST requests.
  110. *
  111. * GET request displays a form to add and configure a feed.
  112. * Request parameter is:
  113. * - url_rss (default: false)
  114. *
  115. * POST request adds a feed in database.
  116. * Parameters are:
  117. * - url_rss (default: false)
  118. * - category (default: false)
  119. * - http_user (default: false)
  120. * - http_pass (default: false)
  121. * It tries to get website information from RSS feed.
  122. * If no category is given, feed is added to the default one.
  123. *
  124. * If url_rss is false, nothing happened.
  125. */
  126. public function addAction(): void {
  127. $url = Minz_Request::paramString('url_rss');
  128. if ($url === '') {
  129. // No url, do nothing
  130. Minz_Request::forward([
  131. 'c' => 'subscription',
  132. 'a' => 'index',
  133. ], true);
  134. }
  135. $feedDAO = FreshRSS_Factory::createFeedDao();
  136. $url_redirect = [
  137. 'c' => 'subscription',
  138. 'a' => 'add',
  139. 'params' => [],
  140. ];
  141. $limits = FreshRSS_Context::systemConf()->limits;
  142. $this->view->feeds = $feedDAO->listFeeds();
  143. if (count($this->view->feeds) >= $limits['max_feeds']) {
  144. Minz_Request::bad(_t('feedback.sub.feed.over_max', $limits['max_feeds']), $url_redirect);
  145. }
  146. if (Minz_Request::isPost()) {
  147. $cat = Minz_Request::paramInt('category');
  148. // HTTP information are useful if feed is protected behind a
  149. // HTTP authentication
  150. $user = Minz_Request::paramString('http_user');
  151. $pass = Minz_Request::paramString('http_pass');
  152. $http_auth = '';
  153. if ($user != '' && $pass != '') { //TODO: Sanitize
  154. $http_auth = $user . ':' . $pass;
  155. }
  156. $cookie = Minz_Request::paramString('curl_params_cookie');
  157. $cookie_file = Minz_Request::paramBoolean('curl_params_cookiefile');
  158. $max_redirs = Minz_Request::paramInt('curl_params_redirects');
  159. $useragent = Minz_Request::paramString('curl_params_useragent');
  160. $proxy_address = Minz_Request::paramString('curl_params');
  161. $proxy_type = Minz_Request::paramString('proxy_type');
  162. $opts = [];
  163. if ($proxy_type !== '') {
  164. $opts[CURLOPT_PROXY] = $proxy_address;
  165. $opts[CURLOPT_PROXYTYPE] = (int)$proxy_type;
  166. }
  167. if ($cookie !== '') {
  168. $opts[CURLOPT_COOKIE] = $cookie;
  169. }
  170. if ($cookie_file) {
  171. // Pass empty cookie file name to enable the libcurl cookie engine
  172. // without reading any existing cookie data.
  173. $opts[CURLOPT_COOKIEFILE] = '';
  174. }
  175. if ($max_redirs !== 0) {
  176. $opts[CURLOPT_MAXREDIRS] = $max_redirs;
  177. $opts[CURLOPT_FOLLOWLOCATION] = 1;
  178. }
  179. if ($useragent !== '') {
  180. $opts[CURLOPT_USERAGENT] = $useragent;
  181. }
  182. $attributes = [
  183. 'curl_params' => empty($opts) ? null : $opts,
  184. ];
  185. $attributes['ssl_verify'] = Minz_Request::paramTernary('ssl_verify');
  186. $timeout = Minz_Request::paramInt('timeout');
  187. $attributes['timeout'] = $timeout > 0 ? $timeout : null;
  188. $feed_kind = Minz_Request::paramInt('feed_kind') ?: FreshRSS_Feed::KIND_RSS;
  189. if ($feed_kind === FreshRSS_Feed::KIND_HTML_XPATH || $feed_kind === FreshRSS_Feed::KIND_XML_XPATH) {
  190. $xPathSettings = [];
  191. if (Minz_Request::paramString('xPathFeedTitle') !== '') {
  192. $xPathSettings['feedTitle'] = Minz_Request::paramString('xPathFeedTitle', true);
  193. }
  194. if (Minz_Request::paramString('xPathItem') !== '') {
  195. $xPathSettings['item'] = Minz_Request::paramString('xPathItem', true);
  196. }
  197. if (Minz_Request::paramString('xPathItemTitle') !== '') {
  198. $xPathSettings['itemTitle'] = Minz_Request::paramString('xPathItemTitle', true);
  199. }
  200. if (Minz_Request::paramString('xPathItemContent') !== '') {
  201. $xPathSettings['itemContent'] = Minz_Request::paramString('xPathItemContent', true);
  202. }
  203. if (Minz_Request::paramString('xPathItemUri') !== '') {
  204. $xPathSettings['itemUri'] = Minz_Request::paramString('xPathItemUri', true);
  205. }
  206. if (Minz_Request::paramString('xPathItemAuthor') !== '') {
  207. $xPathSettings['itemAuthor'] = Minz_Request::paramString('xPathItemAuthor', true);
  208. }
  209. if (Minz_Request::paramString('xPathItemTimestamp') !== '') {
  210. $xPathSettings['itemTimestamp'] = Minz_Request::paramString('xPathItemTimestamp', true);
  211. }
  212. if (Minz_Request::paramString('xPathItemTimeFormat') !== '') {
  213. $xPathSettings['itemTimeFormat'] = Minz_Request::paramString('xPathItemTimeFormat', true);
  214. }
  215. if (Minz_Request::paramString('xPathItemThumbnail') !== '') {
  216. $xPathSettings['itemThumbnail'] = Minz_Request::paramString('xPathItemThumbnail', true);
  217. }
  218. if (Minz_Request::paramString('xPathItemCategories') !== '') {
  219. $xPathSettings['itemCategories'] = Minz_Request::paramString('xPathItemCategories', true);
  220. }
  221. if (Minz_Request::paramString('xPathItemUid') !== '') {
  222. $xPathSettings['itemUid'] = Minz_Request::paramString('xPathItemUid', true);
  223. }
  224. if (!empty($xPathSettings)) {
  225. $attributes['xpath'] = $xPathSettings;
  226. }
  227. }
  228. try {
  229. $feed = self::addFeed($url, '', $cat, '', $http_auth, $attributes, $feed_kind);
  230. } catch (FreshRSS_BadUrl_Exception $e) {
  231. // Given url was not a valid url!
  232. Minz_Log::warning($e->getMessage());
  233. Minz_Request::bad(_t('feedback.sub.feed.invalid_url', $url), $url_redirect);
  234. return;
  235. } catch (FreshRSS_Feed_Exception $e) {
  236. // Something went bad (timeout, server not found, etc.)
  237. Minz_Log::warning($e->getMessage());
  238. Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
  239. return;
  240. } catch (Minz_FileNotExistException $e) {
  241. // Cache directory doesn’t exist!
  242. Minz_Log::error($e->getMessage());
  243. Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
  244. return;
  245. } catch (FreshRSS_AlreadySubscribed_Exception $e) {
  246. Minz_Request::bad(_t('feedback.sub.feed.already_subscribed', $e->feedName()), $url_redirect);
  247. return;
  248. } catch (FreshRSS_FeedNotAdded_Exception $e) {
  249. Minz_Request::bad(_t('feedback.sub.feed.not_added', $e->url()), $url_redirect);
  250. return;
  251. }
  252. // Entries are in DB, we redirect to feed configuration page.
  253. $url_redirect['a'] = 'feed';
  254. $url_redirect['params']['id'] = '' . $feed->id();
  255. Minz_Request::good(_t('feedback.sub.feed.added', $feed->name()), $url_redirect);
  256. } else {
  257. // GET request: we must ask confirmation to user before adding feed.
  258. FreshRSS_View::prependTitle(_t('sub.feed.title_add') . ' · ');
  259. $catDAO = FreshRSS_Factory::createCategoryDao();
  260. $this->view->categories = $catDAO->listCategories(false) ?: [];
  261. $this->view->feed = new FreshRSS_Feed($url);
  262. try {
  263. // We try to get more information about the feed.
  264. $this->view->feed->load(true);
  265. $this->view->load_ok = true;
  266. } catch (Exception $e) {
  267. $this->view->load_ok = false;
  268. }
  269. $feed = $feedDAO->searchByUrl($this->view->feed->url());
  270. if ($feed) {
  271. // Already subscribe so we redirect to the feed configuration page.
  272. $url_redirect['a'] = 'feed';
  273. $url_redirect['params']['id'] = $feed->id();
  274. Minz_Request::good(_t('feedback.sub.feed.already_subscribed', $feed->name()), $url_redirect);
  275. }
  276. }
  277. }
  278. /**
  279. * This action remove entries from a given feed.
  280. *
  281. * It should be reached by a POST action.
  282. *
  283. * Parameter is:
  284. * - id (default: false)
  285. */
  286. public function truncateAction(): void {
  287. $id = Minz_Request::paramInt('id');
  288. $url_redirect = [
  289. 'c' => 'subscription',
  290. 'a' => 'index',
  291. 'params' => ['id' => $id],
  292. ];
  293. if (!Minz_Request::isPost()) {
  294. Minz_Request::forward($url_redirect, true);
  295. }
  296. $feedDAO = FreshRSS_Factory::createFeedDao();
  297. $n = $feedDAO->truncate($id);
  298. invalidateHttpCache();
  299. if ($n === false) {
  300. Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
  301. } else {
  302. Minz_Request::good(_t('feedback.sub.feed.n_entries_deleted', $n), $url_redirect);
  303. }
  304. }
  305. /**
  306. * @return array{0:int,1:FreshRSS_Feed|null,2:int} Number of updated feeds, first feed or null, number of new articles
  307. * @throws FreshRSS_BadUrl_Exception
  308. */
  309. public static function actualizeFeeds(?int $feed_id = null, ?string $feed_url = null, ?int $maxFeeds = null, ?SimplePie $simplePiePush = null): array {
  310. if (function_exists('set_time_limit')) {
  311. @set_time_limit(300);
  312. }
  313. if (!is_int($feed_id) || $feed_id <= 0) {
  314. $feed_id = null;
  315. }
  316. if (!is_string($feed_url) || trim($feed_url) === '') {
  317. $feed_url = null;
  318. }
  319. if (!is_int($maxFeeds) || $maxFeeds <= 0) {
  320. $maxFeeds = PHP_INT_MAX;
  321. }
  322. $feedDAO = FreshRSS_Factory::createFeedDao();
  323. $entryDAO = FreshRSS_Factory::createEntryDao();
  324. // Create a list of feeds to actualize.
  325. $feeds = [];
  326. if ($feed_id !== null || $feed_url !== null) {
  327. $feed = $feed_id !== null ? $feedDAO->searchById($feed_id) : $feedDAO->searchByUrl($feed_url);
  328. if ($feed !== null && $feed->id() > 0) {
  329. $feeds[] = $feed;
  330. $feed_id = $feed->id();
  331. }
  332. } else {
  333. $feeds = $feedDAO->listFeedsOrderUpdate(-1);
  334. // Hydrate category for each feed to avoid that each feed has to make an SQL request
  335. $categories = [];
  336. $catDAO = FreshRSS_Factory::createCategoryDao();
  337. foreach ($catDAO->listCategories(false, false) as $category) {
  338. $categories[$category->id()] = $category;
  339. }
  340. foreach ($feeds as $feed) {
  341. $category = $categories[$feed->categoryId()] ?? null;
  342. if ($category !== null) {
  343. $feed->_category($category);
  344. }
  345. }
  346. }
  347. // WebSub (PubSubHubbub) support
  348. $pubsubhubbubEnabledGeneral = FreshRSS_Context::systemConf()->pubsubhubbub_enabled;
  349. $pshbMinAge = time() - (3600 * 24); //TODO: Make a configuration.
  350. $updated_feeds = 0;
  351. $nb_new_articles = 0;
  352. foreach ($feeds as $feed) {
  353. /** @var FreshRSS_Feed|null $feed */
  354. $feed = Minz_ExtensionManager::callHook('feed_before_actualize', $feed);
  355. if (null === $feed) {
  356. continue;
  357. }
  358. $url = $feed->url(); //For detection of HTTP 301
  359. $pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled();
  360. if ($simplePiePush === null && $feed_id === null && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) {
  361. //$text = 'Skip pull of feed using PubSubHubbub: ' . $url;
  362. //Minz_Log::debug($text);
  363. //Minz_Log::debug($text, PSHB_LOG);
  364. continue; //When PubSubHubbub is used, do not pull refresh so often
  365. }
  366. if ($feed->mute()) {
  367. continue; //Feed refresh is disabled
  368. }
  369. $mtime = $feed->cacheModifiedTime() ?: 0;
  370. $ttl = $feed->ttl();
  371. if ($ttl === FreshRSS_Feed::TTL_DEFAULT) {
  372. $ttl = FreshRSS_Context::userConf()->ttl_default;
  373. }
  374. if ($simplePiePush === null && $feed_id === null && (time() <= $feed->lastUpdate() + $ttl)) {
  375. //Too early to refresh from source, but check whether the feed was updated by another user
  376. $ε = 10; // negligible offset errors in seconds
  377. if ($mtime <= 0 ||
  378. $feed->lastUpdate() + $ε >= $mtime ||
  379. time() + $ε >= $mtime + FreshRSS_Context::systemConf()->limits['cache_duration']) { // is cache still valid?
  380. continue; //Nothing newer from other users
  381. }
  382. Minz_Log::debug('Feed ' . $feed->url(false) . ' was updated at ' . date('c', $feed->lastUpdate()) .
  383. ', and at ' . date('c', $mtime) . ' by another user; take advantage of newer cache.');
  384. }
  385. if (!$feed->lock()) {
  386. Minz_Log::notice('Feed already being actualized: ' . $feed->url(false));
  387. continue;
  388. }
  389. $feedIsNew = $feed->lastUpdate() <= 0;
  390. $feedIsEmpty = false;
  391. $feedIsUnchanged = false;
  392. try {
  393. if ($simplePiePush !== null) {
  394. $simplePie = $simplePiePush; //Used by WebSub
  395. } elseif ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH) {
  396. $simplePie = $feed->loadHtmlXpath();
  397. if ($simplePie === null) {
  398. throw new FreshRSS_Feed_Exception('HTML+XPath Web scraping failed for [' . $feed->url(false) . ']');
  399. }
  400. } elseif ($feed->kind() === FreshRSS_Feed::KIND_XML_XPATH) {
  401. $simplePie = $feed->loadHtmlXpath();
  402. if ($simplePie === null) {
  403. throw new FreshRSS_Feed_Exception('XML+XPath parsing failed for [' . $feed->url(false) . ']');
  404. }
  405. } else {
  406. $simplePie = $feed->load(false, $feedIsNew);
  407. }
  408. if ($simplePie === null) {
  409. // Feed is cached and unchanged
  410. $newGuids = [];
  411. $entries = [];
  412. $feedIsEmpty = false; // We do not know
  413. $feedIsUnchanged = true;
  414. } else {
  415. $newGuids = $feed->loadGuids($simplePie);
  416. $entries = $feed->loadEntries($simplePie);
  417. $feedIsEmpty = $simplePiePush !== null && empty($newGuids);
  418. $feedIsUnchanged = false;
  419. }
  420. $mtime = $feed->cacheModifiedTime() ?: time();
  421. } catch (FreshRSS_Feed_Exception $e) {
  422. Minz_Log::warning($e->getMessage());
  423. $feedDAO->updateLastUpdate($feed->id(), true);
  424. if ($e->getCode() === 410) {
  425. // HTTP 410 Gone
  426. Minz_Log::warning('Muting gone feed: ' . $feed->url(false));
  427. $feedDAO->mute($feed->id(), true);
  428. }
  429. $feed->unlock();
  430. continue;
  431. }
  432. $needFeedCacheRefresh = false;
  433. $nbMarkedUnread = 0;
  434. if (count($newGuids) > 0) {
  435. if ($feed->attributeBoolean('read_when_same_title_in_feed') === null) {
  436. $readWhenSameTitleInFeed = (int)FreshRSS_Context::userConf()->mark_when['same_title_in_feed'];
  437. } elseif ($feed->attributeBoolean('read_when_same_title_in_feed') === false) {
  438. $readWhenSameTitleInFeed = 0;
  439. } else {
  440. $readWhenSameTitleInFeed = $feed->attributeInt('read_when_same_title_in_feed') ?? 0;
  441. }
  442. if ($readWhenSameTitleInFeed > 0) {
  443. $titlesAsRead = array_flip($feedDAO->listTitles($feed->id(), $readWhenSameTitleInFeed));
  444. } else {
  445. $titlesAsRead = [];
  446. }
  447. $mark_updated_article_unread = $feed->attributeBoolean('mark_updated_article_unread') ?? FreshRSS_Context::userConf()->mark_updated_article_unread;
  448. // For this feed, check existing GUIDs already in database.
  449. $existingHashForGuids = $entryDAO->listHashForFeedGuids($feed->id(), $newGuids) ?: [];
  450. /** @var array<string,bool> $newGuids */
  451. $newGuids = [];
  452. // Add entries in database if possible.
  453. /** @var FreshRSS_Entry $entry */
  454. foreach ($entries as $entry) {
  455. if (isset($newGuids[$entry->guid()])) {
  456. continue; //Skip subsequent articles with same GUID
  457. }
  458. $newGuids[$entry->guid()] = true;
  459. $entry->_lastSeen($mtime);
  460. if (isset($existingHashForGuids[$entry->guid()])) {
  461. $existingHash = $existingHashForGuids[$entry->guid()];
  462. if (strcasecmp($existingHash, $entry->hash()) !== 0) {
  463. //This entry already exists but has been updated
  464. //Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->url(false) .
  465. //', old hash ' . $existingHash . ', new hash ' . $entry->hash());
  466. $entry->_isFavorite(null); // Do not change favourite state
  467. $entry->_isRead($mark_updated_article_unread ? false : null); //Change is_read according to policy.
  468. if ($mark_updated_article_unread) {
  469. Minz_ExtensionManager::callHook('entry_auto_unread', $entry, 'updated_article');
  470. }
  471. $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
  472. if (!($entry instanceof FreshRSS_Entry)) {
  473. // An extension has returned a null value, there is nothing to insert.
  474. continue;
  475. }
  476. if (!$entry->isRead()) {
  477. $needFeedCacheRefresh = true; //Maybe
  478. $nbMarkedUnread++;
  479. }
  480. // If the entry has changed, there is a good chance for the full content to have changed as well.
  481. $entry->loadCompleteContent(true);
  482. if (!$entryDAO->inTransaction()) {
  483. $entryDAO->beginTransaction();
  484. }
  485. $entryDAO->updateEntry($entry->toArray());
  486. }
  487. } else {
  488. $id = uTimeString();
  489. $entry->_id($id);
  490. $entry->applyFilterActions($titlesAsRead);
  491. if ($readWhenSameTitleInFeed > 0) {
  492. $titlesAsRead[$entry->title()] = true;
  493. }
  494. $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
  495. if (!($entry instanceof FreshRSS_Entry)) {
  496. // An extension has returned a null value, there is nothing to insert.
  497. continue;
  498. }
  499. if ($pubSubHubbubEnabled && !$simplePiePush) { //We use push, but have discovered an article by pull!
  500. $text = 'An article was discovered by pull although we use PubSubHubbub!: Feed ' .
  501. SimplePie_Misc::url_remove_credentials($url) .
  502. ' GUID ' . $entry->guid();
  503. Minz_Log::warning($text, PSHB_LOG);
  504. Minz_Log::warning($text);
  505. $pubSubHubbubEnabled = false;
  506. $feed->pubSubHubbubError(true);
  507. }
  508. if (!$entryDAO->inTransaction()) {
  509. $entryDAO->beginTransaction();
  510. }
  511. $entryDAO->addEntry($entry->toArray(), true);
  512. $nb_new_articles++;
  513. }
  514. }
  515. // N.B.: Applies to _entry table and not _entrytmp:
  516. $entryDAO->updateLastSeen($feed->id(), array_keys($newGuids), $mtime);
  517. } elseif ($feedIsUnchanged) {
  518. // Feed cache was unchanged, so mark as seen the same entries as last time
  519. if (!$entryDAO->inTransaction()) {
  520. $entryDAO->beginTransaction();
  521. }
  522. $entryDAO->updateLastSeenUnchanged($feed->id(), $mtime);
  523. }
  524. unset($entries);
  525. if (rand(0, 30) === 1) { // Remove old entries once in 30.
  526. if (!$entryDAO->inTransaction()) {
  527. $entryDAO->beginTransaction();
  528. }
  529. $nb = $feed->cleanOldEntries();
  530. if ($nb > 0) {
  531. $needFeedCacheRefresh = true;
  532. }
  533. }
  534. $feedDAO->updateLastUpdate($feed->id(), false, $mtime);
  535. if ($feed->keepMaxUnread() !== null && ($feed->nbNotRead() + $nbMarkedUnread > $feed->keepMaxUnread())) {
  536. Minz_Log::debug('Existing unread entries (' . ($feed->nbNotRead() + $nbMarkedUnread) . ') exceeding max number of ' .
  537. $feed->keepMaxUnread() . ' for [' . $feed->url(false) . ']');
  538. $needFeedCacheRefresh |= ($feed->markAsReadMaxUnread() != false);
  539. }
  540. if ($simplePiePush === null) {
  541. // Do not call for WebSub events, as we do not know the list of articles still on the upstream feed.
  542. $needFeedCacheRefresh |= ($feed->markAsReadUponGone($feedIsEmpty, $mtime) != false);
  543. }
  544. if ($needFeedCacheRefresh) {
  545. $feedDAO->updateCachedValues($feed->id());
  546. }
  547. if ($entryDAO->inTransaction()) {
  548. $entryDAO->commit();
  549. }
  550. $feedProperties = [];
  551. if ($pubsubhubbubEnabledGeneral && $feed->hubUrl() && $feed->selfUrl()) { //selfUrl has priority for WebSub
  552. if ($feed->selfUrl() !== $url) { // https://github.com/pubsubhubbub/PubSubHubbub/wiki/Moving-Feeds-or-changing-Hubs
  553. $selfUrl = checkUrl($feed->selfUrl());
  554. if ($selfUrl) {
  555. Minz_Log::debug('WebSub unsubscribe ' . $feed->url(false));
  556. if (!$feed->pubSubHubbubSubscribe(false)) { //Unsubscribe
  557. Minz_Log::warning('Error while WebSub unsubscribing from ' . $feed->url(false));
  558. }
  559. $feed->_url($selfUrl, false);
  560. Minz_Log::notice('Feed ' . $url . ' canonical address moved to ' . $feed->url(false));
  561. $feedDAO->updateFeed($feed->id(), ['url' => $feed->url()]);
  562. }
  563. }
  564. } elseif ($feed->url() !== $url) { // HTTP 301 Moved Permanently
  565. Minz_Log::notice('Feed ' . SimplePie_Misc::url_remove_credentials($url) .
  566. ' moved permanently to ' . SimplePie_Misc::url_remove_credentials($feed->url(false)));
  567. $feedProperties['url'] = $feed->url();
  568. }
  569. if ($simplePie != null) {
  570. if ($feed->name(true) === '') {
  571. //HTML to HTML-PRE //ENT_COMPAT except '&'
  572. $name = strtr(html_only_entity_decode($simplePie->get_title()), ['<' => '&lt;', '>' => '&gt;', '"' => '&quot;']);
  573. $feed->_name($name);
  574. $feedProperties['name'] = $feed->name(false);
  575. }
  576. if (trim($feed->website()) === '') {
  577. $website = html_only_entity_decode($simplePie->get_link());
  578. $feed->_website($website == '' ? $feed->url() : $website);
  579. $feedProperties['website'] = $feed->website();
  580. $feed->faviconPrepare();
  581. }
  582. if (trim($feed->description()) === '') {
  583. $description = html_only_entity_decode($simplePie->get_description());
  584. if ($description !== '') {
  585. $feed->_description($description);
  586. $feedProperties['description'] = $feed->description();
  587. }
  588. }
  589. }
  590. if (!empty($feedProperties)) {
  591. $ok = $feedDAO->updateFeed($feed->id(), $feedProperties);
  592. if (!$ok && $feedIsNew) {
  593. //Cancel adding new feed in case of database error at first actualize
  594. $feedDAO->deleteFeed($feed->id());
  595. $feed->unlock();
  596. break;
  597. }
  598. }
  599. $feed->faviconPrepare();
  600. if ($pubsubhubbubEnabledGeneral && $feed->pubSubHubbubPrepare()) {
  601. Minz_Log::notice('WebSub subscribe ' . $feed->url(false));
  602. if (!$feed->pubSubHubbubSubscribe(true)) { //Subscribe
  603. Minz_Log::warning('Error while WebSub subscribing to ' . $feed->url(false));
  604. }
  605. }
  606. $feed->unlock();
  607. $updated_feeds++;
  608. unset($feed);
  609. gc_collect_cycles();
  610. if ($updated_feeds >= $maxFeeds) {
  611. break;
  612. }
  613. }
  614. return [$updated_feeds, reset($feeds) ?: null, $nb_new_articles];
  615. }
  616. /**
  617. * @param array<int,int> $newUnreadEntriesPerFeed
  618. * @return int|false The number of articles marked as read, of false if error
  619. */
  620. private static function keepMaxUnreads(array $newUnreadEntriesPerFeed) {
  621. $affected = 0;
  622. $feedDAO = FreshRSS_Factory::createFeedDao();
  623. $feeds = $feedDAO->listFeedsOrderUpdate(-1);
  624. foreach ($feeds as $feed) {
  625. if (!empty($newUnreadEntriesPerFeed[$feed->id()]) && $feed->keepMaxUnread() !== null &&
  626. ($feed->nbNotRead() + $newUnreadEntriesPerFeed[$feed->id()] > $feed->keepMaxUnread())) {
  627. Minz_Log::debug('New unread entries (' . ($feed->nbNotRead() + $newUnreadEntriesPerFeed[$feed->id()]) . ') exceeding max number of ' .
  628. $feed->keepMaxUnread() . ' for [' . $feed->url(false) . ']');
  629. $n = $feed->markAsReadMaxUnread();
  630. if ($n === false) {
  631. $affected = false;
  632. break;
  633. } else {
  634. $affected += $n;
  635. }
  636. }
  637. }
  638. if ($feedDAO->updateCachedValues() === false) {
  639. $affected = false;
  640. }
  641. return $affected;
  642. }
  643. /**
  644. * Auto-add labels to new articles.
  645. * @param int $nbNewEntries The number of top recent entries to process.
  646. * @return int|false The number of new labels added, or false in case of error.
  647. */
  648. private static function applyLabelActions(int $nbNewEntries) {
  649. $tagDAO = FreshRSS_Factory::createTagDao();
  650. $labels = $tagDAO->listTags() ?: [];
  651. $labels = array_filter($labels, static function (FreshRSS_Tag $label) {
  652. return !empty($label->filtersAction('label'));
  653. });
  654. if (count($labels) <= 0) {
  655. return 0;
  656. }
  657. $entryDAO = FreshRSS_Factory::createEntryDao();
  658. /** @var array<array{id_tag:int,id_entry:string}> $applyLabels */
  659. $applyLabels = [];
  660. foreach (FreshRSS_Entry::fromTraversable($entryDAO->selectAll($nbNewEntries)) as $entry) {
  661. foreach ($labels as $label) {
  662. $label->applyFilterActions($entry, $applyLabel);
  663. if ($applyLabel) {
  664. $applyLabels[] = [
  665. 'id_tag' => $label->id(),
  666. 'id_entry' => $entry->id(),
  667. ];
  668. }
  669. }
  670. }
  671. return $tagDAO->tagEntries($applyLabels);
  672. }
  673. public static function commitNewEntries(): bool {
  674. $entryDAO = FreshRSS_Factory::createEntryDao();
  675. $newUnreadEntriesPerFeed = $entryDAO->newUnreadEntriesPerFeed();
  676. $nbNewEntries = array_sum($newUnreadEntriesPerFeed);
  677. if ($nbNewEntries > 0) {
  678. if (!$entryDAO->inTransaction()) {
  679. $entryDAO->beginTransaction();
  680. }
  681. if ($entryDAO->commitNewEntries()) {
  682. self::keepMaxUnreads($newUnreadEntriesPerFeed);
  683. self::applyLabelActions($nbNewEntries);
  684. }
  685. if ($entryDAO->inTransaction()) {
  686. $entryDAO->commit();
  687. }
  688. }
  689. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  690. $databaseDAO->minorDbMaintenance();
  691. return true;
  692. }
  693. /**
  694. * This action actualizes entries from one or several feeds.
  695. *
  696. * Parameters are:
  697. * - id (default: null): Feed ID, or set to -1 to commit new articles to the main database
  698. * - url (default: null): Feed URL (instead of feed ID)
  699. * - maxFeeds (default: 10): Max number of feeds to refresh
  700. * - noCommit (default: 0): Set to 1 to prevent committing the new articles to the main database
  701. * If id and url are not specified, all the feeds are actualized, within the limits of maxFeeds.
  702. */
  703. public function actualizeAction(): int {
  704. Minz_Session::_param('actualize_feeds', false);
  705. $id = Minz_Request::paramInt('id');
  706. $url = Minz_Request::paramString('url');
  707. $maxFeeds = Minz_Request::paramInt('maxFeeds') ?: 10;
  708. $noCommit = ($_POST['noCommit'] ?? 0) == 1;
  709. if ($id === -1 && !$noCommit) { //Special request only to commit & refresh DB cache
  710. $updated_feeds = 0;
  711. $feed = null;
  712. self::commitNewEntries();
  713. } else {
  714. if ($id === 0 && $url === '') {
  715. FreshRSS_category_Controller::refreshDynamicOpmls();
  716. }
  717. [$updated_feeds, $feed, $nbNewArticles] = self::actualizeFeeds($id, $url, $maxFeeds);
  718. if (!$noCommit && $nbNewArticles > 0) {
  719. FreshRSS_feed_Controller::commitNewEntries();
  720. }
  721. }
  722. if (Minz_Request::paramBoolean('ajax')) {
  723. // Most of the time, ajax request is for only one feed. But since
  724. // there are several parallel requests, we should return that there
  725. // are several updated feeds.
  726. Minz_Request::setGoodNotification(_t('feedback.sub.feed.actualizeds'));
  727. // No layout in ajax request.
  728. $this->view->_layout(null);
  729. } elseif ($feed instanceof FreshRSS_Feed) {
  730. // Redirect to the main page with correct notification.
  731. Minz_Request::good(_t('feedback.sub.feed.actualized', $feed->name()), [
  732. 'params' => ['get' => 'f_' . $id]
  733. ]);
  734. } elseif ($updated_feeds >= 1) {
  735. Minz_Request::good(_t('feedback.sub.feed.n_actualized', $updated_feeds), []);
  736. } else {
  737. Minz_Request::good(_t('feedback.sub.feed.no_refresh'), []);
  738. }
  739. return $updated_feeds;
  740. }
  741. /**
  742. * @throws Minz_ConfigurationNamespaceException
  743. * @throws JsonException
  744. * @throws Minz_PDOConnectionException
  745. */
  746. public static function renameFeed(int $feed_id, string $feed_name): bool {
  747. if ($feed_id <= 0 || $feed_name === '') {
  748. return false;
  749. }
  750. FreshRSS_UserDAO::touch();
  751. $feedDAO = FreshRSS_Factory::createFeedDao();
  752. return $feedDAO->updateFeed($feed_id, ['name' => $feed_name]) === 1;
  753. }
  754. public static function moveFeed(int $feed_id, int $cat_id, string $new_cat_name = ''): bool {
  755. if ($feed_id <= 0 || ($cat_id <= 0 && $new_cat_name === '')) {
  756. return false;
  757. }
  758. FreshRSS_UserDAO::touch();
  759. $catDAO = FreshRSS_Factory::createCategoryDao();
  760. if ($cat_id > 0) {
  761. $cat = $catDAO->searchById($cat_id);
  762. $cat_id = $cat === null ? 0 : $cat->id();
  763. }
  764. if ($cat_id <= 1 && $new_cat_name != '') {
  765. $cat_id = $catDAO->addCategory(['name' => $new_cat_name]);
  766. }
  767. if ($cat_id <= 1) {
  768. $catDAO->checkDefault();
  769. $cat_id = FreshRSS_CategoryDAO::DEFAULTCATEGORYID;
  770. }
  771. $feedDAO = FreshRSS_Factory::createFeedDao();
  772. return $feedDAO->updateFeed($feed_id, ['category' => $cat_id]) === 1;
  773. }
  774. /**
  775. * This action changes the category of a feed.
  776. *
  777. * This page must be reached by a POST request.
  778. *
  779. * Parameters are:
  780. * - f_id (default: false)
  781. * - c_id (default: false)
  782. * If c_id is false, default category is used.
  783. *
  784. * @todo should handle order of the feed inside the category.
  785. */
  786. public function moveAction(): void {
  787. if (!Minz_Request::isPost()) {
  788. Minz_Request::forward(['c' => 'subscription'], true);
  789. }
  790. $feed_id = Minz_Request::paramInt('f_id');
  791. $cat_id = Minz_Request::paramInt('c_id');
  792. if (self::moveFeed($feed_id, $cat_id)) {
  793. // TODO: return something useful
  794. // Log a notice to prevent "Empty IF statement" warning in PHP_CodeSniffer
  795. Minz_Log::notice('Moved feed `' . $feed_id . '` in the category `' . $cat_id . '`');
  796. } else {
  797. Minz_Log::warning('Cannot move feed `' . $feed_id . '` in the category `' . $cat_id . '`');
  798. Minz_Error::error(404);
  799. }
  800. }
  801. public static function deleteFeed(int $feed_id): bool {
  802. FreshRSS_UserDAO::touch();
  803. $feedDAO = FreshRSS_Factory::createFeedDao();
  804. if ($feedDAO->deleteFeed($feed_id)) {
  805. // TODO: Delete old favicon
  806. // Remove related queries
  807. /** @var array<array{'get'?:string,'name'?:string,'order'?:string,'search'?:string,'state'?:int,'url'?:string}> $queries */
  808. $queries = remove_query_by_get('f_' . $feed_id, FreshRSS_Context::userConf()->queries);
  809. FreshRSS_Context::userConf()->queries = $queries;
  810. FreshRSS_Context::userConf()->save();
  811. return true;
  812. }
  813. return false;
  814. }
  815. /**
  816. * This action deletes a feed.
  817. *
  818. * This page must be reached by a POST request.
  819. * If there are related queries, they are deleted too.
  820. *
  821. * Parameters are:
  822. * - id (default: false)
  823. */
  824. public function deleteAction(): void {
  825. $from = Minz_Request::paramString('from');
  826. $id = Minz_Request::paramInt('id');
  827. switch ($from) {
  828. case 'stats':
  829. $redirect_url = ['c' => 'stats', 'a' => 'idle'];
  830. break;
  831. case 'normal':
  832. $get = Minz_Request::paramString('get');
  833. if ($get) {
  834. $redirect_url = ['c' => 'index', 'a' => 'normal', 'params' => ['get' => $get]];
  835. } else {
  836. $redirect_url = ['c' => 'index', 'a' => 'normal'];
  837. }
  838. break;
  839. default:
  840. $redirect_url = ['c' => 'subscription', 'a' => 'index'];
  841. if (!Minz_Request::isPost()) {
  842. Minz_Request::forward($redirect_url, true);
  843. }
  844. }
  845. if (self::deleteFeed($id)) {
  846. Minz_Request::good(_t('feedback.sub.feed.deleted'), $redirect_url);
  847. } else {
  848. Minz_Request::bad(_t('feedback.sub.feed.error'), $redirect_url);
  849. }
  850. }
  851. /**
  852. * This action force clears the cache of a feed.
  853. *
  854. * Parameters are:
  855. * - id (mandatory - no default): Feed ID
  856. *
  857. */
  858. public function clearCacheAction(): void {
  859. //Get Feed.
  860. $id = Minz_Request::paramInt('id');
  861. $feedDAO = FreshRSS_Factory::createFeedDao();
  862. $feed = $feedDAO->searchById($id);
  863. if ($feed === null) {
  864. Minz_Request::bad(_t('feedback.sub.feed.not_found'), []);
  865. return;
  866. }
  867. $feed->clearCache();
  868. Minz_Request::good(_t('feedback.sub.feed.cache_cleared', $feed->name()), [
  869. 'params' => ['get' => 'f_' . $feed->id()],
  870. ]);
  871. }
  872. /**
  873. * This action forces reloading the articles of a feed.
  874. *
  875. * Parameters are:
  876. * - id (mandatory - no default): Feed ID
  877. *
  878. * @throws FreshRSS_BadUrl_Exception
  879. */
  880. public function reloadAction(): void {
  881. if (function_exists('set_time_limit')) {
  882. @set_time_limit(300);
  883. }
  884. //Get Feed ID.
  885. $feed_id = Minz_Request::paramInt('id');
  886. $limit = Minz_Request::paramInt('reload_limit') ?: 10;
  887. $feedDAO = FreshRSS_Factory::createFeedDao();
  888. $entryDAO = FreshRSS_Factory::createEntryDao();
  889. $feed = $feedDAO->searchById($feed_id);
  890. if ($feed === null) {
  891. Minz_Request::bad(_t('feedback.sub.feed.not_found'), []);
  892. return;
  893. }
  894. //Re-fetch articles as if the feed was new.
  895. $feedDAO->updateFeed($feed->id(), [ 'lastUpdate' => 0 ]);
  896. [, , $nb_new_articles] = self::actualizeFeeds($feed_id);
  897. if ($nb_new_articles > 0) {
  898. FreshRSS_feed_Controller::commitNewEntries();
  899. }
  900. //Extract all feed entries from database, load complete content and store them back in database.
  901. $entries = $entryDAO->listWhere('f', $feed_id, FreshRSS_Entry::STATE_ALL, 'DESC', $limit);
  902. //We need another DB connection in parallel for unbuffered streaming
  903. Minz_ModelPdo::$usesSharedPdo = false;
  904. if (FreshRSS_Context::systemConf()->db['type'] === 'mysql') {
  905. // Second parallel connection for unbuffered streaming: MySQL
  906. $entryDAO2 = FreshRSS_Factory::createEntryDao();
  907. } else {
  908. // Single connection for buffered queries (in memory): SQLite, PostgreSQL
  909. //TODO: Consider an unbuffered query for PostgreSQL
  910. $entryDAO2 = $entryDAO;
  911. }
  912. foreach ($entries as $entry) {
  913. if ($entry->loadCompleteContent(true)) {
  914. $entryDAO2->updateEntry($entry->toArray());
  915. }
  916. }
  917. Minz_ModelPdo::$usesSharedPdo = true;
  918. //Give feedback to user.
  919. Minz_Request::good(_t('feedback.sub.feed.reloaded', $feed->name()), [
  920. 'params' => ['get' => 'f_' . $feed->id()]
  921. ]);
  922. }
  923. /**
  924. * This action creates a preview of a content-selector.
  925. *
  926. * Parameters are:
  927. * - id (mandatory - no default): Feed ID
  928. * - selector (mandatory - no default): Selector to preview
  929. *
  930. */
  931. public function contentSelectorPreviewAction(): void {
  932. //Configure.
  933. $this->view->fatalError = '';
  934. $this->view->selectorSuccess = false;
  935. $this->view->htmlContent = '';
  936. $this->view->_layout(null);
  937. $this->_csp([
  938. 'default-src' => "'self'",
  939. 'frame-src' => '*',
  940. 'img-src' => '* data:',
  941. 'media-src' => '*',
  942. ]);
  943. //Get parameters.
  944. $feed_id = Minz_Request::paramInt('id');
  945. $content_selector = Minz_Request::paramString('selector');
  946. if (!$content_selector) {
  947. $this->view->fatalError = _t('feedback.sub.feed.selector_preview.selector_empty');
  948. return;
  949. }
  950. //Check Feed ID validity.
  951. $entryDAO = FreshRSS_Factory::createEntryDao();
  952. $entries = $entryDAO->listWhere('f', $feed_id);
  953. $entry = null;
  954. //Get first entry (syntax robust for Generator or Array)
  955. foreach ($entries as $myEntry) {
  956. $entry = $myEntry;
  957. }
  958. if ($entry == null) {
  959. $this->view->fatalError = _t('feedback.sub.feed.selector_preview.no_entries');
  960. return;
  961. }
  962. //Get feed.
  963. $feed = $entry->feed();
  964. if ($feed === null) {
  965. $this->view->fatalError = _t('feedback.sub.feed.selector_preview.no_feed');
  966. return;
  967. }
  968. $attributes = $feed->attributes();
  969. $attributes['path_entries_filter'] = Minz_Request::paramString('selector_filter', true);
  970. //Fetch & select content.
  971. try {
  972. $fullContent = FreshRSS_Entry::getContentByParsing(
  973. htmlspecialchars_decode($entry->link(), ENT_QUOTES),
  974. htmlspecialchars_decode($content_selector, ENT_QUOTES),
  975. $attributes
  976. );
  977. if ($fullContent != '') {
  978. $this->view->selectorSuccess = true;
  979. $this->view->htmlContent = $fullContent;
  980. } else {
  981. $this->view->selectorSuccess = false;
  982. $this->view->htmlContent = $entry->content(false);
  983. }
  984. } catch (Exception $e) {
  985. $this->view->fatalError = _t('feedback.sub.feed.selector_preview.http_error');
  986. }
  987. }
  988. }