A free, self-hostable news aggregator…
Ajout champs de recherche + désactivation des raccourcis quand un input a le focus -> fix bugs #18 et #29
Marien Fressinaud9daa4c14636c
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.phpindex 18d9d43c3..79d430f99 100755--- a/app/controllers/indexController.php+++ b/app/controllers/indexController.php@@ -30,11 +30,13 @@ class indexController extends ActionController {$this->view->get_f = false;$order = $this->view->conf->sortOrder ();+ $search = Request::param ('search');+$error = false;// Récupère les flux par catégorie, favoris ou tousif ($get == 'favoris') {- $entries = $entryDAO->listFavorites ($mode, $order);+ $entries = $entryDAO->listFavorites ($mode, $search, $order);$this->view->get_c = $get;View::prependTitle ('Vos favoris - ');} elseif ($get != false) {@@ -42,7 +44,7 @@ class indexController extends ActionController {$get = substr ($get, 2);if ($typeGet == 'c') {- $entries = $entryDAO->listByCategory ($get, $mode, $order);+ $entries = $entryDAO->listByCategory ($get, $mode, $search, $order);$cat = $catDAO->searchById ($get);if ($cat) {@@ -52,7 +54,7 @@ class indexController extends ActionController {$error = true;}} elseif ($typeGet == 'f') {- $entries = $entryDAO->listByFeed ($get, $mode, $order);+ $entries = $entryDAO->listByFeed ($get, $mode, $search, $order);$feed = $feedDAO->searchById ($get);if ($feed) {@@ -74,7 +76,7 @@ class indexController extends ActionController {// Cas où on ne choisie ni catégorie ni les favoris// ou si la catégorie ne correspond à aucuneif (!isset ($entries)) {- $entries = $entryDAO->listEntries ($mode, $order);+ $entries = $entryDAO->listEntries ($mode, $search, $order);}try {diff --git a/app/layout/header.phtml b/app/layout/header.phtmlindex 04dbd91ff..351984aa7 100644--- a/app/layout/header.phtml+++ b/app/layout/header.phtml@@ -17,7 +17,7 @@<form action="<?php echo _url ('index', 'index'); ?>" method="get"><div class="stick"><?php $s = Request::param ('search', ''); ?>- <input type="text" name="search" id="search" value="<?php echo $s; ?>" placeholder="Rechercher (non fonctionnel)" />+ <input type="text" name="search" id="search" value="<?php echo $s; ?>" placeholder="Rechercher sur les titres" /><button class="btn" type="submit"><i class="icon i_search"></i></button></div></form>diff --git a/app/models/Entry.php b/app/models/Entry.phpindex 8a1ee1449..b1d7b8880 100755--- a/app/models/Entry.php+++ b/app/models/Entry.php@@ -229,12 +229,22 @@ class EntryDAO extends Model_pdo {}}- public function listEntries ($mode, $order = 'high_to_low') {+ public function listEntries ($mode, $search = false, $order = 'high_to_low') {$where = '';if ($mode == 'not_read') {$where = ' WHERE is_read=0';}+ $values = array();+ if ($search) {+ $values[] = '%'.$search.'%';+ if ($mode == 'not_read') {+ $where = ' AND title LIKE ?';+ } else {+ $where = ' WHERE title LIKE ?';+ }+ }+if ($order == 'low_to_high') {$order = ' DESC';} else {@@ -243,7 +253,7 @@ class EntryDAO extends Model_pdo {$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;$stm = $this->bd->prepare ($sql);- $stm->execute ();+ $stm->execute ($values);$res = $stm->fetchAll (PDO::FETCH_ASSOC);$this->nbItems = $res[0]['count'];@@ -254,17 +264,23 @@ class EntryDAO extends Model_pdo {. ' ORDER BY date' . $order. ' LIMIT ' . $deb . ', ' . $fin;$stm = $this->bd->prepare ($sql);- $stm->execute ();+ $stm->execute ($values);return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));}- public function listFavorites ($mode, $order = 'high_to_low') {+ public function listFavorites ($mode, $search = false, $order = 'high_to_low') {$where = ' WHERE is_favorite=1';if ($mode == 'not_read') {$where .= ' AND is_read=0';}+ $values = array();+ if ($search) {+ $values[] = '%'.$search.'%';+ $where = ' AND title LIKE ?';+ }+if ($order == 'low_to_high') {$order = ' DESC';} else {@@ -273,7 +289,7 @@ class EntryDAO extends Model_pdo {$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;$stm = $this->bd->prepare ($sql);- $stm->execute ();+ $stm->execute ($values);$res = $stm->fetchAll (PDO::FETCH_ASSOC);$this->nbItems = $res[0]['count'];@@ -290,17 +306,23 @@ class EntryDAO extends Model_pdo {}$stm = $this->bd->prepare ($sql);- $stm->execute ();+ $stm->execute ($values);return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));}- public function listByCategory ($cat, $mode, $order = 'high_to_low') {+ public function listByCategory ($cat, $mode, $search = false, $order = 'high_to_low') {$where = ' WHERE category=?';if ($mode == 'not_read') {$where .= ' AND is_read=0';}+ $values = array ($cat);+ if ($search) {+ $values[] = '%'.$search.'%';+ $where = ' AND title LIKE ?';+ }+if ($order == 'low_to_high') {$order = ' DESC';} else {@@ -309,7 +331,6 @@ class EntryDAO extends Model_pdo {$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where;$stm = $this->bd->prepare ($sql);- $values = array ($cat);$stm->execute ($values);$res = $stm->fetchAll (PDO::FETCH_ASSOC);$this->nbItems = $res[0]['count'];@@ -322,19 +343,23 @@ class EntryDAO extends Model_pdo {$stm = $this->bd->prepare ($sql);- $values = array ($cat);-$stm->execute ($values);return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));}- public function listByFeed ($feed, $mode, $order = 'high_to_low') {+ public function listByFeed ($feed, $mode, $search = false, $order = 'high_to_low') {$where = ' WHERE id_feed=?';if ($mode == 'not_read') {$where .= ' AND is_read=0';}+ $values = array();+ if ($search) {+ $values[] = '%'.$search.'%';+ $where = ' AND title LIKE ?';+ }+if ($order == 'low_to_high') {$order = ' DESC';} else {diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtmlindex d503cac0f..a4e3229bf 100644--- a/app/views/javascript/main.phtml+++ b/app/views/javascript/main.phtml@@ -153,16 +153,22 @@ $(document).ready (function () {// on marque comme lu ou non luactive = $(".flux.active");mark_read (active);+ }, {+ 'disable_in_input':true});shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {// on marque tout comme luurl = $("#top a.read_all").attr ("href");redirect (url, false);+ }, {+ 'disable_in_input':true});shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {// on marque comme favori ou non favoriactive = $(".flux.active");mark_favorite (active);+ }, {+ 'disable_in_input':true});// Touches de navigation@@ -176,6 +182,8 @@ $(document).ready (function () {} else if (new_active[0] === undefined) {slide (last_active, old_active);}+ }, {+ 'disable_in_input':true});shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {old_active = $(".flux.active");@@ -184,6 +192,8 @@ $(document).ready (function () {if (first.hasClass("flux")) {slide (first, old_active);}+ }, {+ 'disable_in_input':true});shortcut.add("<?php echo $s['next_entry']; ?>", function () {old_active = $(".flux.active");@@ -195,6 +205,8 @@ $(document).ready (function () {} else if (new_active[0] === undefined) {slide (first_active, old_active);}+ }, {+ 'disable_in_input':true});shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {old_active = $(".flux.active");@@ -203,18 +215,26 @@ $(document).ready (function () {if (last.hasClass("flux")) {slide (last, old_active);}+ }, {+ 'disable_in_input':true});shortcut.add("<?php echo $s['next_page']; ?>", function () {url = $(".pager-next a").attr ("href");redirect (url, false);+ }, {+ 'disable_in_input':true});shortcut.add("<?php echo $s['prev_page']; ?>", function () {url = $(".pager-previous a").attr ("href");redirect (url, false);+ }, {+ 'disable_in_input':true});shortcut.add("<?php echo $s['go_website']; ?>", function () {url = $(".flux.active .link a").attr ("href");redirect (url, true);+ }, {+ 'disable_in_input':true});});