v0.7, 15/01

This commit is contained in:
octt
2025-05-23 12:48:47 +02:00
parent 55089a0fcc
commit bb3577b793

View File

@@ -1,5 +1,5 @@
<?php
const APPNAME = 'Proxatore';
const APPNAME = '🎭️ Proxatore';
const PLATFORMS = [
'facebook' => ['facebook.com', 'm.facebook.com'],
@@ -34,7 +34,7 @@ const PLATFORMS_ORDERED = ['telegram'];
const PLATFORMS_TRACKING = ['facebook', 'xiaohongshu'];
const PLATFORMS_VIDEO = ['instagram'];
const PLATFORMS_VIDEO = ['facebook', 'instagram'];
const EMBEDS = [
'reddit' => ['embed.reddit.com'],
@@ -64,6 +64,11 @@ function urlLast($url) {
return end(explode('/', trim(parse_url($url, PHP_URL_PATH), '/')));
}
function redirectTo($internalUrl) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $internalUrl);
die();
}
function fetchContent($url, $redirects=-1) {
$ch = curl_init();
//$useragent = 'Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0';
@@ -87,7 +92,7 @@ function makeCanonicalUrl($item) {
if (!$item) {
return NULL;
}
return 'https://' . (PLATFORMS[$item['platform']][0] ?? '') . '/' . $item['relativeurl'];
return 'https://' . (PLATFORMS[$item['platform']][0] ?: $item['platform']) . '/' . $item['relativeurl'];
}
function makeEmbedUrl($platform, $relativeUrl) {
@@ -96,7 +101,7 @@ function makeEmbedUrl($platform, $relativeUrl) {
} else if (isset(EMBEDS_PREFIXES_FULL[$platform])) {
return 'https://' . EMBEDS_PREFIXES_FULL[$platform] . $relativeUrl;
} else {
return 'https://' . (EMBEDS[$platform][0] ?: PLATFORMS[$platform][0] ?: PLATFORMS_PROXIES[$platform][0] ?: '') . '/' . trim($relativeUrl, '/') . (EMBEDS_SUFFIXES[$platform] ?? '');
return 'https://' . (EMBEDS[$platform][0] ?: PLATFORMS[$platform][0] ?: PLATFORMS_PROXIES[$platform][0] ?: $platform) . '/' . trim($relativeUrl, '/') . (EMBEDS_SUFFIXES[$platform] ?? '');
}
// switch ($platform) {
// case 'tiktok':
@@ -159,8 +164,7 @@ $immediateResult = null;
if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
if (str_starts_with(strtolower($search), 'https://')) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . lstrip($search, 'https://'));
die();
redirectTo(lstrip($search, 'https://'));
}
$searchResults = searchHistory($search);
} else {
@@ -173,38 +177,30 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
if (isset(PLATFORMS[$upstream])) {
if (isset(PLATFORMS_ALIASES[$upstream])) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . PLATFORMS_ALIASES[$upstream] . '/' . $relativeUrl);
die();
redirectTo(PLATFORMS_ALIASES[$upstream] . '/' . $relativeUrl);
}
$platform = $upstream;
$domain = PLATFORMS[$upstream][0];
//$upstreamUrl = "https://$domain";
} else {
foreach ([PLATFORMS_PROXIES, PLATFORMS, EMBEDS] as $array) {
foreach ($array as $platform => $domains) {
if (in_array($upstream, $domains) || in_array(lstrip($upstream, 'www.'), $domains)) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $platform . '/' . $relativeUrl);
die();
//$upstreamUrl = "https://$upstream";
//break;
redirectTo($platform . '/' . $relativeUrl);
}
}
unset($platform);
}
}
//if (!$platform && $upstream === 'vm.tiktok.com') {
// $platform = $upstream;//'tiktok';
// //'https://vm.tiktok.com/ZNeKpMrUB/';
//}
if (!$platform && isset(PLATFORMS_REDIRECTS[$upstream])) {
$relativeUrl = trim(parse_url(fetchContent("$upstream/$relativeUrl", 1)['url'], PHP_URL_PATH), '/');
$platform = PLATFORMS_REDIRECTS[$upstream];
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $platform . '/' . $relativeUrl);
die();
redirectTo($platform . '/' . $relativeUrl);
} else if (!$platform && (str_ends_with($upstream, '.wordpress.com') || str_ends_with($upstream, '.blogspot.com'))) {
$platform = $upstream;
}
if ($relativeUrl && /*$upstreamUrl*/ $platform && ($content = fetchContent(makeScrapeUrl($platform, $relativeUrl)))['body']) {
if ($relativeUrl && $platform && ($content = fetchContent(makeScrapeUrl($platform, $relativeUrl)))['body']) {
if (!in_array($platform, PLATFORMS_TRACKING)) {
$relativeUrl = parse_url($relativeUrl, PHP_URL_PATH);
}
@@ -216,9 +212,11 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
'relativeurl' => $relativeUrl,
//'datetime' => date('Y-m-d H:i:s'),
//'request_time' => time(),
'locale' => $metaTags['og:locale'] ?? '',
'type' => $metaTags['og:type'] ?? '',
'image' => $metaTags['og:image'] ?? '',
'video' => $metaTags['og:video'] ?? '',
'videotype' => $metaTags['og:video:type'] ?? '',
'title' => $metaTags['og:title'] ?: $metaTags['og:title'] ?: '',
//'author' => $metaTags['og:site_name'] ?? '',
'description' => $metaTags['og:description'] ?: $metaTags['description'] ?: '',
@@ -233,12 +231,14 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
//echo $vidstr;
$startpos = $endpos - strpos(strrev($vidstr), '"');
$vidstr = substr($html, $startpos, $endpos-$startpos+1);
//echo $vidstr;
//echo '|' . $vidpos . '|' . $startpos . '|' . $endpos; //substr($html, $startpos, $endpos);
$vidstr = json_decode('"' . json_decode('"' . html_entity_decode($vidstr) . '"'));
$vidstr = html_entity_decode($vidstr);
//$vidstr = json_decode('"' . json_decode('"' . ($vidstr) . '"') . '');
$vidstr = json_decode('"' . json_decode('"' . $vidstr . '"')) ?: json_decode('"' . json_decode('"' . $vidstr) . '"');
//$vidstr = json_decode('"' . $vidstr . '"');
//echo $vidstr;
$immediateResult['video'] = $vidstr;
//echo '"' . $vidstr . '"';
//echo '|'.$startpos.'|'.$endpos.'|';
}
if (!$immediateResult['image']) {
$doc->loadHTML($html);
@@ -254,7 +254,10 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
// saveHistory($immediateResult);
//} else
if ($content['code'] >= 400) {
$searchResults = searchHistory($relativeUrl);
$searchResults = searchHistory(json_encode([
'platform' => $platform,
'relativeurl' => $relativeUrl,
], JSON_UNESCAPED_SLASHES));//('"platform":"' . $platform . '","relativeurl":"' . $relativeUrl . '"');
$immediateResult = $searchResults[0];
} else {
saveHistory($immediateResult);
@@ -275,16 +278,18 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
<meta name="description" content="<?= htmlspecialchars($immediateResult['description'] ?? 'Content Proxy for viewing media and text from various platforms.') ?>" />
<meta property="og:title" content="<?= htmlspecialchars($immediateResult['title'] ?? APPNAME) ?>" />
<meta property="og:description" content="<?= htmlspecialchars($immediateResult['description'] ?? 'View content from supported platforms.') ?>" />
<meta property="og:locale" content="<?= htmlspecialchars($immediateResult['locale'] ?? '') ?>" />
<meta property="og:type" content="<?= htmlspecialchars($immediateResult['type'] ?? '') ?>" />
<meta property="og:image" content="<?= htmlspecialchars($immediateResult['image'] ?? '') ?>" />
<?php if ($immediateResult['video']): ?>
<meta property="og:video" content="<?= htmlspecialchars($immediateResult['video']) ?>" />
<meta property="og:video:secure_url" content="<?= htmlspecialchars($immediateResult['video']) ?>" />
<meta property="og:video:type" content="video/mp4" />
<meta property="og:video:type" content="<?= htmlspecialchars($immediateResult['videotype'] ?: 'video/mp4') ?>" />
<?php endif; ?>
<meta property="og:site_name" content="<?= APPNAME . ' ' . $immediateResult['platform'] ?>" />
<meta property="og:url" content="<?= htmlspecialchars(makeCanonicalUrl($immediateResult)) ?>" />
<link rel="canonical" href="<?= htmlspecialchars(makeCanonicalUrl($immediateResult)) ?>" />
<!--<link rel="alternate" type="application/json+oembed" href="" />
<link rel="alternate" type="application/xml+oembed" href="" />-->
<style>
* {
box-sizing: border-box;
@@ -324,6 +329,12 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
}
a.button.block {
display: block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
a.button.block code {
text-decoration: underline;
}
h1, h1 a {
text-align: center;
@@ -498,7 +509,7 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
</p>
<p style="white-space: preserve-breaks; border-left: 2px solid black; padding: 1em; word-break: break-word;"><?= /*htmlspecialchars*/($item['description']) ?></p>
<p>
<a class="button block" href="https://<?= htmlspecialchars(PLATFORMS[$item['platform']][0] ?? '') ?>/<?= htmlspecialchars($item['relativeurl']) ?>" target="_blank" rel="noopener nofollow">Original on <code><?= htmlspecialchars(PLATFORMS[$item['platform']][0] ?? '') ?></code></a>
<a class="button block" href="<?= htmlspecialchars(makeCanonicalUrl($item)) ?>" target="_blank" rel="noopener nofollow">Original on <code><?= htmlspecialchars(PLATFORMS[$item['platform']][0] ?: $item['platform']) ?>/<?= htmlspecialchars($item['relativeurl']) ?></code></a>
<a class="button block" href="<?= htmlspecialchars($_SERVER['SCRIPT_NAME'] . '/' . $item['platform'] . '/' . $item['relativeurl']) ?>"><?= APPNAME ?> Permalink</a>
</p>
</div>
@@ -508,7 +519,7 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
<?php if (isset($immediateResult)): ?>
<?php if (in_array($immediateResult['platform'], PLATFORMS_ORDERED)): ?>
<div>
<a class="button" href="<?= end(explode('/', $immediateResult['relativeurl']))-1 ?>">⬅️ Previous</a>
<a class="button" href="<?= abs(end(explode('/', $immediateResult['relativeurl']))-1) ?>">⬅️ Previous</a>
<a class="button" style="float:right;" href="<?= end(explode('/', $immediateResult['relativeurl']))+1 ?>">➡️ Next</a>
</div>
<?php endif; ?>