mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-04-14 11:27:09 -04:00
OPML : corrections import/export
À 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
This commit is contained in:
@@ -95,7 +95,7 @@ class CategoryDAO extends Model_pdo {
|
||||
);
|
||||
|
||||
if ($stm && $stm->execute ($values)) {
|
||||
return $stm->rowCount();
|
||||
return $this->bd->lastInsertId();
|
||||
} else {
|
||||
$info = $stm->errorInfo();
|
||||
Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
|
||||
|
||||
@@ -213,7 +213,7 @@ class EntryDAO extends Model_pdo {
|
||||
);
|
||||
|
||||
if ($stm && $stm->execute ($values)) {
|
||||
return $stm->rowCount();
|
||||
return $this->bd->lastInsertId();
|
||||
} else {
|
||||
$info = $stm->errorInfo();
|
||||
if ((int)($info[0] / 1000) !== 23) { //Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries
|
||||
|
||||
@@ -270,7 +270,7 @@ class Feed extends Model {
|
||||
$entries = array ();
|
||||
|
||||
foreach ($feed->get_items () as $item) {
|
||||
$title = self::html_only_entity_decode (strip_tags ($item->get_title ()));
|
||||
$title = html_only_entity_decode (strip_tags ($item->get_title ()));
|
||||
$author = $item->get_author ();
|
||||
$link = $item->get_permalink ();
|
||||
$date = strtotime ($item->get_date ());
|
||||
@@ -280,11 +280,11 @@ class Feed extends Model {
|
||||
$tags = array ();
|
||||
if (!is_null ($tags_tmp)) {
|
||||
foreach ($tags_tmp as $tag) {
|
||||
$tags[] = self::html_only_entity_decode ($tag->get_label ());
|
||||
$tags[] = html_only_entity_decode ($tag->get_label ());
|
||||
}
|
||||
}
|
||||
|
||||
$content = self::html_only_entity_decode ($item->get_content ());
|
||||
$content = html_only_entity_decode ($item->get_content ());
|
||||
|
||||
$elinks = array();
|
||||
foreach ($item->get_enclosures() as $enclosure) {
|
||||
@@ -301,7 +301,7 @@ class Feed extends Model {
|
||||
$this->id (),
|
||||
$item->get_id (),
|
||||
!is_null ($title) ? $title : '',
|
||||
!is_null ($author) ? self::html_only_entity_decode ($author->name) : '',
|
||||
!is_null ($author) ? html_only_entity_decode ($author->name) : '',
|
||||
!is_null ($content) ? $content : '',
|
||||
!is_null ($link) ? $link : '',
|
||||
$date ? $date : time ()
|
||||
@@ -333,7 +333,7 @@ class FeedDAO extends Model_pdo {
|
||||
);
|
||||
|
||||
if ($stm && $stm->execute ($values)) {
|
||||
return $stm->rowCount();
|
||||
return $this->bd->lastInsertId();
|
||||
} else {
|
||||
$info = $stm->errorInfo();
|
||||
Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
|
||||
|
||||
@@ -44,7 +44,7 @@ function opml_export ($cats) {
|
||||
$txt .= '<outline text="' . $cat['name'] . '">' . "\n";
|
||||
|
||||
foreach ($cat['feeds'] as $feed) {
|
||||
$txt .= "\t" . '<outline text="' . cleanText ($feed->name ()) . '" type="rss" xmlUrl="' . htmlentities ($feed->url (), ENT_COMPAT, 'UTF-8') . '" htmlUrl="' . htmlentities ($feed->website (), ENT_COMPAT, 'UTF-8') . '" />' . "\n";
|
||||
$txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" />' . "\n";
|
||||
}
|
||||
|
||||
$txt .= '</outline>' . "\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);
|
||||
|
||||
Reference in New Issue
Block a user