opml.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  3. require_once "sessions.php";
  4. require_once "sanity_check.php";
  5. require_once "functions.php";
  6. require_once "config.php";
  7. require_once "db.php";
  8. require_once "db-prefs.php";
  9. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  10. if (DB_TYPE == "pgsql") {
  11. pg_query($link, "set client_encoding = 'utf-8'");
  12. pg_set_client_encoding("UNICODE");
  13. }
  14. login_sequence($link);
  15. $owner_uid = $_SESSION["uid"];
  16. function opml_export($link, $owner_uid) {
  17. header("Content-type: application/xml+opml");
  18. print "<?xml version=\"1.0\"?>";
  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. $cat_mode = false;
  26. if (get_pref($link, 'ENABLE_FEED_CATS')) {
  27. $cat_mode = true;
  28. $result = db_query($link, "SELECT
  29. title,feed_url,site_url,
  30. (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
  31. FROM ttrss_feeds
  32. WHERE
  33. owner_uid = '$owner_uid'
  34. ORDER BY cat_title,title");
  35. } else {
  36. $result = db_query($link, "SELECT * FROM ttrss_feeds
  37. WHERE owner_uid = '$owner_uid' ORDER BY title");
  38. }
  39. $old_cat_title = "";
  40. while ($line = db_fetch_assoc($result)) {
  41. $title = htmlspecialchars($line["title"]);
  42. $url = htmlspecialchars($line["feed_url"]);
  43. $site_url = htmlspecialchars($line["site_url"]);
  44. if ($cat_mode) {
  45. $cat_title = htmlspecialchars($line["cat_title"]);
  46. if ($old_cat_title != $cat_title) {
  47. if ($old_cat_title) {
  48. print "</outline>\n";
  49. }
  50. if ($cat_title) {
  51. print "<outline title=\"$cat_title\">\n";
  52. }
  53. $old_cat_title = $cat_title;
  54. }
  55. }
  56. if ($site_url) {
  57. $html_url_qpart = "htmlUrl=\"$site_url\"";
  58. } else {
  59. $html_url_qpart = "";
  60. }
  61. print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
  62. }
  63. if ($cat_mode && $old_cat_title) {
  64. print "</outline>\n";
  65. }
  66. print "</body></opml>";
  67. }
  68. // FIXME there are some brackets issues here
  69. $op = $_REQUEST["op"];
  70. if (!$op) $op = "Export";
  71. if ($op == "Export") {
  72. return opml_export($link, $owner_uid);
  73. }
  74. if ($op == "Import") {
  75. print "<html>
  76. <head>
  77. <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
  78. <title>".__("OPML Utility")."</title>
  79. </head>
  80. <body>
  81. <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
  82. <h1>".__('OPML Utility')."</h1>";
  83. if (function_exists('domxml_open_file')) {
  84. print __("<p>Importing OPML (using DOMXML extension)...</p>");
  85. require_once "modules/opml_domxml.php";
  86. opml_import_domxml($link, $owner_uid);
  87. } else {
  88. print __("<p>Importing OPML (using DOMDocument extension)...</p>");
  89. require_once "modules/opml_domdoc.php";
  90. opml_import_domdoc($link, $owner_uid);
  91. }
  92. print "<br><form method=\"GET\" action=\"prefs.php\">
  93. <input type=\"submit\" value=\"".__("Return to preferences")."\">
  94. </form>";
  95. print "</body></html>";
  96. }
  97. // if ($link) db_close($link);
  98. ?>