Verify page

Make sure the page and subpages are valid before recording the page hits.
This commit is contained in:
danpros 2025-11-01 11:56:01 +07:00
commit 050fe31523
2 changed files with 30 additions and 10 deletions

View file

@ -4666,18 +4666,26 @@ get('/:static', function ($static) {
} else {
$pages = '';
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
} else {
$pages = get_static_pages();
if (!empty($pages)) {
foreach ($pages as $index => $v) {
if (stripos($v['basename'], $static . '.md') !== false) {
add_view('page_' . $static);
}
}
}
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
}
$post = find_page($static);
$post = find_page($static, $pages);
if (!$post) {
not_found('page_' . $static);
@ -5050,12 +5058,20 @@ get('/:static/:sub', function ($static, $sub) {
header("location: $redir", TRUE, 301);
}
$sub_pages = '';
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
} else {
$sub_pages = array_values(get_static_subpages($static));
if (!empty($sub_pages)) {
foreach ($sub_pages as $index => $v) {
if (stripos($v['basename'], $sub . '.md') !== false) {
add_view('subpage_' . $static.'.'.$sub);
}
}
}
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
@ -5065,8 +5081,8 @@ get('/:static/:sub', function ($static, $sub) {
if (!$parent_post) {
not_found('subpage_' . $static.'.'.$sub);
}
$post = find_subpage($static, $sub);
$post = find_subpage($static, $sub, $sub_pages);
if (!$post) {
not_found('subpage_' . $static.'.'.$sub);
}

View file

@ -764,9 +764,11 @@ function find_post($year, $month, $name)
}
// Return static page.
function find_page($static = null)
function find_page($static = null, $pages = null)
{
if (empty($pages)) {
$pages = get_static_pages();
}
$tmp = array();
@ -818,9 +820,11 @@ function find_page($static = null)
}
// Return static subpage.
function find_subpage($static, $sub_static = null)
function find_subpage($static, $sub_static = null, $sub_pages = null)
{
if (empty($sub_pages)) {
$sub_pages = array_values(get_static_subpages($static));
}
$tmp = array();