summaryrefslogtreecommitdiff
path: root/opml.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-08-15 12:52:45 +0400
committerAndrew Dolgov <[email protected]>2012-08-15 12:52:45 +0400
commit3a9d5c6e88420336f698ab5239072fc50ae0c1fc (patch)
treea17acf336a08814383f0118f4e1d20906d3a8093 /opml.php
parent9772759980e41da98c2243ce5fa266bae8ddc8f8 (diff)
opml: support proper export of nested categories
Diffstat (limited to 'opml.php')
-rw-r--r--opml.php110
1 files changed, 57 insertions, 53 deletions
diff --git a/opml.php b/opml.php
index d0f60300d..8ddc9dcaf 100644
--- a/opml.php
+++ b/opml.php
@@ -287,53 +287,32 @@
}
- function opml_export($link, $name, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
- if (!$_REQUEST["debug"]) {
- header("Content-type: application/xml+opml");
- header("Content-Disposition: attachment; filename=" . $name );
- } else {
- header("Content-type: text/xml");
- }
-
- $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">";
-
- $out .= "<opml version=\"1.0\">";
- $out .= "<head>
- <dateCreated>" . date("r", time()) . "</dateCreated>
- <title>Tiny Tiny RSS Feed Export</title>
- </head>";
- $out .= "<body>";
-
- $cat_mode = false;
-
- $select = "SELECT * ";
- $where = "WHERE owner_uid = '$owner_uid'";
- $orderby = "ORDER BY order_id, title";
- if ($hide_private_feeds){
- $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
- auth_login = '' AND auth_pass = ''";
- }
+ function opml_export_category($link, $owner_uid, $cat_id, $hide_private_feeds=false) {
+ if ($cat_id)
+ $cat_qpart = "parent_cat = '$cat_id'";
+ else
+ $cat_qpart = "parent_cat IS NULL";
+ if ($hide_private_feeds)
+ $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')";
+ else
+ $hide_qpart = "true";
- if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
- $cat_mode = true;
- $select = "SELECT
- title, feed_url, site_url, order_id,
- (SELECT order_id FROM ttrss_feed_categories WHERE id = cat_id) AS cat_order_id,
- (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
- $orderby = "ORDER BY cat_order_id, cat_title, order_id, title";
+ $out = "";
- }
- else{
- $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
- $out .= "<!-- feeding cats is not enabled -->";
- $out .= "<!-- $cat_feed -->";
-
- }
+ $query = "SELECT
+ ttrss_feeds.title, feed_url, site_url, ttrss_feeds.order_id,
+ ttrss_feed_categories.id AS cat_id,
+ ttrss_feed_categories.title AS cat_title,
+ ttrss_feed_categories.order_id AS cat_order_id
+ FROM ttrss_feeds LEFT JOIN ttrss_feed_categories ON (ttrss_feed_categories.id = ttrss_feeds.cat_id)
+ WHERE ttrss_feeds.owner_uid = '$owner_uid' AND $hide_qpart AND $cat_qpart
+ ORDER BY cat_order_id, cat_title, ttrss_feeds.order_id, title";
+ #$out .= "<!-- $query -->";
- $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
+ $result = db_query($link, $query);
$old_cat_title = "";
@@ -342,20 +321,22 @@
$url = htmlspecialchars($line["feed_url"]);
$site_url = htmlspecialchars($line["site_url"]);
- if ($cat_mode) {
- $cat_title = htmlspecialchars($line["cat_title"]);
+ $cat_title = htmlspecialchars($line["cat_title"]);
- if ($old_cat_title != $cat_title) {
- if ($old_cat_title) {
- $out .= "</outline>\n";
- }
-
- if ($cat_title) {
- $out .= "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
- }
+ if ($old_cat_title != $cat_title) {
+ if ($old_cat_title) {
+ $out .= "</outline>\n";
+ }
- $old_cat_title = $cat_title;
+ if ($cat_title) {
+ $out .= "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
}
+ $old_cat_title = $cat_title;
+
+ $cat_id = (int) $line["cat_id"];
+
+ if ($cat_id > 0)
+ $out .= opml_export_category($link, $owner_uid, $cat_id, $hide_private_feeds);
}
if ($site_url) {
@@ -365,12 +346,35 @@
}
$out .= "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
+
}
- if ($cat_mode && $old_cat_title) {
+ if ($old_cat_title) {
$out .= "</outline>\n";
}
+ return $out;
+ }
+
+ function opml_export($link, $name, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
+ if (!isset($_REQUEST["debug"])) {
+ header("Content-type: application/xml+opml");
+ header("Content-Disposition: attachment; filename=" . $name );
+ } else {
+ header("Content-type: text/xml");
+ }
+
+ $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">";
+
+ $out .= "<opml version=\"1.0\">";
+ $out .= "<head>
+ <dateCreated>" . date("r", time()) . "</dateCreated>
+ <title>Tiny Tiny RSS Feed Export</title>
+ </head>";
+ $out .= "<body>";
+
+ $out .= opml_export_category($link, $owner_uid, false, $hide_private_feeds);
+
# export tt-rss settings
if ($include_settings) {