From 29c65d96590c2a3abb6ca23fe7477bd15f564baa Mon Sep 17 00:00:00 2001 From: danpros Date: Tue, 9 Jan 2024 23:51:44 +0700 Subject: [PATCH] Fix username posts count If username has underscore --- system/htmly.php | 2 +- system/includes/functions.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/system/htmly.php b/system/htmly.php index 1b30351..c9bf520 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -894,7 +894,7 @@ get('/admin/mine', function () { $posts = get_profile_posts($name, $page, $perpage); - $total = get_count($name, 'dirname'); + $total = get_count('/'.$name.'/', 'dirname'); $author = get_author($name); diff --git a/system/includes/functions.php b/system/includes/functions.php index 676b246..a122afa 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -445,7 +445,7 @@ function get_posts($posts, $page = 1, $perpage = 0) } else { $post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]); } - + $post->slug = str_replace('.md', '', $arr[2]); $post->file = $filepath; @@ -1321,10 +1321,16 @@ function get_count($var, $str) $tmp = array(); foreach ($posts as $index => $v) { - $arr = explode('_', $v[$str]); - $url = $arr[0]; - if (stripos($url, "$var") !== false) { - $tmp[] = $v; + if ($str === 'basename') { + $arr = explode('_', $v[$str]); + $url = $arr[0]; + if (stripos($url, "$var") !== false) { + $tmp[] = $v; + } + } else { + if (stripos($v[$str], $var) !== false) { + $tmp[] = $v; + } } }