]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement import/export of labels using OPML
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 27 Dec 2011 12:41:49 +0000 (16:41 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 27 Dec 2011 12:43:14 +0000 (16:43 +0400)
classes/pref_feeds.php
include/functions.php
opml.php

index 5937bfc8adb1a11afd0e240298c5c975a2f39949..d2af977826069a2471224b181e50347bf3766d33 100644 (file)
@@ -1400,7 +1400,7 @@ class Pref_Feeds extends Protected_Handler {
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
 
-               print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.") . " ";
+               print "<p>" . __("Using OPML you can export and import your feeds, labels and Tiny Tiny RSS settings.") . " ";
 
                print "<span class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</span>";
 
index 17595028990b0f54231e722a28ea029faa18bd91..80581433aa6ee2c1e40c6bc2d4e64941686c7107 100644 (file)
                db_query($link, "COMMIT");
        }
 
-       function label_create($link, $caption) {
+       function label_create($link, $caption, $fg_color = '', $bg_color = '') {
 
                db_query($link, "BEGIN");
 
 
                if (db_num_rows($result) == 0) {
                        $result = db_query($link,
-                               "INSERT INTO ttrss_labels2 (caption,owner_uid)
-                                       VALUES ('$caption', '".$_SESSION["uid"]."')");
+                               "INSERT INTO ttrss_labels2 (caption,owner_uid,fg_color,bg_color)
+                                       VALUES ('$caption', '".$_SESSION["uid"]."', '$fg_color', '$bg_color')");
 
                        $result = db_affected_rows($link, $result) != 0;
                }
index feccfaa3576652adefce4290455a4c8526de504c..6e5a499664223b72d40fa9d4b6bf59615bf8a905 100644 (file)
--- a/opml.php
+++ b/opml.php
@@ -1,5 +1,5 @@
 <?php
-       set_include_path(get_include_path() . PATH_SEPARATOR . 
+       set_include_path(get_include_path() . PATH_SEPARATOR .
                dirname(__FILE__) . "/include");
 
        require_once "functions.php";
 
                                foreach ($outlines as $outline) {
 
-                                       $feed_title = db_escape_string($outline->attributes->getNamedItem('text')->nodeValue);
+                                       $attributes = $outline->attributes;
 
-                                       if (!$feed_title) {
-                                               $feed_title = db_escape_string($outline->attributes->getNamedItem('title')->nodeValue);
-                                       }
-
-                                       $cat_title = db_escape_string($outline->attributes->getNamedItem('title')->nodeValue);
+                                       $feed_title = db_escape_string($attributes->getNamedItem('text')->nodeValue);
+                                       if (!$feed_title) $feed_title = db_escape_string($attributes->getNamedItem('title')->nodeValue);
 
-                                       if (!$cat_title) {
-                                               $cat_title = db_escape_string($outline->attributes->getNamedItem('text')->nodeValue);
-                                       }
+                                       $cat_title = db_escape_string($attributes->getNamedItem('title')->nodeValue);
+                                       if (!$cat_title) $cat_title = db_escape_string($attributes->getNamedItem('text')->nodeValue);
 
-                                       $feed_url = db_escape_string($outline->attributes->getNamedItem('xmlUrl')->nodeValue);
+                                       $feed_url = db_escape_string($attributes->getNamedItem('xmlUrl')->nodeValue);
+                                       if (!$feed_url) $feed_url = db_escape_string($attributes->getNamedItem('xmlURL')->nodeValue);
 
-                                       if (!$feed_url)
-                                               $feed_url = db_escape_string($outline->attributes->getNamedItem('xmlURL')->nodeValue);
+                                       $site_url = db_escape_string($attributes->getNamedItem('htmlUrl')->nodeValue);
 
-                                       $site_url = db_escape_string($outline->attributes->getNamedItem('htmlUrl')->nodeValue);
-
-                                       $pref_name = db_escape_string($outline->attributes->getNamedItem('pref-name')->nodeValue);
+                                       $pref_name = db_escape_string($attributes->getNamedItem('pref-name')->nodeValue);
+                                       $label_name = db_escape_string($attributes->getNamedItem('label-name')->nodeValue);
 
                                        if ($cat_title && !$feed_url) {
 
-                                               if ($cat_title != "tt-rss-prefs") {
+                                               if ($cat_title != "tt-rss-prefs" && $cat_title != 'tt-rss-labels') {
 
                                                        db_query($link, "BEGIN");
 
                                                }
                                        }
 
+                                       if ($label_name) {
+                                               $fg_color = db_escape_string($attributes->getNamedItem('label-fg-color')->nodeValue);
+                                               $bg_color = db_escape_string($attributes->getNamedItem('label-bg-color')->nodeValue);
+
+                                               if (!label_find_id($link, $label_name, $_SESSION['uid'])) {
+
+                                                       printf("<li>".__("Adding label %s")."</li>", $label_name);
+
+                                                       label_create($link, $label_name, $fg_color, $bg_color);
+                                               }
+                                       }
+
                                        if (!$feed_title || !$feed_url) continue;
 
                                        db_query($link, "BEGIN");
        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");
                }
-        header("Content-Disposition: attachment; filename=" . $name );
 
                print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
 
                        }
 
                        print "</outline>";
+
+                       print "<outline title=\"tt-rss-labels\">";
+
+                       $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
+                               owner_uid = " . $_SESSION['uid']);
+
+                       while ($line = db_fetch_assoc($result)) {
+                               $name = htmlspecialchars($line['caption']);
+                               $fg_color = htmlspecialchars($line['fg_color']);
+                               $bg_color = htmlspecialchars($line['bg_color']);
+
+                               print "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>";
+
+                       }
+
+                       print "</outline>";
                }
 
                print "</body></opml>";