Merge pull request #867 from splifingate/master

Ensure three-character minimum for $keyword search by @splifingate
This commit is contained in:
Dan 2025-01-29 18:09:26 +07:00 committed by GitHub
commit 410496d0b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 32 deletions

View file

@ -1319,6 +1319,8 @@ function get_frontpage()
// Return search page.
function get_keyword($keyword, $page, $perpage)
{
if (strlen($keyword) >= 3) { // three-character minimum
$posts = get_blog_posts();
$tmp = array();
@ -1327,7 +1329,7 @@ function get_keyword($keyword, $page, $perpage)
$filepath = $v['dirname'] . '/' . $v['basename'];
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only)
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // whole-words only
$findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode
@ -1349,6 +1351,7 @@ function get_keyword($keyword, $page, $perpage)
return $tmp = get_posts($tmp, $page, $perpage);
}
}
// Get related posts base on post category.
function get_related($tag, $custom = null, $count = null)
@ -1513,6 +1516,8 @@ function get_tagcount($var)
// Return search result count
function keyword_count($keyword)
{
if (strlen($keyword) >= 3) { // three-character minimum
$posts = get_blog_posts();
$tmp = array();
@ -1521,7 +1526,7 @@ function keyword_count($keyword)
$filepath = $v['dirname'] . '/' . $v['basename'];
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only)
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // whole-words only
$findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode
@ -1537,9 +1542,9 @@ function keyword_count($keyword)
}
$tmp = array_unique($tmp, SORT_REGULAR);
return count($tmp);
}
}
// Return recent posts lists
function recent_posts($custom = null, $count = null)

View file

@ -31,7 +31,7 @@
<!-- main.html.php -->
<div class="row justify-content-center" style="padding-top: 3rem;">
<div class="col-md-12 text-center">
<h1 class="mt-0">Search: <span style='color: #628B48;'><?php echo $search->title;?></span> (<?php echo $search->count;?>)</h1>
<h1 class="mt-0">Search: <?php echo $search->title;?> (<?php echo $search->count;?>)</h1>
<form><input type="search" name="search" class="form-control is-search" placeholder="<?php echo i18n('Type_to_search');?>"></form>
</div>
</div>