OPML: include (and import) ttrss per-feed update interval and sort order
This commit is contained in:
parent
527e7adc8a
commit
32db1cb872
|
@ -9,10 +9,10 @@ class Opml extends Handler_Protected {
|
||||||
|
|
||||||
function export() {
|
function export() {
|
||||||
$output_name = "tt-rss_".date("Y-m-d").".opml";
|
$output_name = "tt-rss_".date("Y-m-d").".opml";
|
||||||
$show_settings = $_REQUEST["include_settings"];
|
$include_settings = $_REQUEST["include_settings"] == "1";
|
||||||
$owner_uid = $_SESSION["uid"];
|
$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;
|
return $rc;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class Opml extends Handler_Protected {
|
||||||
|
|
||||||
// Export
|
// 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;
|
$cat_id = (int) $cat_id;
|
||||||
|
|
||||||
|
@ -59,15 +59,25 @@ class Opml extends Handler_Protected {
|
||||||
|
|
||||||
$out = "";
|
$out = "";
|
||||||
|
|
||||||
|
$ttrss_specific_qpart = "";
|
||||||
|
|
||||||
if ($cat_id) {
|
if ($cat_id) {
|
||||||
$sth = $this->pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE id = ?
|
$sth = $this->pdo->prepare("SELECT title,order_id
|
||||||
|
FROM ttrss_feed_categories WHERE id = ?
|
||||||
AND owner_uid = ?");
|
AND owner_uid = ?");
|
||||||
$sth->execute([$cat_id, $owner_uid]);
|
$sth->execute([$cat_id, $owner_uid]);
|
||||||
$row = $sth->fetch();
|
$row = $sth->fetch();
|
||||||
$cat_title = htmlspecialchars($row['title']);
|
$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
|
$sth = $this->pdo->prepare("SELECT id,title
|
||||||
FROM ttrss_feed_categories WHERE
|
FROM ttrss_feed_categories WHERE
|
||||||
|
@ -77,10 +87,10 @@ class Opml extends Handler_Protected {
|
||||||
$sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]);
|
$sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]);
|
||||||
|
|
||||||
while ($line = $sth->fetch()) {
|
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
|
FROM ttrss_feeds WHERE
|
||||||
(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart
|
(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart
|
||||||
ORDER BY order_id, title");
|
ORDER BY order_id, title");
|
||||||
|
@ -92,13 +102,22 @@ class Opml extends Handler_Protected {
|
||||||
$url = htmlspecialchars($fline["feed_url"]);
|
$url = htmlspecialchars($fline["feed_url"]);
|
||||||
$site_url = htmlspecialchars($fline["site_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) {
|
if ($site_url) {
|
||||||
$html_url_qpart = "htmlUrl=\"$site_url\"";
|
$html_url_qpart = "htmlUrl=\"$site_url\"";
|
||||||
} else {
|
} else {
|
||||||
$html_url_qpart = "";
|
$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";
|
if ($cat_title) $out .= "</outline>\n";
|
||||||
|
@ -125,7 +144,7 @@ class Opml extends Handler_Protected {
|
||||||
</head>";
|
</head>";
|
||||||
$out .= "<body>";
|
$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
|
# export tt-rss settings
|
||||||
|
|
||||||
|
@ -298,11 +317,17 @@ class Opml extends Handler_Protected {
|
||||||
|
|
||||||
if (!$cat_id) $cat_id = null;
|
if (!$cat_id) $cat_id = null;
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
|
$update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue;
|
||||||
(title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES
|
if (!$update_interval) $update_interval = 0;
|
||||||
(?, ?, ?, ?, ?, 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 {
|
} else {
|
||||||
$this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title));
|
$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);
|
$cat_id = $this->get_feed_category($cat_title, $parent_id);
|
||||||
|
|
||||||
if ($cat_id === false) {
|
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);
|
$cat_id = $this->get_feed_category($cat_title, $parent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1981,7 +1981,7 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_feed_category($feed_cat, $parent_cat_id = false) {
|
function add_feed_category($feed_cat, $parent_cat_id = false, $order_id = 0) {
|
||||||
|
|
||||||
if (!$feed_cat) return false;
|
if (!$feed_cat) return false;
|
||||||
|
|
||||||
|
@ -2004,9 +2004,9 @@
|
||||||
|
|
||||||
if (!$sth->fetch()) {
|
if (!$sth->fetch()) {
|
||||||
|
|
||||||
$sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat)
|
$sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat,order_id)
|
||||||
VALUES (?, ?, ?)");
|
VALUES (?, ?, ?, ?)");
|
||||||
$sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id]);
|
$sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int)$order_id]);
|
||||||
|
|
||||||
if (!$tr_in_progress) $pdo->commit();
|
if (!$tr_in_progress) $pdo->commit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue