instances); $instance = $config->instances[$num]; $url = "https://$instance/api.php"; // Create parameters in cookies // Long time ago parameters like google_language or alternative_frontends are in POST field // IMO those changes are not good for privacy, I will consider to create a fork to bring back POST field method // BTW domain (google) can't be changed but mostly .com is used $site_language = isset($_COOKIE["google_language_site"]) ? trim(htmlspecialchars($_COOKIE["google_language_site"])) : $config->google_language_site; $results_language = isset($_COOKIE["google_language_results"]) ? trim(htmlspecialchars($_COOKIE["google_language_results"])) : $config->google_language_results; $number_of_results = isset($_COOKIE["google_number_of_results"]) ? trim(htmlspecialchars($_COOKIE["google_number_of_results"])) : $config->google_number_of_results; $wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language; $cookies = array( "google_language_site" => ((3 > strlen($site_language) && 0 < strlen($site_language))) ? $site_language : null, "google_language_results" => ((3 > strlen($results_language) && 0 < strlen($results_language))) ? $results_language : null, "google_number_of_results" => ((3 > strlen($number_of_results) && 0 < strlen($number_of_results))) ? $number_of_results : null, "wikipedia_language" => $wikipedia_language, // need some fix "safe_search" => isset($_COOKIE["safe_search"]) ? $_COOKIE["safe_search"] : null, "disable_special" => isset($_COOKIE["disable_special"]) ? $_COOKIE["disable_special"] : null ); // API POST field // Query should be encoded in api/search.php first but dunno why original repo still encode query in this function $query_encoded = urlencode($query); $post_string = "q=$query_encoded&p=$page&t=0"; // Alternative frontends // Fuck the cookie abuse in API if (!isset($_COOKIE["disable_frontends"])) { $frontends = array( "invidious"=>null, "rimgo"=>null, "scribe"=>null, "gothub"=>null, "librarian"=>null, "nitter"=>null, "libreddit"=>null, "proxitok"=>null, "wikiless"=>null, "quetre"=>null, "libremdb"=>null, "breezewiki"=>null, "anonymousoverflow"=>null, "suds"=>null, "biblioreads"=>null ); foreach ($frontends as $i => $value) { if (isset($_COOKIE[$i])) $frontends[$i] = $_COOKIE[$i]; else if (!empty($config->frontends[$i]["instance_url"])) $frontends[$i] = $config->frontends[$i]["instance_url"]; } $cookies=array_merge($cookies, $frontends); } else $cookies=array_merge($cookies, array("disable_frontends"=>$_COOKIE["disable_frontends"])); $api_ch = curl_init($url); curl_setopt_array($api_ch, $config->curl_settings); curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST"); //curl_setopt($api_ch, CURLOPT_POST, true); curl_setopt($api_ch, CURLOPT_COOKIE, urldecode(http_build_query($cookies, '', ';'))); curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string); $results = json_decode(curl_exec($api_ch),true); // In case some instances were broken... if($results == null) $results = "$instance is broken"; return $results; } function print_text_results($results) { $special = $results[0]; if (array_key_exists("special_response", $special)) { $response = $special["special_response"]["response"]; $source = $special["special_response"]["source"]; echo "
"; if (array_key_exists("image", $special["special_response"])) { $image_url = $special["special_response"]["image"]; echo ""; } echo $response; if ($source) echo "" . htmlspecialchars($source) . ""; echo "
"; array_shift($results); } echo "