aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-11 17:40:28 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-11 17:40:28 +0100
commita4fc7becb8553198d132633d775989c89c8116cd (patch)
treebed0b71acabdc0c776d91ac826dbb1779d694f66 /app/models
parent76a027c9bbfc646c9690f00d63be49cc4287b9c3 (diff)
Décode les entités HTML en conservant les entités XML
N'ayant pas trouvé comment régler SimplePie pour ne pas avoir d'entités HTML comme `&eacute;`, voici un patch qui les décode en sortie de SimplePie tout en conservant les entités XML comme `&amp;`. Contribue à https://github.com/marienfressinaud/FreshRSS/issues/247
Diffstat (limited to 'app/models')
-rw-r--r--app/models/Feed.php19
1 files changed, 15 insertions, 4 deletions
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 7f53d7be8..41750d43e 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -241,12 +241,22 @@ class Feed extends Model {
}
}
}
+ static 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);
+ }
private function loadEntries ($feed) {
$entries = array ();
foreach ($feed->get_items () as $item) {
- $title = strip_tags($item->get_title ());
- $author = $item->get_author ();
+ $title = self::html_only_entity_decode (strip_tags ($item->get_title ()));
+ $author = self::html_only_entity_decode ($item->get_author ());
$link = $item->get_permalink ();
$date = strtotime ($item->get_date ());
@@ -255,11 +265,12 @@ class Feed extends Model {
$tags = array ();
if (!is_null ($tags_tmp)) {
foreach ($tags_tmp as $tag) {
- $tags[] = $tag->get_label ();
+ $tags[] = self::html_only_entity_decode ($tag->get_label ());
}
}
- $content = $item->get_content ();
+ $content = self::html_only_entity_decode ($item->get_content ());
+
$elinks = array();
foreach ($item->get_enclosures() as $enclosure) {
$elink = $enclosure->get_link();