]>
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 AD |
34 | |
35 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
36 | $cat_mode = true; | |
86e26f1a MK |
37 | $select = "SELECT |
38 | title, feed_url, site_url, | |
39 | (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title"; | |
40 | $orderby = "ORDER BY cat_title, title"; | |
41 | ||
da49ccf5 AD |
42 | } |
43 | ||
86e26f1a MK |
44 | $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby); |
45 | ||
da49ccf5 | 46 | $old_cat_title = ""; |
9a4506c8 | 47 | |
8158c57a | 48 | while ($line = db_fetch_assoc($result)) { |
6e0584e9 AD |
49 | $title = htmlspecialchars($line["title"]); |
50 | $url = htmlspecialchars($line["feed_url"]); | |
fa7b8749 | 51 | $site_url = htmlspecialchars($line["site_url"]); |
9a4506c8 | 52 | |
da49ccf5 AD |
53 | if ($cat_mode) { |
54 | $cat_title = htmlspecialchars($line["cat_title"]); | |
55 | ||
56 | if ($old_cat_title != $cat_title) { | |
57 | if ($old_cat_title) { | |
5b9af2b9 | 58 | print "</outline>\n"; |
da49ccf5 AD |
59 | } |
60 | ||
5b9af2b9 AD |
61 | if ($cat_title) { |
62 | print "<outline title=\"$cat_title\">\n"; | |
63 | } | |
da49ccf5 AD |
64 | |
65 | $old_cat_title = $cat_title; | |
66 | } | |
67 | } | |
68 | ||
fa7b8749 AD |
69 | if ($site_url) { |
70 | $html_url_qpart = "htmlUrl=\"$site_url\""; | |
71 | } else { | |
72 | $html_url_qpart = ""; | |
73 | } | |
74 | ||
75 | print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n"; | |
9a4506c8 AD |
76 | } |
77 | ||
da49ccf5 | 78 | if ($cat_mode && $old_cat_title) { |
5b9af2b9 | 79 | print "</outline>\n"; |
da49ccf5 AD |
80 | } |
81 | ||
9a4506c8 AD |
82 | print "</body></opml>"; |
83 | } | |
84 | ||
30f782a2 AD |
85 | // FIXME there are some brackets issues here |
86 | ||
87 | $op = $_REQUEST["op"]; | |
88 | ||
89 | if (!$op) $op = "Export"; | |
90 | ||
91 | if ($op == "Export") { | |
a4234239 MK |
92 | |
93 | login_sequence($link); | |
94 | $owner_uid = $_SESSION["uid"]; | |
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 | |
a4234239 MK |
116 | login_sequence($link); |
117 | $owner_uid = $_SESSION["uid"]; | |
118 | ||
e98a3f65 AD |
119 | print "<html> |
120 | <head> | |
ef59e6e8 | 121 | <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\"> |
1025ad87 | 122 | <title>".__("OPML Utility")."</title> |
e98a3f65 | 123 | </head> |
04f6df27 | 124 | <body> |
ef59e6e8 | 125 | <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div> |
d1db26aa | 126 | <h1>".__('OPML Utility')."</h1>"; |
9f311df6 | 127 | |
c03cf250 AD |
128 | db_query($link, "BEGIN"); |
129 | ||
130 | /* create Imported feeds category just in case */ | |
131 | ||
132 | $result = db_query($link, "SELECT id FROM | |
133 | ttrss_feed_categories WHERE title = 'Imported feeds' AND | |
134 | owner_uid = '$owner_uid' LIMIT 1"); | |
135 | ||
136 | if (db_num_rows($result) == 0) { | |
137 | db_query($link, "INSERT INTO ttrss_feed_categories | |
138 | (title,owner_uid) | |
139 | VALUES ('Imported feeds', '$owner_uid')"); | |
140 | } | |
141 | ||
142 | db_query($link, "COMMIT"); | |
143 | ||
144 | /* Handle OPML import by DOMXML/DOMDocument */ | |
145 | ||
30f782a2 | 146 | if (function_exists('domxml_open_file')) { |
06719138 | 147 | print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>"; |
30f782a2 AD |
148 | require_once "modules/opml_domxml.php"; |
149 | opml_import_domxml($link, $owner_uid); | |
5eb66ed7 | 150 | } else if (PHP_VERSION >= 5) { |
06719138 | 151 | print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>"; |
30f782a2 AD |
152 | require_once "modules/opml_domdoc.php"; |
153 | opml_import_domdoc($link, $owner_uid); | |
5eb66ed7 AD |
154 | } else { |
155 | print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); | |
9f311df6 AD |
156 | } |
157 | ||
d7c848d9 | 158 | print "<br><form method=\"GET\" action=\"prefs.php\"> |
1025ad87 | 159 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> |
d7c848d9 | 160 | </form>"; |
9f311df6 | 161 | |
30f782a2 | 162 | print "</body></html>"; |
9f311df6 AD |
163 | |
164 | } | |
165 | ||
3d477c2c | 166 | // if ($link) db_close($link); |
9f311df6 | 167 | |
9a4506c8 | 168 | ?> |