diff options
author | tcit <tcit@tcit.fr> | 2014-03-22 11:09:18 +0100 |
---|---|---|
committer | tcit <tcit@tcit.fr> | 2014-03-22 11:09:18 +0100 |
commit | a33a3d2afb6a861e194599973e31e5e448617296 (patch) | |
tree | a8c846472db8fabe7cadbaad0f87bb420ce228ae | |
parent | 028e34b6c40c3571d35c49d5a27b7eac19ceb4ef (diff) | |
download | wallabag-a33a3d2afb6a861e194599973e31e5e448617296.tar.gz wallabag-a33a3d2afb6a861e194599973e31e5e448617296.tar.zst wallabag-a33a3d2afb6a861e194599973e31e5e448617296.zip |
Implemented rudimental search engine
-rwxr-xr-x | inc/poche/Database.class.php | 8 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 11 | ||||
-rw-r--r-- | inc/poche/global.inc.php | 2 | ||||
-rw-r--r-- | themes/default/_menu.twig | 1 | ||||
-rwxr-xr-x | themes/default/home.twig | 24 |
5 files changed, 42 insertions, 4 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 5b51b507..6aad16c1 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -388,6 +388,14 @@ class Database { | |||
388 | public function getLastId($column = '') { | 388 | public function getLastId($column = '') { |
389 | return $this->getHandle()->lastInsertId($column); | 389 | return $this->getHandle()->lastInsertId($column); |
390 | } | 390 | } |
391 | |||
392 | public function search($term){ | ||
393 | $search = '%'.$term.'%'; | ||
394 | $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ?"); | ||
395 | $query->execute(array($search)); | ||
396 | $entries = $query->fetchAll(); | ||
397 | return $entries; | ||
398 | } | ||
391 | 399 | ||
392 | public function retrieveAllTags($user_id, $term = null) { | 400 | public function retrieveAllTags($user_id, $term = null) { |
393 | $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags | 401 | $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index b1143d0b..74a185bd 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -603,6 +603,14 @@ class Poche | |||
603 | 'tags' => $tags, | 603 | 'tags' => $tags, |
604 | ); | 604 | ); |
605 | break; | 605 | break; |
606 | |||
607 | case 'search': | ||
608 | if (isset($_POST['search'])){ | ||
609 | $search = $_POST['search']; | ||
610 | $tpl_vars['entries'] = $this->store->search($search); | ||
611 | $tpl_vars['nb_results'] = count($tpl_vars['entries']); | ||
612 | } | ||
613 | break; | ||
606 | case 'view': | 614 | case 'view': |
607 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | 615 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
608 | if ($entry != NULL) { | 616 | if ($entry != NULL) { |
@@ -772,8 +780,7 @@ class Poche | |||
772 | $this->emptyCache(); | 780 | $this->emptyCache(); |
773 | 781 | ||
774 | Tools::redirect('?view=config'); | 782 | Tools::redirect('?view=config'); |
775 | } | 783 | } |
776 | |||
777 | /** | 784 | /** |
778 | * get credentials from differents sources | 785 | * get credentials from differents sources |
779 | * it redirects the user to the $referer link | 786 | * it redirects the user to the $referer link |
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index d22b0588..15091387 100644 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php | |||
@@ -38,7 +38,7 @@ if (! file_exists(ROOT . '/vendor/autoload.php')) { | |||
38 | require_once ROOT . '/vendor/autoload.php'; | 38 | require_once ROOT . '/vendor/autoload.php'; |
39 | } | 39 | } |
40 | 40 | ||
41 | # system configuration; database credentials et cetera | 41 | # system configuration; database credentials et caetera |
42 | if (! file_exists(INCLUDES . '/poche/config.inc.php')) { | 42 | if (! file_exists(INCLUDES . '/poche/config.inc.php')) { |
43 | Poche::$configFileAvailable = false; | 43 | Poche::$configFileAvailable = false; |
44 | } else { | 44 | } else { |
diff --git a/themes/default/_menu.twig b/themes/default/_menu.twig index 55583b3d..e2644b0f 100644 --- a/themes/default/_menu.twig +++ b/themes/default/_menu.twig | |||
@@ -4,6 +4,7 @@ | |||
4 | <li><a href="./?view=archive" {% if view == 'archive' %}class="current"{% endif %}>{% trans "archive" %}</a></li> | 4 | <li><a href="./?view=archive" {% if view == 'archive' %}class="current"{% endif %}>{% trans "archive" %}</a></li> |
5 | <li><a href="./?view=tags" {% if view == 'tags' %}class="current"{% endif %}>{% trans "tags" %}</a></li> | 5 | <li><a href="./?view=tags" {% if view == 'tags' %}class="current"{% endif %}>{% trans "tags" %}</a></li> |
6 | <li><a href="javascript: void(null);" id="pocheit">{% trans "save a link" %}</a><span id="pocheit-arrow"></span></li> | 6 | <li><a href="javascript: void(null);" id="pocheit">{% trans "save a link" %}</a><span id="pocheit-arrow"></span></li> |
7 | <li><a href="javascript: void(null);" id="search">{% trans "search" %}</a><span id="search-arrow"></span></li> | ||
7 | <li><a href="./?view=config" {% if view == 'config' %}class="current"{% endif %}>{% trans "config" %}</a></li> | 8 | <li><a href="./?view=config" {% if view == 'config' %}class="current"{% endif %}>{% trans "config" %}</a></li> |
8 | <li><a href="./?logout" title="{% trans "logout" %}">{% trans "logout" %}</a></li> | 9 | <li><a href="./?logout" title="{% trans "logout" %}">{% trans "logout" %}</a></li> |
9 | </ul> | 10 | </ul> |
diff --git a/themes/default/home.twig b/themes/default/home.twig index bd5fc2d6..e3e8c6af 100755 --- a/themes/default/home.twig +++ b/themes/default/home.twig | |||
@@ -12,7 +12,29 @@ | |||
12 | {% include '_menu.twig' %} | 12 | {% include '_menu.twig' %} |
13 | {% endblock %} | 13 | {% endblock %} |
14 | {% block precontent %} | 14 | {% block precontent %} |
15 | {% include '_sorting.twig' %} | 15 | <div id="search-form" class="messages info"> |
16 | <form method="post" action="index.php?view=search"> | ||
17 | <p> | ||
18 | <label>{% trans "Search" %}</label> : <input type="text" placeholder="{% trans "Enter your search here" %}" name="search" /> | ||
19 | <input type="submit" value="{% trans "Search" %} !"></input> | ||
20 | </p> | ||
21 | </form> | ||
22 | </div> | ||
23 | <script type="text/javascript"> | ||
24 | $(document).ready(function() { | ||
25 | |||
26 | $("#search-form").hide(); | ||
27 | |||
28 | $("#search").click(function(){ | ||
29 | $("#search-form").toggle(); | ||
30 | $("#search").toggleClass("current"); | ||
31 | $("#search-arrow").toggleClass("arrow-down"); | ||
32 | }); | ||
33 | |||
34 | |||
35 | }); | ||
36 | </script> | ||
37 | {% include '_sorting.twig' %} | ||
16 | {% endblock %} | 38 | {% endblock %} |
17 | {% block content %} | 39 | {% block content %} |
18 | {% if tag %} | 40 | {% if tag %} |