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 <?php
const APPNAME = 'Proxatore'; const APPNAME = '🎭️ Proxatore';
const PLATFORMS = [ const PLATFORMS = [
'facebook' => ['facebook.com', 'm.facebook.com'], 'facebook' => ['facebook.com', 'm.facebook.com'],
@@ -34,7 +34,7 @@ const PLATFORMS_ORDERED = ['telegram'];
const PLATFORMS_TRACKING = ['facebook', 'xiaohongshu']; const PLATFORMS_TRACKING = ['facebook', 'xiaohongshu'];
const PLATFORMS_VIDEO = ['instagram']; const PLATFORMS_VIDEO = ['facebook', 'instagram'];
const EMBEDS = [ const EMBEDS = [
'reddit' => ['embed.reddit.com'], 'reddit' => ['embed.reddit.com'],
@@ -64,6 +64,11 @@ function urlLast($url) {
return end(explode('/', trim(parse_url($url, PHP_URL_PATH), '/'))); 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) { function fetchContent($url, $redirects=-1) {
$ch = curl_init(); $ch = curl_init();
//$useragent = 'Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0'; //$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) { if (!$item) {
return NULL; return NULL;
} }
return 'https://' . (PLATFORMS[$item['platform']][0] ?? '') . '/' . $item['relativeurl']; return 'https://' . (PLATFORMS[$item['platform']][0] ?: $item['platform']) . '/' . $item['relativeurl'];
} }
function makeEmbedUrl($platform, $relativeUrl) { function makeEmbedUrl($platform, $relativeUrl) {
@@ -96,7 +101,7 @@ function makeEmbedUrl($platform, $relativeUrl) {
} else if (isset(EMBEDS_PREFIXES_FULL[$platform])) { } else if (isset(EMBEDS_PREFIXES_FULL[$platform])) {
return 'https://' . EMBEDS_PREFIXES_FULL[$platform] . $relativeUrl; return 'https://' . EMBEDS_PREFIXES_FULL[$platform] . $relativeUrl;
} else { } 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) { // switch ($platform) {
// case 'tiktok': // case 'tiktok':
@@ -159,8 +164,7 @@ $immediateResult = null;
if (isset($_GET['search']) && ($search = $_GET['search']) !== '') { if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
if (str_starts_with(strtolower($search), 'https://')) { if (str_starts_with(strtolower($search), 'https://')) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . lstrip($search, 'https://')); redirectTo(lstrip($search, 'https://'));
die();
} }
$searchResults = searchHistory($search); $searchResults = searchHistory($search);
} else { } else {
@@ -173,38 +177,30 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
if (isset(PLATFORMS[$upstream])) { if (isset(PLATFORMS[$upstream])) {
if (isset(PLATFORMS_ALIASES[$upstream])) { if (isset(PLATFORMS_ALIASES[$upstream])) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . PLATFORMS_ALIASES[$upstream] . '/' . $relativeUrl); redirectTo(PLATFORMS_ALIASES[$upstream] . '/' . $relativeUrl);
die();
} }
$platform = $upstream; $platform = $upstream;
$domain = PLATFORMS[$upstream][0]; $domain = PLATFORMS[$upstream][0];
//$upstreamUrl = "https://$domain";
} else { } else {
foreach ([PLATFORMS_PROXIES, PLATFORMS, EMBEDS] as $array) { foreach ([PLATFORMS_PROXIES, PLATFORMS, EMBEDS] as $array) {
foreach ($array as $platform => $domains) { foreach ($array as $platform => $domains) {
if (in_array($upstream, $domains) || in_array(lstrip($upstream, 'www.'), $domains)) { if (in_array($upstream, $domains) || in_array(lstrip($upstream, 'www.'), $domains)) {
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $platform . '/' . $relativeUrl); redirectTo($platform . '/' . $relativeUrl);
die();
//$upstreamUrl = "https://$upstream";
//break;
} }
} }
unset($platform); unset($platform);
} }
} }
//if (!$platform && $upstream === 'vm.tiktok.com') {
// $platform = $upstream;//'tiktok';
// //'https://vm.tiktok.com/ZNeKpMrUB/';
//}
if (!$platform && isset(PLATFORMS_REDIRECTS[$upstream])) { if (!$platform && isset(PLATFORMS_REDIRECTS[$upstream])) {
$relativeUrl = trim(parse_url(fetchContent("$upstream/$relativeUrl", 1)['url'], PHP_URL_PATH), '/'); $relativeUrl = trim(parse_url(fetchContent("$upstream/$relativeUrl", 1)['url'], PHP_URL_PATH), '/');
$platform = PLATFORMS_REDIRECTS[$upstream]; $platform = PLATFORMS_REDIRECTS[$upstream];
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . $platform . '/' . $relativeUrl); redirectTo($platform . '/' . $relativeUrl);
die(); } 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)) { if (!in_array($platform, PLATFORMS_TRACKING)) {
$relativeUrl = parse_url($relativeUrl, PHP_URL_PATH); $relativeUrl = parse_url($relativeUrl, PHP_URL_PATH);
} }
@@ -216,9 +212,11 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
'relativeurl' => $relativeUrl, 'relativeurl' => $relativeUrl,
//'datetime' => date('Y-m-d H:i:s'), //'datetime' => date('Y-m-d H:i:s'),
//'request_time' => time(), //'request_time' => time(),
'locale' => $metaTags['og:locale'] ?? '',
'type' => $metaTags['og:type'] ?? '', 'type' => $metaTags['og:type'] ?? '',
'image' => $metaTags['og:image'] ?? '', 'image' => $metaTags['og:image'] ?? '',
'video' => $metaTags['og:video'] ?? '', 'video' => $metaTags['og:video'] ?? '',
'videotype' => $metaTags['og:video:type'] ?? '',
'title' => $metaTags['og:title'] ?: $metaTags['og:title'] ?: '', 'title' => $metaTags['og:title'] ?: $metaTags['og:title'] ?: '',
//'author' => $metaTags['og:site_name'] ?? '', //'author' => $metaTags['og:site_name'] ?? '',
'description' => $metaTags['og:description'] ?: $metaTags['description'] ?: '', 'description' => $metaTags['og:description'] ?: $metaTags['description'] ?: '',
@@ -233,12 +231,14 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
//echo $vidstr; //echo $vidstr;
$startpos = $endpos - strpos(strrev($vidstr), '"'); $startpos = $endpos - strpos(strrev($vidstr), '"');
$vidstr = substr($html, $startpos, $endpos-$startpos+1); $vidstr = substr($html, $startpos, $endpos-$startpos+1);
//echo $vidstr;
//echo '|' . $vidpos . '|' . $startpos . '|' . $endpos; //substr($html, $startpos, $endpos); //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; //echo $vidstr;
$immediateResult['video'] = $vidstr; $immediateResult['video'] = $vidstr;
//echo '"' . $vidstr . '"'; //echo '|'.$startpos.'|'.$endpos.'|';
} }
if (!$immediateResult['image']) { if (!$immediateResult['image']) {
$doc->loadHTML($html); $doc->loadHTML($html);
@@ -254,7 +254,10 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
// saveHistory($immediateResult); // saveHistory($immediateResult);
//} else //} else
if ($content['code'] >= 400) { 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]; $immediateResult = $searchResults[0];
} else { } else {
saveHistory($immediateResult); saveHistory($immediateResult);
@@ -275,21 +278,23 @@ 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 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:title" content="<?= htmlspecialchars($immediateResult['title'] ?? APPNAME) ?>" />
<meta property="og:description" content="<?= htmlspecialchars($immediateResult['description'] ?? 'View content from supported platforms.') ?>" /> <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:type" content="<?= htmlspecialchars($immediateResult['type'] ?? '') ?>" />
<meta property="og:image" content="<?= htmlspecialchars($immediateResult['image'] ?? '') ?>" /> <meta property="og:image" content="<?= htmlspecialchars($immediateResult['image'] ?? '') ?>" />
<?php if ($immediateResult['video']): ?> <?php if ($immediateResult['video']): ?>
<meta property="og:video" content="<?= htmlspecialchars($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="<?= htmlspecialchars($immediateResult['videotype'] ?: 'video/mp4') ?>" />
<meta property="og:video:type" content="video/mp4" />
<?php endif; ?> <?php endif; ?>
<meta property="og:site_name" content="<?= APPNAME . ' ' . $immediateResult['platform'] ?>" /> <meta property="og:site_name" content="<?= APPNAME . ' ' . $immediateResult['platform'] ?>" />
<meta property="og:url" content="<?= htmlspecialchars(makeCanonicalUrl($immediateResult)) ?>" /> <meta property="og:url" content="<?= htmlspecialchars(makeCanonicalUrl($immediateResult)) ?>" />
<link rel="canonical" href="<?= 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> <style>
* { * {
box-sizing: border-box; box-sizing: border-box;
} }
body { body {
font-family: 'Roboto', Arial, sans-serif; font-family: 'Roboto', Arial, sans-serif;
margin: 0; margin: 0;
padding: 0; padding: 0;
@@ -298,13 +303,13 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
align-items: center; align-items: center;
background-color: #f0f2f5; background-color: #f0f2f5;
color: #1c1e21; color: #1c1e21;
} }
iframe { iframe {
width: 100%; width: 100%;
height: 90vh; height: 90vh;
border: none; border: none;
} }
.container { .container {
max-width: 900px; max-width: 900px;
width: 90%; width: 90%;
margin: 20px; margin: 20px;
@@ -313,43 +318,49 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
border-radius: 12px; border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
overflow: hidden; overflow: hidden;
} }
a.button { a.button {
padding: 0.5em; padding: 0.5em;
border: 1px solid gray; border: 1px solid gray;
border-radius: 8px; border-radius: 8px;
text-decoration: none; text-decoration: none;
margin: 0.5em; margin: 0.5em;
display: inline-block; display: inline-block;
} }
a.button.block { a.button.block {
display: block; display: block;
} text-overflow: ellipsis;
h1, h1 a { overflow: hidden;
white-space: nowrap;
}
a.button.block code {
text-decoration: underline;
}
h1, h1 a {
text-align: center; text-align: center;
margin-bottom: 20px; margin-bottom: 20px;
font-size: 2rem; font-size: 2rem;
color: #1877f2; color: #1877f2;
text-decoration: none; text-decoration: none;
} }
h2 { h2 {
font-size: 1.5rem; font-size: 1.5rem;
margin-top: 20px; margin-top: 20px;
color: #444; color: #444;
border-bottom: 2px solid #1877f2; border-bottom: 2px solid #1877f2;
padding-bottom: 5px; padding-bottom: 5px;
} }
.history-item { .history-item {
display: flex; display: flex;
align-items: center; align-items: center;
border-bottom: 1px solid #e6e6e6; border-bottom: 1px solid #e6e6e6;
padding: 15px 0; padding: 15px 0;
transition: background-color 0.3s; transition: background-color 0.3s;
} }
.history-item:hover { .history-item:hover {
background-color: #f9f9f9; background-color: #f9f9f9;
} }
.history-item img, .history-item video { .history-item img, .history-item video {
/*width: 49%; /*width: 49%;
max-width: 49%;*/ max-width: 49%;*/
width: 100%; width: 100%;
@@ -359,49 +370,49 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
margin-right: 15px; margin-right: 15px;
border-radius: 4px; border-radius: 4px;
object-fit: cover; object-fit: cover;
} }
.history-item div { .history-item div {
/*display: flex;*/ /*display: flex;*/
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
max-width: 49%; max-width: 49%;
width: 49%; width: 49%;
/*padding: 1em;*/ /*padding: 1em;*/
} }
img, video { img, video {
padding: 1em; padding: 1em;
} }
img[src=""], video[src=""] { img[src=""], video[src=""] {
display: none; display: none;
} }
img + img, img + img,
video:not(video[src=""]) + img { video:not(video[src=""]) + img {
max-width: 45% !important; max-width: 45% !important;
} }
.history-item strong { .history-item strong {
font-size: 1.2rem; font-size: 1.2rem;
color: #1c1e21; color: #1c1e21;
margin-bottom: 5px; margin-bottom: 5px;
display: -webkit-box; display: -webkit-box;
} }
.history-item.ellipsize strong { .history-item.ellipsize strong {
-webkit-line-clamp: 5; -webkit-line-clamp: 5;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
overflow: hidden; overflow: hidden;
} }
.history-item small { .history-item small {
font-size: 0.9rem; font-size: 0.9rem;
color: #606770; color: #606770;
} }
.history-item .title { .history-item .title {
display: none; display: none;
} }
.search-bar { .search-bar {
margin-bottom: 20px; margin-bottom: 20px;
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.search-bar input { .search-bar input {
flex: 1; flex: 1;
max-width: 600px; max-width: 600px;
padding: 10px 15px; padding: 10px 15px;
@@ -409,13 +420,13 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
border-radius: 25px; border-radius: 25px;
font-size: 1rem; font-size: 1rem;
transition: box-shadow 0.3s, border-color 0.3s; transition: box-shadow 0.3s, border-color 0.3s;
} }
.search-bar input:focus { .search-bar input:focus {
border-color: #1877f2; border-color: #1877f2;
box-shadow: 0 0 5px rgba(24, 119, 242, 0.5); box-shadow: 0 0 5px rgba(24, 119, 242, 0.5);
outline: none; outline: none;
} }
.search-bar button { .search-bar button {
margin-left: 10px; margin-left: 10px;
padding: 10px 20px; padding: 10px 20px;
background-color: #1877f2; background-color: #1877f2;
@@ -425,11 +436,11 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
font-size: 1rem; font-size: 1rem;
cursor: pointer; cursor: pointer;
transition: background-color 0.3s; transition: background-color 0.3s;
} }
.search-bar button:hover { .search-bar button:hover {
background-color: #155dbb; background-color: #155dbb;
} }
@media (max-width: 600px) { @media (max-width: 600px) {
.search-bar input { .search-bar input {
width: 100%; width: 100%;
margin-bottom: 10px; margin-bottom: 10px;
@@ -456,7 +467,7 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
.history-item .title { .history-item .title {
display: block; display: block;
} }
} }
</style> </style>
</head> </head>
<body> <body>
@@ -498,7 +509,7 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
</p> </p>
<p style="white-space: preserve-breaks; border-left: 2px solid black; padding: 1em; word-break: break-word;"><?= /*htmlspecialchars*/($item['description']) ?></p> <p style="white-space: preserve-breaks; border-left: 2px solid black; padding: 1em; word-break: break-word;"><?= /*htmlspecialchars*/($item['description']) ?></p>
<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> <a class="button block" href="<?= htmlspecialchars($_SERVER['SCRIPT_NAME'] . '/' . $item['platform'] . '/' . $item['relativeurl']) ?>"><?= APPNAME ?> Permalink</a>
</p> </p>
</div> </div>
@@ -508,7 +519,7 @@ if (isset($_GET['search']) && ($search = $_GET['search']) !== '') {
<?php if (isset($immediateResult)): ?> <?php if (isset($immediateResult)): ?>
<?php if (in_array($immediateResult['platform'], PLATFORMS_ORDERED)): ?> <?php if (in_array($immediateResult['platform'], PLATFORMS_ORDERED)): ?>
<div> <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> <a class="button" style="float:right;" href="<?= end(explode('/', $immediateResult['relativeurl']))+1 ?>">➡️ Next</a>
</div> </div>
<?php endif; ?> <?php endif; ?>