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