From d769d6c6a1b84836191bd1077d0c14eab778e61e Mon Sep 17 00:00:00 2001 From: Starchenko Alex Date: Mon, 18 Sep 2017 00:11:41 +0300 Subject: [PATCH] Fixed image search for product --- simpla/ajax/get_images.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/simpla/ajax/get_images.php b/simpla/ajax/get_images.php index c474a78..88af503 100755 --- a/simpla/ajax/get_images.php +++ b/simpla/ajax/get_images.php @@ -9,38 +9,39 @@ if(isset($_GET['start'])) $start = intval($_GET['start']); -$url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='.urlencode($keyword).'&start='.$start.'&rsz=8'; +$url = 'http://www.google.com/search?q=' . urlencode($keyword) . '&start=' . $start . '&asearch=ichunk'; if($use_curl && function_exists('curl_init')) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_REFERER, 'http://google.com'); curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51"); curl_setopt($ch, CURLOPT_TIMEOUT, 20); // Для использования прокси используйте строки: - //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); - //curl_setopt($ch, CURLOPT_PROXY, '88.85.108.16:8080'); - //curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password'); - + //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); + //curl_setopt($ch, CURLOPT_PROXY, '88.85.108.16:8080'); + //curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password'); + $page = curl_exec($ch); - curl_close($ch); + curl_close($ch); } else { $page = file_get_contents($url); } -$data = json_decode($page); +preg_match_all('/imgurl=([.\s\S]*)imgrefurl=/U', $page, $data); $images = array(); -if($data) - foreach ($data->responseData->results as $result) - $images[] = urldecode(str_replace('%2520', '%20', $result->url)); +if(isset($data[1])) + foreach ($data[1] as $result) + $images[] = urldecode(html_entity_decode(str_replace(array('%2520', '\\', 'u0026amp;'), array('%20', '', '') + , $result))); header("Content-type: application/json; charset=UTF-8"); header("Cache-Control: must-revalidate"); header("Pragma: no-cache"); -header("Expires: -1"); +header("Expires: -1"); -print(json_encode($images)); \ No newline at end of file +print(json_encode($images));