summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-22 23:41:56 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-22 23:41:56 +0200
commit9a95cb844e80512205c519da69ec373e046b7f52 (patch)
treef153ffbf6952c925227581501ed25fcb94230801
parenta928ebf1d010433d81d3afe5a6981f7ca391b9c7 (diff)
Début gestion import (non fonctionnel) / export (presque fonctionnel)
-rwxr-xr-xapp/controllers/configureController.php22
-rwxr-xr-xapp/controllers/feedController.php20
-rwxr-xr-xapp/controllers/javascriptController.php1
-rw-r--r--app/layout/aside.phtml3
-rw-r--r--app/views/configure/display.phtml66
-rw-r--r--app/views/configure/importExport.phtml24
-rw-r--r--lib/lib_rss.php17
7 files changed, 119 insertions, 34 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
index 5642ef547..c501e5242 100755
--- a/app/controllers/configureController.php
+++ b/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'));
+ }
+ }
+ }
}
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
index 5bf7d9ec6..0a56af2ac 100755
--- a/app/controllers/feedController.php
+++ b/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'));
+ }
}
diff --git a/app/controllers/javascriptController.php b/app/controllers/javascriptController.php
index 8a2f4e761..8060f560c 100755
--- a/app/controllers/javascriptController.php
+++ b/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 () {
diff --git a/app/layout/aside.phtml b/app/layout/aside.phtml
index db4c482c1..b154c5ea3 100644
--- a/app/layout/aside.phtml
+++ b/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 } ?>
diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml
index 5b25a51fc..a5bb085c4 100644
--- a/app/views/configure/display.phtml
+++ b/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>
diff --git a/app/views/configure/importExport.phtml b/app/views/configure/importExport.phtml
new file mode 100644
index 000000000..634800157
--- /dev/null
+++ b/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 } ?>
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 0cfecf3f3..c695b64b7 100644
--- a/lib/lib_rss.php
+++ b/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
+}