image.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. function get_image_results($query, $page)
  3. {
  4. global $config;
  5. $page = $page / 10 + 1; // qwant has a different page system
  6. $url = "https://lite.qwant.com/?q=$query&t=images&p=$page";
  7. $response = request($url);
  8. $xpath = get_xpath($response);
  9. $results = array();
  10. foreach($xpath->query("//a[@rel='noopener']") as $result)
  11. {
  12. $image = $xpath->evaluate(".//img", $result)[0];
  13. if ($image)
  14. {
  15. $encoded_url = $result->getAttribute("href");
  16. $encoded_url_split1 = explode("==/", $encoded_url)[1];
  17. $encoded_url_split2 = explode("?position", $encoded_url_split1)[0];
  18. $real_url = urldecode(base64_decode($encoded_url_split2));
  19. $real_url = check_for_privacy_frontend($real_url);
  20. $alt = $image->getAttribute("alt");
  21. $thumbnail = urlencode($image->getAttribute("src"));
  22. array_push($results,
  23. array (
  24. "thumbnail" => urldecode(htmlspecialchars($thumbnail)),
  25. "alt" => htmlspecialchars($alt),
  26. "url" => htmlspecialchars($real_url)
  27. )
  28. );
  29. }
  30. }
  31. return $results;
  32. }
  33. function print_image_results($results)
  34. {
  35. echo "<div class=\"image-result-container\">";
  36. foreach($results as $result)
  37. {
  38. $thumbnail = urlencode($result["thumbnail"]);
  39. $alt = $result["alt"];
  40. $url = $result["url"];
  41. echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
  42. echo "<img src=\"image_proxy.php?url=$thumbnail\">";
  43. echo "</a>";
  44. }
  45. echo "</div>";
  46. }
  47. ?>