Explorar el Código

Move import/export operations into an independant class

- import and export are now two methods of importExportController
- "opml" has been removed from the title
Marien Fressinaud hace 12 años
padre
commit
dbdda1d0c1

+ 0 - 65
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',

+ 77 - 0
app/Controllers/importExportController.php

@@ -0,0 +1,77 @@
+<?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() {
+		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;
+	}
+}

+ 1 - 1
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',

+ 1 - 1
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',

+ 1 - 1
app/layout/aside_feed.phtml

@@ -39,7 +39,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' : ''; ?>">

+ 0 - 40
app/views/configure/importExport.phtml

@@ -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 } ?>

+ 15 - 0
app/views/importExport/export.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>

+ 23 - 0
app/views/importExport/index.phtml

@@ -0,0 +1,23 @@
+<?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_export'); ?></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 ('importExport', 'export'); ?>"><?php echo Minz_Translate::t ('export'); ?></a>
+			</div>
+		</div>
+	</form>
+</div>