"fox");
}
+ private function bool_to_sql_bool($s) {
+ return $s ? 'true' : 'false';
+ }
+
function xml_import($args) {
$filename = $args['xml_import'];
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Import and export')."\">";
- print "<h3>" . __("Article archive") . "</h3>";
+ print_notice(__("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances of same version."));
- print "<p>" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "</p>";
+ print "<p>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return exportData()\">".
__('Export my data')."</button> ";
print "</form>";
+ print "</p>";
+
print "</div>"; # pane
}
return in_array($method, array("exportget"));
}
+ /**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
function before($method) {
return $_SESSION["uid"] != false;
}
return true;
}
+ /**
+ * @SuppressWarnings(unused)
+ */
function exportget() {
$exportname = CACHE_DIR . "/export/" .
sha1($_SESSION['uid'] . $_SESSION['login']) . ".xml";
if (file_exists($exportname)) {
header("Content-type: text/xml");
+ $timestamp_suffix = date("Y-m-d", filemtime($exportname));
+
if (function_exists('gzencode')) {
- header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml.gz");
+ header("Content-Disposition: attachment; filename=TinyTinyRSS_exported_${timestamp_suffix}.xml.gz");
echo gzencode(file_get_contents($exportname));
} else {
- header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml");
+ header("Content-Disposition: attachment; filename=TinyTinyRSS_exported_${timestamp_suffix}.xml");
echo file_get_contents($exportname);
}
} else {
$num_processed = 0;
$num_feeds_created = 0;
+ libxml_disable_entity_loader(false);
+
$doc = @DOMDocument::load($filename);
if (!$doc) {
$doc = DOMDocument::loadXML($data);
}
+ libxml_disable_entity_loader(true);
+
if ($doc) {
$xpath = new DOMXpath($doc);
$article = array();
foreach ($article_node->childNodes as $child) {
- if ($child->nodeName != 'label_cache')
- $article[$child->nodeName] = db_escape_string($child->nodeValue);
- else
+ if ($child->nodeName == 'content') {
+ $article[$child->nodeName] = db_escape_string($child->nodeValue, false);
+ } else if ($child->nodeName == 'label_cache') {
$article[$child->nodeName] = $child->nodeValue;
+ } else {
+ $article[$child->nodeName] = db_escape_string($child->nodeValue);
+ }
}
//print_r($article);
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']));
+ $marked = $this->bool_to_sql_bool(sql_bool_to_bool($article['marked']));
+ $published = $this->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'] . "<br/>";
published, score, tag_cache, label_cache, uuid, note)
VALUES ($ref_id, $owner_uid, $feed, false,
NULL, $marked, $published, $score, '$tag_cache',
- '$label_cache', '', '$note')");
+ '', '', '$note')");
- $label_cache = json_decode($label_cache, true);
+ $label_cache = json_decode($article['label_cache'], true);
if (is_array($label_cache) && $label_cache["no-labels"] != 1) {
foreach ($label_cache as $label) {
- label_create($label[1],
+ Labels::create($label[1],
$label[2], $label[3], $owner_uid);
- label_add_article($ref_id, $label[1], $owner_uid);
+ Labels::add_article($ref_id, $label[1], $owner_uid);
}
}
print "<p>" .
__("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).
+ 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).
"</p>";
} else {
print "<div style='text-align : center'>";
if ($_FILES['export_file']['error'] != 0) {
- print_error(T_sprintf("Upload failed with error code %d",
- $_FILES['export_file']['error']));
- return;
- }
+ print_error(T_sprintf("Upload failed with error code %d (%s)",
+ $_FILES['export_file']['error'],
+ get_upload_error_message($_FILES['export_file']['error'])));
+ } else {
- $tmp_file = false;
+ $tmp_file = false;
- if (is_uploaded_file($_FILES['export_file']['tmp_name'])) {
- $tmp_file = tempnam(CACHE_DIR . '/upload', 'export');
+ if (is_uploaded_file($_FILES['export_file']['tmp_name'])) {
+ $tmp_file = tempnam(CACHE_DIR . '/upload', 'export');
- $result = move_uploaded_file($_FILES['export_file']['tmp_name'],
- $tmp_file);
+ $result = move_uploaded_file($_FILES['export_file']['tmp_name'],
+ $tmp_file);
- if (!$result) {
- print_error(__("Unable to move uploaded file."));
+ if (!$result) {
+ print_error(__("Unable to move uploaded file."));
+ return;
+ }
+ } else {
+ print_error(__('Error: please upload OPML file.'));
return;
}
- } else {
- print_error(__('Error: please upload OPML file.'));
- return;
- }
- if (is_file($tmp_file)) {
- $this->perform_data_import($tmp_file, $_SESSION['uid']);
- unlink($tmp_file);
- } else {
- print_error(__('No file uploaded.'));
- return;
+ if (is_file($tmp_file)) {
+ $this->perform_data_import($tmp_file, $_SESSION['uid']);
+ unlink($tmp_file);
+ } else {
+ print_error(__('No file uploaded.'));
+ return;
+ }
}
print "<button dojoType=\"dijit.form.Button\"
}
+ function api_version() {
+ return 2;
+ }
}
-?>