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