diff options
| author | 2014-01-29 21:26:19 +0100 | |
|---|---|---|
| committer | 2014-01-29 21:26:19 +0100 | |
| commit | 165eb57459a152b3cc6aa3fd15ca990c3d908829 (patch) | |
| tree | 640ddacbc6eabc985646dd65b0578f369ea92321 /app/controllers | |
| parent | 75096e6a39fe5d34d3951991f296f616e62a9fd8 (diff) | |
| parent | c053825ff8f9792e692c101585481129b006937b (diff) | |
Sortie de la version 0.70.7.0
Diffstat (limited to 'app/controllers')
| -rwxr-xr-x | app/controllers/configureController.php | 375 | ||||
| -rwxr-xr-x | app/controllers/entryController.php | 117 | ||||
| -rw-r--r-- | app/controllers/errorController.php | 26 | ||||
| -rwxr-xr-x | app/controllers/feedController.php | 363 | ||||
| -rwxr-xr-x | app/controllers/indexController.php | 257 | ||||
| -rwxr-xr-x | app/controllers/javascriptController.php | 13 |
6 files changed, 0 insertions, 1151 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php deleted file mode 100755 index 4c1930d31..000000000 --- a/app/controllers/configureController.php +++ /dev/null @@ -1,375 +0,0 @@ -<?php - -class configureController extends ActionController { - public function firstAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } - - $catDAO = new CategoryDAO (); - $catDAO->checkDefault (); - } - - public function categorizeAction () { - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); - $catDAO->checkDefault (); - $defaultCategory = $catDAO->getDefault (); - $defaultId = $defaultCategory->id (); - - if (Request::isPost ()) { - $cats = Request::param ('categories', array ()); - $ids = Request::param ('ids', array ()); - $newCat = trim (Request::param ('new_category', '')); - - foreach ($cats as $key => $name) { - if (strlen ($name) > 0) { - $cat = new Category ($name); - $values = array ( - 'name' => $cat->name (), - 'color' => $cat->color () - ); - $catDAO->updateCategory ($ids[$key], $values); - } elseif ($ids[$key] != $defaultId) { - $feedDAO->changeCategory ($ids[$key], $defaultId); - $catDAO->deleteCategory ($ids[$key]); - } - } - - if ($newCat != '') { - $cat = new Category ($newCat); - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - 'color' => $cat->color () - ); - - if ($catDAO->searchByName ($newCat) == false) { - $catDAO->addCategory ($values); - } - } - - // notif - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('categories_updated') - ); - Session::_param ('notification', $notif); - - Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true); - } - - $this->view->categories = $catDAO->listCategories (false); - $this->view->defaultCategory = $catDAO->getDefault (); - $this->view->feeds = $feedDAO->listFeeds (); - $this->view->flux = false; - - View::prependTitle (Translate::t ('categories_management') . ' - '); - } - - public function feedAction () { - $catDAO = new CategoryDAO (); - $this->view->categories = $catDAO->listCategories (false); - - $feedDAO = new FeedDAO (); - $this->view->feeds = $feedDAO->listFeeds (); - - $id = Request::param ('id'); - if ($id == false && !empty ($this->view->feeds)) { - $id = current ($this->view->feeds)->id (); - } - - $this->view->flux = false; - if ($id != false) { - $this->view->flux = $feedDAO->searchById ($id); - - if (!$this->view->flux) { - Error::error ( - 404, - array ('error' => array (Translate::t ('page_not_found'))) - ); - } else { - $catDAO = new CategoryDAO (); - $this->view->categories = $catDAO->listCategories (false); - - if (Request::isPost () && $this->view->flux) { - $name = Request::param ('name', ''); - $hist = Request::param ('keep_history', 'no'); - $cat = Request::param ('category', 0); - $path = Request::param ('path_entries', ''); - $priority = Request::param ('priority', 0); - $user = Request::param ('http_user', ''); - $pass = Request::param ('http_pass', ''); - - $keep_history = false; - if ($hist == 'yes') { - $keep_history = true; - } - - $httpAuth = ''; - if ($user != '' || $pass != '') { - $httpAuth = $user . ':' . $pass; - } - - $values = array ( - 'name' => $name, - 'category' => $cat, - 'pathEntries' => $path, - 'priority' => $priority, - 'httpAuth' => $httpAuth, - 'keep_history' => $keep_history - ); - - if ($feedDAO->updateFeed ($id, $values)) { - $this->view->flux->_category ($cat); - - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_updated') - ); - } else { - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('error_occurred_update') - ); - } - - Session::_param ('notification', $notif); - Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true); - } - - View::prependTitle (Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - '); - } - } else { - View::prependTitle (Translate::t ('rss_feed_management') . ' - '); - } - } - - public function displayAction () { - if (Request::isPost ()) { - $current_token = $this->view->conf->token (); - - $language = Request::param ('language', 'en'); - $nb = Request::param ('posts_per_page', 10); - $mode = Request::param ('view_mode', 'normal'); - $view = Request::param ('default_view', 'all'); - $auto_load_more = Request::param ('auto_load_more', 'no'); - $display = Request::param ('display_posts', 'no'); - $onread_jump_next = Request::param ('onread_jump_next', 'no'); - $lazyload = Request::param ('lazyload', 'no'); - $sort = Request::param ('sort_order', 'low_to_high'); - $old = Request::param ('old_entries', 3); - $mail = Request::param ('mail_login', false); - $anon = Request::param ('anon_access', 'no'); - $token = Request::param ('token', $current_token); - $openArticle = Request::param ('mark_open_article', 'no'); - $openSite = Request::param ('mark_open_site', 'no'); - $scroll = Request::param ('mark_scroll', 'no'); - $urlShaarli = Request::param ('shaarli', ''); - $theme = Request::param ('theme', 'default'); - $topline_read = Request::param ('topline_read', 'no'); - $topline_favorite = Request::param ('topline_favorite', 'no'); - $topline_date = Request::param ('topline_date', 'no'); - $topline_link = Request::param ('topline_link', 'no'); - $bottomline_read = Request::param ('bottomline_read', 'no'); - $bottomline_favorite = Request::param ('bottomline_favorite', 'no'); - $bottomline_sharing = Request::param ('bottomline_sharing', 'no'); - $bottomline_tags = Request::param ('bottomline_tags', 'no'); - $bottomline_date = Request::param ('bottomline_date', 'no'); - $bottomline_link = Request::param ('bottomline_link', 'no'); - - $this->view->conf->_language ($language); - $this->view->conf->_postsPerPage (intval ($nb)); - $this->view->conf->_viewMode ($mode); - $this->view->conf->_defaultView ($view); - $this->view->conf->_autoLoadMore ($auto_load_more); - $this->view->conf->_displayPosts ($display); - $this->view->conf->_onread_jump_next ($onread_jump_next); - $this->view->conf->_lazyload ($lazyload); - $this->view->conf->_sortOrder ($sort); - $this->view->conf->_oldEntries ($old); - $this->view->conf->_mailLogin ($mail); - $this->view->conf->_anonAccess ($anon); - $this->view->conf->_token ($token); - $this->view->conf->_markWhen (array ( - 'article' => $openArticle, - 'site' => $openSite, - 'scroll' => $scroll, - )); - $this->view->conf->_urlShaarli ($urlShaarli); - $this->view->conf->_theme ($theme); - $this->view->conf->_topline_read ($topline_read); - $this->view->conf->_topline_favorite ($topline_favorite); - $this->view->conf->_topline_date ($topline_date); - $this->view->conf->_topline_link ($topline_link); - $this->view->conf->_bottomline_read ($bottomline_read); - $this->view->conf->_bottomline_favorite ($bottomline_favorite); - $this->view->conf->_bottomline_sharing ($bottomline_sharing); - $this->view->conf->_bottomline_tags ($bottomline_tags); - $this->view->conf->_bottomline_date ($bottomline_date); - $this->view->conf->_bottomline_link ($bottomline_link); - - $values = array ( - 'language' => $this->view->conf->language (), - 'posts_per_page' => $this->view->conf->postsPerPage (), - 'view_mode' => $this->view->conf->viewMode (), - 'default_view' => $this->view->conf->defaultView (), - 'auto_load_more' => $this->view->conf->autoLoadMore (), - 'display_posts' => $this->view->conf->displayPosts (), - 'onread_jump_next' => $this->view->conf->onread_jump_next (), - 'lazyload' => $this->view->conf->lazyload (), - 'sort_order' => $this->view->conf->sortOrder (), - 'old_entries' => $this->view->conf->oldEntries (), - 'mail_login' => $this->view->conf->mailLogin (), - 'anon_access' => $this->view->conf->anonAccess (), - 'token' => $this->view->conf->token (), - 'mark_when' => $this->view->conf->markWhen (), - 'url_shaarli' => $this->view->conf->urlShaarli (), - 'theme' => $this->view->conf->theme (), - 'topline_read' => $this->view->conf->toplineRead () ? 'yes' : 'no', - 'topline_favorite' => $this->view->conf->toplineFavorite () ? 'yes' : 'no', - 'topline_date' => $this->view->conf->toplineDate () ? 'yes' : 'no', - 'topline_link' => $this->view->conf->toplineLink () ? 'yes' : 'no', - 'bottomline_read' => $this->view->conf->bottomlineRead () ? 'yes' : 'no', - 'bottomline_favorite' => $this->view->conf->bottomlineFavorite () ? 'yes' : 'no', - 'bottomline_sharing' => $this->view->conf->bottomlineSharing () ? 'yes' : 'no', - 'bottomline_tags' => $this->view->conf->bottomlineTags () ? 'yes' : 'no', - 'bottomline_date' => $this->view->conf->bottomlineDate () ? 'yes' : 'no', - 'bottomline_link' => $this->view->conf->bottomlineLink () ? 'yes' : 'no', - ); - - $confDAO = new RSSConfigurationDAO (); - $confDAO->update ($values); - Session::_param ('conf', $this->view->conf); - Session::_param ('mail', $this->view->conf->mailLogin ()); - - Session::_param ('language', $this->view->conf->language ()); - Translate::reset (); - - // notif - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('configuration_updated') - ); - Session::_param ('notification', $notif); - - Request::forward (array ('c' => 'configure', 'a' => 'display'), true); - } - - $this->view->themes = RSSThemes::get(); - - View::prependTitle (Translate::t ('general_and_reading_management') . ' - '); - } - - public function importExportAction () { - $catDAO = new CategoryDAO (); - $this->view->categories = $catDAO->listCategories (); - - $this->view->req = Request::param ('q'); - - if ($this->view->req == 'export') { - View::_title ('freshrss_feeds.opml'); - - $this->view->_useLayout (false); - header('Content-Type: application/xml; charset=utf-8'); - header('Content-disposition: attachment; filename=freshrss_feeds.opml'); - - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); - - $list = array (); - foreach ($catDAO->listCategories () as $key => $cat) { - $list[$key]['name'] = $cat->name (); - $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ()); - } - - $this->view->categories = $list; - } elseif ($this->view->req == 'import' && Request::isPost ()) { - if ($_FILES['file']['error'] == 0) { - // on parse le fichier OPML pour récupérer les catégories et les flux associés - try { - list ($categories, $feeds) = opml_import ( - file_get_contents ($_FILES['file']['tmp_name']) - ); - - // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD - // les flux sont mis au préalable dans des variables de Request - Request::_param ('q', 'null'); - Request::_param ('categories', $categories); - Request::_param ('feeds', $feeds); - Request::forward (array ('c' => 'feed', 'a' => 'massiveImport')); - } catch (OpmlException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('bad_opml_file') - ); - Session::_param ('notification', $notif); - - Request::forward (array ( - 'c' => 'configure', - 'a' => 'importExport' - ), true); - } - } - } - - $feedDAO = new FeedDAO (); - $this->view->feeds = $feedDAO->listFeeds (); - - // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste - $this->view->flux = false; - - View::prependTitle (Translate::t ('import_export_opml') . ' - '); - } - - public function shortcutAction () { - $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter', - 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left', - 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right', - 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y', - 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', - 'f10', 'f11', 'f12'); - $this->view->list_keys = $list_keys; - $list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry', - 'prev_entry', 'next_page', 'prev_page'); - - if (Request::isPost ()) { - $shortcuts = Request::param ('shortcuts'); - $shortcuts_ok = array (); - - foreach ($shortcuts as $key => $value) { - if (in_array ($key, $list_names) - && in_array ($value, $list_keys)) { - $shortcuts_ok[$key] = $value; - } - } - - $this->view->conf->_shortcuts ($shortcuts_ok); - - $values = array ( - 'shortcuts' => $this->view->conf->shortcuts () - ); - - $confDAO = new RSSConfigurationDAO (); - $confDAO->update ($values); - Session::_param ('conf', $this->view->conf); - - // notif - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('shortcuts_updated') - ); - Session::_param ('notification', $notif); - - Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true); - } - - View::prependTitle (Translate::t ('shortcuts_management') . ' - '); - } -} diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php deleted file mode 100755 index d4023c519..000000000 --- a/app/controllers/entryController.php +++ /dev/null @@ -1,117 +0,0 @@ -<?php - -class entryController extends ActionController { - public function firstAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } - - $this->params = array (); - $this->redirect = false; - $ajax = Request::param ('ajax'); - if ($ajax) { - $this->view->_useLayout (false); - } - } - public function lastAction () { - $ajax = Request::param ('ajax'); - if (!$ajax && $this->redirect) { - Request::forward (array ( - 'c' => 'index', - 'a' => 'index', - 'params' => $this->params - ), true); - } else { - Request::_param ('ajax'); - } - } - - public function readAction () { - $this->redirect = true; - - $id = Request::param ('id'); - $is_read = Request::param ('is_read'); - $get = Request::param ('get'); - $nextGet = Request::param ('nextGet', $get); - $dateMax = Request::param ('dateMax', 0); - - $is_read = !!$is_read; - - $entryDAO = new EntryDAO (); - if ($id == false) { - if (!$get) { - $entryDAO->markReadEntries ($is_read, $dateMax); - } else { - $typeGet = $get[0]; - $get = substr ($get, 2); - - if ($typeGet == 'c') { - $entryDAO->markReadCat ($get, $is_read, $dateMax); - $this->params = array ('get' => $nextGet); - } elseif ($typeGet == 'f') { - $entryDAO->markReadFeed ($get, $is_read, $dateMax); - $this->params = array ('get' => $nextGet); - } - } - - // notif - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feeds_marked_read') - ); - Session::_param ('notification', $notif); - } else { - $entryDAO->updateEntry ($id, array ('is_read' => $is_read)); - } - } - - public function bookmarkAction () { - $this->redirect = true; - - $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); - } - } - } - - public function optimizeAction() { - // La table des entrées a tendance à grossir énormément - // Cette action permet d'optimiser cette table permettant de grapiller un peu de place - // Cette fonctionnalité n'est à appeler qu'occasionnellement - $entryDAO = new EntryDAO(); - $entryDAO->optimizeTable(); - - touch(PUBLIC_PATH . '/data/touch.txt'); - - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('optimization_complete') - ); - Session::_param ('notification', $notif); - - Request::forward(array( - 'c' => 'configure', - 'a' => 'display' - ), true); - } -} diff --git a/app/controllers/errorController.php b/app/controllers/errorController.php deleted file mode 100644 index 092609280..000000000 --- a/app/controllers/errorController.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -class ErrorController extends ActionController { - public function indexAction () { - 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'); - - View::prependTitle ($this->view->code . ' - '); - } -} diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php deleted file mode 100755 index 76fca8828..000000000 --- a/app/controllers/feedController.php +++ /dev/null @@ -1,363 +0,0 @@ -<?php - -class feedController extends ActionController { - public function firstAction () { - $token = $this->view->conf->token(); - $token_param = Request::param ('token', ''); - $token_is_ok = ($token != '' && $token == $token_param); - $action = Request::actionName (); - - if (login_is_conf ($this->view->conf) && - !is_logged () && - !($token_is_ok && $action == 'actualize')) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } - - $this->catDAO = new CategoryDAO (); - $this->catDAO->checkDefault (); - } - - public function addAction () { - if (Request::isPost ()) { - $url = Request::param ('url_rss'); - $cat = Request::param ('category', false); - if ($cat === false) { - $def_cat = $this->catDAO->getDefault (); - $cat = $def_cat->id (); - } - - $user = Request::param ('username'); - $pass = Request::param ('password'); - $params = array (); - - try { - $feed = new Feed ($url); - $feed->_category ($cat); - - $httpAuth = ''; - if ($user != '' || $pass != '') { - $httpAuth = $user . ':' . $pass; - } - $feed->_httpAuth ($httpAuth); - - $feed->load (); - - $feedDAO = new FeedDAO (); - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - 'lastUpdate' => time (), - 'httpAuth' => $feed->httpAuth (), - ); - - if ($feedDAO->searchByUrl ($values['url'])) { - // on est déjà abonné à ce flux - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('already_subscribed', $feed->name ()) - ); - Session::_param ('notification', $notif); - } elseif (!$feedDAO->addFeed ($values)) { - // problème au niveau de la base de données - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('feed_not_added', $feed->name ()) - ); - Session::_param ('notification', $notif); - } else { - $entryDAO = new EntryDAO (); - $entries = $feed->entries (); - - // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); - $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); - - // on ajoute les articles en masse sans vérification - foreach ($entries as $entry) { - if ($entry->date (true) >= $date_min || - $feed->keepHistory ()) { - $values = $entry->toArray (); - $entryDAO->addEntry ($values); - } - } - - // ok, ajout terminé - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_added', $feed->name ()) - ); - Session::_param ('notification', $notif); - - // permet de rediriger vers la page de conf du flux - $params['id'] = $feed->id (); - } - } catch (BadUrlException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('invalid_url', $url) - ); - Session::_param ('notification', $notif); - } catch (FeedException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('internal_problem_feed') - ); - Session::_param ('notification', $notif); - } catch (FileNotExistException $e) { - // Répertoire de cache n'existe pas - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('internal_problem_feed') - ); - Session::_param ('notification', $notif); - } - - Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true); - } - } - - public function actualizeAction () { - $feedDAO = new FeedDAO (); - $entryDAO = new EntryDAO (); - - $id = Request::param ('id'); - $force = Request::param ('force', false); - - // on créé la liste des flux à mettre à actualiser - // si on veut mettre un flux à jour spécifiquement, on le met - // dans la liste, mais seul (permet d'automatiser le traitement) - $feeds = array (); - if ($id) { - $feed = $feedDAO->searchById ($id); - if ($feed) { - $feeds = array ($feed); - } - } else { - $feeds = $feedDAO->listFeedsOrderUpdate (); - } - - // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); - $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); - - $i = 0; - $flux_update = 0; - foreach ($feeds as $feed) { - try { - $feed->load (); - $entries = $feed->entries (); - - //For this feed, check last n entry IDs already in database - $existingIds = array_fill_keys ($entryDAO->listLastIdsByFeed ($feed->id (), count($entries) + 2), 1); - - // ajout des articles en masse sans se soucier des erreurs - // On ne vérifie pas que l'article n'est pas déjà en BDD - // car demanderait plus de ressources - // La BDD refusera l'ajout de son côté car l'id doit être - // unique - foreach ($entries as $entry) { - if ((!isset ($existingIds[$entry->id ()])) && - ($entry->date (true) >= $date_min || - $feed->keepHistory ())) { - $values = $entry->toArray (); - $entryDAO->addEntry ($values); - } - } - - // on indique que le flux vient d'être mis à jour en BDD - $feedDAO->updateLastUpdate ($feed->id ()); - $flux_update++; - } catch (FeedException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $feedDAO->isInError ($feed->id ()); - } - - // On arrête à 10 flux pour ne pas surcharger le serveur - // sauf si le paramètre $force est à vrai - $i++; - if ($i >= 10 && !$force) { - break; - } - } - - $entryDAO->cleanOldEntries ($nb_month_old); - - $url = array (); - if ($flux_update === 1) { - // on a mis un seul flux à jour - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_actualized', $feed->name ()) - ); - } elseif ($flux_update > 1) { - // plusieurs flux on été mis à jour - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('n_feeds_actualized', $flux_update) - ); - } else { - // aucun flux n'a été mis à jour, oups - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('no_feed_actualized') - ); - } - - if ($i === 1) { - // Si on a voulu mettre à jour qu'un flux - // on filtre l'affichage par ce flux - $feed = reset ($feeds); - $url['params'] = array ('get' => 'f_' . $feed->id ()); - } - - if (Request::param ('ajax', 0) === 0) { - Session::_param ('notification', $notif); - Request::forward ($url, true); - } else { - // Une requête Ajax met un seul flux à jour. - // Comme en principe plusieurs requêtes ont lieu, - // on indique que "plusieurs flux ont été mis à jour". - // Cela permet d'avoir une notification plus proche du - // ressenti utilisateur - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feeds_actualized') - ); - Session::_param ('notification', $notif); - // et on désactive le layout car ne sert à rien - $this->view->_useLayout (false); - } - } - - public function massiveImportAction () { - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - - $categories = Request::param ('categories', array (), true); - $feeds = Request::param ('feeds', array (), true); - - // on ajoute les catégories en masse dans une fonction à part - $this->addCategories ($categories); - - // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->oldEntries (); - $date_min = time () - (60 * 60 * 24 * 30 * $nb_month_old); - - // la variable $error permet de savoir si une erreur est survenue - // Le but est de ne pas arrêter l'import même en cas d'erreur - // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais - // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées - $error = false; - $i = 0; - foreach ($feeds as $feed) { - try { - $feed->load (); - - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - 'lastUpdate' => 0, - 'httpAuth' => $feed->httpAuth () - ); - - // ajout du flux que s'il n'est pas déjà en BDD - if (!$feedDAO->searchByUrl ($values['url'])) { - if (!$feedDAO->addFeed ($values)) { - $error = true; - } - } - } catch (FeedException $e) { - $error = true; - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - } - } - - if ($error) { - $res = Translate::t ('feeds_imported_with_errors'); - } else { - $res = Translate::t ('feeds_imported'); - } - - $notif = array ( - 'type' => 'good', - 'content' => $res - ); - Session::_param ('notification', $notif); - Session::_param ('actualize_feeds', true); - - // et on redirige vers la page import/export - Request::forward (array ( - 'c' => 'configure', - 'a' => 'importExport' - ), true); - } - - public function deleteAction () { - $type = Request::param ('type', 'feed'); - $id = Request::param ('id'); - - $feedDAO = new FeedDAO (); - if ($type == 'category') { - if ($feedDAO->deleteFeedByCategory ($id)) { - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('category_emptied') - ); - } else { - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('error_occured') - ); - } - } else { - if ($feedDAO->deleteFeed ($id)) { - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_deleted') - ); - } else { - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('error_occured') - ); - } - } - - Session::_param ('notification', $notif); - - if ($type == 'category') { - Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true); - } else { - Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); - } - } - - private function addCategories ($categories) { - $catDAO = new CategoryDAO (); - - foreach ($categories as $cat) { - if (!$catDAO->searchByName ($cat->name ())) { - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - 'color' => $cat->color () - ); - $catDAO->addCategory ($values); - } - } - } -} diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php deleted file mode 100755 index 140bbfc72..000000000 --- a/app/controllers/indexController.php +++ /dev/null @@ -1,257 +0,0 @@ -<?php - -class indexController extends ActionController { - private $get = false; - private $nb_not_read = 0; - private $nb_not_read_cat = 0; - - public function indexAction () { - $output = Request::param ('output'); - - $token = $this->view->conf->token(); - $token_param = Request::param ('token', ''); - $token_is_ok = ($token != '' && $token == $token_param); - - // check if user is log in - if(login_is_conf ($this->view->conf) && - !is_logged() && - $this->view->conf->anonAccess() == 'no' && - !($output == 'rss' && $token_is_ok)) { - return; - } - - // construction of RSS url of this feed - $params = Request::params (); - $params['output'] = 'rss'; - if (isset ($params['search'])) { - $params['search'] = urlencode ($params['search']); - } - if (login_is_conf($this->view->conf) && - $this->view->conf->anonAccess() == 'no' && - $token != '') { - $params['token'] = $token; - } - $this->view->rss_url = array ( - 'c' => 'index', - 'a' => 'index', - 'params' => $params - ); - - $this->view->rss_title = View::title(); - - if ($output == 'rss') { - // no layout for RSS output - $this->view->_useLayout (false); - header('Content-Type: application/rss+xml; charset=utf-8'); - } else { - View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); - - if ($output == 'global') { - View::appendScript (Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); - } - } - - $nb_not_read = $this->view->nb_not_read; - if($nb_not_read > 0) { - View::appendTitle (' (' . $nb_not_read . ')'); - } - View::prependTitle (' - '); - - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); - - $this->view->cat_aside = $catDAO->listCategories (); - $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); - $this->view->nb_total = $entryDAO->count (); - $this->view->currentName = ''; - - $this->view->get_c = ''; - $this->view->get_f = ''; - - $type = $this->getType (); - $error = $this->checkAndProcessType ($type); - - // mise à jour des titres - $this->view->rss_title = $this->view->currentName . ' - ' . $this->view->rss_title; - View::prependTitle ( - $this->view->currentName . - ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') - ); - - if (!$error) { - // On récupère les différents éléments de filtrage - $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); - $filter = Request::param ('search', ''); - $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ()); - $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); - $first = Request::param ('next', ''); - - try { - // EntriesGetter permet de déporter la complexité du filtrage - $getter = new EntriesGetter ($type, $state, $filter, $order, $nb, $first); - $getter->execute (); - $entries = $getter->getPaginator (); - - // Si on a récupéré aucun article "non lus" - // on essaye de récupérer tous les articles - if ($state == 'not_read' && $entries->isEmpty ()) { - $this->view->state = 'all'; - $getter->_state ('all'); - $getter->execute (); - $entries = $getter->getPaginator (); - } - - $this->view->entryPaginator = $entries; - } catch(EntriesGetterException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); - Error::error ( - 404, - array ('error' => array (Translate::t ('page_not_found'))) - ); - } - } else { - Error::error ( - 404, - array ('error' => array (Translate::t ('page_not_found'))) - ); - } - } - - /* - * Détermine le type d'article à récupérer : - * "tous", "favoris", "public", "catégorie" ou "flux" - */ - private function getType () { - $get = Request::param ('get', 'all'); - $typeGet = $get[0]; - $id = substr ($get, 2); - - $type = null; - if ($get == 'all' || $get == 'favoris' || $get == 'public') { - $type = array ( - 'type' => $get, - 'id' => $get - ); - } elseif ($typeGet == 'f' || $typeGet == 'c') { - $type = array ( - 'type' => $typeGet, - 'id' => $id - ); - } - - return $type; - } - /* - * Vérifie que la catégorie / flux sélectionné existe - * + Initialise correctement les variables de vue get_c et get_f - * + Met à jour la variable $this->nb_not_read_cat - */ - private function checkAndProcessType ($type) { - if ($type['type'] == 'all') { - $this->view->currentName = Translate::t ('your_rss_feeds'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'favoris') { - $this->view->currentName = Translate::t ('your_favorites'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'public') { - $this->view->currentName = Translate::t ('public'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'c') { - $catDAO = new CategoryDAO (); - $cat = $catDAO->searchById ($type['id']); - if ($cat) { - $this->view->currentName = $cat->name (); - $this->nb_not_read_cat = $cat->nbNotRead (); - $this->view->get_c = $type['id']; - return false; - } else { - return true; - } - } elseif ($type['type'] == 'f') { - $feedDAO = new FeedDAO (); - $feed = $feedDAO->searchById ($type['id']); - if ($feed) { - $this->view->currentName = $feed->name (); - $this->nb_not_read_cat = $feed->nbNotRead (); - $this->view->get_f = $type['id']; - $this->view->get_c = $feed->category (); - return false; - } else { - return true; - } - } else { - return true; - } - } - - public function aboutAction () { - View::prependTitle (Translate::t ('about') . ' - '); - } - - public function logsAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } - - View::prependTitle (Translate::t ('logs') . ' - '); - - $logs = array(); - try { - $logDAO = new LogDAO (); - $logs = $logDAO->lister (); - $logs = array_reverse ($logs); - } catch(FileNotExistException $e) { - - } - - //gestion pagination - $page = Request::param ('page', 1); - $this->view->logsPaginator = new Paginator ($logs); - $this->view->logsPaginator->_nbItemsPerPage (50); - $this->view->logsPaginator->_currentPage ($page); - } - - public function loginAction () { - $this->view->_useLayout (false); - - $url = 'https://verifier.login.persona.org/verify'; - $assert = Request::param ('assertion'); - $params = 'assertion=' . $assert . '&audience=' . - urlencode (Url::display (null, 'php', true)); - $ch = curl_init (); - $options = array ( - CURLOPT_URL => $url, - CURLOPT_RETURNTRANSFER => TRUE, - CURLOPT_POST => 2, - CURLOPT_POSTFIELDS => $params - ); - curl_setopt_array ($ch, $options); - $result = curl_exec ($ch); - curl_close ($ch); - - $res = json_decode ($result, true); - if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { - Session::_param ('mail', $res['email']); - touch(PUBLIC_PATH . '/data/touch.txt'); - } else { - $res = array (); - $res['status'] = 'failure'; - $res['reason'] = Translate::t ('invalid_login'); - } - - $this->view->res = json_encode ($res); - } - - public function logoutAction () { - $this->view->_useLayout (false); - Session::_param ('mail'); - touch(PUBLIC_PATH . '/data/touch.txt'); - } -} diff --git a/app/controllers/javascriptController.php b/app/controllers/javascriptController.php deleted file mode 100755 index 291474130..000000000 --- a/app/controllers/javascriptController.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -class javascriptController extends ActionController { - public function firstAction () { - $this->view->_useLayout (false); - header('Content-type: text/javascript'); - } - - public function actualizeAction () { - $feedDAO = new FeedDAO (); - $this->view->feeds = $feedDAO->listFeeds (); - } -} |
