From d1c5db7461ecb69c529149536718baf9b73a1f2c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 18 Mar 2014 22:42:47 +0100 Subject: New version to export articles + opml It does not work yet! A lot of work has still to be done. Next versions should fix TODOs - OPML export works fine but can be improved - a framework has been created for articles export --- app/Controllers/importExportController.php | 48 +++++++++++++++++++++++++++--- app/views/helpers/export/articles.phtml | 30 +++++++++++++++++++ app/views/helpers/export/opml.phtml | 15 ++++++++++ app/views/importExport/export.phtml | 15 ---------- app/views/importExport/index.phtml | 33 ++++++++++++++++++-- 5 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 app/views/helpers/export/articles.phtml create mode 100644 app/views/helpers/export/opml.phtml delete mode 100644 app/views/importExport/export.phtml (limited to 'app') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 7ed142b33..458814676 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -57,12 +57,40 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } public function exportAction() { - Minz_View::_title ('freshrss_feeds.opml'); + if (Minz_Request::isPost()) { + $this->view->_useLayout (false); - $this->view->_useLayout (false); - header('Content-Type: application/xml; charset=utf-8'); - header('Content-disposition: attachment; filename=freshrss_feeds.opml'); + $export_opml = Minz_Request::param('export_opml', false); + $export_starred = Minz_Request::param('export_starred', false); + $export_all = Minz_Request::param('export_all', false); + // code from https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly + $file = tempnam("tmp", "zip"); + $zip = new ZipArchive(); + $zip->open($file, ZipArchive::OVERWRITE); + + // Stuff with content + if ($export_opml) { + $zip->addFromString('feeds.opml', $this->generate_opml()); + } + if ($export_starred) { + $zip->addFromString('starred.json', $this->generate_articles('starred')); + } + if ($export_all) { + $zip->addFromString('all.json', $this->generate_articles('all')); + } + + // Close and send to users + $zip->close(); + header('Content-Type: application/zip'); + header('Content-Length: ' . filesize($file)); + header('Content-Disposition: attachment; filename="freshrss_export.zip"'); + readfile($file); + unlink($file); + } + } + + private function generate_opml() { $feedDAO = new FreshRSS_FeedDAO (); $catDAO = new FreshRSS_CategoryDAO (); @@ -73,5 +101,17 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $this->view->categories = $list; + + // TODO: add a parameter to renderHelper in order to get a variable + ob_start(); + $this->view->renderHelper('export/opml'); + return ob_get_clean(); + } + + private function generate_articles($type) { + // TODO: same here + we should get articles according to $type + ob_start(); + $this->view->renderHelper('export/articles'); + return ob_get_clean(); } } diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml new file mode 100644 index 000000000..b7df58caf --- /dev/null +++ b/app/views/helpers/export/articles.phtml @@ -0,0 +1,30 @@ +{ + "id": "user//state/org.freshrss/", + "title": "", + "author": "", + "items": [ + 1 ? ', ': ''; ?>{ + "id": "id(); ?>", + "categories": [], + "title": "title()); ?>", + "published": date(true); ?>, + "updated": date(true); ?>, + "content": "content()); ?>", + "origin": { + + "streamId": "", + "title": "", + "htmlUrl": "", + "feedUrl": "" + } + } + + ] +} \ No newline at end of file diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml new file mode 100644 index 000000000..2e66e5054 --- /dev/null +++ b/app/views/helpers/export/opml.phtml @@ -0,0 +1,15 @@ +'; +?> + + + + <?php echo Minz_Configuration::title (); ?> OPML Feed + + + +categories); ?> + + diff --git a/app/views/importExport/export.phtml b/app/views/importExport/export.phtml deleted file mode 100644 index 2e66e5054..000000000 --- a/app/views/importExport/export.phtml +++ /dev/null @@ -1,15 +0,0 @@ -'; -?> - - - - <?php echo Minz_Configuration::title (); ?> OPML Feed - - - -categories); ?> - - diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index c7db752a7..d8c76543e 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -4,7 +4,7 @@
- +
@@ -15,8 +15,35 @@
- - +
+
+ + +
+ +
+
+ + + + + +
+
+ +
+
+
-- cgit v1.2.3