]> git.wh0rd.org - tt-rss.git/blob - opml.php
opml/db updater tweaks
[tt-rss.git] / opml.php
1 <?php
2 require_once "sessions.php";
3 require_once "sanity_check.php";
4 require_once "functions.php";
5 require_once "config.php";
6 require_once "db.php";
7 require_once "db-prefs.php";
8
9 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
10
11 if (DB_TYPE == "pgsql") {
12 pg_query($link, "set client_encoding = 'utf-8'");
13 pg_set_client_encoding("UNICODE");
14 }
15
16 login_sequence($link);
17
18 $owner_uid = $_SESSION["uid"];
19
20 function opml_export($link) {
21 header("Content-type: application/xml+opml");
22 print "<?phpxml version=\"1.0\"?>";
23
24 print "<opml version=\"1.0\">";
25 print "<head>
26 <dateCreated>" . date("r", time()) . "</dateCreated>
27 <title>Tiny Tiny RSS Feed Export</title>
28 </head>";
29 print "<body>";
30
31 $cat_mode = false;
32
33 if (get_pref($link, 'ENABLE_FEED_CATS')) {
34 $cat_mode = true;
35 $result = db_query($link, "SELECT
36 title,feed_url,site_url,
37 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
38 FROM ttrss_feeds
39 WHERE
40 owner_uid = '$owner_uid'
41 ORDER BY cat_title,title");
42 } else {
43 $result = db_query($link, "SELECT * FROM ttrss_feeds
44 WHERE owner_uid = '$owner_uid' ORDER BY title");
45 }
46
47 $old_cat_title = "";
48
49 while ($line = db_fetch_assoc($result)) {
50 $title = htmlspecialchars($line["title"]);
51 $url = htmlspecialchars($line["feed_url"]);
52 $site_url = htmlspecialchars($line["site_url"]);
53
54 if ($cat_mode) {
55 $cat_title = htmlspecialchars($line["cat_title"]);
56
57 if ($old_cat_title != $cat_title) {
58 if ($old_cat_title) {
59 print "</outline>\n";
60 }
61
62 if ($cat_title) {
63 print "<outline title=\"$cat_title\">\n";
64 }
65
66 $old_cat_title = $cat_title;
67 }
68 }
69
70 if ($site_url) {
71 $html_url_qpart = "htmlUrl=\"$site_url\"";
72 } else {
73 $html_url_qpart = "";
74 }
75
76 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
77 }
78
79 if ($cat_mode && $old_cat_title) {
80 print "</outline>\n";
81 }
82
83 print "</body></opml>";
84 }
85
86 // FIXME there are some brackets issues here
87
88 $op = $_REQUEST["op"];
89
90 if (!$op) $op = "Export";
91
92 if ($op == "Export") {
93 return opml_export($link);
94 }
95
96 if ($op == "Import") {
97
98 print "<html>
99 <head>
100 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
101 <title>OPML Utility</title>
102 </head>
103 <body>
104 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
105 <h1>"._('OPML Utility')."</h1>";
106
107 if (function_exists('domxml_open_file')) {
108 print "<p>Importing OPML (using DOMXML extension)...</p>";
109 require_once "modules/opml_domxml.php";
110 opml_import_domxml($link, $owner_uid);
111 } else {
112 print "<p>Importing OPML (using DOMDocument extension)...</p>";
113 require_once "modules/opml_domdoc.php";
114 opml_import_domdoc($link, $owner_uid);
115 }
116
117 print "<br><form method=\"GET\" action=\"prefs.php\">
118 <input type=\"submit\" value=\"Return to preferences\">
119 </form>";
120
121 print "</body></html>";
122
123 }
124
125 // if ($link) db_close($link);
126
127 ?>