diff --git a/cache/export/.empty b/cache/export/.empty
new file mode 100755
index 000000000..e69de29bb
diff --git a/classes/dlg.php b/classes/dlg.php
index bd18f54dc..2d1cb9cc5 100644
--- a/classes/dlg.php
+++ b/classes/dlg.php
@@ -16,6 +16,24 @@ class Dlg extends Protected_Handler {
print "";
}
+ function exportData() {
+
+ print "
You need to prepare exported data first by clicking the button below.
";
+
+ print "";
+ print "
";
+
+ print "
" . __("OPML") . "
";
+
+ print "
" . __("Import") . "
";
print "
" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
- print "" . __("Note: Only main settings profile can be migrated using OPML.") . "";
-
- print "
";
-
- print "
" . __("Import") . "
";
+ print __("Only main settings profile can be migrated using OPML.") . "";
print "
"; # pane
if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
diff --git a/classes/rpc.php b/classes/rpc.php
index 4cdaef935..497b1a55d 100644
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -2,7 +2,7 @@
class RPC extends Protected_Handler {
function csrf_ignore($method) {
- $csrf_ignored = array("sanitycheck", "buttonplugin");
+ $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget");
return array_search($method, $csrf_ignored) !== false;
}
@@ -14,6 +14,83 @@ class RPC extends Protected_Handler {
$_SESSION["prefs_cache"] = array();
}
+ function exportget() {
+ $exportname = CACHE_DIR . "/export/" .
+ sha1($_SESSION['uid'] . $_SESSION['login']) . ".xml";
+
+ if (file_exists($exportname)) {
+ header("Content-type: text/xml");
+ header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml");
+
+ echo file_get_contents($exportname);
+ } else {
+ echo "File not found.";
+ }
+ }
+
+ function exportrun() {
+ $offset = (int) db_escape_string($_REQUEST['offset']);
+ $exported = 0;
+ $limit = 250;
+
+ if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) {
+ $result = db_query($this->link, "SELECT
+ ttrss_entries.guid,
+ ttrss_entries.title,
+ content,
+ marked,
+ published,
+ score,
+ note,
+ tag_cache,
+ label_cache,
+ ttrss_feeds.title AS feed_title,
+ ttrss_feeds.feed_url AS feed_url,
+ ttrss_entries.updated
+ FROM
+ ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id),
+ ttrss_entries
+ WHERE
+ (marked = true OR feed_id IS NULL) AND
+ ref_id = ttrss_entries.id AND
+ ttrss_user_entries.owner_uid = " . $_SESSION['uid'] . "
+ ORDER BY ttrss_entries.id LIMIT $limit OFFSET $offset");
+
+ $exportname = sha1($_SESSION['uid'] . $_SESSION['login']);
+
+ if ($offset == 0) {
+ $fp = fopen(CACHE_DIR . "/export/$exportname.xml", "w");
+ fputs($fp, "
");
+ } else {
+ $fp = fopen(CACHE_DIR . "/export/$exportname.xml", "a");
+ }
+
+ if ($fp) {
+
+ while ($line = db_fetch_assoc($result)) {
+ fputs($fp, "");
+
+ foreach ($line as $k => $v) {
+ fputs($fp, "<$k>$k>");
+ }
+
+ fputs($fp, "");
+ }
+
+ $exported = db_num_rows($result);
+
+ if ($exported < $limit && $exported > 0) {
+ fputs($fp, "");
+ }
+
+ fclose($fp);
+ }
+
+ }
+
+ print json_encode(array("exported" => $exported));
+ }
+
function remprofiles() {
$ids = explode(",", db_escape_string(trim($_REQUEST["ids"])));
diff --git a/include/sanity_check.php b/include/sanity_check.php
index c12c09334..4fe28c307 100644
--- a/include/sanity_check.php
+++ b/include/sanity_check.php
@@ -21,6 +21,14 @@
$err_msg = "HTMLPurifier cache directory should be writable by anyone (chmod -R 777 $purifier_cache_dir)";
}
+ if (!is_writable(CACHE_DIR . "/images")) {
+ $err_msg = "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)";
+ }
+
+ if (!is_writable(CACHE_DIR . "/export")) {
+ $err_msg = "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)";
+ }
+
if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
$err_msg = "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh";
}
diff --git a/js/prefs.js b/js/prefs.js
index 27598285c..7f9e44ad5 100644
--- a/js/prefs.js
+++ b/js/prefs.js
@@ -1935,3 +1935,81 @@ function showHelp() {
exception_error("showHelp", e);
}
}
+
+function exportData() {
+ try {
+
+ var query = "backend.php?op=dlg&method=exportData";
+
+ if (dijit.byId("dataExportDlg"))
+ dijit.byId("dataExportDlg").destroyRecursive();
+
+ var exported = 0;
+
+ dialog = new dijit.Dialog({
+ id: "dataExportDlg",
+ title: __("Export Data"),
+ style: "width: 600px",
+ prepare: function() {
+
+ notify_progress("Loading, please wait...");
+
+ new Ajax.Request("backend.php", {
+ parameters: "?op=rpc&method=exportrun&offset=" + exported,
+ onComplete: function(transport) {
+ try {
+ var rv = JSON.parse(transport.responseText);
+
+ if (rv && rv.exported != undefined) {
+ if (rv.exported > 0) {
+
+ exported += rv.exported;
+
+ $("export_status_message").innerHTML =
+ "
" +
+ "Exported %d articles, please wait...".replace("%d",
+ exported);
+
+ setTimeout('dijit.byId("dataExportDlg").prepare()', 2000);
+
+ } else {
+
+ $("export_status_message").innerHTML =
+ __("Finished, exported %d articles. You can download the data
here.")
+ .replace("%d", exported)
+ .replace("%u", "backend.php?op=rpc&subop=exportget");
+
+ exported = 0;
+
+ }
+
+ } else {
+ $("export_status_message").innerHTML =
+ "Error occured, could not export data.";
+ }
+ } catch (e) {
+ exception_error("exportData", e, transport.responseText);
+ }
+
+ notify('');
+
+ } });
+
+ },
+ execute: function() {
+ if (this.validate()) {
+
+
+
+ }
+ },
+ href: query});
+
+ dialog.show();
+
+
+ } catch (e) {
+ exception_error("exportData", e);
+ }
+}
+