aboutsummaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-21 18:47:57 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-21 18:47:57 +0200
commitfb57be5a5af3a2fb46b2dbf2b503ffe78eb5cf49 (patch)
tree9440fc7846d8a56a7005b9ef029669c96ad959aa /app/controllers
First commit
Diffstat (limited to 'app/controllers')
-rwxr-xr-xapp/controllers/configureController.php33
-rwxr-xr-xapp/controllers/entryController.php58
-rw-r--r--app/controllers/errorController.php26
-rwxr-xr-xapp/controllers/feedController.php89
-rwxr-xr-xapp/controllers/indexController.php34
5 files changed, 240 insertions, 0 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
new file mode 100755
index 000000000..0f5d6b658
--- /dev/null
+++ b/app/controllers/configureController.php
@@ -0,0 +1,33 @@
+<?php
+
+class configureController extends ActionController {
+ public function categorizeAction () {
+
+ }
+
+ public function fluxAction () {
+
+ }
+
+ public function displayAction () {
+ if (Request::isPost ()) {
+ $nb = Request::param ('posts_per_page', 10);
+ $view = Request::param ('default_view', 'all');
+ $display = Request::param ('display_posts', 'no');
+
+ $this->view->conf->_postsPerPage (intval ($nb));
+ $this->view->conf->_defaultView ($view);
+ $this->view->conf->_displayPosts ($display);
+
+ $values = array (
+ 'posts_per_page' => $this->view->conf->postsPerPage (),
+ 'default_view' => $this->view->conf->defaultView (),
+ 'display_posts' => $this->view->conf->displayPosts ()
+ );
+
+ $confDAO = new RSSConfigurationDAO ();
+ $confDAO->save ($values);
+ Session::_param ('conf', $this->view->conf);
+ }
+ }
+}
diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php
new file mode 100755
index 000000000..e180cc7f1
--- /dev/null
+++ b/app/controllers/entryController.php
@@ -0,0 +1,58 @@
+<?php
+
+class entryController extends ActionController {
+ public function readAction () {
+ $id = Request::param ('id');
+ $is_read = Request::param ('is_read');
+
+ if ($is_read) {
+ $is_read = true;
+ } else {
+ $is_read = false;
+ }
+
+ $entryDAO = new EntryDAO ();
+ if ($id == false) {
+ $entries = $entryDAO->listNotReadEntries ();
+ } else {
+ $entry = $entryDAO->searchById ($id);
+ $entries = $entry !== false ? array ($entry) : array ();
+ }
+
+ foreach ($entries as $entry) {
+ $values = array (
+ 'is_read' => $is_read,
+ );
+
+ $entryDAO->updateEntry ($entry->id (), $values);
+ }
+
+ Request::forward (array (), true);
+ }
+
+ public function bookmarkAction () {
+ $id = Request::param ('id');
+ $is_fav = Request::param ('is_favorite');
+
+ if ($is_fav) {
+ $is_fav = true;
+ } else {
+ $is_fav = false;
+ }
+
+ $entryDAO = new EntryDAO ();
+ if ($id != false) {
+ $entry = $entryDAO->searchById ($id);
+
+ if ($entry != false) {
+ $values = array (
+ 'is_favorite' => $is_fav,
+ );
+
+ $entryDAO->updateEntry ($entry->id (), $values);
+ }
+ }
+
+ Request::forward (array (), true);
+ }
+}
diff --git a/app/controllers/errorController.php b/app/controllers/errorController.php
new file mode 100644
index 000000000..3b6f202ab
--- /dev/null
+++ b/app/controllers/errorController.php
@@ -0,0 +1,26 @@
+<?php
+
+class ErrorController extends ActionController {
+ public function indexAction () {
+ View::prependTitle (Translate::t ('error') . ' - ');
+
+ switch (Request::param ('code')) {
+ case 403:
+ $this->view->code = 'Error 403 - Forbidden';
+ break;
+ case 404:
+ $this->view->code = 'Error 404 - Not found';
+ break;
+ case 500:
+ $this->view->code = 'Error 500 - Internal Server Error';
+ break;
+ case 503:
+ $this->view->code = 'Error 503 - Service Unavailable';
+ break;
+ default:
+ $this->view->code = 'Error 404 - Not found';
+ }
+
+ $this->view->logs = Request::param ('logs');
+ }
+}
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
new file mode 100755
index 000000000..3b4a90b64
--- /dev/null
+++ b/app/controllers/feedController.php
@@ -0,0 +1,89 @@
+<?php
+
+class feedController extends ActionController {
+ public function addAction () {
+ if (Request::isPost ()) {
+ $url = Request::param ('url_rss');
+
+ try {
+ $feed = new Feed ($url);
+ $entries = $feed->loadEntries ();
+ $feed_entries = array ();
+
+ if ($entries !== false) {
+ $entryDAO = new EntryDAO ();
+
+ 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 (),
+ );
+ $entryDAO->addEntry ($values);
+
+ $feed_entries[] = $entry->id ();
+ }
+ }
+
+ $feedDAO = new FeedDAO ();
+ $values = array (
+ 'id' => $feed->id (),
+ 'url' => $feed->url (),
+ 'categories' => $feed->categories (),
+ 'entries' => $feed_entries
+ );
+ $feedDAO->addFeed ($values);
+ } catch (Exception $e) {
+ // TODO ajouter une erreur : url non valide
+ }
+
+ Request::forward (array (), true);
+ }
+ }
+
+ public function actualizeAction () {
+ $feedDAO = new FeedDAO ();
+ $entryDAO = new EntryDAO ();
+
+ $feeds = $feedDAO->listFeeds ();
+
+ foreach ($feeds as $feed) {
+ $entries = $feed->loadEntries ();
+ $feed_entries = $feed->entries ();
+
+ 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 (),
+ );
+ $entryDAO->addEntry ($values);
+
+ if (!in_array ($entry->id (), $feed_entries)) {
+ $feed_entries[] = $entry->id ();
+ }
+ }
+ }
+
+ $values = array (
+ 'entries' => $feed_entries
+ );
+ $feedDAO->updateFeed ($values);
+ }
+
+ Request::forward (array (), true);
+ }
+}
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php
new file mode 100755
index 000000000..3fda234ca
--- /dev/null
+++ b/app/controllers/indexController.php
@@ -0,0 +1,34 @@
+<?php
+
+class indexController extends ActionController {
+ public function indexAction () {
+ $entryDAO = new EntryDAO ();
+
+ $mode = Session::param ('mode', $this->view->conf->defaultView ());
+ if ($mode == 'not_read') {
+ $entries = $entryDAO->listNotReadEntries ();
+ } elseif ($mode == 'all') {
+ $entries = $entryDAO->listEntries ();
+ }
+
+ usort ($entries, 'sortEntriesByDate');
+
+ //gestion pagination
+ $page = Request::param ('page', 1);
+ $this->view->entryPaginator = new Paginator ($entries);
+ $this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
+ $this->view->entryPaginator->_currentPage ($page);
+ }
+
+ public function changeModeAction () {
+ $mode = Request::param ('mode');
+
+ if ($mode == 'not_read') {
+ Session::_param ('mode', 'not_read');
+ } else {
+ Session::_param ('mode', 'all');
+ }
+
+ Request::forward (array (), true);
+ }
+}