diff options
Diffstat (limited to 'classes/opml.php')
-rw-r--r-- | classes/opml.php | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/classes/opml.php b/classes/opml.php index fe43a096c..720798065 100644 --- a/classes/opml.php +++ b/classes/opml.php @@ -9,10 +9,10 @@ class Opml extends Handler_Protected { function export() { $output_name = "tt-rss_".date("Y-m-d").".opml"; - $show_settings = $_REQUEST["include_settings"]; + $include_settings = $_REQUEST["include_settings"] == "1"; $owner_uid = $_SESSION["uid"]; - $rc = $this->opml_export($output_name, $owner_uid, false, ($show_settings == 1)); + $rc = $this->opml_export($output_name, $owner_uid, false, $include_settings); return $rc; } @@ -48,7 +48,7 @@ class Opml extends Handler_Protected { // Export - private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds=false) { + private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds = false, $include_settings = true) { $cat_id = (int) $cat_id; @@ -59,15 +59,25 @@ class Opml extends Handler_Protected { $out = ""; + $ttrss_specific_qpart = ""; + if ($cat_id) { - $sth = $this->pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE id = ? - AND owner_uid = ?"); + $sth = $this->pdo->prepare("SELECT title,order_id + FROM ttrss_feed_categories WHERE id = ? + AND owner_uid = ?"); $sth->execute([$cat_id, $owner_uid]); $row = $sth->fetch(); $cat_title = htmlspecialchars($row['title']); + + if ($include_settings) { + $order_id = (int)$row["order_id"]; + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; + } + } else { + $cat_title = ""; } - if ($cat_title) $out .= "<outline text=\"$cat_title\">\n"; + if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; $sth = $this->pdo->prepare("SELECT id,title FROM ttrss_feed_categories WHERE @@ -77,10 +87,10 @@ class Opml extends Handler_Protected { $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); while ($line = $sth->fetch()) { - $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds); + $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings); } - $fsth = $this->pdo->prepare("select title, feed_url, site_url + $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id FROM ttrss_feeds WHERE (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart ORDER BY order_id, title"); @@ -92,13 +102,22 @@ class Opml extends Handler_Protected { $url = htmlspecialchars($fline["feed_url"]); $site_url = htmlspecialchars($fline["site_url"]); + if ($include_settings) { + $update_interval = (int)$fline["update_interval"]; + $order_id = (int)$fline["order_id"]; + + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; + } else { + $ttrss_specific_qpart = ""; + } + if ($site_url) { $html_url_qpart = "htmlUrl=\"$site_url\""; } else { $html_url_qpart = ""; } - $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n"; + $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; } if ($cat_title) $out .= "</outline>\n"; @@ -106,7 +125,7 @@ class Opml extends Handler_Protected { return $out; } - function opml_export($name, $owner_uid, $hide_private_feeds=false, $include_settings=true) { + function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { if (!$owner_uid) return; if (!isset($_REQUEST["debug"])) { @@ -125,7 +144,7 @@ class Opml extends Handler_Protected { </head>"; $out .= "<body>"; - $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds); + $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings); # export tt-rss settings @@ -176,7 +195,7 @@ class Opml extends Handler_Protected { WHERE filter_id = ?"); $tmph->execute([$line['id']]); - while ($tmp_line = $tmph->fetch()) { + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { unset($tmp_line["id"]); unset($tmp_line["filter_id"]); @@ -224,7 +243,7 @@ class Opml extends Handler_Protected { WHERE filter_id = ?"); $tmph->execute([$line['id']]); - while ($tmp_line = $tmph->fetch()) { + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { unset($tmp_line["id"]); unset($tmp_line["filter_id"]); @@ -298,11 +317,17 @@ class Opml extends Handler_Protected { if (!$cat_id) $cat_id = null; + $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; + if (!$update_interval) $update_interval = 0; + + $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; + if (!$order_id) $order_id = 0; + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds - (title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES - (?, ?, ?, ?, ?, 0)"); + (title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES + (?, ?, ?, ?, ?, ?, ?)"); - $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url]); + $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]); } else { $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); @@ -370,7 +395,7 @@ class Opml extends Handler_Protected { $filter_id = $row['id']; if ($filter_id) { - $this->opml_notice(T_sprintf("Adding filter...")); + $this->opml_notice(T_sprintf("Adding filter %s...", $title)); foreach ($filter["rules"] as $rule) { $feed_id = null; @@ -387,8 +412,6 @@ class Opml extends Handler_Protected { array_push($match_on, ($is_cat ? "CAT:" : "") . $name); } else { - $match_id = false; - if (!$is_cat) { $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE title = ? AND owner_uid = ?"); @@ -397,6 +420,8 @@ class Opml extends Handler_Protected { if ($row = $tsth->fetch()) { $match_id = $row['id']; + + array_push($match_on, $match_id); } } else { $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories @@ -405,10 +430,10 @@ class Opml extends Handler_Protected { if ($row = $tsth->fetch()) { $match_id = $row['id']; + + array_push($match_on, "CAT:$match_id"); } } - - if ($match_id) array_push($match_on, $match_id); } } @@ -487,7 +512,10 @@ class Opml extends Handler_Protected { $cat_id = $this->get_feed_category($cat_title, $parent_id); if ($cat_id === false) { - add_feed_category($cat_title, $parent_id); + $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; + if (!$order_id) $order_id = 0; + + add_feed_category($cat_title, $parent_id, $order_id); $cat_id = $this->get_feed_category($cat_title, $parent_id); } |