LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

image.php (2454B)

      1 <?php
      2     class QwantImageSearch extends EngineRequest {
      3         public function get_request_url() {
      4             $page = $this->page / 10 + 1; // qwant has a different page system
      5             $query = urlencode($this->query);
      6 
      7             return "https://lite.qwant.com/?q=$query&t=images&p=$page";
      8         }
      9 
     10         public function parse_results($response) {
     11             $results = array();
     12             $xpath = get_xpath($response);
     13 
     14             if (!$xpath)
     15                 return $results;
     16 
     17             foreach($xpath->query("//a[@rel='noopener']") as $result)
     18             {
     19                     $image = $xpath->evaluate(".//img", $result)[0];
     20 
     21                     if ($image)
     22                     {
     23                         $encoded_url = $result->getAttribute("href");
     24                         $encoded_url_split1 = explode("==/", $encoded_url)[1];
     25                         $encoded_url_split2 = explode("?position", $encoded_url_split1)[0];
     26                         $real_url = urldecode(base64_decode($encoded_url_split2));
     27 
     28                         $alt = $image->getAttribute("alt");
     29                         $thumbnail = urlencode($image->getAttribute("src"));
     30 
     31                         array_push($results,
     32                             array (
     33                                 "thumbnail" => urldecode(htmlspecialchars($thumbnail)),
     34                                 "alt" => htmlspecialchars($alt),
     35                                 "url" => htmlspecialchars($real_url)
     36                             )
     37                         );
     38 
     39                     }
     40             }
     41 
     42             return $results;
     43         }
     44 
     45         public static function print_results($results, $opts) {
     46             echo "<div class=\"image-result-container\">";
     47 
     48                 foreach($results as $result)
     49                 {
     50                     if (!$result 
     51                         || !array_key_exists("url", $result)
     52                         || !array_key_exists("alt", $result))
     53                         continue;
     54                     $thumbnail = urlencode($result["thumbnail"]);
     55                     $alt = $result["alt"];
     56                     $url = $result["url"];
     57                     $url = check_for_privacy_frontend($url, $opts);
     58 
     59                     echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
     60                     echo "<img src=\"image_proxy.php?url=$thumbnail\">";
     61                     echo "</a>";
     62                 }
     63 
     64             echo "</div>";
     65         }
     66     }
     67 ?>