From 5c7f2f17f9c471d306955df457c7cab4e5c6ed3b Mon Sep 17 00:00:00 2001 From: Snap Date: Thu, 16 Apr 2015 14:51:26 -0700 Subject: Google's OpenID Connect method $google_client_id & $google_client_secret must be added to db.inc.php! --- .../src/Google/Http/Batch.php | 143 +++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 includes/google-api-php-client-master/src/Google/Http/Batch.php (limited to 'includes/google-api-php-client-master/src/Google/Http/Batch.php') diff --git a/includes/google-api-php-client-master/src/Google/Http/Batch.php b/includes/google-api-php-client-master/src/Google/Http/Batch.php new file mode 100644 index 0000000..6286f31 --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Http/Batch.php @@ -0,0 +1,143 @@ +client = $client; + $this->base_path = $this->client->getBasePath(); + $this->expected_classes = array(); + $boundary = (false == $boundary) ? mt_rand() : $boundary; + $this->boundary = str_replace('"', '', $boundary); + } + + public function add(Google_Http_Request $request, $key = false) + { + if (false == $key) { + $key = mt_rand(); + } + + $this->requests[$key] = $request; + } + + public function execute() + { + $body = ''; + + /** @var Google_Http_Request $req */ + foreach ($this->requests as $key => $req) { + $body .= "--{$this->boundary}\n"; + $body .= $req->toBatchString($key) . "\n"; + $this->expected_classes["response-" . $key] = $req->getExpectedClass(); + } + + $body = rtrim($body); + $body .= "\n--{$this->boundary}--"; + + $url = $this->base_path . '/batch'; + $httpRequest = new Google_Http_Request($url, 'POST'); + $httpRequest->setRequestHeaders( + array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary) + ); + + $httpRequest->setPostBody($body); + $response = $this->client->getIo()->makeRequest($httpRequest); + + return $this->parseResponse($response); + } + + public function parseResponse(Google_Http_Request $response) + { + $contentType = $response->getResponseHeader('content-type'); + $contentType = explode(';', $contentType); + $boundary = false; + foreach ($contentType as $part) { + $part = (explode('=', $part, 2)); + if (isset($part[0]) && 'boundary' == trim($part[0])) { + $boundary = $part[1]; + } + } + + $body = $response->getResponseBody(); + if ($body) { + $body = str_replace("--$boundary--", "--$boundary", $body); + $parts = explode("--$boundary", $body); + $responses = array(); + + foreach ($parts as $part) { + $part = trim($part); + if (!empty($part)) { + list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2); + $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders); + + $status = substr($part, 0, strpos($part, "\n")); + $status = explode(" ", $status); + $status = $status[1]; + + list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false); + $response = new Google_Http_Request(""); + $response->setResponseHttpCode($status); + $response->setResponseHeaders($partHeaders); + $response->setResponseBody($partBody); + + // Need content id. + $key = $metaHeaders['content-id']; + + if (isset($this->expected_classes[$key]) && + strlen($this->expected_classes[$key]) > 0) { + $class = $this->expected_classes[$key]; + $response->setExpectedClass($class); + } + + try { + $response = Google_Http_REST::decodeHttpResponse($response, $this->client); + $responses[$key] = $response; + } catch (Google_Service_Exception $e) { + // Store the exception as the response, so successful responses + // can be processed. + $responses[$key] = $e; + } + } + } + + return $responses; + } + + return null; + } +} -- cgit v1.2.3