google.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. function get_google_results($query, $page, $type=0)
  3. {
  4. require "config.php";
  5. require_once "results/google/image.php";
  6. require_once "results/google/text.php";
  7. require_once "results/google/video.php";
  8. $query_encoded = urlencode($query);
  9. $google = "https://www.google.$config_google_domain/search?&q=$query_encoded&start=$page&hl=$config_google_language";
  10. if ($type == 1)
  11. $google .= "&tbm=isch";
  12. else if ($type == 2)
  13. $google .= "&tbm=vid";
  14. $ch = curl_init($google);
  15. curl_setopt_array($ch, $config_curl_settings);
  16. $response = curl_exec($ch);
  17. if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
  18. {
  19. echo "<p id=\"special-result\">";
  20. echo "Google rejected the request! :C";
  21. echo "</p>";
  22. die();
  23. }
  24. $htmlDom = new DOMDocument;
  25. @$htmlDom->loadHTML($response);
  26. $xpath = new DOMXPath($htmlDom);
  27. switch ($type)
  28. {
  29. case 0:
  30. return text_results($xpath);
  31. case 1:
  32. return image_results($xpath);
  33. case 2:
  34. return video_results($xpath);
  35. default:
  36. return text_results($xpath);
  37. }
  38. }
  39. ?>