X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=opml.php;h=35e36d24a351035e95a29ec8b000493620d3d172;hb=432c64caced5f7cd4ad534a0f2b04acf059b6e8c;hp=63f64a670f02abca950fcbceedc1ac7665b44eb5;hpb=18d37445a33ea01d099ef4d09840f0351f593ee8;p=tt-rss.git
diff --git a/opml.php b/opml.php
index 63f64a67..35e36d24 100644
--- a/opml.php
+++ b/opml.php
@@ -1,199 +1,205 @@
-
- session_start();
+";
- }
-
+ require_once "functions.php";
require_once "config.php";
require_once "db.php";
require_once "db-prefs.php";
- $owner_uid = $_SESSION["uid"];
-
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- if (DB_TYPE == "pgsql") {
- pg_query($link, "set client_encoding = 'utf-8'");
- }
+ init_connection($link);
+
+ function opml_export($link, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
+ if (!$_REQUEST["debug"]) {
+ header("Content-type: application/xml+opml");
+ } else {
+ header("Content-type: text/xml");
+ }
+ print "";
- if ($op == "Export") {
print "";
- print "" . date("r", time()) . "";
+ print "
+ " . date("r", time()) . "
+ Tiny Tiny RSS Feed Export
+ ";
print "";
$cat_mode = false;
+
+ $select = "SELECT * ";
+ $where = "WHERE owner_uid = '$owner_uid'";
+ $orderby = "ORDER BY title";
+ if ($hide_private_feeds){
+ $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
+ auth_login = '' AND auth_pass = ''";
+ }
+
+
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
+ if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
$cat_mode = true;
- $result = db_query($link, "SELECT
- ttrss_feeds.feed_url AS feed_url,
- ttrss_feeds.title AS title,
- (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
- FROM ttrss_feeds
- ORDER BY cat_title,title");
- } else {
- $result = db_query($link, "SELECT * FROM ttrss_feeds
- ORDER BY title");
+ $select = "SELECT
+ title, feed_url, site_url,
+ (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
+ $orderby = "ORDER BY cat_title, title";
+
+ }
+ else{
+ $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
+ print "";
+ print "";
+
}
+
+ $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
+
$old_cat_title = "";
while ($line = db_fetch_assoc($result)) {
$title = htmlspecialchars($line["title"]);
$url = htmlspecialchars($line["feed_url"]);
+ $site_url = htmlspecialchars($line["site_url"]);
if ($cat_mode) {
$cat_title = htmlspecialchars($line["cat_title"]);
if ($old_cat_title != $cat_title) {
if ($old_cat_title) {
- print "";
+ print "\n";
}
- print "";
+ if ($cat_title) {
+ print "\n";
+ }
$old_cat_title = $cat_title;
}
}
- print "";
- }
+ if ($site_url) {
+ $html_url_qpart = "htmlUrl=\"$site_url\"";
+ } else {
+ $html_url_qpart = "";
+ }
- if ($cat_mode && $old_cat_title) {
- print "";
+ print "\n";
}
- print "";
- }
-
- if ($op == "Import") {
-
- print "
-
-
-
- Importing OPML...
- ";
-
- return;
+ if ($cat_mode && $old_cat_title) {
+ print "\n";
}
- if (is_file($_FILES['opml_file']['tmp_name'])) {
- $dom = domxml_open_file($_FILES['opml_file']['tmp_name']);
-
- if ($dom) {
- $root = $dom->document_element();
-
- $body = $root->get_elements_by_tagname('body');
+ # export tt-rss settings
- if ($body[0]) {
- $body = $body[0];
+ if ($include_settings) {
+ print "";
- $outlines = $body->get_elements_by_tagname('outline');
+ $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
+ profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
- $active_category = '';
+ while ($line = db_fetch_assoc($result)) {
- foreach ($outlines as $outline) {
- $feed_title = $outline->get_attribute('text');
- $cat_title = $outline->get_attribute('title');
- $feed_url = $outline->get_attribute('xmlUrl');
+ $name = $line["pref_name"];
+ $value = htmlspecialchars($line["value"]);
+
+ print "";
- if ($cat_title) {
- $active_category = $cat_title;
+ print "";
- db_query($link, "BEGIN");
-
- $result = db_query($link, "SELECT id FROM
- ttrss_feed_categories WHERE title = '$cat_title' AND
- owner_uid = '$owner_uid' LIMIT 1");
+ }
- if (db_num_rows($result) == 0) {
-
- print "Adding category $cat_title...
";
-
- db_query($link, "INSERT INTO ttrss_feed_categories
- (title,owner_uid) VALUES ('$cat_title', '$owner_uid')");
- }
-
- db_query($link, "COMMIT");
- }
-
-// print "$active_category : $feed_title : $xmlurl
";
+ print "";
+ }
- if (!$feed_title || !$feed_url) continue;
+ print "
+ ![](\"images/ttrss_logo.png\")
+ ".__('OPML Utility')."
";
- print "Feed $feed_title ($feed_url)... ";
+ db_query($link, "BEGIN");
- if (db_num_rows($result) > 0) {
- print " Already imported.
";
- } else {
+ /* create Imported feeds category just in case */
- if ($cat_id) {
- $add_query = "INSERT INTO ttrss_feeds
- (title, feed_url, owner_uid, cat_id) VALUES
- ('$feed_title', '$feed_url', '$owner_uid', '$cat_id')";
+ $result = db_query($link, "SELECT id FROM
+ ttrss_feed_categories WHERE title = 'Imported feeds' AND
+ owner_uid = '$owner_uid' LIMIT 1");
- } else {
- $add_query = "INSERT INTO ttrss_feeds
- (title, feed_url, owner_uid) VALUES
- ('$feed_title', '$feed_url', '$owner_uid')";
+ if (db_num_rows($result) == 0) {
+ db_query($link, "INSERT INTO ttrss_feed_categories
+ (title,owner_uid)
+ VALUES ('Imported feeds', '$owner_uid')");
+ }
- }
-
- db_query($link, $add_query);
-
- print "Done.
";
- }
-
- db_query($link, "COMMIT");
- }
+ db_query($link, "COMMIT");
- } else {
- print "Error: can't find body element.";
- }
- } else {
- print "Error while parsing document.";
- }
+ /* Handle OPML import by DOMXML/DOMDocument */
+ if (function_exists('domxml_open_file')) {
+ print "".__("Importing OPML (using DOMXML extension)...")."
";
+ require_once "modules/opml_domxml.php";
+ opml_import_domxml($link, $owner_uid);
+ } else if (PHP_VERSION >= 5) {
+ print "".__("Importing OPML (using DOMDocument extension)...")."
";
+ require_once "modules/opml_domdoc.php";
+ opml_import_domdoc($link, $owner_uid);
} else {
- print "Error: please upload OPML file.";
+ print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
}
- print "
- Return to preferences";
+ print "
";
- print "";
+ }
- db_query($link, "BEGIN");
+ // FIXME there are some brackets issues here
- $cat_id = null;
+ $op = $_REQUEST["op"];
+
+ if (!$op) $op = "Export";
+
+ if ($op == "Export") {
+
+ login_sequence($link);
+ $owner_uid = $_SESSION["uid"];
+ return opml_export($link, $owner_uid);
+ }
+
+ if ($op == "publish"){
+ $key = db_escape_string($_REQUEST["key"]);
+
+ $result = db_query($link, "SELECT login, owner_uid
+ FROM ttrss_user_prefs, ttrss_users WHERE
+ pref_name = '_PREFS_PUBLISH_KEY' AND
+ value = '$key' AND
+ ttrss_users.id = owner_uid");
+
+ if (db_num_rows($result) == 1) {
+ $owner = db_fetch_result($result, 0, "owner_uid");
+ return opml_export($link, $owner, true, false);
+ } else {
+ print "User not found";
+ }
+ }
- if ($active_category) {
+ if ($op == "Import") {
- $result = db_query($link, "SELECT id FROM
- ttrss_feed_categories WHERE title = '$active_category' AND
- owner_uid = '$owner_uid' LIMIT 1");
+ login_sequence($link);
+ $owner_uid = $_SESSION["uid"];
- if (db_num_rows($result) == 1) {
- $cat_id = db_fetch_result($result, 0, "id");
- }
- }
+ header('Content-Type: text/html; charset=utf-8');
- $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
- (title = '$feed_title' OR feed_url = '$feed_url')
- AND owner_uid = '$owner_uid'");
+ print "
+