From 8e6ef073de483e5517ce6aa78d22f0bdc749cf66 Mon Sep 17 00:00:00 2001 From: octt <6083316-octospacc@users.noreply.gitlab.com> Date: Fri, 23 May 2025 12:44:21 +0200 Subject: [PATCH] v0.2, 14/01 --- Proxatore.php | 382 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 317 insertions(+), 65 deletions(-) diff --git a/Proxatore.php b/Proxatore.php index 497bab2..e236d59 100644 --- a/Proxatore.php +++ b/Proxatore.php @@ -1,33 +1,59 @@ ['facebook.com', 'm.facebook.com'], + 'instagram' => ['instagram.com', 'ddinstagram.com', 'd.ddinstagram.com'], + 'reddit' => ['old.reddit.com', 'reddit.com'], + 'telegram' => ['t.me', 'telegram.me'], + 'tiktok' => ['tiktok.com', 'vxtiktok.com'], + 'twitter' => ['twitter.com', 'fxtwitter.com', 'vxtwitter.com'], + 'x' => ['x.com', 'fixupx.com'], + //'wordpress' => ['wordpress.com'], +]; + +const EMBEDS = [ + 'reddit' => ['embed.reddit.com'], +]; + +const EMBEDS_SUFFIXES = [ + 'instagram' => '/embed/captioned/', + 'telegram' => '?embed=1&mode=tme', +]; + define('HISTORY_FILE', './' . $_SERVER['SCRIPT_NAME'] . '.history.jsonl'); -$platforms = [ - 'telegram' => ['t.me', 'telegram.me'], - 'reddit' => ['reddit.com', 'old.reddit.com'], - 'instagram' => ['instagram.com'], - 'facebook' => ['facebook.com'], - 'tiktok' => ['tiktok.com'], - 'twitter' => ['twitter.com'], - 'x' => ['x.com'], -]; +function lstrip($str, $sub) { + return implode($sub, array_slice(explode($sub, $str), 1)); +} function fetchContent($url) { $ch = curl_init(); + //$useragent = 'Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0'; + $useragent = 'curl/' . curl_version()['version']; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Content Proxy)'); - $html = curl_exec($ch); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); + $body = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + http_response_code(); curl_close($ch); - return $html ?: null; + return [ + 'body' => $body, + 'code' => $code, + ]; } -function parseMetaTags($html) { - $doc = new DOMDocument(); - @$doc->loadHTML($html); +function makeEmbedUrl($platform, $relativeUrl) { + return 'https://' . (EMBEDS[$platform][0] ?: PLATFORMS[$platform][0] ?: '') . '/' . $relativeUrl . (EMBEDS_SUFFIXES[$platform] ?? ''); +} + +function parseMetaTags($doc) { $metaTags = []; foreach ($doc->getElementsByTagName('meta') as $meta) { - if ($meta->hasAttribute('property')) { - $metaTags[$meta->getAttribute('property')] = $meta->getAttribute('content'); + if ($meta->hasAttribute('name') || $meta->hasAttribute('property')) { + $metaTags[$meta->getAttribute('name') ?: $meta->getAttribute('property')] = $meta->getAttribute('content'); } } return $metaTags; @@ -68,59 +94,94 @@ function searchHistory($keyword) { $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $immediateResult = null; -if (isset($_GET['search']) && $_GET['search'] !== '') { - $searchResults = searchHistory($_GET['search']); +if (isset($_GET['search']) && ($search = $_GET['search']) !== '') { + if (str_starts_with(strtolower($search), 'https://')) { + header('Location: ' . $_SERVER['SCRIPT_NAME'] . '/' . lstrip($search, 'https://')); + die(); + } + $searchResults = searchHistory($search); } else { $segments = explode('/', trim($path, '/')); array_shift($segments); + $platform = null; + $upstreamUrl = null; + $upstream = $segments[0] ?? null; $relativeUrl = implode('/', array_slice($segments, 1)); - if (isset($platforms[$upstream])) { + if (isset(PLATFORMS[$upstream])) { $platform = $upstream; - $domain = $platforms[$upstream][0]; - $upstreamUrl = "https://$domain/$relativeUrl"; + $domain = PLATFORMS[$upstream][0]; + $upstreamUrl = "https://$domain"; } else { - foreach ($platforms as $platform => $domains) { - if (in_array($upstream, $domains) || in_array(implode('www.', array_slice(explode('www.', $upstream), 1)), $domains)) { - $upstreamUrl = "https://$upstream/$relativeUrl"; - break; + foreach ([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; + } } } } - if ($relativeUrl && ($html = fetchContent("$upstreamUrl/$relativeUrl"))) { - $metaTags = parseMetaTags($html); - + if ($relativeUrl && $upstreamUrl && ($content = fetchContent("$upstreamUrl/$relativeUrl"))['body']) { + $doc = new DOMDocument(); + $doc->loadHTML($content['body']); + $metaTags = parseMetaTags($doc); $immediateResult = [ 'platform' => $platform, 'relativeurl' => $relativeUrl, - 'datetime' => date('Y-m-d H:i:s'), - 'request_time' => time(), - 'mediaurls' => [$metaTags['og:image'] ?? null], - 'title' => $metaTags['og:title'] ?? 'No title', - 'author' => $metaTags['og:site_name'] ?? 'Unknown', - 'description' => $metaTags['og:description'] ?? 'No description', + //'datetime' => date('Y-m-d H:i:s'), + //'request_time' => time(), + 'type' => $metaTags['og:type'] ?? '', + 'image' => $metaTags['og:image'] ?? '', + 'video' => $metaTags['og:video'] ?? '', + 'title' => $metaTags['og:title'] ?? '', + 'author' => $metaTags['og:site_name'] ?? '', + 'description' => $metaTags['og:description'] ?: $metaTags['description'] ?: '', ]; - - saveHistory($immediateResult); + if (!$immediateResult['video']) { + $html = fetchContent(makeEmbedUrl($platform, $relativeUrl))['body']; + $vidpos = strpos($html, '.mp4'); + if ($vidpos) { + $startpos = strpos(substr(strrev($html), 0, $vidpos), '"'); + $endpos = strpos(substr($html, $vidpos), '"'); + echo $startpos . '|' . $endpos; //substr($html, $startpos, $endpos); + } + } + $searchResults = [$immediateResult]; + //if ($immediateResult['title'] || $immediateResult['description']) { + // saveHistory($immediateResult); + //} else + if ($content['code'] >= 400) { + $searchResults = searchHistory($relativeUrl); + $immediateResult = $searchResults[0]; + } else { + saveHistory($immediateResult); + } + } else { + http_response_code(404); } } ?> - - - - Content Proxy + + + <?php echo APPNAME; ?> - + + + "> - + --> + +
-

Content Proxy

- - -
- Media -
-
- Platform: |
-
- View Original -
-
-
- Media
-
- Platform: |
-
- View Original + + +
+
+

+ + +

+

+

+ Open Original on + Proxatore Permalink +

+ + + + +