diff options
author | tcit <tcit@tcit.fr> | 2014-04-02 17:44:47 +0200 |
---|---|---|
committer | tcit <tcit@tcit.fr> | 2014-04-02 17:44:47 +0200 |
commit | d967a1fa14237648fc63c44f6a28c9c077b3e1bc (patch) | |
tree | e8c81af9d50c140f00da15e720eb3f29cdaede96 | |
parent | 22db488d21bc23dc28fc2d60574803525fe53b53 (diff) | |
download | wallabag-d967a1fa14237648fc63c44f6a28c9c077b3e1bc.tar.gz wallabag-d967a1fa14237648fc63c44f6a28c9c077b3e1bc.tar.zst wallabag-d967a1fa14237648fc63c44f6a28c9c077b3e1bc.zip |
Important fixes for search engine (thx @mariroz)
So sorry for the mess... :(
* search only in users' own articles
* sanitized what is searched
* display what is searched
* pagination, sorting available when searching
* use existing function to query db
* bad encoding caracters fixed
* link to JQuery into default theme, no longer in each theme
* some spaces instead of tabs
-rwxr-xr-x | inc/poche/Database.class.php | 13 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 18 | ||||
-rw-r--r-- | install/index.php | 6 | ||||
-rwxr-xr-x | themes/baggy/home.twig | 8 | ||||
-rwxr-xr-x | themes/courgette/home.twig | 8 | ||||
-rwxr-xr-x | themes/default/_sorting.twig | 4 | ||||
-rwxr-xr-x | themes/default/home.twig | 8 |
7 files changed, 45 insertions, 20 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 6f5c9ac0..2257f281 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -389,12 +389,13 @@ class Database { | |||
389 | return $this->getHandle()->lastInsertId($column); | 389 | return $this->getHandle()->lastInsertId($column); |
390 | } | 390 | } |
391 | 391 | ||
392 | public function search($term){ | 392 | public function search($term,$id,$limit = ''){ |
393 | $search = '%'.$term.'%'; | 393 | $search = '%'.$term.'%'; |
394 | $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ? OR title LIKE ? OR url LIKE ?"); //searches in content, title and URL | 394 | $sql_action = ("SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "); //searches in content, title and URL |
395 | $query->execute(array($search,$search,$search)); | 395 | $sql_action .= $this->getEntriesOrder().' ' . $limit; |
396 | $entries = $query->fetchAll(); | 396 | $params_action = array($id,$search,$search,$search); |
397 | return $entries; | 397 | $query = $this->executeQuery($sql_action, $params_action); |
398 | return $query->fetchAll(); | ||
398 | } | 399 | } |
399 | 400 | ||
400 | public function retrieveAllTags($user_id, $term = null) { | 401 | public function retrieveAllTags($user_id, $term = null) { |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 7d9faed1..42a2dd9a 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -604,12 +604,18 @@ class Poche | |||
604 | ); | 604 | ); |
605 | break; | 605 | break; |
606 | 606 | ||
607 | case 'search': | 607 | case 'search': |
608 | if (isset($_GET['search'])){ | 608 | if (isset($_GET['search'])){ |
609 | $search = $_GET['search']; | 609 | $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING); |
610 | $tpl_vars['entries'] = $this->store->search($search); | 610 | $tpl_vars['entries'] = $this->store->search($search,$this->user->getId()); |
611 | $tpl_vars['nb_results'] = count($tpl_vars['entries']); | 611 | $count = count($tpl_vars['entries']); |
612 | } | 612 | $this->pagination->set_total($count); |
613 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), | ||
614 | $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); | ||
615 | $tpl_vars['page_links'] = $page_links; | ||
616 | $tpl_vars['nb_results'] = $count; | ||
617 | $tpl_vars['search_term'] = $search; | ||
618 | } | ||
613 | break; | 619 | break; |
614 | case 'view': | 620 | case 'view': |
615 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | 621 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
diff --git a/install/index.php b/install/index.php index e63b2423..e02952e0 100644 --- a/install/index.php +++ b/install/index.php | |||
@@ -24,7 +24,7 @@ if (isset($_GET['clean'])) { | |||
24 | 24 | ||
25 | if (isset($_POST['download'])) { | 25 | if (isset($_POST['download'])) { |
26 | if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) { | 26 | if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) { |
27 | $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually<∕a> and unzip it in your wallabag folder.'; | 27 | $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.'; |
28 | } | 28 | } |
29 | else { | 29 | else { |
30 | if (extension_loaded('zip')) { | 30 | if (extension_loaded('zip')) { |
@@ -165,7 +165,7 @@ else if (isset($_POST['install'])) { | |||
165 | <!--[if IE]> | 165 | <!--[if IE]> |
166 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | 166 | <meta http-equiv="X-UA-Compatible" content="IE=10"> |
167 | <![endif]--> | 167 | <![endif]--> |
168 | <title>wallabag — installation</title> | 168 | <title>wallabag - installation</title> |
169 | <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" /> | 169 | <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" /> |
170 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png"> | 170 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png"> |
171 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png"> | 171 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png"> |
@@ -176,7 +176,7 @@ else if (isset($_POST['install'])) { | |||
176 | <link rel="stylesheet" href="themes/baggy/css/main.css" media="all"> | 176 | <link rel="stylesheet" href="themes/baggy/css/main.css" media="all"> |
177 | <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all"> | 177 | <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all"> |
178 | <link rel="stylesheet" href="themes/baggy/css/print.css" media="print"> | 178 | <link rel="stylesheet" href="themes/baggy/css/print.css" media="print"> |
179 | <script src="themes/baggy/js/jquery-2.0.3.min.js"></script> | 179 | <script src="themes/default/js/jquery-2.0.3.min.js"></script> |
180 | <script src="themes/baggy/js/init.js"></script> | 180 | <script src="themes/baggy/js/init.js"></script> |
181 | </head> | 181 | </head> |
182 | <body> | 182 | <body> |
diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index e34897fa..5dd91307 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig | |||
@@ -25,9 +25,15 @@ | |||
25 | {% block pager %} | 25 | {% block pager %} |
26 | {% if nb_results > 1 %} | 26 | {% if nb_results > 1 %} |
27 | <div class="results"> | 27 | <div class="results"> |
28 | <div class="nb-results">{{ nb_results }} {% trans "results" %}</div> | 28 | <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div> |
29 | {{ page_links | raw }} | 29 | {{ page_links | raw }} |
30 | </div> | 30 | </div> |
31 | {% elseif nb_results == 1 %} | ||
32 | {% if search_term is defined %} | ||
33 | <div class="results"> | ||
34 | <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div> | ||
35 | </div> | ||
36 | {% endif %} | ||
31 | {% endif %} | 37 | {% endif %} |
32 | {% endblock %} | 38 | {% endblock %} |
33 | <div id="list-entries" class="list-entries"> | 39 | <div id="list-entries" class="list-entries"> |
diff --git a/themes/courgette/home.twig b/themes/courgette/home.twig index 5b229ce9..6ba72d35 100755 --- a/themes/courgette/home.twig +++ b/themes/courgette/home.twig | |||
@@ -26,9 +26,15 @@ | |||
26 | {% block pager %} | 26 | {% block pager %} |
27 | {% if nb_results > 1 %} | 27 | {% if nb_results > 1 %} |
28 | <div class="results"> | 28 | <div class="results"> |
29 | <div class="nb-results">{{ nb_results }} {% trans "results" %}</div> | 29 | <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div> |
30 | {{ page_links | raw }} | 30 | {{ page_links | raw }} |
31 | </div> | 31 | </div> |
32 | {% elseif nb_results == 1 %} | ||
33 | {% if search_term is defined %} | ||
34 | <div class="results"> | ||
35 | <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div> | ||
36 | </div> | ||
37 | {% endif %} | ||
32 | {% endif %} | 38 | {% endif %} |
33 | {% endblock %} | 39 | {% endblock %} |
34 | {% for entry in entries %} | 40 | {% for entry in entries %} |
diff --git a/themes/default/_sorting.twig b/themes/default/_sorting.twig index dfa5cfe4..ce3d38bc 100755 --- a/themes/default/_sorting.twig +++ b/themes/default/_sorting.twig | |||
@@ -1,6 +1,6 @@ | |||
1 | {% if entries|length > 1 %} | 1 | {% if entries|length > 1 %} |
2 | <ul id="sort"> | 2 | <ul id="sort"> |
3 | <li><a href="./?sort=ia&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li> | 3 | <li><a href="./?sort=ia&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li> |
4 | <li><a href="./?sort=ta&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li> | 4 | <li><a href="./?sort=ta&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li> |
5 | </ul> | 5 | </ul> |
6 | {% endif %} | 6 | {% endif %} |
diff --git a/themes/default/home.twig b/themes/default/home.twig index b6185df1..7bee883b 100755 --- a/themes/default/home.twig +++ b/themes/default/home.twig | |||
@@ -26,9 +26,15 @@ | |||
26 | {% block pager %} | 26 | {% block pager %} |
27 | {% if nb_results > 1 %} | 27 | {% if nb_results > 1 %} |
28 | <div class="results"> | 28 | <div class="results"> |
29 | <div class="nb-results">{{ nb_results }} {% trans "results" %}</div> | 29 | <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div> |
30 | {{ page_links | raw }} | 30 | {{ page_links | raw }} |
31 | </div> | 31 | </div> |
32 | {% elseif nb_results == 1 %} | ||
33 | {% if search_term is defined %} | ||
34 | <div class="results"> | ||
35 | <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div> | ||
36 | </div> | ||
37 | {% endif %} | ||
32 | {% endif %} | 38 | {% endif %} |
33 | {% endblock %} | 39 | {% endblock %} |
34 | {% for entry in entries %} | 40 | {% for entry in entries %} |