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