summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-23 22:33:16 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-23 22:33:16 +0200
commit5383f6206c6dfc7f2fe2376c12ce8879783e3506 (patch)
tree5722d302bd43a0c74567e87aaf380f8ac11396e2
parentfca236dc6d6ff6e09182c560f3566904cbc7a70a (diff)
ajout fonction importation fichiers OPMs OPML
-rwxr-xr-xapp/controllers/configureController.php8
-rwxr-xr-xapp/controllers/entryController.php2
-rwxr-xr-xapp/controllers/feedController.php44
-rw-r--r--app/views/configure/importExport.phtml2
-rw-r--r--lib/lib_rss.php73
-rw-r--r--lib/lib_simplepie.php3
-rw-r--r--public/theme/base.css19
7 files changed, 118 insertions, 33 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
index e61eb3872..00bc571da 100755
--- a/app/controllers/configureController.php
+++ b/app/controllers/configureController.php
@@ -110,12 +110,12 @@ class configureController extends ActionController {
$this->view->categories = $list;
} elseif ($this->view->req == 'import' && Request::isPost ()) {
if ($_FILES['file']['error'] == 0) {
- $content = file_get_contents ($_FILES['file']['tmp_name']);
- $feeds = opml_import ($content);
+ list ($categories, $feeds) = opml_import (file_get_contents ($_FILES['file']['tmp_name']));
- Request::_param ('q');
+ Request::_param ('q', 'null');
+ Request::_param ('categories', $categories);
Request::_param ('feeds', $feeds);
- Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
+ Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
}
}
}
diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php
index 9ae7bcd07..a99038068 100755
--- a/app/controllers/entryController.php
+++ b/app/controllers/entryController.php
@@ -26,7 +26,7 @@ class entryController extends ActionController {
$entryDAO = new EntryDAO ();
if ($id == false) {
- $entries = $entryDAO->listNotReadEntries ();
+ $entries = $entryDAO->listEntries ('not_read');
} else {
$entry = $entryDAO->searchById ($id);
$entries = $entry !== false ? array ($entry) : array ();
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
index 0a56af2ac..789d2a901 100755
--- a/app/controllers/feedController.php
+++ b/app/controllers/feedController.php
@@ -96,16 +96,56 @@ class feedController extends ActionController {
Request::forward (array (), true);
}
- public function massiveImport () {
+ public function massiveImportAction () {
+ $entryDAO = new EntryDAO ();
$feedDAO = new FeedDAO ();
+ $catDAO = new CategoryDAO ();
+
+ $categories = Request::param ('categories', array ());
$feeds = Request::param ('feeds', array ());
+ foreach ($categories as $cat) {
+ $values = array (
+ 'id' => $cat->id (),
+ 'name' => $cat->name (),
+ 'color' => $cat->color ()
+ );
+ $catDAO->addCategory ($values);
+ $catDAO->save ();
+ }
+
foreach ($feeds as $feed) {
+ $feed->load ();
+ $entries = $feed->entries (false);
+ $feed_entries = array ();
+
+ // Chargement du flux
+ if ($entries !== false) {
+ foreach ($entries as $entry) {
+ $values = array (
+ 'id' => $entry->id (),
+ 'guid' => $entry->guid (),
+ 'title' => $entry->title (),
+ 'author' => $entry->author (),
+ 'content' => $entry->content (),
+ 'link' => $entry->link (),
+ 'date' => $entry->date (true),
+ 'is_read' => $entry->isRead (),
+ 'is_favorite' => $entry->isFavorite (),
+ 'feed' => $feed->id ()
+ );
+ $entryDAO->addEntry ($values);
+
+ $feed_entries[] = $entry->id ();
+ }
+ }
+
+ // Enregistrement du flux
$values = array (
'id' => $feed->id (),
'url' => $feed->url (),
'category' => $feed->category (),
- 'entries' => array (),
+ 'entries' => $feed_entries,
'name' => $feed->name (),
'website' => $feed->website (),
'description' => $feed->description (),
diff --git a/app/views/configure/importExport.phtml b/app/views/configure/importExport.phtml
index 7f2fbd7c5..add78d1e1 100644
--- a/app/views/configure/importExport.phtml
+++ b/app/views/configure/importExport.phtml
@@ -14,7 +14,7 @@
<form method="post" action="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'import'))); ?>" 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>
+ <button formaction="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'export'))); ?>">Exporter</button>
<h1>Importer au format OPML</h1>
<label for="file">Fichier</label>
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 74a86558c..7d01a4a0f 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -1,13 +1,12 @@
<?php
// tiré de Shaarli de Seb Sauvage
function small_hash ($txt) {
+ $t = rtrim (base64_encode (hash ('crc32', $txt, true)), '=');
+ $t = str_replace ('+', '-', $t); // Get rid of characters which need encoding in URLs.
+ $t = str_replace ('/', '_', $t);
+ $t = str_replace ('=', '@', $t);
- $t = rtrim (base64_encode (hash ('crc32', $txt, true)), '=');
- $t = str_replace ('+', '-', $t); // Get rid of characters which need encoding in URLs.
- $t = str_replace ('/', '_', $t);
- $t = str_replace ('=', '@', $t);
-
- return $t;
+ return $t;
}
function timestamptodate ($t, $hour = true) {
@@ -90,5 +89,65 @@ function opml_export ($cats) {
}
function opml_import ($xml) {
- // TODO
+ $opml = @simplexml_load_string ($xml);
+
+ if (!$opml) {
+ return array (array (), array ());
+ }
+
+ $categories = array ();
+ $feeds = array ();
+
+ foreach ($opml->body->outline as $outline) {
+ if (!isset ($outline['xmlUrl'])) {
+ // Catégorie
+ $title = '';
+
+ if (isset ($outline['text'])) {
+ $title = (string) $outline['text'];
+ } elseif (isset ($outline['title'])) {
+ $title = (string) $outline['title'];
+ }
+
+ if ($title) {
+ $cat = new Category ($title);
+ $categories[] = $cat;
+
+ $feeds = array_merge ($feeds, getFeedsOutline ($outline, $cat->id ()));
+ }
+ } else {
+ // Flux rss
+ $feeds[] = getFeed ($outline, '');
+ }
+ }
+
+ return array ($categories, $feeds);
+}
+
+/**
+ * import all feeds of a given outline tag
+ */
+function getFeedsOutline ($outline, $cat_id) {
+ $feeds = array ();
+
+ foreach ($outline->children () as $child) {
+ if (isset ($child['xmlUrl'])) {
+ $feeds[] = getFeed ($child, $cat_id);
+ } else {
+ $feeds = array_merge(
+ $feeds,
+ getFeedsOutline ($child, $cat_id)
+ );
+ }
+ }
+
+ return $feeds;
+}
+
+function getFeed ($outline, $cat_id) {
+ $url = (string) $outline['xmlUrl'];
+ $feed = new Feed ($url);
+ $feed->_category ($cat_id);
+
+ return $feed;
}
diff --git a/lib/lib_simplepie.php b/lib/lib_simplepie.php
index 178378297..6f7aac1ef 100644
--- a/lib/lib_simplepie.php
+++ b/lib/lib_simplepie.php
@@ -5184,6 +5184,9 @@ class SimplePie_IRI
{
$match['fragment'] = null;
}
+
+ $match['path'] = preg_replace ('#//#', '/', $match['path']); // fix un bug lorsque 2 slashs se suivent
+
return $match;
}
else
diff --git a/public/theme/base.css b/public/theme/base.css
index e4bb55081..f15c51826 100644
--- a/public/theme/base.css
+++ b/public/theme/base.css
@@ -14,23 +14,6 @@ a {
a:hover {
text-decoration: underline;
}
- a.add, a.update, a.delete, a.back {
- height: 30px;
- padding: 0 20px;
- line-height: 30px;
- }
- a.add {
- background: url("img/add.png") no-repeat left 3px;
- }
- a.update {
- background: url("img/update.png") no-repeat left 3px;
- }
- a.delete {
- background: url("img/delete.png") no-repeat left 3px;
- }
- a.back {
- background: url("img/back.png") no-repeat left 5px;
- }
/* LISTES */
ul, ol {
@@ -89,7 +72,7 @@ form {
line-height: 150%;
font-family: Monospace;
}
- input[type="submit"] {
+ input[type="submit"], button {
width: 100%;
margin: 5px 0 5px;
padding: 5px 0;