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