From 9a95cb844e80512205c519da69ec373e046b7f52 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 22 Oct 2012 23:41:56 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20gestion=20import=20(non=20fonction?= =?UTF-8?q?nel)=20/=20export=20(presque=20fonctionnel)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/configureController.php | 22 ++++++++ app/controllers/feedController.php | 20 +++++++ app/controllers/javascriptController.php | 1 + app/layout/aside.phtml | 3 ++ app/views/configure/display.phtml | 66 ++++++++++++------------ app/views/configure/importExport.phtml | 24 +++++++++ lib/lib_rss.php | 17 ++++++ 7 files changed, 119 insertions(+), 34 deletions(-) create mode 100644 app/views/configure/importExport.phtml 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 @@
  • > Affichage
  • +
  • > + Import / Export OPML +
  • 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 @@ -
    -
    -

    Configuration de l'affichage

    - - - - - -
    - conf->defaultView () == 'all' ? ' checked="checked"' : ''; ?> /> - -
    - conf->defaultView () == 'not_read' ? ' checked="checked"' : ''; ?> /> - -
    - - - - - -
    - conf->displayPosts () == 'yes' ? ' checked="checked"' : ''; ?> /> - -
    - conf->displayPosts () == 'no' ? ' checked="checked"' : ''; ?> /> - -
    - - -
    -
    +
    +

    Configuration de l'affichage

    + + + + + +
    + conf->defaultView () == 'all' ? ' checked="checked"' : ''; ?> /> + +
    + conf->defaultView () == 'not_read' ? ' checked="checked"' : ''; ?> /> + +
    + + + + + +
    + conf->displayPosts () == 'yes' ? ' checked="checked"' : ''; ?> /> + +
    + conf->displayPosts () == 'no' ? ' checked="checked"' : ''; ?> /> + +
    + + +
    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 @@ +req == 'export') { ?> + + + + + <?php echo Configuration::title (); ?> OPML Feed + + + +feeds); ?> + + + + +
    +

    Exporter au format OPML

    + Exporter + +

    Importer au format OPML

    + + + +
    + 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 = '' . "\n"; + + foreach ($feeds as $feed) { + $txt .= "\t" . '' . "\n"; + } + + $txt .= '' . "\n"; + + return $txt; +} + +function opml_import ($xml) { + // TODO +}