From bca265aea67ec62499aaa113a6490ce9ec7fe730 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sat, 22 Jul 2023 14:41:14 -0400 Subject: still missing things on google scraper --- web.php | 496 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 web.php (limited to 'web.php') diff --git a/web.php b/web.php new file mode 100644 index 0000000..b0745e6 --- /dev/null +++ b/web.php @@ -0,0 +1,496 @@ +getscraperfilters("web"); + +$get = $frontend->parsegetfilters($_GET, $filters); + +$frontend->loadheader( + $get, + $filters, + "web" +); + +$payload = [ + "class" => "", + "right-left" => "", + "right-right" => "", + "left" => "" +]; + +try{ + $results = $scraper->web($get); + +}catch(Exception $error){ + + echo + $frontend->drawerror( + "Shit", + 'This scraper returned an error:' . + '
' . htmlspecialchars($error->getMessage()) . '
' . + 'Things you can try:' . + '
' . + 'If the error persists, please contact the administrator.' + ); + die(); +} + +$answerlen = 0; + +/* + Spelling checker +*/ +if($results["spelling"]["type"] != "no_correction"){ + + switch($results["spelling"]["type"]){ + + case "including": + $type = "Including results for"; + break; + + case "not_many": + $type = "Not many results contains"; + break; + } + + $payload["left"] .= + '
' . + $type . ' ' . htmlspecialchars($results["spelling"]["using"]) . '.
' . + 'Did you mean ' . $results["spelling"]["correction"] . '?' . + '
'; +} + +/* + Populate links +*/ +if(count($results["web"]) === 0){ + + $payload["left"] .= + '
' . + "

Nobody here but us chickens!

" . + 'Have you tried:' . + '' . + '
'; +} + +foreach($results["web"] as $site){ + + $n = null; + + if($site["date"] !== null){ + + $date = date("jS M y @ g:ia", $site["date"]); + }else{ + + $date = null; + } + + $payload["left"] .= $frontend->drawtextresult($site, $date, $n, $get["s"]); +} + +$right = []; + +/* + Generate images +*/ +if(count($results["image"]) !== 0){ + + $answerlen++; + $right["image"] = + '
' . + '' . + '
' . + '
' . + '

Images

' . + '
' . + '
'; + + foreach($results["image"] as $image){ + + $c = count($image["source"]) - 1; + + if( + preg_match( + '/^data:/', + $image["source"][$c]["url"] + ) + ){ + + $src = htmlspecialchars($image["source"][$c]["url"]); + }else{ + + $src = "/proxy?i=" . urlencode($image["source"][$c]["url"]) . "&s=square"; + } + + $right["image"] .= + '' . + 'thumb' . + '
' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '
' . + '
'; + } + + $right["image"] .= + '
' . + '
'; +} + +/* + Generate videos +*/ +if(count($results["video"]) !== 0){ + + $answerlen++; + $right["video"] = + '
' . + '' . + '
' . + '
' . + '

Videos

' . + '
'; + + foreach($results["video"] as $video){ + + if($video["views"] !== null){ + + $greentext = number_format($video["views"]) . " views"; + }else{ + + $greentext = null; + } + + if($video["date"] !== null){ + + if($greentext !== null){ + + $greentext .= " • "; + } + + $greentext .= date("jS M y @ g:ia", $video["date"]); + } + + if($video["duration"] !== null){ + + if($video["duration"] == "_LIVE"){ + + $duration = 'LIVE'; + }else{ + + $duration = $frontend->s_to_timestamp($video["duration"]); + } + }else{ + + $duration = null; + } + + $right["video"] .= $frontend->drawtextresult($video, $greentext, $duration, $get["s"], false); + } + + $right["video"] .= + '
' . + '
'; +} + +/* + Generate news +*/ +if(count($results["news"]) !== 0){ + + $answerlen++; + $right["news"] = + '
' . + '' . + '
' . + '
' . + '

News

' . + '
'; + + foreach($results["news"] as $news){ + + if($news["date"] !== null){ + + $greentext = date("jS M y @ g:ia", $news["date"]); + }else{ + + $greentext = null; + } + + $right["news"] .= $frontend->drawtextresult($news, $greentext, null, $get["s"], false); + } + + $right["news"] .= + '
' . + '
'; +} + +/* + Generate answers +*/ +if(count($results["answer"]) !== 0){ + + $right["answer"] = ""; + + foreach($results["answer"] as $answer){ + + $answerlen++; + $right["answer"] .= + '
' . + '' . + '
'; + + if(!empty($answer["title"])){ + + $right["answer"] .= + '
'; + + if(!empty($answer["url"])){ + + $right["answer"] .= ''; + } + + $right["answer"] .= '

' . htmlspecialchars($answer["title"]) . '

'; + + if(!empty($answer["url"])){ + + $right["answer"] .= '
'; + } + + + $right["answer"] .= '
'; + } + + if(!empty($answer["url"])){ + + $right["answer"] .= + $frontend->drawlink($answer["url"]); + } + + $right["answer"] .= '
'; + + if(!empty($answer["thumb"])){ + + $right["answer"] .= + '' . + 'thumb' . + ''; + } + + foreach($answer["description"] as $description){ + + switch($description["type"]){ + + case "text": + $right["answer"] .= $frontend->highlighttext($get["s"], $description["value"]); + break; + + case "title": + $right["answer"] .= + '

' . + htmlspecialchars($description["value"]) . + '

'; + break; + + case "italic": + $right["answer"] .= + '' . + $frontend->highlighttext($get["s"], $description["value"]) . + ''; + break; + + case "quote": + $right["answer"] .= + '
' . + $frontend->highlighttext($get["s"], $description["value"]) . + '
'; + break; + + case "code": + $right["answer"] .= + '
' . + $frontend->highlightcode($description["value"], true) . + '
'; + break; + + case "inline_code": + $right["answer"] .= + '
' . + htmlspecialchars($description["value"]) . + '
'; + break; + + case "link": + $right["answer"] .= + '' . htmlspecialchars($description["value"]) . ''; + break; + + case "image": + $right["answer"] .= + 'image'; + break; + + case "audio": + $right["answer"] .= + ''; + break; + } + } + + $right["answer"] .= '
'; + + if(count($answer["table"]) !== 0){ + + $right["answer"] .= ''; + + foreach($answer["table"] as $info => $value){ + + $right["answer"] .= + '' . + '' . + '' . + ''; + } + + $right["answer"] .= '
' . $info . '' . $value . '
'; + } + + if(count($answer["sublink"]) !== 0){ + + $right["answer"] .= '
'; + $icons = glob("static/icon/*"); + + foreach($answer["sublink"] as $website => $url){ + + $flag = false; + $icon = str_replace(" ", "", strtolower($website)); + + foreach($icons as $path){ + + if(pathinfo($path, PATHINFO_FILENAME) == $icon){ + + $flag = true; + break; + } + } + + if($flag === false){ + + $icon = "website"; + } + + $right["answer"] .= + '' . + '
' . + 'icon' . + '
' . $website . '
' . + '
' . + '
'; + } + + $right["answer"] .= '
'; + } + + $right["answer"] .= + '
' . + '
'; + } +} + +/* + Add right containers +*/ +if(isset($right["answer"])){ + + if(count($right) >= 2){ + + $payload["right-right"] = $right["answer"]; + unset($right["answer"]); + } +} + +$c = 0; +foreach($right as $snippet){ + + if($c % 2 === 0){ + + $payload["right-left"] .= $snippet; + }else{ + + $payload["right-right"] .= $snippet; + } + + $c++; +} + +if($c !== 0){ + + $payload["class"] = " has-answer"; +} + +/* + Generate related searches +*/ +$c = count($results["related"]); + +if($c !== 0){ + $payload["left"] .= '

Related searches

'; + + $opentr = false; + + for($i=0; $i<$c; $i++){ + + if(($i % 2) === 0){ + + $opentr = true; + $payload["left"] .= ''; + }else{ + + $opentr = false; + } + + $payload["left"] .= + ''; + + if($opentr === false){ + + $payload["left"] .= ''; + } + } + + if($opentr === true){ + + $payload["left"] .= ''; + } + + $payload["left"] .= ''; +} + +/* + Load next page +*/ +if($results["npt"] !== null){ + + $payload["left"] .= + 'Next page >'; +} + +echo $frontend->load("search.html", $payload); -- cgit v1.2.3