diff options
Diffstat (limited to 'app/controllers')
| -rwxr-xr-x | app/controllers/configureController.php | 11 | ||||
| -rwxr-xr-x | app/controllers/feedController.php | 175 | ||||
| -rwxr-xr-x | app/controllers/indexController.php | 19 | ||||
| -rwxr-xr-x | app/controllers/javascriptController.php | 9 | ||||
| -rwxr-xr-x | app/controllers/rssController.php | 35 |
5 files changed, 167 insertions, 82 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index 243c155f9..18a56c066 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -56,6 +56,7 @@ class configureController extends ActionController { } $this->view->categories = $catDAO->listCategories (); + $this->view->defaultCategory = $catDAO->getDefault (); View::prependTitle ('Gestion des catégories - '); } @@ -88,10 +89,12 @@ class configureController extends ActionController { if (Request::isPost () && $this->view->flux) { $cat = Request::param ('category', 0); $path = Request::param ('path_entries', ''); + $priority = Request::param ('priority', 0); $values = array ( 'category' => $cat, - 'pathEntries' => $path + 'pathEntries' => $path, + 'priority' => $priority ); if ($feedDAO->updateFeed ($id, $values)) { @@ -130,6 +133,7 @@ class configureController extends ActionController { $openArticle = Request::param ('mark_open_article', 'no'); $openSite = Request::param ('mark_open_site', 'no'); $openPage = Request::param ('mark_open_page', 'no'); + $urlShaarli = Request::param ('shaarli', ''); $this->view->conf->_postsPerPage (intval ($nb)); $this->view->conf->_defaultView ($view); @@ -142,6 +146,7 @@ class configureController extends ActionController { 'site' => $openSite, 'page' => $openPage, )); + $this->view->conf->_urlShaarli ($urlShaarli); $values = array ( 'posts_per_page' => $this->view->conf->postsPerPage (), @@ -151,6 +156,7 @@ class configureController extends ActionController { 'old_entries' => $this->view->conf->oldEntries (), 'mail_login' => $this->view->conf->mailLogin (), 'mark_when' => $this->view->conf->markWhen (), + 'url_shaarli' => $this->view->conf->urlShaarli (), ); $confDAO = new RSSConfigurationDAO (); @@ -178,7 +184,8 @@ class configureController extends ActionController { View::_title ('feeds_opml.xml'); $this->view->_useLayout (false); - header('Content-type: text/xml'); + header('Content-Type: text/xml; charset=utf-8'); + header('Content-disposition: attachment; filename=feeds_opml.xml'); $feedDAO = new FeedDAO (); $catDAO = new CategoryDAO (); diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index e16161842..c67609d57 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -33,9 +33,17 @@ class feedController extends ActionController { 'description' => $feed->description (), 'lastUpdate' => time () ); - if ($feedDAO->addFeed ($values)) { + + if ($feedDAO->searchByUrl ($values['url'])) { + $notif = array ( + 'type' => 'bad', + 'content' => 'Vous êtes déjà abonné à <em>' . $feed->name () . '</em>' + ); + Session::_param ('notification', $notif); + } elseif ($feedDAO->addFeed ($values)) { $entryDAO = new EntryDAO (); $entries = $feed->entries (); + foreach ($entries as $entry) { $values = $entry->toArray (); $entryDAO->addEntry ($values); @@ -56,6 +64,13 @@ class feedController extends ActionController { ); Session::_param ('notification', $notif); } + } catch (FeedException $e) { + Log::record ($e->getMessage (), Log::ERROR); + $notif = array ( + 'type' => 'bad', + 'content' => 'Un problème interne a été rencontré, le flux n\'a pas pu être ajouté' + ); + Session::_param ('notification', $notif); } catch (FileNotExistException $e) { Log::record ($e->getMessage (), Log::ERROR); // notif @@ -82,7 +97,16 @@ class feedController extends ActionController { $feedDAO = new FeedDAO (); $entryDAO = new EntryDAO (); - $feeds = $feedDAO->listFeedsOrderUpdate (); + $id = Request::param ('id'); + $feeds = array (); + if ($id) { + $feed = $feedDAO->searchById ($id); + if ($feed) { + $feeds = array ($feed); + } + } else { + $feeds = $feedDAO->listFeedsOrderUpdate (); + } // pour ne pas ajouter des entrées trop anciennes $nb_month_old = $this->view->conf->oldEntries (); @@ -90,17 +114,21 @@ class feedController extends ActionController { $i = 0; foreach ($feeds as $feed) { - $feed->load (); - $entries = $feed->entries (); + try { + $feed->load (); + $entries = $feed->entries (); - foreach ($entries as $entry) { - if ($entry->date (true) >= $date_min) { - $values = $entry->toArray (); - $entryDAO->addEntry ($values); + foreach ($entries as $entry) { + if ($entry->date (true) >= $date_min) { + $values = $entry->toArray (); + $entryDAO->addEntry ($values); + } } - } - $feedDAO->updateLastUpdate ($feed->id ()); + $feedDAO->updateLastUpdate ($feed->id ()); + } catch (FeedException $e) { + Log::record ($e->getMessage (), Log::ERROR); + } $i++; if ($i >= 10) { @@ -111,13 +139,37 @@ class feedController extends ActionController { $entryDAO->cleanOldEntries ($nb_month_old); // notif - $notif = array ( - 'type' => 'good', - 'content' => '10 flux ont été mis à jour' - ); - Session::_param ('notification', $notif); + $url = array (); + if ($i == 1) { + $feed = reset ($feeds); + $notif = array ( + 'type' => 'good', + 'content' => '<em>' . $feed->name () . '</em> a été mis à jour' + ); + $url['params'] = array ('get' => 'f_' . $feed->id ()); + } elseif ($i > 0) { + $notif = array ( + 'type' => 'good', + 'content' => $i . ' flux ont été mis à jour' + ); + } else { + $notif = array ( + 'type' => 'bad', + 'content' => 'Aucun flux n\'a pu être mis à jour' + ); + } - Request::forward (array (), true); + if (Request::param ('ajax', 0) == 0) { + Session::_param ('notification', $notif); + Request::forward ($url, true); + } else { + $notif = array ( + 'type' => 'good', + 'content' => 'Les flux ont été mis à jour' + ); + Session::_param ('notification', $notif); + $this->view->_useLayout (false); + } } public function massiveImportAction () { @@ -138,28 +190,49 @@ class feedController extends ActionController { $nb_month_old = $this->view->conf->oldEntries (); $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); + $error = false; $i = 0; foreach ($feeds as $feed) { - $feed->load (); + try { + $feed->load (); - // Enregistrement du flux - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - 'lastUpdate' => 0 - ); + // Enregistrement du flux + $values = array ( + 'id' => $feed->id (), + 'url' => $feed->url (), + 'category' => $feed->category (), + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), + 'lastUpdate' => 0 + ); - $feedDAO->addFeed ($values); + if (!$feedDAO->searchByUrl ($values['url'])) { + if (!$feedDAO->addFeed ($values)) { + $error = true; + } + } + } catch (FeedException $e) { + $error = true; + Log::record ($e->getMessage (), Log::ERROR); + } } + if ($error) { + $res = 'Les flux ont été importés mais des erreurs sont survenus'; + } else { + $res = 'Les flux ont été importés'; + } + $notif = array ( + 'type' => 'good', + 'content' => $res + ); + Session::_param ('notification', $notif); + Request::forward (array ( - 'c' => 'feed', - 'a' => 'actualize' - )); + 'c' => 'configure', + 'a' => 'importExport' + ), true); } } @@ -170,19 +243,43 @@ class feedController extends ActionController { array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) ); } else { + $type = Request::param ('type', 'feed'); $id = Request::param ('id'); $feedDAO = new FeedDAO (); - $feedDAO->deleteFeed ($id); + if ($type == 'category') { + if ($feedDAO->deleteFeedByCategory ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => 'La catégorie a été vidée' + ); + } else { + $notif = array ( + 'type' => 'bad', + 'content' => 'Un problème est survenu' + ); + } + } else { + if ($feedDAO->deleteFeed ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => 'Le flux a été supprimé' + ); + } else { + $notif = array ( + 'type' => 'bad', + 'content' => 'Un problème est survenu' + ); + } + } - // notif - $notif = array ( - 'type' => 'good', - 'content' => 'Le flux a été supprimé' - ); Session::_param ('notification', $notif); - Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); + if ($type == 'category') { + Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true); + } else { + Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); + } } } @@ -190,7 +287,7 @@ class feedController extends ActionController { $catDAO = new CategoryDAO (); foreach ($categories as $cat) { - if (!$catDAO->searchByName ()) { + if (!$catDAO->searchByName ($cat->name ())) { $values = array ( 'id' => $cat->id (), 'name' => $cat->name (), diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index c83f7f1d2..8fa911631 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -8,6 +8,7 @@ class indexController extends ActionController { public function indexAction () { View::appendScript (Url::display ('/scripts/shortcut.js')); View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main'))); + View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'actualize'))); $entryDAO = new EntryDAO (); $feedDAO = new FeedDAO (); @@ -38,6 +39,9 @@ class indexController extends ActionController { } elseif ($this->get['type'] == 'favoris') { $entries = $entryDAO->listFavorites ($this->mode, $search, $order); View::prependTitle ('Vos favoris - '); + } elseif ($this->get['type'] == 'public') { + $entries = $entryDAO->listPublic ($this->mode, $search, $order); + View::prependTitle ('Public - '); } elseif ($this->get != false) { if ($this->get['type'] == 'c') { $cat = $catDAO->searchById ($this->get['filter']); @@ -76,13 +80,15 @@ class indexController extends ActionController { try { $this->view->entryPaginator = $entryDAO->getPaginator ($entries); - } catch (CurrentPagePaginationException $e) { - - } + } catch (CurrentPagePaginationException $e) { } $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countFavorites (); $this->view->nb_total = $entryDAO->count (); + + if (Request::param ('output', '') == 'rss') { + $this->view->_useLayout (false); + } } } @@ -163,6 +169,13 @@ class indexController extends ActionController { 'type' => $get, 'filter' => $get ); + } elseif ($get == 'public') { + $this->view->get_c = $get; + + $this->get = array ( + 'type' => $get, + 'filter' => $get + ); } elseif ($get == false) { $this->get = array ( 'type' => 'all', diff --git a/app/controllers/javascriptController.php b/app/controllers/javascriptController.php index 8060f560c..071cf65a4 100755 --- a/app/controllers/javascriptController.php +++ b/app/controllers/javascriptController.php @@ -5,8 +5,11 @@ class javascriptController extends ActionController { $this->view->_useLayout (false); header('Content-type: text/javascript'); } - - public function mainAction () { - + + public function mainAction () {} + + public function actualizeAction () { + $feedDAO = new FeedDAO (); + $this->view->feeds = $feedDAO->listFeeds (); } } diff --git a/app/controllers/rssController.php b/app/controllers/rssController.php deleted file mode 100755 index 1f66f4517..000000000 --- a/app/controllers/rssController.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -class rssController extends ActionController { - public function firstAction() { - header('Content-Type: text/xml'); - header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - - $this->view->_useLayout (false); - } - - public function publicAction () { - $entryDAO = new EntryDAO (); - $entryDAO->_nbItemsPerPage (-1); - - $items = $entryDAO->listPublic ('low_to_high'); - - try { - $page = Request::param('page', 1); - $nb = Request::param('nb', 15); - $this->view->itemPaginator = new Paginator($items); - $this->view->itemPaginator->_nbItemsPerPage($nb); - $this->view->itemPaginator->_currentPage($page); - } catch(CurrentPagePaginationException $e) { - Error::error( - 404, - array('error' => array('La page que vous cherchez n\'existe pas')) - ); - } - } - - public function getNbNotReadAction() { - } -} |
