From: Andrew Dolgov Date: Wed, 15 Aug 2012 08:52:45 +0000 (+0400) Subject: opml: support proper export of nested categories X-Git-Tag: 1.6.0~152 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=3a9d5c6e88420336f698ab5239072fc50ae0c1fc;p=tt-rss.git opml: support proper export of nested categories --- diff --git a/opml.php b/opml.php index d0f60300..8ddc9dca 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 = ""; - - $out .= ""; - $out .= " - " . date("r", time()) . " - Tiny Tiny RSS Feed Export - "; - $out .= ""; - - $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 .= ""; - $out .= ""; - - } + $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 .= ""; - $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 .= "\n"; - } - - if ($cat_title) { - $out .= "\n"; - } + if ($old_cat_title != $cat_title) { + if ($old_cat_title) { + $out .= "\n"; + } - $old_cat_title = $cat_title; + if ($cat_title) { + $out .= "\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 .= "\n"; + } - if ($cat_mode && $old_cat_title) { + if ($old_cat_title) { $out .= "\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 = ""; + + $out .= ""; + $out .= " + " . date("r", time()) . " + Tiny Tiny RSS Feed Export + "; + $out .= ""; + + $out .= opml_export_category($link, $owner_uid, false, $hide_private_feeds); + # export tt-rss settings if ($include_settings) {