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