Add try catch to avoid error when loading a invalid URL see #14784

pull/2688/head
Julio 7 years ago
parent b1927eec0a
commit 8bbcd6affe
  1. 25
      plugin/rss/index.php
  2. 1
      plugin/rss/lang/english.php

@ -16,17 +16,20 @@ if (empty($url)) {
return; return;
} }
try {
$channel = Reader::import($url); $channel = Reader::import($url);
if (!empty($channel)) {
if (!empty($channel)) { /** @var FeedInterface $item */
/** @var FeedInterface $item */ foreach ($channel as $item) {
foreach ($channel as $item) { $title = $item->getTitle();
$title = $item->getTitle(); $link = $item->getLink();
$link = $item->getLink(); if (!empty($link)) {
if (!empty($link)) { $title = Display::url($title, $link, ['target' => '_blank']);
$title = Display::url($title, $link, ['target' => '_blank']); }
echo Display::panel($item->getDescription(), $title);
} }
echo Display::panel($item->getDescription(), $title);
} }
} catch (Exception $e) {
echo Display::return_message($plugin->get_lang('no_valid_rss'), 'warning');
error_log($e->getMessage());
} }

@ -13,3 +13,4 @@ $strings['block_title'] = "Block title";
$strings['title'] = "Title"; $strings['title'] = "Title";
$strings['no_rss'] = "There is no RSS configured. Please add a RSS"; $strings['no_rss'] = "There is no RSS configured. Please add a RSS";
$strings['no_valid_rss'] = "Please check if the URL contains a valid RSS URL";

Loading…
Cancel
Save