From ebc1f7bada448854e8ac1ce33b5c7f15caf03f83 Mon Sep 17 00:00:00 2001 From: octt <6083316-octospacc@users.noreply.gitlab.com> Date: Fri, 23 May 2025 12:49:18 +0200 Subject: [PATCH] v0.8, 17/01 --- Proxatore.php | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/Proxatore.php b/Proxatore.php index 1cc9bc9..2e56e68 100644 --- a/Proxatore.php +++ b/Proxatore.php @@ -54,6 +54,7 @@ const EMBEDS_SUFFIXES = [ 'telegram' => '?embed=1&mode=tme', ]; +define('SCRIPT_NAME', /* $_SERVER['SCRIPT_NAME'] . */ '/'); define('HISTORY_FILE', './' . $_SERVER['SCRIPT_NAME'] . '.history.jsonl'); function lstrip($str, $sub) { @@ -64,8 +65,15 @@ function urlLast($url) { return end(explode('/', trim(parse_url($url, PHP_URL_PATH), '/'))); } +function parseAbsoluteUrl($str) { + $strlow = strtolower($str); + if (str_starts_with($strlow, 'http://') || str_starts_with($strlow, 'https://')) { + return implode('://', array_slice(explode('://', $str), 1)); + } +} + function redirectTo($internalUrl) { - header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $internalUrl); + header('Location: ' . SCRIPT_NAME . $internalUrl); die(); } @@ -162,14 +170,25 @@ function searchHistory($keyword) { $path = $_SERVER['REQUEST_URI'];//parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $immediateResult = null; -if (isset($_GET['search']) && ($search = $_GET['search']) !== '') { - if (str_starts_with(strtolower($search), 'https://')) { - redirectTo(lstrip($search, 'https://')); +if (isset($_GET['proxatore-search']) && ($search = $_GET['proxatore-search']) !== '') { + //if (str_starts_with(strtolower($search), 'https://')) { + // redirectTo(lstrip($search, 'https://')); + if ($url = parseAbsoluteUrl($search)) { + redirectTo($url); + } else { + $searchResults = searchHistory($search); } - $searchResults = searchHistory($search); } else { - $segments = explode('/', trim($path, '/')); - array_shift($segments); + $path = trim($path, '/'); + if ($url = parseAbsoluteUrl($path)) { + //$path = $url; + redirectTo($url); + } + + $segments = explode('/', $path); + if (SCRIPT_NAME !== '/') { + array_shift($segments); + } $platform = null; $upstream = $segments[0] ?? null; @@ -472,9 +491,9 @@ video:not(video[src=""]) + img {
Original on = htmlspecialchars(PLATFORMS[$item['platform']][0] ?: $item['platform']) ?>/= htmlspecialchars($item['relativeurl']) ?>
- = APPNAME ?> Permalink
+ = APPNAME ?> Permalink