From: Andrew Dolgov Date: Sun, 12 Feb 2006 10:15:24 +0000 (+0100) Subject: skip counters output when number of unread articles at backend equals frontend, move... X-Git-Tag: 1.1.3~18 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=3f286c4c2bb531156e16f3a1f809d36811ca1cd4;p=tt-rss.git skip counters output when number of unread articles at backend equals frontend, move tools to utils/ folder --- diff --git a/sanity_check.php b/sanity_check.php index 322aa9bf..21fc0819 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -12,4 +12,11 @@ subdirectory of TT-RSS tree."; exit; } + + if (file_exists("xml-export.php") || file_exists("xml-import.php")) { + print "Fatal Error: XML Import/Export tools (xml-export.php + and xml-import.php) could be used maliciously. Please remove them + from your TT-RSS instance."; + exit; + } ?> diff --git a/utils/xml-export.php b/utils/xml-export.php new file mode 100644 index 00000000..620331fb --- /dev/null +++ b/utils/xml-export.php @@ -0,0 +1,164 @@ + + + + + + + XML Export + + + +

+ +
+

XML Export

+
+ Limit to: starred, + unread.
+

+
+
+ + + + + + + + +Source database schema is invalid + (got version $schema_version; expected ".SCHEMA_VERSION.")"; + print ""; + return; + } */ + + print "$schema_version"; + + if ($schema_version > 1) { + $owner_uid = $_SESSION["uid"]; + print "$owner_uid"; + } + + print "" . time() . ""; +?> + += 2 && $schema_version <= MAX_SCHEMA_VERSION) { + + $result = db_query($link, "SELECT + ttrss_entries.title AS title, + content, + marked, + unread, + updated, + guid, + link, + SUBSTRING(date_entered,1,16) AS date_entered, + SUBSTRING(last_read,1,16) AS last_read, + comments, + ttrss_feeds.feed_url AS feed_url, + ttrss_feeds.title AS feed_title + FROM + ttrss_entries,ttrss_feeds,ttrss_user_entries + WHERE + ttrss_user_entries.owner_uid = '$owner_uid' AND + ref_id = ttrss_entries.id AND + feed_id = ttrss_feeds.id $marked_qpart $unread_qpart + ORDER BY ttrss_entries.id"); + + } else { + + // BAD SCHEMA, NO COOKIE + + print "Source database schema is invalid + (got version $schema_version)"; + } + + print "" . db_num_rows($result) . ""; + +?> + + + +"; + + foreach (array_keys($line) as $key) { + $line[$key] = str_replace("", "", $line[$key]); + + print "<$key>"; + + } + + print ""; + } + +?> + + + + + diff --git a/utils/xml-import.php b/utils/xml-import.php new file mode 100644 index 00000000..6cae60e0 --- /dev/null +++ b/utils/xml-import.php @@ -0,0 +1,198 @@ +Article: ".$data["title"]. + " (".$data["feed_title"].")
"; + + $owner_uid = $_SESSION["uid"]; + + db_query($link, "BEGIN"); + + $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '". + db_escape_string($data["feed_url"]) . "' AND owner_uid = '$owner_uid'"); + + if (db_num_rows($result) == 0) { + return false; + } + + $feed_id = db_fetch_result($result, 0, "id"); + + $result = db_query($link, "SELECT id FROM ttrss_entries WHERE + guid = '".$data["guid"]."'"); + + if (db_num_rows($result) == 0) { + + print "Adding base entry...
"; + + $entry_title = db_escape_string($data["title"]); + $entry_guid = db_escape_string($data["guid"]); + $entry_link = db_escape_string($data["link"]); + $updated = db_escape_string($data["updated"]); + $date_entered = db_escape_string($data["date_entered"]); + $entry_content = db_escape_string($data["content"]); + $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); + $entry_comments = db_escape_string($data["comments"]); + + $result = db_query($link, + "INSERT INTO ttrss_entries + (title, + guid, + link, + updated, + content, + content_hash, + no_orig_date, + date_entered, + comments) + VALUES + ('$entry_title', + '$entry_guid', + '$entry_link', + '$updated', + '$entry_content', + '$content_hash', + false, + '$date_entered', + '$entry_comments')"); + } + + $result = db_query($link, "SELECT id FROM ttrss_entries WHERE + guid = '".$data["guid"]."'"); + + if (db_num_rows($result) == 0) { return false; } + + $entry_id = db_fetch_result($result, 0, "id"); + + print "Found base ID: $entry_id
"; + + $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$entry_id' AND owner_uid = '$owner_uid'"); + + if (db_num_rows($result) == 0) { + print "User table entry not found, creating...
"; + + $unread = sql_bool_to_string(db_escape_string($data["unread"])); + $marked = sql_bool_to_string(db_escape_string($data["marked"])); + $last_read = db_escape_string($data["last_read"]); + + if (!$last_read) { + $last_read_qpart = 'NULL'; + } else { + $last_read_qpart = "'$last_read'"; + } + + $result = db_query($link, + "INSERT INTO ttrss_user_entries + (ref_id, owner_uid, feed_id, unread, marked, last_read) + VALUES ('$entry_id', '$owner_uid', '$feed_id', $unread, $marked, + $last_read_qpart)"); + + } else { + print "User table entry already exists, nothing to do.
"; + } + + db_query($link, "COMMIT"); + + } + +?> + + + XML Import + + + + +

+ +
+ + + +

Import XMLDB

+ +
+ File:   + +
+ + Importing data"; + + if (is_file($_FILES['xmldb']['tmp_name'])) { + $dom = domxml_open_file($_FILES['xmldb']['tmp_name']); +// $dom = domxml_open_file('xmldb.xml'); + + if ($dom) { + $root = $dom->document_element(); + + $schema_version = $root->get_elements_by_tagname('schema_version'); + $schema_version = $schema_version[0]->get_content(); + + if ($schema_version > MAX_SOURCE_SCHEMA_VERSION) { + die("Incorrect source schema version"); + } + + $articles = $root->get_elements_by_tagname("article"); + + foreach ($articles as $article) { + $child_nodes = $article->child_nodes(); + + $article_data = array(); + + foreach ($child_nodes as $child) { + $article_data[$child->tagname()] = $child->get_content(); + } + + $is_imported = import_article($link, $article_data); + } + + print "

Return to preferences"; + } else { + print "Error: could not parse document."; + } + } else { + print "

Error: please upload XMLDB.

"; + } + + } ?> +
+ + + diff --git a/xml-export.php b/xml-export.php deleted file mode 100644 index 620331fb..00000000 --- a/xml-export.php +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - XML Export - - - -

- -
-

XML Export

-
- Limit to: starred, - unread.
-

-
-
- - - - - - - - -Source database schema is invalid - (got version $schema_version; expected ".SCHEMA_VERSION.")"; - print ""; - return; - } */ - - print "$schema_version"; - - if ($schema_version > 1) { - $owner_uid = $_SESSION["uid"]; - print "$owner_uid"; - } - - print "" . time() . ""; -?> - -= 2 && $schema_version <= MAX_SCHEMA_VERSION) { - - $result = db_query($link, "SELECT - ttrss_entries.title AS title, - content, - marked, - unread, - updated, - guid, - link, - SUBSTRING(date_entered,1,16) AS date_entered, - SUBSTRING(last_read,1,16) AS last_read, - comments, - ttrss_feeds.feed_url AS feed_url, - ttrss_feeds.title AS feed_title - FROM - ttrss_entries,ttrss_feeds,ttrss_user_entries - WHERE - ttrss_user_entries.owner_uid = '$owner_uid' AND - ref_id = ttrss_entries.id AND - feed_id = ttrss_feeds.id $marked_qpart $unread_qpart - ORDER BY ttrss_entries.id"); - - } else { - - // BAD SCHEMA, NO COOKIE - - print "Source database schema is invalid - (got version $schema_version)"; - } - - print "" . db_num_rows($result) . ""; - -?> - - - -"; - - foreach (array_keys($line) as $key) { - $line[$key] = str_replace("", "", $line[$key]); - - print "<$key>"; - - } - - print ""; - } - -?> - - - - - diff --git a/xml-import.php b/xml-import.php deleted file mode 100644 index 6cae60e0..00000000 --- a/xml-import.php +++ /dev/null @@ -1,198 +0,0 @@ -Article: ".$data["title"]. - " (".$data["feed_title"].")
"; - - $owner_uid = $_SESSION["uid"]; - - db_query($link, "BEGIN"); - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '". - db_escape_string($data["feed_url"]) . "' AND owner_uid = '$owner_uid'"); - - if (db_num_rows($result) == 0) { - return false; - } - - $feed_id = db_fetch_result($result, 0, "id"); - - $result = db_query($link, "SELECT id FROM ttrss_entries WHERE - guid = '".$data["guid"]."'"); - - if (db_num_rows($result) == 0) { - - print "Adding base entry...
"; - - $entry_title = db_escape_string($data["title"]); - $entry_guid = db_escape_string($data["guid"]); - $entry_link = db_escape_string($data["link"]); - $updated = db_escape_string($data["updated"]); - $date_entered = db_escape_string($data["date_entered"]); - $entry_content = db_escape_string($data["content"]); - $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); - $entry_comments = db_escape_string($data["comments"]); - - $result = db_query($link, - "INSERT INTO ttrss_entries - (title, - guid, - link, - updated, - content, - content_hash, - no_orig_date, - date_entered, - comments) - VALUES - ('$entry_title', - '$entry_guid', - '$entry_link', - '$updated', - '$entry_content', - '$content_hash', - false, - '$date_entered', - '$entry_comments')"); - } - - $result = db_query($link, "SELECT id FROM ttrss_entries WHERE - guid = '".$data["guid"]."'"); - - if (db_num_rows($result) == 0) { return false; } - - $entry_id = db_fetch_result($result, 0, "id"); - - print "Found base ID: $entry_id
"; - - $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE - ref_id = '$entry_id' AND owner_uid = '$owner_uid'"); - - if (db_num_rows($result) == 0) { - print "User table entry not found, creating...
"; - - $unread = sql_bool_to_string(db_escape_string($data["unread"])); - $marked = sql_bool_to_string(db_escape_string($data["marked"])); - $last_read = db_escape_string($data["last_read"]); - - if (!$last_read) { - $last_read_qpart = 'NULL'; - } else { - $last_read_qpart = "'$last_read'"; - } - - $result = db_query($link, - "INSERT INTO ttrss_user_entries - (ref_id, owner_uid, feed_id, unread, marked, last_read) - VALUES ('$entry_id', '$owner_uid', '$feed_id', $unread, $marked, - $last_read_qpart)"); - - } else { - print "User table entry already exists, nothing to do.
"; - } - - db_query($link, "COMMIT"); - - } - -?> - - - XML Import - - - - -

- -
- - - -

Import XMLDB

- -
- File:   - -
- - Importing data"; - - if (is_file($_FILES['xmldb']['tmp_name'])) { - $dom = domxml_open_file($_FILES['xmldb']['tmp_name']); -// $dom = domxml_open_file('xmldb.xml'); - - if ($dom) { - $root = $dom->document_element(); - - $schema_version = $root->get_elements_by_tagname('schema_version'); - $schema_version = $schema_version[0]->get_content(); - - if ($schema_version > MAX_SOURCE_SCHEMA_VERSION) { - die("Incorrect source schema version"); - } - - $articles = $root->get_elements_by_tagname("article"); - - foreach ($articles as $article) { - $child_nodes = $article->child_nodes(); - - $article_data = array(); - - foreach ($child_nodes as $child) { - $article_data[$child->tagname()] = $child->get_content(); - } - - $is_imported = import_article($link, $article_data); - } - - print "

Return to preferences"; - } else { - print "Error: could not parse document."; - } - } else { - print "

Error: please upload XMLDB.

"; - } - - } ?> -
- - -