From a33a3d2afb6a861e194599973e31e5e448617296 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 22 Mar 2014 11:09:18 +0100 Subject: [PATCH] Implemented rudimental search engine --- inc/poche/Database.class.php | 8 ++++++++ inc/poche/Poche.class.php | 11 +++++++++-- inc/poche/global.inc.php | 2 +- themes/default/_menu.twig | 1 + 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 5b51b50..6aad16c 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -388,6 +388,14 @@ class Database { public function getLastId($column = '') { return $this->getHandle()->lastInsertId($column); } + + public function search($term){ + $search = '%'.$term.'%'; + $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ?"); + $query->execute(array($search)); + $entries = $query->fetchAll(); + return $entries; + } public function retrieveAllTags($user_id, $term = null) { $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 b1143d0..74a185b 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -603,6 +603,14 @@ class Poche 'tags' => $tags, ); break; + + case 'search': + if (isset($_POST['search'])){ + $search = $_POST['search']; + $tpl_vars['entries'] = $this->store->search($search); + $tpl_vars['nb_results'] = count($tpl_vars['entries']); + } + break; case 'view': $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { @@ -772,8 +780,7 @@ class Poche $this->emptyCache(); Tools::redirect('?view=config'); - } - + } /** * get credentials from differents sources * it redirects the user to the $referer link diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index d22b058..1509138 100644 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -38,7 +38,7 @@ if (! file_exists(ROOT . '/vendor/autoload.php')) { require_once ROOT . '/vendor/autoload.php'; } -# system configuration; database credentials et cetera +# system configuration; database credentials et caetera if (! file_exists(INCLUDES . '/poche/config.inc.php')) { Poche::$configFileAvailable = false; } else { diff --git a/themes/default/_menu.twig b/themes/default/_menu.twig index 55583b3..e2644b0 100644 --- a/themes/default/_menu.twig +++ b/themes/default/_menu.twig @@ -4,6 +4,7 @@
  • {% trans "archive" %}
  • {% trans "tags" %}
  • {% trans "save a link" %}
  • +
  • {% trans "search" %}
  • {% trans "config" %}
  • {% trans "logout" %}
  • diff --git a/themes/default/home.twig b/themes/default/home.twig index bd5fc2d..e3e8c6a 100755 --- a/themes/default/home.twig +++ b/themes/default/home.twig @@ -12,7 +12,29 @@ {% include '_menu.twig' %} {% endblock %} {% block precontent %} - {% include '_sorting.twig' %} +
    +
    +

    + : + +

    +
    +
    + +{% include '_sorting.twig' %} {% endblock %} {% block content %} {% if tag %}