diff --git a/api.php b/api.php new file mode 100644 index 0000000..c947b38 --- /dev/null +++ b/api.php @@ -0,0 +1,115 @@ +array( + "query"=>$query + ) + ); + if ($bookmark != null) + $data_param_obj["options"]["bookmarks"] = array($bookmark); + + $data_param = urlencode(json_encode($data_param_obj)); + + $headers = array(); + if ($csrftoken != null) + { + $headers[] = "x-csrftoken: $csrftoken"; + $headers[] = "cookie: csrftoken=$csrftoken"; + } + + $finalurl = $url; + if ($bookmark == null) + $finalurl = "$url?data=$data_param"; + + $ch = curl_init($finalurl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADERFUNCTION, $header_function); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + if ($bookmark != null) + { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, "data=$data_param"); + } + return $ch; +}; + +$search = function($query, $bookmark) use($prepare_search_curl_obj) +{ + $ch = $prepare_search_curl_obj($query, $bookmark); + $response = curl_exec($ch); + $data = json_decode($response); + $images = array(); + foreach ($data->{"resource_response"}->{"data"}->{"results"} as $result) + { + $image = $result->{"images"}->{"orig"}; + $url = $image->{"url"}; + array_push($images, $url); + } + echo json_encode($images); + $result = new SearchResult(); + $result->images = $images; + if (property_exists($data->{"resource_response"}, "bookmark")) + $result->bookmark = $data->{"resource_response"}->{"bookmark"}; + return $result; +}; + +$result = $search($query, $bookmark); + +if ($result->bookmark != null) +{ + $query_encoded = urlencode($query); + $bookmark_encoded = urlencode($result->bookmark); + $csrftoken_encoded = urlencode($csrftoken); + // echo "