diff --git a/plugins/greaderstarredimport/init.js b/plugins/greaderstarredimport/init.js new file mode 100644 index 000000000..e7057d82a --- /dev/null +++ b/plugins/greaderstarredimport/init.js @@ -0,0 +1,53 @@ +function starredImportComplete(iframe) { + try { + if (!iframe.contentDocument.body.innerHTML) return false; + + Element.show(iframe); + + notify(''); + + if (dijit.byId('starredImportDlg')) + dijit.byId('starredImportDlg').destroyRecursive(); + + var content = iframe.contentDocument.body.innerHTML; + + if (content) Element.hide(iframe); + + dialog = new dijit.Dialog({ + id: "starredImportDlg", + title: __("OPML Import"), + style: "width: 600px", + onCancel: function() { + Element.hide(iframe); + this.hide(); + }, + execute: function() { + Element.hide(iframe); + this.hide(); + }, + content: content}); + + dialog.show(); + + } catch (e) { + exception_error("starredImportComplete", e); + } +} + +function starredImport() { + + var starred_file = $("starred_file"); + + if (starred_file.value.length == 0) { + alert(__("Please choose a file first.")); + return false; + } else { + notify_progress("Importing, please wait...", true); + + Element.show("starred_upload_iframe"); + + return true; + } +} + + diff --git a/plugins/greaderstarredimport/init.php b/plugins/greaderstarredimport/init.php new file mode 100644 index 000000000..2c374d991 --- /dev/null +++ b/plugins/greaderstarredimport/init.php @@ -0,0 +1,168 @@ +link = $host->get_link(); + $this->host = $host; + + $host->add_hook($host::HOOK_PREFS_TAB, $this); + } + + function get_prefs_js() { + return file_get_contents(dirname(__FILE__) . "/init.js"); + } + + function import() { + + header("Content-Type: text/html"); + + if (is_file($_FILES['starred_file']['tmp_name'])) { + $doc = json_decode(file_get_contents($_FILES['starred_file']['tmp_name']), true); + } else { + print_error(__('No file uploaded.')); + return; + } + + if ($doc) { + if (isset($doc['items'])) { + $processed = 0; + + foreach ($doc['items'] as $item) { +// print_r($item); + + $guid = db_escape_string($this->link, $item['id']); + $title = db_escape_string($this->link, $item['title']); + $updated = date('Y-m-d h:i:s', $item['updated']); + $link = ''; + $content = ''; + $author = db_escape_string($this->link, $item['author']); + + if (is_array($item['alternate'])) { + foreach ($item['alternate'] as $alt) { + if (isset($alt['type']) && $alt['type'] == 'text/html') { + $link = db_escape_string($this->link, $alt['href']); + } + } + } + + if (is_array($item['content'])) { + $content = db_escape_string($this->link, + $item['content']['content'], false); + } + + $processed++; + + $imported += (int) $this->create_article($guid, $title, + $updated, $link, $content, $author); + + } + + print "
" . T_sprintf("All done. %d out of %d articles imported.", $imported, $processed) . "
"; + + } else { + print_error(__('The document has incorrect format.')); + } + + } else { + print_error(__('Error while parsing document.')); + } + + print "".__("Paste your starred.json into the form below."). "
"; + + print ""; + + print "