X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=inline;f=opml.php;h=35e36d24a351035e95a29ec8b000493620d3d172;hb=432c64caced5f7cd4ad534a0f2b04acf059b6e8c;hp=b9986cda6474606955530e4dcb9c76de62eab30b;hpb=04f6df27b991f9811ab4ee1b79151f7c1667df36;p=tt-rss.git diff --git a/opml.php b/opml.php index b9986cda..35e36d24 100644 --- a/opml.php +++ b/opml.php @@ -1,55 +1,68 @@ -"; - } - + 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 - WHERE - owner_uid = '$owner_uid' - ORDER BY cat_title,title"); - } else { - $result = db_query($link, "SELECT * FROM ttrss_feeds - ORDER BY title WHERE owner_uid = '$owner_uid'"); + $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"]); @@ -60,150 +73,133 @@ } if ($cat_title) { - print "\n"; + print "\n"; } $old_cat_title = $cat_title; } } - print "\n"; + if ($site_url) { + $html_url_qpart = "htmlUrl=\"$site_url\""; + } else { + $html_url_qpart = ""; + } + + print "\n"; } if ($cat_mode && $old_cat_title) { print "\n"; } - print ""; - } - - if ($op == "Import") { - - print " - - - - -

Importing OPML...

-
"; - - if (WEB_DEMO_MODE) { - print "OPML import is disabled in demo-mode."; - print "

- Return to preferences

"; - - return; - } - - 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'); - - if ($body[0]) { - $body = $body[0]; - - $outlines = $body->get_elements_by_tagname('outline'); + # export tt-rss settings - foreach ($outlines as $outline) { - $feed_title = db_escape_string($outline->get_attribute('text')); - $cat_title = db_escape_string($outline->get_attribute('title')); - $feed_url = db_escape_string($outline->get_attribute('xmlUrl')); + if ($include_settings) { + print ""; - if ($cat_title) { + $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE + profile IS NULL AND owner_uid = " . $_SESSION["uid"]); - 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"); + while ($line = db_fetch_assoc($result)) { - if (db_num_rows($result) == 0) { + $name = $line["pref_name"]; + $value = htmlspecialchars($line["value"]); + + print ""; - print "Adding category $cat_title...
"; + print "
"; - 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
"; - - if (!$feed_title || !$feed_url) continue; - - db_query($link, "BEGIN"); - - $cat_id = null; + print "
"; + } - $parent_node = $outline->parent_node(); + print ""; + } - if ($parent_node && $parent_node->node_name() == "outline") { - $element_category = $parent_node->get_attribute('title'); - } else { - $element_category = ''; - } + // FIXME there are some brackets issues here - if ($element_category) { + $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"; + } + } - $result = db_query($link, "SELECT id FROM - ttrss_feed_categories WHERE title = '$element_category' AND - owner_uid = '$owner_uid' LIMIT 1"); + if ($op == "Import") { - if (db_num_rows($result) == 1) { - $cat_id = db_fetch_result($result, 0, "id"); - } - } + login_sequence($link); + $owner_uid = $_SESSION["uid"]; - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - (title = '$feed_title' OR feed_url = '$feed_url') - AND owner_uid = '$owner_uid'"); + header('Content-Type: text/html; charset=utf-8'); - print "Feed $feed_title ($feed_url)... "; + print " + + + ".__("OPML Utility")." + + + +
+

".__('OPML Utility')."

"; - if (db_num_rows($result) > 0) { - print " Already imported.
"; - } else { + db_query($link, "BEGIN"); - 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')"; + /* create Imported feeds category just in case */ - } else { - $add_query = "INSERT INTO ttrss_feeds - (title, feed_url, owner_uid) VALUES - ('$feed_title', '$feed_url', '$owner_uid')"; + $result = db_query($link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); - } + 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 ""; + print ""; }