From 0e95494e29353a9ae31fb1196c6c9aaf556ae981 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 27 Apr 2013 21:08:29 +0200 Subject: Fix issue #26 : possibilité de s'abonner à des flux derrière authentification HTTP + correction quelques traductions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/Feed.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/models/Feed.php b/app/models/Feed.php index 222e22256..08cf7425f 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -59,9 +59,13 @@ class Feed extends Model { if ($raw) { return $this->httpAuth; } else { + $pos_colon = strpos ($this->httpAuth, ':'); + $user = substr ($this->httpAuth, 0, $pos_colon); + $pass = substr ($this->httpAuth, $pos_colon + 1); + return array ( - 'username' => '', - 'password' => '' + 'username' => $user, + 'password' => $pass ); } } @@ -134,7 +138,12 @@ class Feed extends Model { ); } else { $feed = new SimplePie (); - $feed->set_feed_url (preg_replace ('/&/', '&', $this->url)); + $url = preg_replace ('/&/', '&', $this->url); + if ($this->httpAuth != '') { + $url = preg_replace ('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url); + } + + $feed->set_feed_url ($url); $feed->set_cache_location (CACHE_PATH); $feed->init (); @@ -144,6 +153,9 @@ class Feed extends Model { $subscribe_url = $feed->subscribe_url (); if (!is_null ($subscribe_url) && $subscribe_url != $this->url) { + if ($this->httpAuth != '') { + $subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url); + } $this->_url ($subscribe_url); } $title = $feed->get_title (); @@ -205,7 +217,7 @@ class Feed extends Model { class FeedDAO extends Model_pdo { public function addFeed ($valuesTmp) { - $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate, priority, error) VALUES(?, ?, ?, ?, ?, ?, ?, 10, 0)'; + $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate, priority, httpAuth, error) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -216,6 +228,7 @@ class FeedDAO extends Model_pdo { $valuesTmp['website'], $valuesTmp['description'], $valuesTmp['lastUpdate'], + base64_encode ($valuesTmp['httpAuth']), ); if ($stm && $stm->execute ($values)) { @@ -231,6 +244,10 @@ class FeedDAO extends Model_pdo { $set = ''; foreach ($valuesTmp as $key => $v) { $set .= $key . '=?, '; + + if ($key == 'httpAuth') { + $valuesTmp[$key] = base64_encode ($v); + } } $set = substr ($set, 0, -2); @@ -408,7 +425,7 @@ class HelperFeed { $list[$key]->_lastUpdate ($dao['lastUpdate']); $list[$key]->_priority ($dao['priority']); $list[$key]->_pathEntries ($dao['pathEntries']); - $list[$key]->_httpAuth ($dao['httpAuth']); + $list[$key]->_httpAuth (base64_decode ($dao['httpAuth'])); if (isset ($dao['id'])) { $list[$key]->_id ($dao['id']); -- cgit v1.2.3 From 21dc4ceace513a0d6cd934f5fc4bb9cc643bb570 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 27 Apr 2013 22:33:14 +0200 Subject: Fix issue #64 : stockage des favicons en local --- app/layout/aside_feed.phtml | 2 +- app/layout/aside_flux.phtml | 2 +- app/models/Feed.php | 10 ++++++++++ app/views/index/index.phtml | 2 +- lib/lib_rss.php | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index 4be37868d..ec4993a70 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -43,7 +43,7 @@ feeds as $feed) { ?>
  • - + name (); ?>
  • diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 60fcbe457..d2e5341e3 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -87,7 +87,7 @@ nbNotRead (); ?> - + 0 ? '' : ''; ?> 0 ? '(' . $not_read . ') ' : ''; ?> diff --git a/app/models/Feed.php b/app/models/Feed.php index 08cf7425f..97cbe55d1 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -77,6 +77,16 @@ class Feed extends Model { $feedDAO = new FeedDAO (); return $feedDAO->countNotRead ($this->id ()); } + public function favicon () { + $file = '/data/favicons/' . $this->id () . '.ico'; + + $favicon_url = Url::display ($file); + if (!file_exists (PUBLIC_PATH . $file)) { + $favicon_url = dowload_favicon ($this->website (), $this->id ()); + } + + return $favicon_url; + } public function _id ($value) { $this->id = $value; diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index a7b67bcbc..c9be7169d 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -49,7 +49,7 @@ if (isset ($this->entryPaginator)) { feed (true); ?> -
  • name (); ?>
  • +
  • name (); ?>
  • title (); ?>
  • date (); ?>
  • diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 76c304064..e004b7498 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -152,3 +152,41 @@ function get_content_by_parsing ($url, $path) { throw new Exception (); } } + +/* Télécharge le favicon d'un site, le place sur le serveur et retourne l'URL */ +function dowload_favicon ($website, $id) { + $url = 'http://g.etfv.co/' . $website; + $favicons_dir = PUBLIC_PATH . '/data/favicons'; + $dest = $favicons_dir . '/' . $id . '.ico'; + $favicon_url = '/data/favicons/' . $id . '.ico'; + + if (!is_dir ($favicons_dir)) { + if (!mkdir ($favicons_dir, 0755, true)) { + return $url; + } + } + + if (!file_exists ($dest)) { + $c = curl_init ($url); + curl_setopt ($c, CURLOPT_HEADER, false); + curl_setopt ($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($c, CURLOPT_BINARYTRANSFER, true); + $imgRaw = curl_exec ($c); + + if (curl_getinfo ($c, CURLINFO_HTTP_CODE) == 200) { + $file = fopen ($dest, 'w'); + if ($file === false) { + return $url; + } + + fwrite ($file, $imgRaw); + fclose ($file); + } else { + return $url; + } + + curl_close ($c); + } + + return $favicon_url; +} -- cgit v1.2.3 From 1bee8ad9a7c02c0f53d1f334467cb6d1e5044511 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 28 Apr 2013 14:18:34 +0200 Subject: Flux déplacés de catégories lors de la suppression de la leur (issue #28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/configureController.php | 6 +++++- app/models/Feed.php | 24 ++++++++++++++++++++++++ app/views/configure/feed.phtml | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index f4d1a38e7..d6d210099 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -11,8 +11,11 @@ class configureController extends ActionController { } 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 ()); @@ -27,7 +30,8 @@ class configureController extends ActionController { 'color' => $cat->color () ); $catDAO->updateCategory ($ids[$key], $values); - } elseif ($ids[$key] != '000000') { + } elseif ($ids[$key] != $defaultId) { + $feedDAO->changeCategory ($ids[$key], $defaultId); $catDAO->deleteCategory ($ids[$key]); } } diff --git a/app/models/Feed.php b/app/models/Feed.php index 97cbe55d1..e519a91cb 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -296,6 +296,30 @@ class FeedDAO extends Model_pdo { } } + public function changeCategory ($idOldCat, $idNewCat) { + $catDAO = new CategoryDAO (); + $newCat = $catDAO->searchById ($idNewCat); + if (!$newCat) { + $newCat = $catDAO->getDefault (); + } + + $sql = 'UPDATE feed SET category=? WHERE category=?'; + $stm = $this->bd->prepare ($sql); + + $values = array ( + $newCat->id (), + $idOldCat + ); + + if ($stm && $stm->execute ($values)) { + return true; + } else { + $info = $stm->errorInfo(); + Log::record ('SQL error : ' . $info[2], Log::ERROR); + return false; + } + } + public function deleteFeed ($id) { $sql = 'DELETE FROM feed WHERE id=?'; $stm = $this->bd->prepare ($sql); diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml index 0d9c5cae6..33483f72d 100644 --- a/app/views/configure/feed.phtml +++ b/app/views/configure/feed.phtml @@ -2,7 +2,7 @@ flux) { ?>
    - +

    flux->name (); ?>

    flux->description (); ?> -- cgit v1.2.3 From 864318bf68b28ff6340701bce24e25768164e138 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 28 Apr 2013 16:01:14 +0200 Subject: Meilleure gestion des erreurs lors de l'ajout d'un flux RSS + les vidéos apparaissent maintenant dans les articles + si connexion paramétrée l'actualisation des flux n'est plus permis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/feedController.php | 332 ++++++++++++++++----------------- app/layout/nav_menu.phtml | 2 +- app/models/Exception/FeedException.php | 6 + app/models/Feed.php | 14 +- 4 files changed, 184 insertions(+), 170 deletions(-) (limited to 'app/models/Feed.php') diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index c235e8b0f..b535e7bc4 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -2,96 +2,108 @@ class feedController extends ActionController { public function firstAction () { - $catDAO = new CategoryDAO (); - $catDAO->checkDefault (); - } - - public function addAction () { if (login_is_conf ($this->view->conf) && !is_logged ()) { Error::error ( 403, array ('error' => array (Translate::t ('access_denied'))) ); - } else { - if (Request::isPost ()) { - $url = Request::param ('url_rss'); - $cat = Request::param ('category'); - $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'])) { - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('already_subscribed', $feed->name ()) - ); - Session::_param ('notification', $notif); - } elseif ($feedDAO->addFeed ($values)) { - $entryDAO = new EntryDAO (); - $entries = $feed->entries (); - - foreach ($entries as $entry) { - $values = $entry->toArray (); - $entryDAO->addEntry ($values); - } - - // notif - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_added', $feed->name ()) - ); - Session::_param ('notification', $notif); - $params['id'] = $feed->id (); - } else { - // notif - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('feed_not_added', $feed->name ()) - ); - Session::_param ('notification', $notif); - } - } catch (FeedException $e) { - Log::record ($e->getMessage (), Log::ERROR); + $catDAO = new CategoryDAO (); + $catDAO->checkDefault (); + } + + public function addAction () { + if (Request::isPost ()) { + $url = Request::param ('url_rss'); + $cat = Request::param ('category'); + $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 ('internal_problem_feed') + 'content' => Translate::t ('already_subscribed', $feed->name ()) ); Session::_param ('notification', $notif); - } catch (Exception $e) { - // notif + } elseif (!$feedDAO->addFeed ($values)) { + // problème au niveau de la base de données $notif = array ( 'type' => 'bad', - 'content' => Translate::t ('invalid_url', $url) + 'content' => Translate::t ('feed_not_added', $feed->name ()) ); Session::_param ('notification', $notif); - } + } else { + $entryDAO = new EntryDAO (); + $entries = $feed->entries (); - Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true); + // on ajoute les articles en masse sans vérification + foreach ($entries as $entry) { + $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) { + Log::record ($e->getMessage (), Log::ERROR); + $notif = array ( + 'type' => 'bad', + 'content' => Translate::t ('invalid_url', $url) + ); + Session::_param ('notification', $notif); + } catch (FeedException $e) { + Log::record ($e->getMessage (), 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 + Log::record ($e->getMessage (), 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); } } @@ -175,114 +187,100 @@ class feedController extends ActionController { } public function massiveImportAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } else { - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - - $categories = Request::param ('categories', array ()); - $feeds = Request::param ('feeds', array ()); - - $this->addCategories ($categories); - - $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) { - 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 - ); + $entryDAO = new EntryDAO (); + $feedDAO = new FeedDAO (); + + $categories = Request::param ('categories', array ()); + $feeds = Request::param ('feeds', array ()); + + $this->addCategories ($categories); + + $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) { + try { + $feed->load (); - if (!$feedDAO->searchByUrl ($values['url'])) { - if (!$feedDAO->addFeed ($values)) { - $error = true; - } + // 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 + ); + + if (!$feedDAO->searchByUrl ($values['url'])) { + if (!$feedDAO->addFeed ($values)) { + $error = true; } - } catch (FeedException $e) { - $error = true; - Log::record ($e->getMessage (), Log::ERROR); } + } catch (FeedException $e) { + $error = true; + Log::record ($e->getMessage (), 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); - - Request::forward (array ( - 'c' => 'configure', - 'a' => 'importExport' - ), true); + 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); + + Request::forward (array ( + 'c' => 'configure', + 'a' => 'importExport' + ), true); } public function deleteAction () { - if (login_is_conf ($this->view->conf) && !is_logged ()) { - Error::error ( - 403, - array ('error' => array (Translate::t ('access_denied'))) - ); - } else { - $type = Request::param ('type', 'feed'); - $id = Request::param ('id'); + $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') - ); - } + $feedDAO = new FeedDAO (); + if ($type == 'category') { + if ($feedDAO->deleteFeedByCategory ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => Translate::t ('category_emptied') + ); } else { - if ($feedDAO->deleteFeed ($id)) { - $notif = array ( - 'type' => 'good', - 'content' => Translate::t ('feed_deleted') - ); - } else { - $notif = array ( - 'type' => 'bad', - 'content' => Translate::t ('error_occured') - ); - } + $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 { + if ($feedDAO->deleteFeed ($id)) { + $notif = array ( + 'type' => 'good', + 'content' => Translate::t ('feed_deleted') + ); } else { - Request::forward (array ('c' => 'configure', 'a' => 'feed'), true); + $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) { diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 1ee935db9..ce124da11 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -1,6 +1,7 @@