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