cleanup: quick cleanup of bot checking code

This commit is contained in:
Floorb 2023-08-21 12:26:35 -04:00
parent e78b800c64
commit 3e44d88ed8
2 changed files with 12 additions and 8 deletions

View file

@ -170,10 +170,7 @@ function pp_html_escape(string $unescaped) : string {
return htmlspecialchars($unescaped, ENT_QUOTES, 'UTF-8', false);
}
/* I think there is one row for each day, and in that row, tpage = non-unique, tvisit = unique page views for that day */
function updatePageViews() : void {
global $redis;
function isRequesterLikelyBot() : bool {
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
// Don't count bots
@ -181,6 +178,17 @@ function updatePageViews() : void {
|| str_contains($userAgent, 'bot')
|| str_contains($userAgent, 'spider')
|| str_contains($userAgent, 'crawl')) {
return true;
}
return false;
}
/* I think there is one row for each day, and in that row, tpage = non-unique, tvisit = unique page views for that day */
function updatePageViews() : void {
global $redis;
if (isRequesterLikelyBot()) {
return;
}

View file

@ -8,10 +8,6 @@ use PonePaste\Models\Paste;
use PonePaste\Models\User;
use PonePaste\Pastedown;
function isRequesterLikelyBot() : bool {
return str_contains(strtolower($_SERVER['HTTP_USER_AGENT']), 'bot');
}
function rawView($content, $p_code) : void {
if ($p_code) {
header('Content-Type: text/plain');