2022-02-19 17:40:56 -03:00
|
|
|
<?php
|
2022-02-25 06:42:32 -03:00
|
|
|
function get_image_results($query)
|
2022-02-19 17:40:56 -03:00
|
|
|
{
|
2022-03-11 06:04:36 -03:00
|
|
|
global $config;
|
2022-02-25 06:42:32 -03:00
|
|
|
|
2022-03-11 06:04:36 -03:00
|
|
|
$url = "https://www.google.$config->google_domain/search?&q=$query&hl=$config->google_language&tbm=isch";
|
2022-02-25 06:42:32 -03:00
|
|
|
$response = request($url);
|
|
|
|
$xpath = get_xpath($response);
|
2022-02-19 17:40:56 -03:00
|
|
|
|
|
|
|
$mh = curl_multi_init();
|
2022-06-09 05:02:59 -04:00
|
|
|
$chs = $results = array();
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
foreach($xpath->query("//div[@class='isv-r PNCib MSM1fd BUooTd']") as $result)
|
2022-02-19 17:40:56 -03:00
|
|
|
{
|
2022-06-09 05:02:59 -04:00
|
|
|
$image = $xpath->evaluate(".//img[@data-src]", $result)[0];
|
2022-06-14 08:06:29 -04:00
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
$url = $xpath->evaluate(".//a/@href", $result)[0]->textContent;
|
2022-06-27 17:00:22 -04:00
|
|
|
$url = check_for_privacy_frontend($url);
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
if (!empty($image))
|
2022-02-19 17:40:56 -03:00
|
|
|
{
|
2022-06-09 05:02:59 -04:00
|
|
|
$alt = $image->getAttribute("alt");
|
2022-06-27 17:00:22 -04:00
|
|
|
$thumbnail = $image->getAttribute("data-src");
|
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
if (!empty($alt))
|
|
|
|
{
|
|
|
|
array_push($results,
|
|
|
|
array (
|
2022-06-27 17:00:22 -04:00
|
|
|
"thumbnail" => $thumbnail,
|
2022-06-09 05:02:59 -04:00
|
|
|
"alt" => htmlspecialchars($alt),
|
|
|
|
"url" => htmlspecialchars($url)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2022-02-19 17:40:56 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
2022-02-25 06:42:32 -03:00
|
|
|
|
|
|
|
function print_image_results($results)
|
|
|
|
{
|
|
|
|
echo "<div class=\"image-result-container\">";
|
|
|
|
|
|
|
|
foreach($results as $result)
|
|
|
|
{
|
2022-06-27 17:00:22 -04:00
|
|
|
$thumbnail = $result["thumbnail"];
|
2022-02-25 06:42:32 -03:00
|
|
|
$alt = $result["alt"];
|
2022-06-09 05:02:59 -04:00
|
|
|
$url = $result["url"];
|
2022-02-25 06:42:32 -03:00
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
echo "<a title=\"$alt\" href=\"$url\" target=\"_blank\">";
|
2022-06-27 17:00:22 -04:00
|
|
|
echo "<img src=\"engines/google/image_proxy.php?url=$thumbnail\">";
|
2022-02-25 06:42:32 -03:00
|
|
|
echo "</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</div>";
|
|
|
|
}
|
2022-05-15 04:34:46 -04:00
|
|
|
?>
|