]> git.wh0rd.org Git - tt-rss.git/commitdiff
support import and export of tt-rss preferences in OPML with DOMDocument OPML path
authorAndrew Dolgov <fox@bah.org.ru>
Tue, 29 Jun 2010 10:26:10 +0000 (14:26 +0400)
committerAndrew Dolgov <fox@bah.org.ru>
Tue, 29 Jun 2010 10:26:10 +0000 (14:26 +0400)
functions.php
modules/opml_domdoc.php
opml.php

index 7320f0fac6f4c5f61b8832c6cb794d0c00a528e4..4bf9cee4c601bdabc6a5844121fb33d7dec1ef90 100644 (file)
                                        $rss_1_date = $item['dc']['date'];
                                        $atom_date = $item['issued'];
                                        if (!$atom_date) $atom_date = $item['updated'];
-                       
+
                                        if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
                                        if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
                                        if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
+
                                }
 
                                if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
index 51b77133743a424ebca94f847bcb846945b0a701..72eeeb1d6c5ba15df53e307e33f6ac49b5a0aa60 100644 (file)
@@ -1,6 +1,8 @@
 <?php
        function opml_import_domdoc($link, $owner_uid) {
 
+               $_FILES['opml_file']['tmp_name'] = '/home/fox/opml.php';
+
                if (is_file($_FILES['opml_file']['tmp_name'])) {
                        $doc = DOMDocument::load($_FILES['opml_file']['tmp_name']);
 
                                        $feed_url = db_escape_string($outline->attributes->getNamedItem('xmlUrl')->nodeValue);
                                        $site_url = db_escape_string($outline->attributes->getNamedItem('htmlUrl')->nodeValue);
 
+                                       $pref_name = db_escape_string($outline->attributes->getNamedItem('pref-name')->nodeValue);
+
                                        if ($cat_title && !$feed_url) {
 
-                                               db_query($link, "BEGIN");
+                                               if ($cat_title != "tt-rss-prefs") {
+
+                                                       db_query($link, "BEGIN");
+       
+                                                       $result = db_query($link, "SELECT id FROM
+                                                                       ttrss_feed_categories WHERE title = '$cat_title' AND
+                                                                       owner_uid = '$owner_uid' LIMIT 1");
+       
+                                                       if (db_num_rows($result) == 0) {
+       
+                                                               printf(__("<li>Adding category <b>%s</b>.</li>"), $cat_title);
+       
+                                                               db_query($link, "INSERT INTO ttrss_feed_categories
+                                                                               (title,owner_uid) 
+                                                                               VALUES ('$cat_title', '$owner_uid')");
+                                                       }
+       
+                                                       db_query($link, "COMMIT");
+                                               }
+                                       }
 
-                                               $result = db_query($link, "SELECT id FROM
-                                                               ttrss_feed_categories WHERE title = '$cat_title' AND
-                                                               owner_uid = '$owner_uid' LIMIT 1");
+                                       //                                              print "$active_category : $feed_title : $feed_url<br>";
 
-                                               if (db_num_rows($result) == 0) {
+                                       if ($pref_name) {
+                                               $parent_node = $outline->parentNode;
 
-                                                       printf(__("<li>Adding category <b>%s</b>.</li>"), $cat_title);
+                                               if ($parent_node && $parent_node->nodeName == "outline") {
+                                                       $cat_check = $parent_node->attributes->getNamedItem('title')->nodeValue;
+                                                       if ($cat_check == "tt-rss-prefs") {
+                                                               $pref_value = db_escape_string($outline->attributes->getNamedItem('value')->nodeValue);
 
-                                                       db_query($link, "INSERT INTO ttrss_feed_categories
-                                                                       (title,owner_uid) 
-                                                                       VALUES ('$cat_title', '$owner_uid')");
-                                               }
+                                                               printf("<li>".
+                                                                       __("Setting preference key %s to %s")."</li>", 
+                                                                               $pref_name, $pref_value);
 
-                                               db_query($link, "COMMIT");
-                                       }
+                                                               set_pref($link, $pref_name, $pref_value);       
 
-                                       //                                              print "$active_category : $feed_title : $feed_url<br>";
+                                                       }
+                                               }
+                                       }
 
                                        if (!$feed_title || !$feed_url) continue;
 
index d808c8f9e3a45d109710eac626e9bb7431a74e0f..d3a352fa2dbbd62a52c73dfdc374c5a6b61af02b 100644 (file)
--- a/opml.php
+++ b/opml.php
        init_connection($link);
 
        function opml_export($link, $owner_uid, $hide_private_feeds=False) {
-               header("Content-type: application/xml+opml");
+               if (!$_REQUEST["debug"]) {
+                       header("Content-type: application/xml+opml");
+               } else {
+                       header("Content-type: text/xml");
+               }
                print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
 
                print "<opml version=\"1.0\">";
                        print "</outline>\n";   
                }
 
+               # export tt-rss settings
+
+               print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">";
+
+               $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
+                  profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $name = $line["pref_name"];
+                       $value = htmlspecialchars($line["value"]);
+               
+                       print "<outline pref-name=\"$name\" value=\"$value\">";
+
+                       print "</outline>";
+
+               }               
+
+               print "</outline>";
+
                print "</body></opml>";
        }
 
                login_sequence($link);
                $owner_uid = $_SESSION["uid"];
 
+               header('Content-Type: text/html; charset=utf-8');
+
                print "<html>
                        <head>
                                <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
                                <title>".__("OPML Utility")."</title>
+                               <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
                        </head>
                        <body>
                        <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>