A free, self-hostable news aggregator…
Fix issue #84 : affichage erreur si fichier OPML invalide
Marien Fressinaudc96225df6d6b
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.phpindex 2f56da177..8500a4a04 100755--- a/app/controllers/configureController.php+++ b/app/controllers/configureController.php@@ -218,14 +218,31 @@ class configureController extends ActionController {} elseif ($this->view->req == 'import' && Request::isPost ()) {if ($_FILES['file']['error'] == 0) {// on parse le fichier OPML pour récupérer les catégories et les flux associés- list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));-- // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD- // les flux sont mis au préalable dans des variables de Request- Request::_param ('q', 'null');- Request::_param ('categories', $categories);- Request::_param ('feeds', $feeds);- Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));+ try {+ list ($categories, $feeds) = opml_import (+ file_get_contents ($_FILES['file']['tmp_name'])+ );++ // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD+ // les flux sont mis au préalable dans des variables de Request+ Request::_param ('q', 'null');+ Request::_param ('categories', $categories);+ Request::_param ('feeds', $feeds);+ Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));+ } catch (OpmlException $e) {+ Log::record ($e->getMessage (), Log::ERROR);++ $notif = array (+ 'type' => 'bad',+ 'content' => Translate::t ('bad_opml_file')+ );+ Session::_param ('notification', $notif);++ Request::forward (array (+ 'c' => 'configure',+ 'a' => 'importExport'+ ), true);+ }}}diff --git a/app/i18n/en.php b/app/i18n/en.phpindex 52a1674ba..c832a519f 100644--- a/app/i18n/en.php+++ b/app/i18n/en.php@@ -58,6 +58,7 @@ return array ('rss_feed_management' => 'RSS feeds management','configuration_updated' => 'Configuration has been updated','general_and_reading_management'=> 'General and reading management',+ 'bad_opml_file' => 'Your OPML file is invalid','shortcuts_updated' => 'Shortcuts have been updated','shortcuts_management' => 'Shortcuts management','feeds_marked_read' => 'Feeds have been marked as read',diff --git a/app/i18n/fr.php b/app/i18n/fr.phpindex 74dfaf8be..165b183eb 100644--- a/app/i18n/fr.php+++ b/app/i18n/fr.php@@ -58,6 +58,7 @@ return array ('rss_feed_management' => 'Gestion des flux RSS','configuration_updated' => 'La configuration a été mise à jour','general_and_reading_management'=> 'Gestion générale et affichage',+ 'bad_opml_file' => 'Votre fichier OPML n\'est pas valide','shortcuts_updated' => 'Les raccourcis ont été mis à jour','shortcuts_management' => 'Gestion des raccourcis','feeds_marked_read' => 'Les flux ont été marqués comme lu',diff --git a/app/models/Exception/FeedException.php b/app/models/Exception/FeedException.phpindex bc61e1736..bff297eb9 100644--- a/app/models/Exception/FeedException.php+++ b/app/models/Exception/FeedException.php@@ -11,3 +11,9 @@ class BadUrlException extends FeedException {parent::__construct ('`' . $url . '` is not a valid URL');}}++class OpmlException extends FeedException {+ public function __construct ($name_file) {+ parent::__construct ('OPML file is invalid');+ }+}diff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex c574cd3fd..77d3ac2db 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -65,7 +65,7 @@ function opml_import ($xml) {$opml = @simplexml_load_string ($xml);if (!$opml) {- return array (array (), array ());+ throw new OpmlException ();}$categories = array ();