]>
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 | if (DB_TYPE == "pgsql") { | |
14 | pg_query($link, "set client_encoding = 'utf-8'"); | |
15 | pg_set_client_encoding("UNICODE"); | |
16 | } else { | |
17 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { | |
18 | db_query($link, "SET NAMES " . MYSQL_CHARSET); | |
19 | // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET); | |
20 | } | |
21 | } | |
22 | ||
23 | login_sequence($link); | |
24 | ||
25 | $owner_uid = $_SESSION["uid"]; | |
26 | ||
27 | function opml_export($link, $owner_uid) { | |
28 | header("Content-type: application/xml+opml"); | |
29 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | |
30 | ||
31 | print "<opml version=\"1.0\">"; | |
32 | print "<head> | |
33 | <dateCreated>" . date("r", time()) . "</dateCreated> | |
34 | <title>Tiny Tiny RSS Feed Export</title> | |
35 | </head>"; | |
36 | print "<body>"; | |
37 | ||
38 | $cat_mode = false; | |
39 | ||
40 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
41 | $cat_mode = true; | |
42 | $result = db_query($link, "SELECT | |
43 | title,feed_url,site_url, | |
44 | (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title | |
45 | FROM ttrss_feeds | |
46 | WHERE | |
47 | owner_uid = '$owner_uid' | |
48 | ORDER BY cat_title,title"); | |
49 | } else { | |
50 | $result = db_query($link, "SELECT * FROM ttrss_feeds | |
51 | WHERE owner_uid = '$owner_uid' ORDER BY title"); | |
52 | } | |
53 | ||
54 | $old_cat_title = ""; | |
55 | ||
56 | while ($line = db_fetch_assoc($result)) { | |
57 | $title = htmlspecialchars($line["title"]); | |
58 | $url = htmlspecialchars($line["feed_url"]); | |
59 | $site_url = htmlspecialchars($line["site_url"]); | |
60 | ||
61 | if ($cat_mode) { | |
62 | $cat_title = htmlspecialchars($line["cat_title"]); | |
63 | ||
64 | if ($old_cat_title != $cat_title) { | |
65 | if ($old_cat_title) { | |
66 | print "</outline>\n"; | |
67 | } | |
68 | ||
69 | if ($cat_title) { | |
70 | print "<outline title=\"$cat_title\">\n"; | |
71 | } | |
72 | ||
73 | $old_cat_title = $cat_title; | |
74 | } | |
75 | } | |
76 | ||
77 | if ($site_url) { | |
78 | $html_url_qpart = "htmlUrl=\"$site_url\""; | |
79 | } else { | |
80 | $html_url_qpart = ""; | |
81 | } | |
82 | ||
83 | print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n"; | |
84 | } | |
85 | ||
86 | if ($cat_mode && $old_cat_title) { | |
87 | print "</outline>\n"; | |
88 | } | |
89 | ||
90 | print "</body></opml>"; | |
91 | } | |
92 | ||
93 | // FIXME there are some brackets issues here | |
94 | ||
95 | $op = $_REQUEST["op"]; | |
96 | ||
97 | if (!$op) $op = "Export"; | |
98 | ||
99 | if ($op == "Export") { | |
100 | return opml_export($link, $owner_uid); | |
101 | } | |
102 | ||
103 | if ($op == "Import") { | |
104 | ||
105 | print "<html> | |
106 | <head> | |
107 | <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\"> | |
108 | <title>".__("OPML Utility")."</title> | |
109 | </head> | |
110 | <body> | |
111 | <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div> | |
112 | <h1>".__('OPML Utility')."</h1>"; | |
113 | ||
114 | if (function_exists('domxml_open_file')) { | |
115 | print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>"; | |
116 | require_once "modules/opml_domxml.php"; | |
117 | opml_import_domxml($link, $owner_uid); | |
118 | } else if (PHP_VERSION >= 5) { | |
119 | print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>"; | |
120 | require_once "modules/opml_domdoc.php"; | |
121 | opml_import_domdoc($link, $owner_uid); | |
122 | } else { | |
123 | print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); | |
124 | } | |
125 | ||
126 | print "<br><form method=\"GET\" action=\"prefs.php\"> | |
127 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> | |
128 | </form>"; | |
129 | ||
130 | print "</body></html>"; | |
131 | ||
132 | } | |
133 | ||
134 | // if ($link) db_close($link); | |
135 | ||
136 | ?> |