]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Important fixes for search engine (thx @mariroz)
authortcit <tcit@tcit.fr>
Wed, 2 Apr 2014 15:44:47 +0000 (17:44 +0200)
committertcit <tcit@tcit.fr>
Wed, 2 Apr 2014 15:44:47 +0000 (17:44 +0200)
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

inc/poche/Database.class.php
inc/poche/Poche.class.php
install/index.php
themes/baggy/home.twig
themes/courgette/home.twig
themes/default/_sorting.twig
themes/default/home.twig

index 6f5c9ac04755deb5fa0ed1679aa22a9f8dfde981..2257f28177e8d4abed9fe743142f3a9e82b05537 100755 (executable)
@@ -389,12 +389,13 @@ class Database {
         return $this->getHandle()->lastInsertId($column);
     }
        
-       public function search($term){
-               $search = '%'.$term.'%';
-               $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ? OR title LIKE ? OR url LIKE ?"); //searches in content, title and URL
-               $query->execute(array($search,$search,$search));
-               $entries = $query->fetchAll();
-               return $entries;
+   public function search($term,$id,$limit = ''){
+      $search = '%'.$term.'%';
+      $sql_action     = ("SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "); //searches in content, title and URL
+      $sql_action .= $this->getEntriesOrder().' ' . $limit;
+      $params_action  = array($id,$search,$search,$search);
+      $query          = $this->executeQuery($sql_action, $params_action);
+      return $query->fetchAll();
        }
 
     public function retrieveAllTags($user_id, $term = null) {
index 7d9faed14e386d04391891d3ea3c8ee3890bfe56..42a2dd9a2fa73a76de1aa9d576a37a65abe8cf34 100755 (executable)
@@ -604,12 +604,18 @@ class Poche
                 );
                 break;
                                
-                       case 'search':
-                               if (isset($_GET['search'])){
-                                       $search = $_GET['search'];
-                                       $tpl_vars['entries'] = $this->store->search($search);
-                                       $tpl_vars['nb_results'] = count($tpl_vars['entries']);
-                               }
+         case 'search':
+            if (isset($_GET['search'])){
+               $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING);
+               $tpl_vars['entries'] = $this->store->search($search,$this->user->getId());
+               $count = count($tpl_vars['entries']);
+               $this->pagination->set_total($count);
+               $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
+                        $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
+               $tpl_vars['page_links'] = $page_links;
+               $tpl_vars['nb_results'] = $count;
+               $tpl_vars['search_term'] = $search;
+            }
                                break;
             case 'view':
                 $entry = $this->store->retrieveOneById($id, $this->user->getId());
index e63b24239bab2a7c640d6f63fbd040368d2c39aa..e02952e011f2b032dccb20a58a1b6cdb6eace1cc 100644 (file)
@@ -24,7 +24,7 @@ if (isset($_GET['clean'])) {
 
 if (isset($_POST['download'])) {
     if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) {
-        $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually<∕a> and unzip it in your wallabag folder.';
+        $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.';
     }
     else {
         if (extension_loaded('zip')) {
@@ -165,7 +165,7 @@ else if (isset($_POST['install'])) {
         <!--[if IE]>
         <meta http-equiv="X-UA-Compatible" content="IE=10">
         <![endif]-->
-        <title>wallabag â€” installation</title>
+        <title>wallabag - installation</title>
         <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" />
         <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
         <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'])) {
         <link rel="stylesheet" href="themes/baggy/css/main.css" media="all">
         <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all">
         <link rel="stylesheet" href="themes/baggy/css/print.css" media="print">
-        <script src="themes/baggy/js/jquery-2.0.3.min.js"></script>
+        <script src="themes/default/js/jquery-2.0.3.min.js"></script>
         <script src="themes/baggy/js/init.js"></script>
     </head>
     <body>
index e34897fa86862d4f072820001e33a299bcb2ed31..5dd91307748bd7c40a75908f540bcd808f90cee5 100755 (executable)
                 {% block pager %}
                     {% if nb_results > 1 %}
                 <div class="results">
-                    <div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
+                    <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
                         {{ page_links | raw }}
                 </div>
+                    {% elseif nb_results == 1 %}
+                        {% if search_term is defined %}
+                     <div class="results">
+                        <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
+                     </div>
+                        {% endif %}
                     {% endif %}
                 {% endblock %}
             <div id="list-entries" class="list-entries">
index 5b229ce9e6416ea03b681daac276624409a61630..6ba72d353576175a2b781b21c8f284b23a44a2bd 100755 (executable)
                 {% block pager %}
                     {% if nb_results > 1 %}
                 <div class="results">
-                    <div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
+                    <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
                         {{ page_links | raw }}
                 </div>
+                    {% elseif nb_results == 1 %}
+                        {% if search_term is defined %}
+                     <div class="results">
+                        <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
+                     </div>
+                        {% endif %}
                     {% endif %}
                 {% endblock %}
                 {% for entry in entries %}
index dfa5cfe40787435814d6d3b819eec8f293a844a0..ce3d38bc94845736a794b750a1204dcace304f47 100755 (executable)
@@ -1,6 +1,6 @@
 {% if entries|length > 1 %}
   <ul id="sort">
-      <li><a href="./?sort=ia&amp;view={{ view }}&amp;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&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
-      <li><a href="./?sort=ta&amp;view={{ view }}&amp;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&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
+      <li><a href="./?sort=ia&amp;view={{ view }}{% if search_term is defined %}&amp;search={{ search_term }}{% endif %}&amp;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&amp;view={{ view }}{% if search_term is defined %}&amp;search={{ search_term }}{% endif %}&amp;id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
+      <li><a href="./?sort=ta&amp;view={{ view }}{% if search_term is defined %}&amp;search={{ search_term }}{% endif %}&amp;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&amp;view={{ view }}{% if search_term is defined %}&amp;search={{ search_term }}{% endif %}&amp;id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
   </ul>
 {% endif %}
index b6185df18ba6c57285e30bc4c866119df1275b78..7bee883b649d2c7f1ee3f4c47724b8389f15779f 100755 (executable)
                 {% block pager %}
                     {% if nb_results > 1 %}
                 <div class="results">
-                    <div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
+                    <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
                         {{ page_links | raw }}
                 </div>
+                    {% elseif nb_results == 1 %}
+                        {% if search_term is defined %}
+                     <div class="results">
+                        <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
+                     </div>
+                        {% endif %}
                     {% endif %}
                 {% endblock %}
                 {% for entry in entries %}