mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 07:25:54 +00:00
OPML: include (and import) ttrss per-feed update interval and sort order
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -298,11 +317,17 @@ class Opml extends Handler_Protected {
|
||||
|
||||
if (!$cat_id) $cat_id = null;
|
||||
|
||||
$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
|
||||
(title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES
|
||||
(?, ?, ?, ?, ?, 0)");
|
||||
$update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue;
|
||||
if (!$update_interval) $update_interval = 0;
|
||||
|
||||
$sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url]);
|
||||
$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, update_interval) VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
$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));
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user