From ee40846bd68433d324dc364c6f719d3f3e2e73b4 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 11 Nov 2022 15:39:28 +0100 Subject: [PATCH] Controllers+JS: Search in blog contents, fix special character search --- app/controllers/BlogController.php | 4 +++- public/js/site.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/BlogController.php b/app/controllers/BlogController.php index 23f595e..579261b 100644 --- a/app/controllers/BlogController.php +++ b/app/controllers/BlogController.php @@ -41,7 +41,9 @@ class BlogController extends PageController { LEFT JOIN section ON page.section_id = section.id LEFT JOIN log ON blog_post.log_id = log.id WHERE blog_post.archived = 0 AND - (blog_post.title LIKE :query OR blog_post.tag LIKE :query) + (blog_post.content LIKE :query OR + blog_post.title LIKE :query OR + blog_post.tag LIKE :query) ', [[':query', "%$query%", \PDO::PARAM_STR]]); } diff --git a/public/js/site.js b/public/js/site.js index 13f8273..6f5a13b 100644 --- a/public/js/site.js +++ b/public/js/site.js @@ -19,7 +19,7 @@ $(document).ready(function() { { var url = input.data("url"); var search = input.val(); - window.location.href = url + '?search=' + search; + window.location.href = url + '?search=' + encodeURIComponent(search); } $("#js-blog-search").keydown(function(e) { @@ -37,7 +37,7 @@ $(document).ready(function() { var url = $(this).data("url"); var search = $(this).val(); if (search.length == 0 || search.length >= 3) { - fetch(url + '/search?query=' + search) + fetch(url + '/search?query=' + encodeURIComponent(search)) .then(response => response.text()) .then(data => { $("#blog-posts").empty().append(data);