12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- function get_image_results($query, $page)
- {
- global $config;
- // Randomly choose a instance
- $results = array();
- $num = array_rand($config->instances);
- $instance = $config->instances[$num];
- $url = "https://$instance/api.php";
- // API POST field
- $post_string = "q=$query&p=$page&t=1";
- // 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_COOKIE, http_build_query($cookies, '', ';'));
- curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
- $results = json_decode(curl_exec($api_ch),true);
- if($results == null) $results = "$instance is broken";
- return $results;
- }
- function print_image_results($results)
- {
- echo "<div class=\"image-result-container\">";
- foreach($results as $result)
- {
- $thumbnail = urlencode($result["thumbnail"]);
- $alt = $result["alt"];
- $url = $result["url"];
- echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
- echo "<img src=\"image_proxy.php?url=$thumbnail\">";
- echo "</a>";
- }
- echo "</div>";
- }
- ?>
|