add support for displaying cucked urls

This commit is contained in:
lolcat committed 2026-11-30 23:54:44 -05:00
1 parent b120d441d5
commit eca698c94d
4 files changed
+85 -41

No files matched your search

+68 -40
View File
@@ -238,7 +238,17 @@ class frontend{
$payload = '<div class="text-result">';
// add favicon, link and archive links
$payload .= $this->drawlink($site["url"]);
// add cucked URL if /resolver is present
$cucked =
isset($site["cuckurl"]) &&
preg_match(
'/\/resolver/',
$site["url"]
) !== 0 ?
$site["cuckurl"] : null;
$payload .= $this->drawlink($site["url"], $cucked);
/*
Draw title + description + filetype
@@ -290,7 +300,7 @@ class frontend{
$payload .=
'</div>';
}
$payload .=
'<div class="title">';
@@ -487,11 +497,24 @@ class frontend{
return $text;
}
public function drawlink($link){
public function drawlink(string $link, $cucked = null){
/*
Add favicon
*/
$f404_host = "404";
if($cucked !== null){
// attempt to get the host from the cucked URL
$host = parse_url($cucked);
if(isset($host["host"])){
$f404_host = "https://" . $host["host"];
}
}
$host = parse_url($link);
// special case for when we're not drawing a full url
@@ -500,7 +523,7 @@ class frontend{
$payload =
'<div class="url">' .
'<button class="favicon" tabindex="-1">' .
'<img src="/favicon?s=404" alt="xx">' .
'<img src="/favicon?s=' . urlencode($f404_host) . '" alt="xx">' .
'</button>';
}else{
@@ -529,7 +552,7 @@ class frontend{
$payload =
'<div class="url">' .
'<button class="favicon" tabindex="-1">' .
'<img src="/favicon?s=' . htmlspecialchars($host["scheme"] . "://" . $host["host"]) . '" alt="' . htmlspecialchars($esc) . '">' .
'<img src="/favicon?s=' . urlencode($host["scheme"] . "://" . $host["host"]) . '" alt="' . htmlspecialchars($esc) . '">' .
//'<img src="/404.php" alt="' . htmlspecialchars($esc) . '">' .
'</button>' .
'<div class="favicon-dropdown">';
@@ -1023,46 +1046,51 @@ class frontend{
/*
Draw link
*/
$parts = explode("/", $link);
$clickurl = "";
// remove trailing /
$c = count($parts) - 1;
if($parts[$c] == ""){
if($cucked === null){
$parts = explode("/", $link);
$clickurl = "";
$parts[$c - 1] = $parts[$c - 1] . "/";
unset($parts[$c]);
}
// merge https://site together
if(isset($host["host"])){
$parts = [
$parts[0] . $parts[1] . '//' . $parts[2],
...array_slice($parts, 3, count($parts) - 1)
];
}
$c = count($parts);
for($i=0; $i<$c; $i++){
if($i !== 0){ $clickurl .= "/"; }
$clickurl .= $parts[$i];
if($i === $c - 1){
// remove trailing /
$c = count($parts) - 1;
if($parts[$c] == ""){
$parts[$i] = rtrim($parts[$i], "/");
$parts[$c - 1] = $parts[$c - 1] . "/";
unset($parts[$c]);
}
$payload .=
'<a class="part" href="' . htmlspecialchars($clickurl) . '" rel="noreferrer nofollow" tabindex="-1">' .
htmlspecialchars(urldecode($parts[$i])) .
'</a>';
if($i !== $c - 1){
$payload .= '<span class="separator"></span>';
// merge https://site together
if(isset($host["host"])){
$parts = [
$parts[0] . $parts[1] . '//' . $parts[2],
...array_slice($parts, 3, count($parts) - 1)
];
}
$c = count($parts);
for($i=0; $i<$c; $i++){
if($i !== 0){ $clickurl .= "/"; }
$clickurl .= $parts[$i];
if($i === $c - 1){
$parts[$i] = rtrim($parts[$i], "/");
}
$payload .=
'<a class="part" href="' . htmlspecialchars($clickurl) . '" rel="noreferrer nofollow" tabindex="-1">' .
htmlspecialchars(urldecode($parts[$i])) .
'</a>';
if($i !== $c - 1){
$payload .= '<span class="separator"></span>';
}
}
}else{
$payload .= '<a class="url-cucked" href="' . $link . '" rel="noreferrer nofollow" tabindex="-1" title="This URL was cucked by the upstream search engine. The full URL is only available by following their redirect endpoint. 4get will proxy your click to prevent tracking.">' . htmlspecialchars($cucked) . '</a>';
}
return $payload . '</div>';