From 180bc0b0d9859ec204e4f1a7f84bc310f740ecec Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 26 Oct 2021 17:18:16 +0200 Subject: [PATCH] dev21w43d-a --- src/search/Search.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/search/Search.php b/src/search/Search.php index d486f1f..a2f39cf 100644 --- a/src/search/Search.php +++ b/src/search/Search.php @@ -5,7 +5,9 @@ class Search extends Database { public function __construct() { - $this->query = $query; + parent::__construct("search"); + + $this->query = $this->real_escape_string($query); $mime_type = $_SERVER["HTTP_CONTENT_TYPE"] ? $_SERVER["HTTP_CONTENT_TYPE"] : $_GET["f"]; switch($mime_type) { @@ -22,6 +24,15 @@ } } + private function get_results() { + $sql = "SELECT id,template,content FROM `search` WHERE `content` LIKE '%{$this->query}%'"; + $query = $this->query($sql); + if(!$query->num_rows()) { + return false; + } + return $query->fetch_assoc(); + } + private function get_html_template($name) { $path = dirname(__FILE__,1)."/templates/${name}.html"; if(!is_file($path)) { @@ -38,11 +49,18 @@ $this->get_html_template("card_default"), $this->get_html_template("result_about") ]; + + header("Content-Type: text/html"); echo implode("",$results); } private function get_json() { + $data = [ + "results" => [] + ]; + $json = json_encode($data); + header("Content-Type: application/json"); - echo "{}"; + echo $json; } }