From 08ff116f040f4c735722963e39fd6eb3716ef352 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 24 Nov 2013 17:08:48 +0100 Subject: OPML : corrections import/export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit À tester plus. En particulier, ne supporte pas bien les fichiers OPML qui sont à la fois avec des entités HTML et pas en UTF-8. Devrait corriger https://github.com/marienfressinaud/FreshRSS/issues/287 --- lib/lib_rss.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lib/lib_rss.php') diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 1d9d5c7e0..8e58e4048 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -44,7 +44,7 @@ function opml_export ($cats) { $txt .= '' . "\n"; foreach ($cat['feeds'] as $feed) { - $txt .= "\t" . '' . "\n"; + $txt .= "\t" . '' . "\n"; } $txt .= '' . "\n"; @@ -53,12 +53,20 @@ function opml_export ($cats) { return $txt; } -function cleanText ($text) { - return preg_replace ('/&[\w]+;/', '', $text); +function html_only_entity_decode($text) { + static $htmlEntitiesOnly = null; + if ($htmlEntitiesOnly === null) { + $htmlEntitiesOnly = array_flip(array_diff( + get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'), //Decode HTML entities + get_html_translation_table(HTML_SPECIALCHARS, ENT_NOQUOTES, 'UTF-8') //Preserve XML entities + )); + } + return strtr($text, $htmlEntitiesOnly); } function opml_import ($xml) { - $opml = @simplexml_load_string ($xml); + $xml = html_only_entity_decode($xml); //!\ Assume UTF-8 + $opml = simplexml_load_string ($xml); if (!$opml) { throw new OpmlException (); @@ -89,12 +97,17 @@ function opml_import ($xml) { // alors qu'il existe déjà la catégorie X mais avec l'id Z // Y ne sera pas ajouté et le flux non plus vu que l'id // de sa catégorie n'exisera pas + $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); $catDAO = new CategoryDAO (); $cat = $catDAO->searchByName ($title); if ($cat === false) { $cat = new Category ($title); + $values = array ( + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $cat->_id ($catDAO->addCategory ($values)); } - $categories[] = $cat; $feeds = array_merge ($feeds, getFeedsOutline ($outline, $cat->id ())); } @@ -129,12 +142,14 @@ function getFeedsOutline ($outline, $cat_id) { function getFeed ($outline, $cat_id) { $url = (string) $outline['xmlUrl']; + $url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); $title = ''; if (isset ($outline['text'])) { $title = (string) $outline['text']; } elseif (isset ($outline['title'])) { $title = (string) $outline['title']; } + $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); $feed = new Feed ($url); $feed->_category ($cat_id); $feed->_name ($title); -- cgit v1.2.3