From fb57be5a5af3a2fb46b2dbf2b503ffe78eb5cf49 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 21 Oct 2012 18:47:57 +0200 Subject: First commit --- app/controllers/configureController.php | 33 ++++++++++++ app/controllers/entryController.php | 58 +++++++++++++++++++++ app/controllers/errorController.php | 26 ++++++++++ app/controllers/feedController.php | 89 +++++++++++++++++++++++++++++++++ app/controllers/indexController.php | 34 +++++++++++++ 5 files changed, 240 insertions(+) create mode 100755 app/controllers/configureController.php create mode 100755 app/controllers/entryController.php create mode 100644 app/controllers/errorController.php create mode 100755 app/controllers/feedController.php create mode 100755 app/controllers/indexController.php (limited to 'app/controllers') 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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); + } +} -- cgit v1.2.3