Просмотр исходного кода

Début gestion import (non fonctionnel) / export (presque fonctionnel)

Marien Fressinaud 13 лет назад
Родитель
Сommit
9a95cb844e

+ 22 - 0
app/controllers/configureController.php

@@ -88,4 +88,26 @@ class configureController extends ActionController {
 			Session::_param ('conf', $this->view->conf);
 		}
 	}
+	
+	public function importExportAction () {
+		$this->view->req = Request::param ('q');
+		
+		if ($this->view->req == 'export') {
+			View::_title ('feeds_opml.xml');
+			
+			$this->view->_useLayout (false);
+			header('Content-type: text/xml');
+			
+			$feedDAO = new FeedDAO ();
+			$this->view->feeds = $feedDAO->listFeeds ();
+		} elseif (Request::isPost ()) {
+			if ($_FILES['file']['error'] == 0) {
+				$content = file_get_contents ($_FILES['file']['tmp_name']);
+				$feeds = opml_import ($content);
+				
+				Request::_param ('feeds', $feeds);
+				Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
+			}
+		}
+	}
 }

+ 20 - 0
app/controllers/feedController.php

@@ -95,4 +95,24 @@ class feedController extends ActionController {
 		
 		Request::forward (array (), true);
 	}
+	
+	public function massiveImport () {
+		$feedDAO = new FeedDAO ();
+		$feeds = Request::param ('feeds', array ());
+		
+		foreach ($feeds as $feed) {
+			$values = array (
+				'id' => $feed->id (),
+				'url' => $feed->url (),
+				'category' => $feed->category (),
+				'entries' => array (),
+				'name' => $feed->name (),
+				'website' => $feed->website (),
+				'description' => $feed->description (),
+			);
+			$feedDAO->addFeed ($values);
+		}
+	
+		Request::forward (array ('c' => 'configure', 'a' => 'importExport'));
+	}
 }

+ 1 - 0
app/controllers/javascriptController.php

@@ -3,6 +3,7 @@
 class javascriptController extends ActionController {
 	public function firstAction () {
 		$this->view->_useLayout (false);
+		header('Content-type: text/javascript');
 	}
 	
 	public function mainAction () {

+ 3 - 0
app/layout/aside.phtml

@@ -30,6 +30,9 @@
 		<li <?php echo Request::actionName () == 'display' ? 'class="active"' : ''; ?>>
 			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'display')); ?>">Affichage</a>
 		</li>
+		<li <?php echo Request::actionName () == 'importExport' ? 'class="active"' : ''; ?>>
+			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport')); ?>">Import / Export OPML</a>
+		</li>
 	</ul>
 </div>
 <?php } ?>

+ 32 - 34
app/views/configure/display.phtml

