]> git.wh0rd.org - tt-rss.git/blame - opml.php
add Public_Handler
[tt-rss.git] / opml.php
CommitLineData
1d3a17c7 1<?php
107d0cf3
AD
2 set_include_path(get_include_path() . PATH_SEPARATOR . "include");
3
fb074239 4 require_once "functions.php";
1559e374 5 require_once "sessions.php";
66581886 6 require_once "sanity_check.php";
9a4506c8 7 require_once "config.php";
8158c57a 8 require_once "db.php";
a0111294 9 require_once "db-prefs.php";
9a4506c8 10
0a13e84e 11 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
9f311df6 12
5f0a3741 13 if (!init_connection($link)) return;
4e9f5c24 14
08ae2a5b 15 function opml_export($link, $name, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
e9558345
AD
16 if (!$_REQUEST["debug"]) {
17 header("Content-type: application/xml+opml");
18 } else {
19 header("Content-type: text/xml");
20 }
08ae2a5b
CM
21 header("Content-Disposition: attachment; filename=" . $name );
22
981e8107 23 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
4e9f5c24 24
9a4506c8 25 print "<opml version=\"1.0\">";
a90005e6
AD
26 print "<head>
27 <dateCreated>" . date("r", time()) . "</dateCreated>
28 <title>Tiny Tiny RSS Feed Export</title>
0a13e84e 29 </head>";
9a4506c8
AD
30 print "<body>";
31
da49ccf5 32 $cat_mode = false;
0a13e84e 33
86e26f1a
MK
34 $select = "SELECT * ";
35 $where = "WHERE owner_uid = '$owner_uid'";
36 $orderby = "ORDER BY title";
37 if ($hide_private_feeds){
0a13e84e 38 $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
c107797c 39 auth_login = '' AND auth_pass = ''";
86e26f1a 40 }
da49ccf5 41
fee909d5
MK
42
43
44 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
da49ccf5 45 $cat_mode = true;
0a13e84e 46 $select = "SELECT
86e26f1a
MK
47 title, feed_url, site_url,
48 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
49 $orderby = "ORDER BY cat_title, title";
50
da49ccf5 51 }
fee909d5
MK
52 else{
53 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
54 print "<!-- feeding cats is not enabled -->";
55 print "<!-- $cat_feed -->";
56
57 }
58
da49ccf5 59
86e26f1a
MK
60 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
61
da49ccf5 62 $old_cat_title = "";
9a4506c8 63
8158c57a 64 while ($line = db_fetch_assoc($result)) {
6e0584e9
AD
65 $title = htmlspecialchars($line["title"]);
66 $url = htmlspecialchars($line["feed_url"]);
fa7b8749 67 $site_url = htmlspecialchars($line["site_url"]);
9a4506c8 68
da49ccf5
AD
69 if ($cat_mode) {
70 $cat_title = htmlspecialchars($line["cat_title"]);
71
72 if ($old_cat_title != $cat_title) {
73 if ($old_cat_title) {
0a13e84e 74 print "</outline>\n";
da49ccf5
AD
75 }
76
5b9af2b9 77 if ($cat_title) {
fee909d5 78 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
5b9af2b9 79 }
da49ccf5
AD
80
81 $old_cat_title = $cat_title;
82 }
83 }
84
fa7b8749
AD
85 if ($site_url) {
86 $html_url_qpart = "htmlUrl=\"$site_url\"";
87 } else {
88 $html_url_qpart = "";
89 }
90
91 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
9a4506c8
AD
92 }
93
da49ccf5 94 if ($cat_mode && $old_cat_title) {
0a13e84e 95 print "</outline>\n";
da49ccf5
AD
96 }
97
e9558345
AD
98 # export tt-rss settings
99
442f326b
AD
100 if ($include_settings) {
101 print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">";
e9558345 102
442f326b
AD
103 $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
104 profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
e9558345 105
442f326b 106 while ($line = db_fetch_assoc($result)) {
e9558345 107
442f326b
AD
108 $name = $line["pref_name"];
109 $value = htmlspecialchars($line["value"]);
0a13e84e 110
442f326b 111 print "<outline pref-name=\"$name\" value=\"$value\">";
e9558345 112
442f326b 113 print "</outline>";
e9558345 114
0a13e84e 115 }
e9558345 116
442f326b
AD
117 print "</outline>";
118 }
e9558345 119
9a4506c8
AD
120 print "</body></opml>";
121 }
122
30f782a2
AD
123 // FIXME there are some brackets issues here
124
125 $op = $_REQUEST["op"];
08ae2a5b
CM
126 if (!$op) $op = "Export";
127
128 $output_name = $_REQUEST["filename"];
129 if (!$output_name) $output_name = "TinyTinyRSS.opml";
0a13e84e 130
08ae2a5b 131 $show_settings = $_REQUEST["settings"];
0a13e84e 132
30f782a2 133 if ($op == "Export") {
0a13e84e 134
a4234239
MK
135 login_sequence($link);
136 $owner_uid = $_SESSION["uid"];
08ae2a5b 137 return opml_export($link, $output_name, $owner_uid, false, ($show_settings == 1));
30f782a2 138 }
0a13e84e 139
442f326b 140 if ($op == "publish"){
86e26f1a
MK
141 $key = db_escape_string($_REQUEST["key"]);
142
2e7f046f
AD
143 $result = db_query($link, "SELECT owner_uid
144 FROM ttrss_access_keys WHERE
145 access_key = '$key' AND feed_id = 'OPML:Publish'");
86e26f1a
MK
146
147 if (db_num_rows($result) == 1) {
2e7f046f 148 $owner_uid = db_fetch_result($result, 0, "owner_uid");
08ae2a5b 149 return opml_export($link, "", $owner_uid, true, false);
86e26f1a
MK
150 } else {
151 print "<error>User not found</error>";
152 }
153 }
30f782a2 154
e98a3f65 155 if ($op == "Import") {
8158c57a 156
a4234239
MK
157 login_sequence($link);
158 $owner_uid = $_SESSION["uid"];
159
e9558345
AD
160 header('Content-Type: text/html; charset=utf-8');
161
e98a3f65
AD
162 print "<html>
163 <head>
ef59e6e8 164 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
1025ad87 165 <title>".__("OPML Utility")."</title>
e9558345 166 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
e98a3f65 167 </head>
04f6df27 168 <body>
0ae2bb2a 169 <div class=\"floatingLogo\"><img src=\"images/logo_wide.png\"></div>
d1db26aa 170 <h1>".__('OPML Utility')."</h1>";
9f311df6 171
c03cf250
AD
172 db_query($link, "BEGIN");
173
174 /* create Imported feeds category just in case */
175
176 $result = db_query($link, "SELECT id FROM
177 ttrss_feed_categories WHERE title = 'Imported feeds' AND
178 owner_uid = '$owner_uid' LIMIT 1");
179
180 if (db_num_rows($result) == 0) {
181 db_query($link, "INSERT INTO ttrss_feed_categories
0a13e84e 182 (title,owner_uid)
c03cf250
AD
183 VALUES ('Imported feeds', '$owner_uid')");
184 }
185
186 db_query($link, "COMMIT");
187
0a13e84e
AD
188 print "<p>".__("Importing OPML...")."</p>";
189 require_once "modules/opml_domdoc.php";
190 opml_import_domdoc($link, $owner_uid);
9f311df6 191
d7c848d9 192 print "<br><form method=\"GET\" action=\"prefs.php\">
1025ad87 193 <input type=\"submit\" value=\"".__("Return to preferences")."\">
d7c848d9 194 </form>";
9f311df6 195
30f782a2 196 print "</body></html>";
9f311df6
AD
197
198 }
199
3d477c2c 200// if ($link) db_close($link);
9f311df6 201
9a4506c8 202?>