summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-03-27 18:36:48 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-03-27 18:36:48 +0100
commit51a70ede0299c7ec44431d0fe86616d8c427144e (patch)
tree9d25dc6fdebd91ab80699f0b8d7fb91788a1ca4b /app
parent72ae58d45534b4c8b49ea0ac33a9a9ec9df4bdb1 (diff)
parentc8aa451c768a3d4dfce3d19648f3c8420dedb74c (diff)
Merge branch '163-export' into dev
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/configureController.php65
-rw-r--r--app/Controllers/importExportController.php111
-rwxr-xr-xapp/actualize_script.php1
-rw-r--r--app/i18n/en.php2
-rw-r--r--app/i18n/fr.php2
-rw-r--r--app/layout/aside_feed.phtml2
-rw-r--r--app/views/configure/importExport.phtml40
-rw-r--r--app/views/helpers/export/articles.phtml30
-rw-r--r--app/views/helpers/export/opml.phtml15
-rw-r--r--app/views/importExport/index.phtml50
10 files changed, 209 insertions, 109 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 41a7920f0..bd0d0a185 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -210,71 +210,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
Minz_View::prependTitle (Minz_Translate::t ('sharing') . ' · ');
}
- public function importExportAction () {
- require_once(LIB_PATH . '/lib_opml.php');
- $catDAO = new FreshRSS_CategoryDAO ();
- $this->view->categories = $catDAO->listCategories ();
-
- $this->view->req = Minz_Request::param ('q');
-
- if ($this->view->req == 'export') {
- Minz_View::_title ('freshrss_feeds.opml');
-
- $this->view->_useLayout (false);
- header('Content-Type: application/xml; charset=utf-8');
- header('Content-disposition: attachment; filename=freshrss_feeds.opml');
-
- $feedDAO = new FreshRSS_FeedDAO ();
- $catDAO = new FreshRSS_CategoryDAO ();
-
- $list = array ();
- foreach ($catDAO->listCategories () as $key => $cat) {
- $list[$key]['name'] = $cat->name ();
- $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
- }
-
- $this->view->categories = $list;
- } elseif ($this->view->req == 'import' && Minz_Request::isPost ()) {
- if ($_FILES['file']['error'] == 0) {
- invalidateHttpCache();
- // on parse le fichier OPML pour récupérer les catégories et les flux associés
- try {
- list ($categories, $feeds) = opml_import (
- file_get_contents ($_FILES['file']['tmp_name'])
- );
-
- // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
- // les flux sont mis au préalable dans des variables de Request
- Minz_Request::_param ('q', 'null');
- Minz_Request::_param ('categories', $categories);
- Minz_Request::_param ('feeds', $feeds);
- Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
- } catch (FreshRSS_Opml_Exception $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
-
- $notif = array (
- 'type' => 'bad',
- 'content' => Minz_Translate::t ('bad_opml_file')
- );
- Minz_Session::_param ('notification', $notif);
-
- Minz_Request::forward (array (
- 'c' => 'configure',
- 'a' => 'importExport'
- ), true);
- }
- }
- }
-
- $feedDAO = new FreshRSS_FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
-
- // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
- $this->view->flux = false;
-
- Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' · ');
- }
-
public function shortcutAction () {
$list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
'escape', 'f', 'g', 'h', 'home', 'i', 'insert', 'j', 'k', 'l', 'left',
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
new file mode 100644
index 000000000..f697f4c9e
--- /dev/null
+++ b/app/Controllers/importExportController.php
@@ -0,0 +1,111 @@
+<?php
+
+class FreshRSS_importExport_Controller extends Minz_ActionController {
+ public function firstAction() {
+ if (!$this->view->loginOk) {
+ Minz_Error::error (
+ 403,
+ array ('error' => array (Minz_Translate::t ('access_denied')))
+ );
+ }
+
+ require_once(LIB_PATH . '/lib_opml.php');
+ }
+
+ public function indexAction() {
+ $catDAO = new FreshRSS_CategoryDAO ();
+ $this->view->categories = $catDAO->listCategories ();
+
+ $feedDAO = new FreshRSS_FeedDAO ();
+ $this->view->feeds = $feedDAO->listFeeds ();
+
+ // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
+ $this->view->flux = false;
+
+ Minz_View::prependTitle (Minz_Translate::t ('import_export') . ' · ');
+ }
+
+ public function importAction() {
+ if (Minz_Request::isPost() && $_FILES['file']['error'] == 0) {
+ invalidateHttpCache();
+ // on parse le fichier OPML pour récupérer les catégories et les flux associés
+ try {
+ list ($categories, $feeds) = opml_import (
+ file_get_contents ($_FILES['file']['tmp_name'])
+ );
+
+ // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
+ // les flux sont mis au préalable dans des variables de Request
+ Minz_Request::_param ('categories', $categories);
+ Minz_Request::_param ('feeds', $feeds);
+ Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
+ } catch (FreshRSS_Opml_Exception $e) {
+ Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
+
+ $notif = array (
+ 'type' => 'bad',
+ 'content' => Minz_Translate::t ('bad_opml_file')
+ );
+ Minz_Session::_param ('notification', $notif);
+
+ Minz_Request::forward (array (
+ 'c' => 'configure',
+ 'a' => 'importExport'
+ ), true);
+ }
+ }
+ }
+
+ public function exportAction() {
+ if (Minz_Request::isPost()) {
+ $this->view->_useLayout (false);
+
+ $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 ();
+
+ $list = array ();
+ foreach ($catDAO->listCategories () as $key => $cat) {
+ $list[$key]['name'] = $cat->name ();
+ $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
+ }
+
+ $this->view->categories = $list;
+ return $this->view->helperToString('export/opml');
+ }
+
+ private function generate_articles($type) {
+ // TODO: we should get articles according to $type
+ return $this->view->helperToString('export/articles');
+ }
+}
diff --git a/app/actualize_script.php b/app/actualize_script.php
index 8d81e0189..4c306b8da 100755
--- a/app/actualize_script.php
+++ b/app/actualize_script.php
@@ -28,7 +28,6 @@ foreach ($users as $myUser) {
$_SERVER['HTTP_HOST'] = '';
$freshRSS = new FreshRSS();
- $freshRSS->_useOb(false);
Minz_Configuration::_authType('none');
diff --git a/app/i18n/en.php b/app/i18n/en.php
index 7f95500ad..e9bed39a7 100644
--- a/app/i18n/en.php
+++ b/app/i18n/en.php
@@ -21,7 +21,7 @@ return array (
'your_rss_feeds' => 'Your RSS feeds',
'add_rss_feed' => 'Add a RSS feed',
'no_rss_feed' => 'No RSS feed',
- 'import_export_opml' => 'Import / export (OPML)',
+ 'import_export' => 'Import / export',
'subscription_management' => 'Subscriptions management',
'main_stream' => 'Main stream',
diff --git a/app/i18n/fr.php b/app/i18n/fr.php
index 91daa4f51..24f3741c8 100644
--- a/app/i18n/fr.php
+++ b/app/i18n/fr.php
@@ -21,7 +21,7 @@ return array (
'your_rss_feeds' => 'Vos flux RSS',
'add_rss_feed' => 'Ajouter un flux RSS',
'no_rss_feed' => 'Aucun flux RSS',
- 'import_export_opml' => 'Importer / exporter (OPML)',
+ 'import_export' => 'Importer / exporter',
'subscription_management' => 'Gestion des abonnements',
'main_stream' => 'Flux principal',
diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml
index 6f3cdafb2..899cafe02 100644
--- a/app/layout/aside_feed.phtml
+++ b/app/layout/aside_feed.phtml
@@ -44,7 +44,7 @@
</form></li>
<li class="item<?php echo Minz_Request::actionName () == 'importExport' ? ' active' : ''; ?>">
- <a href="<?php echo _url ('configure', 'importExport'); ?>"><?php echo Minz_Translate::t ('import_export_opml'); ?></a>
+ <a href="<?php echo _url ('importExport', 'index'); ?>"><?php echo Minz_Translate::t ('import_export'); ?></a>
</li>
<li class="item<?php echo Minz_Request::actionName () == 'categorize' ? ' active' : ''; ?>">
diff --git a/app/views/configure/importExport.phtml b/app/views/configure/importExport.phtml
deleted file mode 100644
index e2217d9ed..000000000
--- a/app/views/configure/importExport.phtml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-require_once(LIB_PATH . '/lib_opml.php');
-if ($this->req == 'export') {
- echo '<?xml version="1.0" encoding="UTF-8" ?>';
-?>
-<!-- Generated by <?php echo Minz_Configuration::title (); ?> -->
-<opml version="2.0">
- <head>
- <title><?php echo Minz_Configuration::title (); ?> OPML Feed</title>
- <dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
- </head>
- <body>
-<?php echo opml_export ($this->categories); ?>
- </body>
-</opml>
-<?php } else { ?>
-<?php $this->partial ('aside_feed'); ?>
-
-<div class="post ">
- <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Minz_Translate::t ('back_to_rss_feeds'); ?></a>
-
- <form method="post" action="<?php echo Minz_Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'import'))); ?>" enctype="multipart/form-data">
- <legend><?php echo Minz_Translate::t ('import_export_opml'); ?></legend>
- <div class="form-group">
- <label class="group-name" for="file"><?php echo Minz_Translate::t ('file_to_import'); ?></label>
- <div class="group-controls">
- <input type="file" name="file" id="file" />
- </div>
- </div>
-
- <div class="form-group form-actions">
- <div class="group-controls">
- <button type="submit" class="btn btn-important"><?php echo Minz_Translate::t ('import'); ?></button>
- <?php echo Minz_Translate::t ('or'); ?>
- <a target="_blank" class="btn btn-important" href="<?php echo _url ('configure', 'importExport', 'q', 'export'); ?>"><?php echo Minz_Translate::t ('export'); ?></a>
- </div>
- </div>
- </form>
-</div>
-<?php } ?>
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 @@
+<?php
+ // TODO: A lot have to be done!
+ $username = Minz_Session::param('currentUser', '_');
+ $type_id = "TODO";
+ $title = Minz_Translate::t("TODO");
+ $entries = [];
+?>{
+ "id": "user/<?php echo str_replace("\"", "", $username); ?>/state/org.freshrss/<?php echo $type_id; ?>",
+ "title": "<?php echo addslashes($title); ?>",
+ "author": "<?php echo addslashes($username); ?>",
+ "items": [
+ <?php $i = 0; foreach($entries as $entry) { $i++;
+ echo $i > 1 ? ', ': ''; ?>{
+ "id": "<?php echo $entry->id(); ?>",
+ "categories": [<?php /* TODO */ ?>],
+ "title": "<?php echo addslashes($entry->title()); ?>",
+ "published": <?php echo $entry->date(true); ?>,
+ "updated": <?php echo $entry->date(true); ?>,
+ "content": "<?php echo addslashes($entry->content()); ?>",
+ "origin": {
+ <?php /* TODO */ ?>
+ "streamId": "",
+ "title": "",
+ "htmlUrl": "",
+ "feedUrl": ""
+ }
+ }
+ <?php } ?>
+ ]
+} \ 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
+require_once(LIB_PATH . '/lib_opml.php');
+
+echo '<?xml version="1.0" encoding="UTF-8" ?>';
+?>
+<!-- Generated by <?php echo Minz_Configuration::title (); ?> -->
+<opml version="2.0">
+ <head>
+ <title><?php echo Minz_Configuration::title (); ?> OPML Feed</title>
+ <dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
+ </head>
+ <body>
+<?php echo opml_export ($this->categories); ?>
+ </body>
+</opml>
diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml
new file mode 100644
index 000000000..d8c76543e
--- /dev/null
+++ b/app/views/importExport/index.phtml
@@ -0,0 +1,50 @@
+<?php $this->partial ('aside_feed'); ?>
+
+<div class="post ">
+ <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Minz_Translate::t ('back_to_rss_feeds'); ?></a>
+
+ <form method="post" action="<?php echo _url('importExport', 'import'); ?>" enctype="multipart/form-data">
+ <legend><?php echo Minz_Translate::t ('import'); ?></legend>
+ <div class="form-group">
+ <label class="group-name" for="file"><?php echo Minz_Translate::t ('file_to_import'); ?></label>
+ <div class="group-controls">
+ <input type="file" name="file" id="file" />
+ </div>
+ </div>
+
+ <div class="form-group form-actions">
+ <div class="group-controls">
+ <button type="submit" class="btn btn-important"><?php echo Minz_Translate::t ('import'); ?></button>
+ </div>
+ </div>
+ </form>
+
+ <form method="post" action="<?php echo _url('importExport', 'export'); ?>">
+ <legend><?php echo Minz_Translate::t ('export'); ?></legend>
+ <div class="form-group">
+ <div class="group-controls">
+ <label class="checkbox" for="export_opml">
+ <input type="checkbox" name="export_opml" id="export_opml" value="1" checked="checked" />
+ <?php echo Minz_Translate::t ('export_opml'); ?>
+ </label>
+
+ <label class="checkbox" for="export_starred">
+ <input type="checkbox" name="export_starred" id="export_starred" value="1" checked="checked" />
+ <?php echo Minz_Translate::t ('export_starred'); ?>
+ </label>
+
+ <label class="checkbox" for="export_all">
+ <input type="checkbox" name="export_all" id="export_all" value="1" />
+ <?php echo Minz_Translate::t ('export_all'); ?>
+ <?php echo FreshRSS_Themes::icon('help'); ?> <?php echo Minz_Translate::t('export_all_is_long'); ?>
+ </label>
+ </div>
+ </div>
+
+ <div class="form-group form-actions">
+ <div class="group-controls">
+ <button type="submit" class="btn btn-important"><?php echo Minz_Translate::t ('export'); ?></button>
+ </div>
+ </div>
+ </form>
+</div>