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