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