@@ -1,34 +1,32 @@
-<div class="post">
-	<form method="post" action="">
-		<h1>Configuration de l'affichage</h1>
-		
-		<label for="posts_per_page">Nombre d'articles par page</label>
-		<input type="number" id="posts_per_page" name="posts_per_page" value="<?php echo $this->conf->postsPerPage (); ?>" />
-		
-		<label>Vue par défaut</label>
-		<div class="radio_group">
-			<input type="radio" name="default_view" id="radio_all" value="all"<?php echo $this->conf->defaultView () == 'all' ? ' checked="checked"' : ''; ?> />
-			<label for="radio_all">Tout afficher</label>
-			<br />
-			<input type="radio" name="default_view" id="radio_not_read" value="not_read"<?php echo $this->conf->defaultView () == 'not_read' ? ' checked="checked"' : ''; ?> />
-			<label for="radio_not_read">Afficher les non lus</label>
-		</div>
-		
-		<label for="sort_order">Ordre de tri</label>
-		<select name="sort_order" id="sort_order">
-			<option value="low_to_high"<?php echo $this->conf->sortOrder () == 'low_to_high' ? ' selected="selected"' : ''; ?>>Du plus récent au plus ancien</option>
-			<option value="high_to_low"<?php echo $this->conf->sortOrder () == 'high_to_low' ? ' selected="selected"' : ''; ?>>Du plus ancien au plus récent</option>
-		</select>
-		
-		<label>Afficher les articles dépliés par défaut</label>
-		<div class="radio_group">
-			<input type="radio" name="display_posts" id="radio_yes" value="yes"<?php echo $this->conf->displayPosts () == 'yes' ? ' checked="checked"' : ''; ?> />
-			<label for="radio_yes">Oui</label>
-			<br />
-			<input type="radio" name="display_posts" id="radio_no" value="no"<?php echo $this->conf->displayPosts () == 'no' ? ' checked="checked"' : ''; ?> />
-			<label for="radio_no">Non<noscript> - <strong>nécessite que javascript soit activé</strong></noscript></label>
-		</div>
-		
-		<input type="submit" value="Valider" />
-	</form>
-</div>
+<form method="post" action="">
+	<h1>Configuration de l'affichage</h1>
+	
+	<label for="posts_per_page">Nombre d'articles par page</label>
+	<input type="number" id="posts_per_page" name="posts_per_page" value="<?php echo $this->conf->postsPerPage (); ?>" />
+	
+	<label>Vue par défaut</label>
+	<div class="radio_group">
+		<input type="radio" name="default_view" id="radio_all" value="all"<?php echo $this->conf->defaultView () == 'all' ? ' checked="checked"' : ''; ?> />
+		<label for="radio_all">Tout afficher</label>
+		<br />
+		<input type="radio" name="default_view" id="radio_not_read" value="not_read"<?php echo $this->conf->defaultView () == 'not_read' ? ' checked="checked"' : ''; ?> />
+		<label for="radio_not_read">Afficher les non lus</label>
+	</div>
+	
+	<label for="sort_order">Ordre de tri</label>
+	<select name="sort_order" id="sort_order">
+		<option value="low_to_high"<?php echo $this->conf->sortOrder () == 'low_to_high' ? ' selected="selected"' : ''; ?>>Du plus récent au plus ancien</option>
+		<option value="high_to_low"<?php echo $this->conf->sortOrder () == 'high_to_low' ? ' selected="selected"' : ''; ?>>Du plus ancien au plus récent</option>
+	</select>
+	
+	<label>Afficher les articles dépliés par défaut</label>
+	<div class="radio_group">
+		<input type="radio" name="display_posts" id="radio_yes" value="yes"<?php echo $this->conf->displayPosts () == 'yes' ? ' checked="checked"' : ''; ?> />
+		<label for="radio_yes">Oui</label>
+		<br />
+		<input type="radio" name="display_posts" id="radio_no" value="no"<?php echo $this->conf->displayPosts () == 'no' ? ' checked="checked"' : ''; ?> />
+		<label for="radio_no">Non<noscript> - <strong>nécessite que javascript soit activé</strong></noscript></label>
+	</div>
+	
+	<input type="submit" value="Valider" />
+</form>

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

@@ -0,0 +1,24 @@
+<?php if ($this->req == 'export') { ?>
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Generated by <?php echo Configuration::title (); ?> -->
+<opml version="2.0">
+	<head>
+		<title><?php echo Configuration::title (); ?> OPML Feed</title>
+		<dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
+	</head>
+	<body>
+<?php echo opml_export ($this->feeds); ?>
+	</body>
+</opml>
+<?php } else { ?>
+
+<form method="post" action="" enctype="multipart/form-data">
+	<h1>Exporter au format OPML</h1>
+	<a class="button" href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'export'))); ?>">Exporter</a>
+	
+	<h1>Importer au format OPML</h1>
+	<label for="file">Fichier</label>
+	<input type="file" name="file" id="file" />
+	<input type="submit" value="Charger" />
+</form>
+<?php } ?>

+ 17 - 0
lib/lib_rss.php

@@ -68,3 +68,20 @@ function sortEntriesByDate ($entry1, $entry2) {
 function sortReverseEntriesByDate ($entry1, $entry2) {
 	return $entry1->date (true) - $entry2->date (true);
 }
+
+function opml_export ($feeds) {
+	// TODO gérer les catégories
+	$txt = '<outline text="default">' . "\n";
+	
+	foreach ($feeds as $feed) {
+		$txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" />' . "\n";
+	}
+	
+	$txt .= '</outline>' . "\n";
+	
+	return $txt;
+}
+
+function opml_import ($xml) {
+	// TODO
+}