DrupalOAuthRequest.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class DrupalOAuthRequest extends OAuthRequest {
  3. /**
  4. * Creates a OAuthRequest object from the current request
  5. *
  6. * @param string $http_method
  7. * @param string $http_url
  8. * @param array $parameters
  9. * @return OAuthRequest
  10. * A OAuthRequest generated from the request
  11. */
  12. public static function from_request($http_method = NULL, $http_url = NULL, $parameters = NULL) {
  13. // Preparations that has to be made if we're going to detect parameters
  14. if ($parameters == NULL) {
  15. $qs = $_SERVER['QUERY_STRING'];
  16. $q = $_GET['q'];
  17. // Unset $_GET['q'] if it was created by a redirect
  18. if (isset($_SERVER['REDIRECT_URL'])) {
  19. $q = FALSE;
  20. }
  21. // Check that the q parameter hasn't been created or altered by drupal
  22. elseif (isset($_GET['q'])) {
  23. $get = array();
  24. parse_str($_SERVER['QUERY_STRING'], $get);
  25. // The q parameter was in the original request, make sure it hasn't been altered
  26. if (isset($get['q'])) {
  27. $q = $get['q'];
  28. }
  29. // The q parameter was set by drupal, unset it
  30. else {
  31. $q = FALSE;
  32. }
  33. }
  34. $parsed = array();
  35. parse_str($_SERVER['QUERY_STRING'], $parsed);
  36. if ($q === FALSE) {
  37. unset($parsed['q']);
  38. }
  39. else {
  40. $parsed['q'] = $q;
  41. }
  42. $_SERVER['QUERY_STRING'] = http_build_query($parsed, '', '&');
  43. }
  44. $req = parent::from_request($http_method, $http_url, $parameters);
  45. // Restore $_SERVER['QUERY_STRING'] if it was touched
  46. if (isset($qs)) {
  47. $_SERVER['QUERY_STRING'] = $qs;
  48. }
  49. return $req;
  50. }
  51. }