query = $opts->query; $this->page = $opts->page; $this->opts = $opts; $this->engine = $opts->preferred_engines["text"] ?? "google"; $query_parts = explode(" ", $this->query); $last_word_query = end($query_parts); if (substr($this->query, 0, 1) == "!" || substr($last_word_query, 0, 1) == "!") check_ddg_bang($this->query, $opts); if ($this->engine == "google") { require "engines/text/google.php"; $this->engine_request = new GoogleRequest($opts, $mh); } if ($this->engine == "duckduckgo") { require "engines/text/duckduckgo.php"; $this->engine_request = new DuckDuckGoRequest($opts, $mh); } if (has_cooldown($this->engine, $this->opts->cooldowns) && !has_cached_results($this->engine_request->url)) { // TODO dont add it in the first place curl_multi_remove_handle($mh, $this->engine_request->ch); $this->engine_request = null; return; } require "engines/special/special.php"; $this->special_request = get_special_search_request($opts, $mh); } public function parse_results($response) { if (!isset($this->engine_request)) return array(); $results = $this->engine_request->get_results(); if (empty($results)) { set_cooldown($this->engine, ($opts->request_cooldown ?? "1") * 60, $this->opts->cooldowns); } else { if ($this->special_request) { $special_result = $this->special_request->get_results(); if ($special_result) $results = array_merge(array($special_result), $results); } } return $results; } public static function print_results($results, $opts) { if (empty($results)) { echo "
An error occured fetching results
" . $results["error"]["message"] . "
Did you mean "; echo "$didyoumean"; echo "?
"; } 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) { $source = check_for_privacy_frontend($source, $opts); echo "$source"; } echo "
"; } echo "