]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | require_once "functions.php"; | |
3 | require_once "sessions.php"; | |
4 | require_once "sanity_check.php"; | |
5 | require_once "config.php"; | |
6 | require_once "db.php"; | |
7 | require_once "db-prefs.php"; | |
8 | ||
9 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
10 | ||
11 | init_connection($link); | |
12 | ||
13 | function opml_export($link, $owner_uid, $hide_private_feeds=false, $include_settings=true) { | |
14 | if (!$_REQUEST["debug"]) { | |
15 | header("Content-type: application/xml+opml"); | |
16 | } else { | |
17 | header("Content-type: text/xml"); | |
18 | } | |
19 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | |
20 | ||
21 | print "<opml version=\"1.0\">"; | |
22 | print "<head> | |
23 | <dateCreated>" . date("r", time()) . "</dateCreated> | |
24 | <title>Tiny Tiny RSS Feed Export</title> | |
25 | </head>"; | |
26 | print "<body>"; | |
27 | ||
28 | $cat_mode = false; | |
29 | ||
30 | $select = "SELECT * "; | |
31 | $where = "WHERE owner_uid = '$owner_uid'"; | |
32 | $orderby = "ORDER BY title"; | |
33 | if ($hide_private_feeds){ | |
34 | $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND | |
35 | auth_login = '' AND auth_pass = ''"; | |
36 | } | |
37 | ||
38 | ||
39 | ||
40 | if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) { | |
41 | $cat_mode = true; | |
42 | $select = "SELECT | |
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 | ||
47 | } | |
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 | ||
55 | ||
56 | $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby); | |
57 | ||
58 | $old_cat_title = ""; | |
59 | ||
60 | while ($line = db_fetch_assoc($result)) { | |
61 | $title = htmlspecialchars($line["title"]); | |
62 | $url = htmlspecialchars($line["feed_url"]); | |
63 | $site_url = htmlspecialchars($line["site_url"]); | |
64 | ||
65 | if ($cat_mode) { | |
66 | $cat_title = htmlspecialchars($line["cat_title"]); | |
67 | ||
68 | if ($old_cat_title != $cat_title) { | |
69 | if ($old_cat_title) { | |
70 | print "</outline>\n"; | |
71 | } | |
72 | ||
73 | if ($cat_title) { | |
74 | print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n"; | |
75 | } | |
76 | ||
77 | $old_cat_title = $cat_title; | |
78 | } | |
79 | } | |
80 | ||
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"; | |
88 | } | |
89 | ||
90 | if ($cat_mode && $old_cat_title) { | |
91 | print "</outline>\n"; | |
92 | } | |
93 | ||
94 | # export tt-rss settings | |
95 | ||
96 | if ($include_settings) { | |
97 | print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; | |
98 | ||
99 | $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE | |
100 | profile IS NULL AND owner_uid = " . $_SESSION["uid"]); | |
101 | ||
102 | while ($line = db_fetch_assoc($result)) { | |
103 | ||
104 | $name = $line["pref_name"]; | |
105 | $value = htmlspecialchars($line["value"]); | |
106 | ||
107 | print "<outline pref-name=\"$name\" value=\"$value\">"; | |
108 | ||
109 | print "</outline>"; | |
110 | ||
111 | } | |
112 | ||
113 | print "</outline>"; | |
114 | } | |
115 | ||
116 | print "</body></opml>"; | |
117 | } | |
118 | ||
119 | // FIXME there are some brackets issues here | |
120 | ||
121 | $op = $_REQUEST["op"]; | |
122 | ||
123 | if (!$op) $op = "Export"; | |
124 | ||
125 | if ($op == "Export") { | |
126 | ||
127 | login_sequence($link); | |
128 | $owner_uid = $_SESSION["uid"]; | |
129 | return opml_export($link, $owner_uid); | |
130 | } | |
131 | ||
132 | if ($op == "publish"){ | |
133 | $key = db_escape_string($_REQUEST["key"]); | |
134 | ||
135 | $result = db_query($link, "SELECT owner_uid | |
136 | FROM ttrss_access_keys WHERE | |
137 | access_key = '$key' AND feed_id = 'OPML:Publish'"); | |
138 | ||
139 | if (db_num_rows($result) == 1) { | |
140 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
141 | return opml_export($link, $owner_uid, true, false); | |
142 | } else { | |
143 | print "<error>User not found</error>"; | |
144 | } | |
145 | } | |
146 | ||
147 | if ($op == "Import") { | |
148 | ||
149 | login_sequence($link); | |
150 | $owner_uid = $_SESSION["uid"]; | |
151 | ||
152 | header('Content-Type: text/html; charset=utf-8'); | |
153 | ||
154 | print "<html> | |
155 | <head> | |
156 | <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\"> | |
157 | <title>".__("OPML Utility")."</title> | |
158 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> | |
159 | </head> | |
160 | <body> | |
161 | <div class=\"floatingLogo\"><img src=\"images/logo_wide.png\"></div> | |
162 | <h1>".__('OPML Utility')."</h1>"; | |
163 | ||
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 | |
174 | (title,owner_uid) | |
175 | VALUES ('Imported feeds', '$owner_uid')"); | |
176 | } | |
177 | ||
178 | db_query($link, "COMMIT"); | |
179 | ||
180 | print "<p>".__("Importing OPML...")."</p>"; | |
181 | require_once "modules/opml_domdoc.php"; | |
182 | opml_import_domdoc($link, $owner_uid); | |
183 | ||
184 | print "<br><form method=\"GET\" action=\"prefs.php\"> | |
185 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> | |
186 | </form>"; | |
187 | ||
188 | print "</body></html>"; | |
189 | ||
190 | } | |
191 | ||
192 | // if ($link) db_close($link); | |
193 | ||
194 | ?> |