]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | error_reporting(E_ERROR | E_WARNING | E_PARSE); | |
3 | ||
4 | require_once "sessions.php"; | |
5 | require_once "sanity_check.php"; | |
6 | require_once "functions.php"; | |
7 | require_once "config.php"; | |
8 | require_once "db.php"; | |
9 | require_once "db-prefs.php"; | |
10 | ||
11 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
12 | ||
13 | init_connection($link); | |
14 | ||
15 | function opml_export($link, $owner_uid, $hide_private_feeds=False) { | |
16 | header("Content-type: application/xml+opml"); | |
17 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | |
18 | ||
19 | print "<opml version=\"1.0\">"; | |
20 | print "<head> | |
21 | <dateCreated>" . date("r", time()) . "</dateCreated> | |
22 | <title>Tiny Tiny RSS Feed Export</title> | |
23 | </head>"; | |
24 | print "<body>"; | |
25 | ||
26 | $cat_mode = false; | |
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 | } | |
34 | ||
35 | ||
36 | ||
37 | if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) { | |
38 | $cat_mode = true; | |
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 | ||
44 | } | |
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 | ||
52 | ||
53 | $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby); | |
54 | ||
55 | $old_cat_title = ""; | |
56 | ||
57 | while ($line = db_fetch_assoc($result)) { | |
58 | $title = htmlspecialchars($line["title"]); | |
59 | $url = htmlspecialchars($line["feed_url"]); | |
60 | $site_url = htmlspecialchars($line["site_url"]); | |
61 | ||
62 | if ($cat_mode) { | |
63 | $cat_title = htmlspecialchars($line["cat_title"]); | |
64 | ||
65 | if ($old_cat_title != $cat_title) { | |
66 | if ($old_cat_title) { | |
67 | print "</outline>\n"; | |
68 | } | |
69 | ||
70 | if ($cat_title) { | |
71 | print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n"; | |
72 | } | |
73 | ||
74 | $old_cat_title = $cat_title; | |
75 | } | |
76 | } | |
77 | ||
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"; | |
85 | } | |
86 | ||
87 | if ($cat_mode && $old_cat_title) { | |
88 | print "</outline>\n"; | |
89 | } | |
90 | ||
91 | print "</body></opml>"; | |
92 | } | |
93 | ||
94 | // FIXME there are some brackets issues here | |
95 | ||
96 | $op = $_REQUEST["op"]; | |
97 | ||
98 | if (!$op) $op = "Export"; | |
99 | ||
100 | if ($op == "Export") { | |
101 | ||
102 | login_sequence($link); | |
103 | $owner_uid = $_SESSION["uid"]; | |
104 | return opml_export($link, $owner_uid); | |
105 | } | |
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 | } | |
122 | ||
123 | if ($op == "Import") { | |
124 | ||
125 | login_sequence($link); | |
126 | $owner_uid = $_SESSION["uid"]; | |
127 | ||
128 | print "<html> | |
129 | <head> | |
130 | <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\"> | |
131 | <title>".__("OPML Utility")."</title> | |
132 | </head> | |
133 | <body> | |
134 | <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div> | |
135 | <h1>".__('OPML Utility')."</h1>"; | |
136 | ||
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 | ||
155 | if (function_exists('domxml_open_file')) { | |
156 | print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>"; | |
157 | require_once "modules/opml_domxml.php"; | |
158 | opml_import_domxml($link, $owner_uid); | |
159 | } else if (PHP_VERSION >= 5) { | |
160 | print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>"; | |
161 | require_once "modules/opml_domdoc.php"; | |
162 | opml_import_domdoc($link, $owner_uid); | |
163 | } else { | |
164 | print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); | |
165 | } | |
166 | ||
167 | print "<br><form method=\"GET\" action=\"prefs.php\"> | |
168 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> | |
169 | </form>"; | |
170 | ||
171 | print "</body></html>"; | |
172 | ||
173 | } | |
174 | ||
175 | // if ($link) db_close($link); | |
176 | ||
177 | ?> |