Move checking for frontends to printing instead of parsing
This commit is contained in:
parent
c9ff9a0de8
commit
c70436b257
10 changed files with 28 additions and 39 deletions
|
@ -32,8 +32,8 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function print_results($results) {
|
||||
TextSearch::print_results($results);
|
||||
public static function print_results($results, $opts) {
|
||||
TextSearch::print_results($results, $opts);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function print_results($results) {
|
||||
public static function print_results($results, $opts) {
|
||||
echo "<div class=\"text-result-container\">";
|
||||
|
||||
if (empty($results)) {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
if ($response["type"] == "video") {
|
||||
$title = $response["title"];
|
||||
$url = "https://youtube.com/watch?v=" . $response["videoId"];
|
||||
$url = check_for_privacy_frontend($url, $this->opts);
|
||||
$uploader = $response["author"];
|
||||
$views = $response["viewCount"];
|
||||
$date = $response["publishedText"];
|
||||
|
@ -37,12 +36,13 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function print_results($results) {
|
||||
public static function print_results($results, $opts) {
|
||||
echo "<div class=\"text-result-container\">";
|
||||
|
||||
foreach($results as $result) {
|
||||
$title = $result["title"];
|
||||
$url = $result["url"];
|
||||
$url = check_for_privacy_frontend($url, $opts);
|
||||
$base_url = $result["base_url"];
|
||||
$uploader = $result["uploader"];
|
||||
$views = $result["views"];
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
$encoded_url_split1 = explode("==/", $encoded_url)[1];
|
||||
$encoded_url_split2 = explode("?position", $encoded_url_split1)[0];
|
||||
$real_url = urldecode(base64_decode($encoded_url_split2));
|
||||
$real_url = check_for_privacy_frontend($real_url, $this->opts);
|
||||
|
||||
$alt = $image->getAttribute("alt");
|
||||
$thumbnail = urlencode($image->getAttribute("src"));
|
||||
|
@ -43,7 +42,7 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function print_results($results) {
|
||||
public static function print_results($results, $opts) {
|
||||
echo "<div class=\"image-result-container\">";
|
||||
|
||||
foreach($results as $result)
|
||||
|
@ -51,6 +50,7 @@
|
|||
$thumbnail = urlencode($result["thumbnail"]);
|
||||
$alt = $result["alt"];
|
||||
$url = $result["url"];
|
||||
$url = check_for_privacy_frontend($url, $opts);
|
||||
|
||||
echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
|
||||
echo "<img src=\"image_proxy.php?url=$thumbnail\">";
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
$description = substr($first_page["extract"], 0, 250) . "...";
|
||||
|
||||
$source = check_for_privacy_frontend("https://$this->wikipedia_language.wikipedia.org/wiki/$this->query", $this->opts);
|
||||
$source = "https://$this->wikipedia_language.wikipedia.org/wiki/$this->query";
|
||||
$response = array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($description),
|
||||
|
|
|
@ -30,23 +30,19 @@
|
|||
if (!$xpath)
|
||||
return $results;
|
||||
|
||||
foreach($xpath->query("/html/body/div[1]/div[". count($xpath->query('/html/body/div[1]/div')) ."]/div/div/div[contains(@class, 'web-result')]/div") as $result)
|
||||
{
|
||||
foreach($xpath->query("/html/body/div[1]/div[". count($xpath->query('/html/body/div[1]/div')) ."]/div/div/div[contains(@class, 'web-result')]/div") as $result) {
|
||||
$url = $xpath->evaluate(".//h2[@class='result__title']//a/@href", $result)[0];
|
||||
|
||||
if ($url == null)
|
||||
continue;
|
||||
|
||||
if (!empty($results)) // filter duplicate results
|
||||
{
|
||||
if (!empty($results)) // filter duplicate results {
|
||||
if (end($results)["url"] == $url->textContent)
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $url->textContent;
|
||||
|
||||
$url = check_for_privacy_frontend($url, $this->opts);
|
||||
|
||||
$title = $xpath->evaluate(".//h2[@class='result__title']", $result)[0];
|
||||
$description = $xpath->evaluate(".//a[@class='result__snippet']", $result)[0];
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
}
|
||||
|
||||
$url = $url->textContent;
|
||||
$url = check_for_privacy_frontend($url, $this->opts);
|
||||
|
||||
$title = $xpath->evaluate(".//h3", $result)[0];
|
||||
$description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
public static function print_results($results) {
|
||||
public static function print_results($results, $opts) {
|
||||
|
||||
if (empty($results)) {
|
||||
echo "<div class=\"text-result-container\"><p>An error occured fetching results</p></div>";
|
||||
|
@ -69,8 +69,7 @@
|
|||
|
||||
$special = $results[0];
|
||||
|
||||
if (array_key_exists("did_you_mean", $special))
|
||||
{
|
||||
if (array_key_exists("did_you_mean", $special)) {
|
||||
$didyoumean = $special["did_you_mean"];
|
||||
$new_url = "/search.php?q=" . urlencode($didyoumean);
|
||||
echo "<p class=\"did-you-mean\">Did you mean ";
|
||||
|
@ -78,32 +77,33 @@
|
|||
echo "?</p>";
|
||||
}
|
||||
|
||||
if (array_key_exists("special_response", $special))
|
||||
{
|
||||
if (array_key_exists("special_response", $special)) {
|
||||
$response = $special["special_response"]["response"];
|
||||
$source = $special["special_response"]["source"];
|
||||
|
||||
echo "<p class=\"special-result-container\">";
|
||||
if (array_key_exists("image", $special["special_response"]))
|
||||
{
|
||||
if (array_key_exists("image", $special["special_response"])) {
|
||||
$image_url = $special["special_response"]["image"];
|
||||
echo "<img src=\"image_proxy.php?url=$image_url\">";
|
||||
}
|
||||
echo $response;
|
||||
if ($source)
|
||||
if ($source) {
|
||||
$source = check_for_privacy_frontend($source, $opts);
|
||||
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
||||
}
|
||||
echo "</p>";
|
||||
}
|
||||
|
||||
echo "<div class=\"text-result-container\">";
|
||||
|
||||
foreach($results as $result)
|
||||
{
|
||||
foreach($results as $result) {
|
||||
if (!array_key_exists("title", $result))
|
||||
continue;
|
||||
|
||||
$title = $result["title"];
|
||||
$url = $result["url"];
|
||||
$url = check_for_privacy_frontend($url, $opts);
|
||||
|
||||
$base_url = $result["base_url"];
|
||||
$description = $result["description"];
|
||||
|
||||
|
@ -120,8 +120,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
function check_ddg_bang($query, $opts)
|
||||
{
|
||||
function check_ddg_bang($query, $opts) {
|
||||
|
||||
$bangs_json = file_get_contents("static/misc/ddg_bang.json");
|
||||
$bangs = json_decode($bangs_json, true);
|
||||
|
@ -133,22 +132,18 @@
|
|||
|
||||
$bang_url = null;
|
||||
|
||||
foreach($bangs as $bang)
|
||||
{
|
||||
if ($bang["t"] == $search_word)
|
||||
{
|
||||
foreach($bangs as $bang) {
|
||||
if ($bang["t"] == $search_word) {
|
||||
$bang_url = $bang["u"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($bang_url)
|
||||
{
|
||||
if ($bang_url) {
|
||||
$bang_query_array = explode("!" . $search_word, $query);
|
||||
$bang_query = trim(implode("", $bang_query_array));
|
||||
|
||||
$request_url = str_replace("{{{s}}}", str_replace('%26quot%3B','%22', urlencode($bang_query)), $bang_url);
|
||||
$request_url = check_for_privacy_frontend($request_url, $opts);
|
||||
|
||||
header("Location: " . $request_url);
|
||||
die();
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
return $results;
|
||||
}
|
||||
|
||||
static public function print_results($results){}
|
||||
public static function print_results($results, $opts) {}
|
||||
}
|
||||
|
||||
function load_opts() {
|
||||
|
@ -165,7 +165,7 @@
|
|||
return $results;
|
||||
|
||||
print_elapsed_time($start_time);
|
||||
$search_category->print_results($results);
|
||||
$search_category->print_results($results, $opts);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
function get_base_url($url) {
|
||||
$split_url = explode("/", $url);
|
||||
$base_url = $split_url[0] . "//" . $split_url[2] . "/";
|
||||
return $base_url;
|
||||
$parsed = parse_url($url);
|
||||
return $parsed["scheme"] . "://" . $parsed["host"] . "/";
|
||||
}
|
||||
|
||||
function get_root_domain($url) {
|
||||
|
|
Loading…
Reference in a new issue