]> git.wh0rd.org Git - tt-rss.git/commitdiff
opml: support proper export of nested categories
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 15 Aug 2012 08:52:45 +0000 (12:52 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 15 Aug 2012 08:52:45 +0000 (12:52 +0400)
opml.php

index d0f60300d9623fb7030792381ed3032eb1db9b43..8ddc9dcaff8cfb3705d91c4c1e618e4e73d5ee7d 100644 (file)
--- a/opml.php
+++ b/opml.php
 
        }
 
-       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 = "";
 
                        $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) {
                        }
 
                        $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) {