dev21w43d-a

This commit is contained in:
Victor Westerlund 2021-10-26 17:18:16 +02:00
parent 65632140d8
commit 180bc0b0d9

View file

@ -5,7 +5,9 @@
class Search extends Database { class Search extends Database {
public function __construct() { 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"]; $mime_type = $_SERVER["HTTP_CONTENT_TYPE"] ? $_SERVER["HTTP_CONTENT_TYPE"] : $_GET["f"];
switch($mime_type) { 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) { private function get_html_template($name) {
$path = dirname(__FILE__,1)."/templates/${name}.html"; $path = dirname(__FILE__,1)."/templates/${name}.html";
if(!is_file($path)) { if(!is_file($path)) {
@ -38,11 +49,18 @@
$this->get_html_template("card_default"), $this->get_html_template("card_default"),
$this->get_html_template("result_about") $this->get_html_template("result_about")
]; ];
header("Content-Type: text/html");
echo implode("",$results); echo implode("",$results);
} }
private function get_json() { private function get_json() {
$data = [
"results" => []
];
$json = json_encode($data);
header("Content-Type: application/json"); header("Content-Type: application/json");
echo "{}"; echo $json;
} }
} }