oauth-functions.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /* ------------------------------------------------------------------------------------
  3. * Goosle - A meta search engine for private and fast internet fun.
  4. *
  5. * COPYRIGHT NOTICE
  6. * Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
  7. *
  8. * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
  9. * By using this code you agree to indemnify Arnan de Gans from any
  10. * liability that might arise from its use.
  11. ------------------------------------------------------------------------------------ */
  12. /*--------------------------------------
  13. // Curl requests for oAUTH
  14. --------------------------------------*/
  15. function oath_curl_request($url, $user_agent, $method, $header, $post) {
  16. $ch = curl_init();
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. if($method == "post") {
  19. curl_setopt($ch, CURLOPT_POST, 1);
  20. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  21. } else {
  22. curl_setopt($ch, CURLOPT_HTTPGET, 1);
  23. }
  24. curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
  25. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  26. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  27. curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge(array('Accept: application/json, */*;q=0.8'), $header));
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  30. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  31. curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
  32. curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
  33. curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  34. curl_setopt($ch, CURLOPT_VERBOSE, false);
  35. $response = curl_exec($ch);
  36. curl_close($ch);
  37. return json_decode($response, true);
  38. }
  39. /*--------------------------------------
  40. // Store generated tokens
  41. --------------------------------------*/
  42. function oath_store_token($token_file, $connect, $token) {
  43. if(!is_file($token_file)){
  44. // Create token file
  45. file_put_contents($token_file, serialize(array($connect => $token)));
  46. } else {
  47. // Update token file
  48. $tokens = unserialize(file_get_contents($token_file));
  49. $tokens[$connect] = $token;
  50. file_put_contents($token_file, serialize($tokens));
  51. }
  52. }
  53. ?>