host = $host; $host->add_hook($host::HOOK_PREFS_TAB, $this); $host->add_command("xml-import", "import articles from XML", $this, ":", "FILE"); } function about() { return array(1.0, "Imports and exports user data using neutral XML format", "fox"); } function xml_import($args) { $filename = $args['xml_import']; if (!is_file($filename)) { print "error: input filename ($filename) doesn't exist.\n"; return; } _debug("please enter your username:"); $username = db_escape_string(trim(read_stdin())); _debug("importing $filename for user $username...\n"); $result = db_query("SELECT id FROM ttrss_users WHERE login = '$username'"); if (db_num_rows($result) == 0) { print "error: could not find user $username.\n"; return; } $owner_uid = db_fetch_result($result, 0, "id"); $this->perform_data_import($filename, $owner_uid); } function save() { $example_value = db_escape_string($_POST["example_value"]); echo "Value set to $example_value (not really)"; } function get_prefs_js() { return file_get_contents(dirname(__FILE__) . "/import_export.js"); } function hook_prefs_tab($args) { if ($args != "prefFeeds") return; print "
" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "
"; print " "; print "" .__("Could not import: incorrect schema version.") . "
"; return; } } else { print "" . __("Could not import: unrecognized document format.") . "
"; return; } $articles = $xpath->query("//article"); foreach ($articles as $article_node) { if ($article_node->childNodes) { $ref_id = 0; $article = array(); foreach ($article_node->childNodes as $child) { if ($child->nodeName != 'label_cache') $article[$child->nodeName] = db_escape_string($child->nodeValue); else $article[$child->nodeName] = $child->nodeValue; } //print_r($article); if ($article['guid']) { ++$num_processed; //db_query("BEGIN"); //print 'GUID:' . $article['guid'] . "\n"; $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '".$article['guid']."'"); if (db_num_rows($result) == 0) { $result = db_query( "INSERT INTO ttrss_entries (title, guid, link, updated, content, content_hash, no_orig_date, date_updated, date_entered, comments, num_comments, author) VALUES ('".$article['title']."', '".$article['guid']."', '".$article['link']."', '".$article['updated']."', '".$article['content']."', '".sha1($article['content'])."', false, NOW(), NOW(), '', '0', '')"); $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '".$article['guid']."'"); if (db_num_rows($result) != 0) { $ref_id = db_fetch_result($result, 0, "id"); } } else { $ref_id = db_fetch_result($result, 0, "id"); } //print "Got ref ID: $ref_id\n"; if ($ref_id) { $feed_url = $article['feed_url']; $feed_title = $article['feed_title']; $feed = 'NULL'; if ($feed_url && $feed_title) { $result = db_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid = '$owner_uid'"); if (db_num_rows($result) != 0) { $feed = db_fetch_result($result, 0, "id"); } else { // try autocreating feed in Uncategorized... $result = db_query("INSERT INTO ttrss_feeds (owner_uid, feed_url, title) VALUES ($owner_uid, '$feed_url', '$feed_title')"); $result = db_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid = '$owner_uid'"); if (db_num_rows($result) != 0) { ++$num_feeds_created; $feed = db_fetch_result($result, 0, "id"); } } } if ($feed != 'NULL') $feed_qpart = "feed_id = $feed"; else $feed_qpart = "feed_id IS NULL"; //print "$ref_id / $feed / " . $article['title'] . "\n"; $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND $feed_qpart"); if (db_num_rows($result) == 0) { $marked = bool_to_sql_bool(sql_bool_to_bool($article['marked'])); $published = bool_to_sql_bool(sql_bool_to_bool($article['published'])); $score = (int) $article['score']; $tag_cache = $article['tag_cache']; $label_cache = db_escape_string($article['label_cache']); $note = $article['note']; //print "Importing " . $article['title'] . "" . __("Finished: "). vsprintf(ngettext("%d article processed, ", "%d articles processed, ", $num_processed), $num_processed). vsprintf(ngettext("%d imported, ", "%d imported, ", $num_imported), $num_imported). vsprintf(ngettext("%d feed created.", "%d feeds created.", $num_feeds_created), $num_feeds_created). "
"; } else { print "" . __("Could not load XML document.") . "
"; } } function exportData() { print "You need to prepare exported data first by clicking the button below.
"; print "