@@ -73,29 +73,29 @@ discard block |
||
73 | 73 | * only used if resumable=True |
74 | 74 | */ |
75 | 75 | public function __construct( |
76 | - Google_Client $client, |
|
77 | - Google_Http_Request $request, |
|
78 | - $mimeType, |
|
79 | - $data, |
|
80 | - $resumable = false, |
|
81 | - $chunkSize = false, |
|
82 | - $boundary = false |
|
76 | + Google_Client $client, |
|
77 | + Google_Http_Request $request, |
|
78 | + $mimeType, |
|
79 | + $data, |
|
80 | + $resumable = false, |
|
81 | + $chunkSize = false, |
|
82 | + $boundary = false |
|
83 | 83 | ) { |
84 | - $this->client = $client; |
|
85 | - $this->request = $request; |
|
86 | - $this->mimeType = $mimeType; |
|
87 | - $this->data = $data; |
|
88 | - $this->size = strlen($this->data); |
|
89 | - $this->resumable = $resumable; |
|
90 | - if (!$chunkSize) { |
|
91 | - $chunkSize = 256 * 1024; |
|
92 | - } |
|
93 | - $this->chunkSize = $chunkSize; |
|
94 | - $this->progress = 0; |
|
95 | - $this->boundary = $boundary; |
|
96 | - |
|
97 | - // Process Media Request |
|
98 | - $this->process(); |
|
84 | + $this->client = $client; |
|
85 | + $this->request = $request; |
|
86 | + $this->mimeType = $mimeType; |
|
87 | + $this->data = $data; |
|
88 | + $this->size = strlen($this->data); |
|
89 | + $this->resumable = $resumable; |
|
90 | + if (!$chunkSize) { |
|
91 | + $chunkSize = 256 * 1024; |
|
92 | + } |
|
93 | + $this->chunkSize = $chunkSize; |
|
94 | + $this->progress = 0; |
|
95 | + $this->boundary = $boundary; |
|
96 | + |
|
97 | + // Process Media Request |
|
98 | + $this->process(); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setFileSize($size) |
106 | 106 | { |
107 | - $this->size = $size; |
|
107 | + $this->size = $size; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getProgress() |
115 | 115 | { |
116 | - return $this->progress; |
|
116 | + return $this->progress; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getHttpResultCode() |
124 | 124 | { |
125 | - return $this->httpResultCode; |
|
125 | + return $this->httpResultCode; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,56 +132,56 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function nextChunk($chunk = false) |
134 | 134 | { |
135 | - if (false == $this->resumeUri) { |
|
136 | - $this->resumeUri = $this->getResumeUri(); |
|
137 | - } |
|
138 | - |
|
139 | - if (false == $chunk) { |
|
140 | - $chunk = substr($this->data, $this->progress, $this->chunkSize); |
|
141 | - } |
|
142 | - |
|
143 | - $lastBytePos = $this->progress + strlen($chunk) - 1; |
|
144 | - $headers = array( |
|
145 | - 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", |
|
146 | - 'content-type' => $this->request->getRequestHeader('content-type'), |
|
147 | - 'content-length' => $this->chunkSize, |
|
148 | - 'expect' => '', |
|
149 | - ); |
|
150 | - |
|
151 | - $httpRequest = new Google_Http_Request( |
|
152 | - $this->resumeUri, |
|
153 | - 'PUT', |
|
154 | - $headers, |
|
155 | - $chunk |
|
156 | - ); |
|
157 | - |
|
158 | - if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) { |
|
159 | - $httpRequest->enableGzip(); |
|
160 | - } else { |
|
161 | - $httpRequest->disableGzip(); |
|
162 | - } |
|
163 | - |
|
164 | - $response = $this->client->getIo()->makeRequest($httpRequest); |
|
165 | - $response->setExpectedClass($this->request->getExpectedClass()); |
|
166 | - $code = $response->getResponseHttpCode(); |
|
167 | - $this->httpResultCode = $code; |
|
168 | - |
|
169 | - if (308 == $code) { |
|
170 | - // Track the amount uploaded. |
|
171 | - $range = explode('-', $response->getResponseHeader('range')); |
|
172 | - $this->progress = $range[1] + 1; |
|
173 | - |
|
174 | - // Allow for changing upload URLs. |
|
175 | - $location = $response->getResponseHeader('location'); |
|
176 | - if ($location) { |
|
177 | - $this->resumeUri = $location; |
|
178 | - } |
|
179 | - |
|
180 | - // No problems, but upload not complete. |
|
181 | - return false; |
|
182 | - } else { |
|
183 | - return Google_Http_REST::decodeHttpResponse($response, $this->client); |
|
184 | - } |
|
135 | + if (false == $this->resumeUri) { |
|
136 | + $this->resumeUri = $this->getResumeUri(); |
|
137 | + } |
|
138 | + |
|
139 | + if (false == $chunk) { |
|
140 | + $chunk = substr($this->data, $this->progress, $this->chunkSize); |
|
141 | + } |
|
142 | + |
|
143 | + $lastBytePos = $this->progress + strlen($chunk) - 1; |
|
144 | + $headers = array( |
|
145 | + 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", |
|
146 | + 'content-type' => $this->request->getRequestHeader('content-type'), |
|
147 | + 'content-length' => $this->chunkSize, |
|
148 | + 'expect' => '', |
|
149 | + ); |
|
150 | + |
|
151 | + $httpRequest = new Google_Http_Request( |
|
152 | + $this->resumeUri, |
|
153 | + 'PUT', |
|
154 | + $headers, |
|
155 | + $chunk |
|
156 | + ); |
|
157 | + |
|
158 | + if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) { |
|
159 | + $httpRequest->enableGzip(); |
|
160 | + } else { |
|
161 | + $httpRequest->disableGzip(); |
|
162 | + } |
|
163 | + |
|
164 | + $response = $this->client->getIo()->makeRequest($httpRequest); |
|
165 | + $response->setExpectedClass($this->request->getExpectedClass()); |
|
166 | + $code = $response->getResponseHttpCode(); |
|
167 | + $this->httpResultCode = $code; |
|
168 | + |
|
169 | + if (308 == $code) { |
|
170 | + // Track the amount uploaded. |
|
171 | + $range = explode('-', $response->getResponseHeader('range')); |
|
172 | + $this->progress = $range[1] + 1; |
|
173 | + |
|
174 | + // Allow for changing upload URLs. |
|
175 | + $location = $response->getResponseHeader('location'); |
|
176 | + if ($location) { |
|
177 | + $this->resumeUri = $location; |
|
178 | + } |
|
179 | + |
|
180 | + // No problems, but upload not complete. |
|
181 | + return false; |
|
182 | + } else { |
|
183 | + return Google_Http_REST::decodeHttpResponse($response, $this->client); |
|
184 | + } |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,53 +192,53 @@ discard block |
||
192 | 192 | */ |
193 | 193 | private function process() |
194 | 194 | { |
195 | - $postBody = false; |
|
196 | - $contentType = false; |
|
197 | - |
|
198 | - $meta = $this->request->getPostBody(); |
|
199 | - $meta = is_string($meta) ? json_decode($meta, true) : $meta; |
|
200 | - |
|
201 | - $uploadType = $this->getUploadType($meta); |
|
202 | - $this->request->setQueryParam('uploadType', $uploadType); |
|
203 | - $this->transformToUploadUrl(); |
|
204 | - $mimeType = $this->mimeType ? |
|
205 | - $this->mimeType : |
|
206 | - $this->request->getRequestHeader('content-type'); |
|
207 | - |
|
208 | - if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { |
|
209 | - $contentType = $mimeType; |
|
210 | - $postBody = is_string($meta) ? $meta : json_encode($meta); |
|
211 | - } else if (self::UPLOAD_MEDIA_TYPE == $uploadType) { |
|
212 | - $contentType = $mimeType; |
|
213 | - $postBody = $this->data; |
|
214 | - } else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
215 | - // This is a multipart/related upload. |
|
216 | - $boundary = $this->boundary ? $this->boundary : mt_rand(); |
|
217 | - $boundary = str_replace('"', '', $boundary); |
|
218 | - $contentType = 'multipart/related; boundary=' . $boundary; |
|
219 | - $related = "--$boundary\r\n"; |
|
220 | - $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
|
221 | - $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
222 | - $related .= "--$boundary\r\n"; |
|
223 | - $related .= "Content-Type: $mimeType\r\n"; |
|
224 | - $related .= "Content-Transfer-Encoding: base64\r\n"; |
|
225 | - $related .= "\r\n" . base64_encode($this->data) . "\r\n"; |
|
226 | - $related .= "--$boundary--"; |
|
227 | - $postBody = $related; |
|
228 | - } |
|
229 | - |
|
230 | - $this->request->setPostBody($postBody); |
|
231 | - |
|
232 | - if (isset($contentType) && $contentType) { |
|
233 | - $contentTypeHeader['content-type'] = $contentType; |
|
234 | - $this->request->setRequestHeaders($contentTypeHeader); |
|
235 | - } |
|
195 | + $postBody = false; |
|
196 | + $contentType = false; |
|
197 | + |
|
198 | + $meta = $this->request->getPostBody(); |
|
199 | + $meta = is_string($meta) ? json_decode($meta, true) : $meta; |
|
200 | + |
|
201 | + $uploadType = $this->getUploadType($meta); |
|
202 | + $this->request->setQueryParam('uploadType', $uploadType); |
|
203 | + $this->transformToUploadUrl(); |
|
204 | + $mimeType = $this->mimeType ? |
|
205 | + $this->mimeType : |
|
206 | + $this->request->getRequestHeader('content-type'); |
|
207 | + |
|
208 | + if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { |
|
209 | + $contentType = $mimeType; |
|
210 | + $postBody = is_string($meta) ? $meta : json_encode($meta); |
|
211 | + } else if (self::UPLOAD_MEDIA_TYPE == $uploadType) { |
|
212 | + $contentType = $mimeType; |
|
213 | + $postBody = $this->data; |
|
214 | + } else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) { |
|
215 | + // This is a multipart/related upload. |
|
216 | + $boundary = $this->boundary ? $this->boundary : mt_rand(); |
|
217 | + $boundary = str_replace('"', '', $boundary); |
|
218 | + $contentType = 'multipart/related; boundary=' . $boundary; |
|
219 | + $related = "--$boundary\r\n"; |
|
220 | + $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
|
221 | + $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
222 | + $related .= "--$boundary\r\n"; |
|
223 | + $related .= "Content-Type: $mimeType\r\n"; |
|
224 | + $related .= "Content-Transfer-Encoding: base64\r\n"; |
|
225 | + $related .= "\r\n" . base64_encode($this->data) . "\r\n"; |
|
226 | + $related .= "--$boundary--"; |
|
227 | + $postBody = $related; |
|
228 | + } |
|
229 | + |
|
230 | + $this->request->setPostBody($postBody); |
|
231 | + |
|
232 | + if (isset($contentType) && $contentType) { |
|
233 | + $contentTypeHeader['content-type'] = $contentType; |
|
234 | + $this->request->setRequestHeaders($contentTypeHeader); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | private function transformToUploadUrl() |
239 | 239 | { |
240 | - $base = $this->request->getBaseComponent(); |
|
241 | - $this->request->setBaseComponent($base . '/upload'); |
|
240 | + $base = $this->request->getBaseComponent(); |
|
241 | + $this->request->setBaseComponent($base . '/upload'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -252,56 +252,56 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function getUploadType($meta) |
254 | 254 | { |
255 | - if ($this->resumable) { |
|
256 | - return self::UPLOAD_RESUMABLE_TYPE; |
|
257 | - } |
|
255 | + if ($this->resumable) { |
|
256 | + return self::UPLOAD_RESUMABLE_TYPE; |
|
257 | + } |
|
258 | 258 | |
259 | - if (false == $meta && $this->data) { |
|
260 | - return self::UPLOAD_MEDIA_TYPE; |
|
261 | - } |
|
259 | + if (false == $meta && $this->data) { |
|
260 | + return self::UPLOAD_MEDIA_TYPE; |
|
261 | + } |
|
262 | 262 | |
263 | - return self::UPLOAD_MULTIPART_TYPE; |
|
263 | + return self::UPLOAD_MULTIPART_TYPE; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | private function getResumeUri() |
267 | 267 | { |
268 | - $result = null; |
|
269 | - $body = $this->request->getPostBody(); |
|
270 | - if ($body) { |
|
271 | - $headers = array( |
|
272 | - 'content-type' => 'application/json; charset=UTF-8', |
|
273 | - 'content-length' => Google_Utils::getStrLen($body), |
|
274 | - 'x-upload-content-type' => $this->mimeType, |
|
275 | - 'x-upload-content-length' => $this->size, |
|
276 | - 'expect' => '', |
|
277 | - ); |
|
278 | - $this->request->setRequestHeaders($headers); |
|
279 | - } |
|
280 | - |
|
281 | - $response = $this->client->getIo()->makeRequest($this->request); |
|
282 | - $location = $response->getResponseHeader('location'); |
|
283 | - $code = $response->getResponseHttpCode(); |
|
284 | - |
|
285 | - if (200 == $code && true == $location) { |
|
286 | - return $location; |
|
287 | - } |
|
288 | - $message = $code; |
|
289 | - $body = @json_decode($response->getResponseBody()); |
|
290 | - if (!empty($body->error->errors) ) { |
|
291 | - $message .= ': '; |
|
292 | - foreach ($body->error->errors as $error) { |
|
293 | - $message .= "{$error->domain}, {$error->message};"; |
|
294 | - } |
|
295 | - $message = rtrim($message, ';'); |
|
296 | - } |
|
297 | - |
|
298 | - $error = "Failed to start the resumable upload (HTTP {$message})"; |
|
299 | - $this->client->getLogger()->error($error); |
|
300 | - throw new Google_Exception($error); |
|
268 | + $result = null; |
|
269 | + $body = $this->request->getPostBody(); |
|
270 | + if ($body) { |
|
271 | + $headers = array( |
|
272 | + 'content-type' => 'application/json; charset=UTF-8', |
|
273 | + 'content-length' => Google_Utils::getStrLen($body), |
|
274 | + 'x-upload-content-type' => $this->mimeType, |
|
275 | + 'x-upload-content-length' => $this->size, |
|
276 | + 'expect' => '', |
|
277 | + ); |
|
278 | + $this->request->setRequestHeaders($headers); |
|
279 | + } |
|
280 | + |
|
281 | + $response = $this->client->getIo()->makeRequest($this->request); |
|
282 | + $location = $response->getResponseHeader('location'); |
|
283 | + $code = $response->getResponseHttpCode(); |
|
284 | + |
|
285 | + if (200 == $code && true == $location) { |
|
286 | + return $location; |
|
287 | + } |
|
288 | + $message = $code; |
|
289 | + $body = @json_decode($response->getResponseBody()); |
|
290 | + if (!empty($body->error->errors) ) { |
|
291 | + $message .= ': '; |
|
292 | + foreach ($body->error->errors as $error) { |
|
293 | + $message .= "{$error->domain}, {$error->message};"; |
|
294 | + } |
|
295 | + $message = rtrim($message, ';'); |
|
296 | + } |
|
297 | + |
|
298 | + $error = "Failed to start the resumable upload (HTTP {$message})"; |
|
299 | + $this->client->getLogger()->error($error); |
|
300 | + throw new Google_Exception($error); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | public function setChunkSize($chunkSize) |
304 | 304 | { |
305 | - $this->chunkSize = $chunkSize; |
|
305 | + $this->chunkSize = $chunkSize; |
|
306 | 306 | } |
307 | 307 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -202,8 +202,7 @@ discard block |
||
202 | 202 | $this->request->setQueryParam('uploadType', $uploadType); |
203 | 203 | $this->transformToUploadUrl(); |
204 | 204 | $mimeType = $this->mimeType ? |
205 | - $this->mimeType : |
|
206 | - $this->request->getRequestHeader('content-type'); |
|
205 | + $this->mimeType : $this->request->getRequestHeader('content-type'); |
|
207 | 206 | |
208 | 207 | if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { |
209 | 208 | $contentType = $mimeType; |
@@ -215,14 +214,14 @@ discard block |
||
215 | 214 | // This is a multipart/related upload. |
216 | 215 | $boundary = $this->boundary ? $this->boundary : mt_rand(); |
217 | 216 | $boundary = str_replace('"', '', $boundary); |
218 | - $contentType = 'multipart/related; boundary=' . $boundary; |
|
217 | + $contentType = 'multipart/related; boundary='.$boundary; |
|
219 | 218 | $related = "--$boundary\r\n"; |
220 | 219 | $related .= "Content-Type: application/json; charset=UTF-8\r\n"; |
221 | - $related .= "\r\n" . json_encode($meta) . "\r\n"; |
|
220 | + $related .= "\r\n".json_encode($meta)."\r\n"; |
|
222 | 221 | $related .= "--$boundary\r\n"; |
223 | 222 | $related .= "Content-Type: $mimeType\r\n"; |
224 | 223 | $related .= "Content-Transfer-Encoding: base64\r\n"; |
225 | - $related .= "\r\n" . base64_encode($this->data) . "\r\n"; |
|
224 | + $related .= "\r\n".base64_encode($this->data)."\r\n"; |
|
226 | 225 | $related .= "--$boundary--"; |
227 | 226 | $postBody = $related; |
228 | 227 | } |
@@ -238,7 +237,7 @@ discard block |
||
238 | 237 | private function transformToUploadUrl() |
239 | 238 | { |
240 | 239 | $base = $this->request->getBaseComponent(); |
241 | - $this->request->setBaseComponent($base . '/upload'); |
|
240 | + $this->request->setBaseComponent($base.'/upload'); |
|
242 | 241 | } |
243 | 242 | |
244 | 243 | /** |
@@ -287,7 +286,7 @@ discard block |
||
287 | 286 | } |
288 | 287 | $message = $code; |
289 | 288 | $body = @json_decode($response->getResponseBody()); |
290 | - if (!empty($body->error->errors) ) { |
|
289 | + if (!empty($body->error->errors)) { |
|
291 | 290 | $message .= ': '; |
292 | 291 | foreach ($body->error->errors as $error) { |
293 | 292 | $message .= "{$error->domain}, {$error->message};"; |
@@ -41,105 +41,105 @@ |
||
41 | 41 | |
42 | 42 | public function __construct(Google_Client $client, $boundary = false, $rootUrl = '', $batchPath = '') |
43 | 43 | { |
44 | - $this->client = $client; |
|
45 | - $this->root_url = rtrim($rootUrl ? $rootUrl : $this->client->getBasePath(), '/'); |
|
46 | - $this->batch_path = $batchPath ? $batchPath : 'batch'; |
|
47 | - $this->expected_classes = array(); |
|
48 | - $boundary = (false == $boundary) ? mt_rand() : $boundary; |
|
49 | - $this->boundary = str_replace('"', '', $boundary); |
|
44 | + $this->client = $client; |
|
45 | + $this->root_url = rtrim($rootUrl ? $rootUrl : $this->client->getBasePath(), '/'); |
|
46 | + $this->batch_path = $batchPath ? $batchPath : 'batch'; |
|
47 | + $this->expected_classes = array(); |
|
48 | + $boundary = (false == $boundary) ? mt_rand() : $boundary; |
|
49 | + $this->boundary = str_replace('"', '', $boundary); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function add(Google_Http_Request $request, $key = false) |
53 | 53 | { |
54 | - if (false == $key) { |
|
55 | - $key = mt_rand(); |
|
56 | - } |
|
54 | + if (false == $key) { |
|
55 | + $key = mt_rand(); |
|
56 | + } |
|
57 | 57 | |
58 | - $this->requests[$key] = $request; |
|
58 | + $this->requests[$key] = $request; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function execute() |
62 | 62 | { |
63 | - $body = ''; |
|
63 | + $body = ''; |
|
64 | 64 | |
65 | - /** @var Google_Http_Request $req */ |
|
66 | - foreach ($this->requests as $key => $req) { |
|
67 | - $body .= "--{$this->boundary}\n"; |
|
68 | - $body .= $req->toBatchString($key) . "\n\n"; |
|
69 | - $this->expected_classes["response-" . $key] = $req->getExpectedClass(); |
|
70 | - } |
|
65 | + /** @var Google_Http_Request $req */ |
|
66 | + foreach ($this->requests as $key => $req) { |
|
67 | + $body .= "--{$this->boundary}\n"; |
|
68 | + $body .= $req->toBatchString($key) . "\n\n"; |
|
69 | + $this->expected_classes["response-" . $key] = $req->getExpectedClass(); |
|
70 | + } |
|
71 | 71 | |
72 | - $body .= "--{$this->boundary}--"; |
|
72 | + $body .= "--{$this->boundary}--"; |
|
73 | 73 | |
74 | - $url = $this->root_url . '/' . $this->batch_path; |
|
75 | - $httpRequest = new Google_Http_Request($url, 'POST'); |
|
76 | - $httpRequest->setRequestHeaders( |
|
77 | - array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary) |
|
78 | - ); |
|
74 | + $url = $this->root_url . '/' . $this->batch_path; |
|
75 | + $httpRequest = new Google_Http_Request($url, 'POST'); |
|
76 | + $httpRequest->setRequestHeaders( |
|
77 | + array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary) |
|
78 | + ); |
|
79 | 79 | |
80 | - $httpRequest->setPostBody($body); |
|
81 | - $response = $this->client->getIo()->makeRequest($httpRequest); |
|
80 | + $httpRequest->setPostBody($body); |
|
81 | + $response = $this->client->getIo()->makeRequest($httpRequest); |
|
82 | 82 | |
83 | - return $this->parseResponse($response); |
|
83 | + return $this->parseResponse($response); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public function parseResponse(Google_Http_Request $response) |
87 | 87 | { |
88 | - $contentType = $response->getResponseHeader('content-type'); |
|
89 | - $contentType = explode(';', $contentType); |
|
90 | - $boundary = false; |
|
91 | - foreach ($contentType as $part) { |
|
92 | - $part = (explode('=', $part, 2)); |
|
93 | - if (isset($part[0]) && 'boundary' == trim($part[0])) { |
|
94 | - $boundary = $part[1]; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - $body = $response->getResponseBody(); |
|
99 | - if ($body) { |
|
100 | - $body = str_replace("--$boundary--", "--$boundary", $body); |
|
101 | - $parts = explode("--$boundary", $body); |
|
102 | - $responses = array(); |
|
103 | - |
|
104 | - foreach ($parts as $part) { |
|
105 | - $part = trim($part); |
|
106 | - if (!empty($part)) { |
|
107 | - list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2); |
|
108 | - $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders); |
|
109 | - |
|
110 | - $status = substr($part, 0, strpos($part, "\n")); |
|
111 | - $status = explode(" ", $status); |
|
112 | - $status = $status[1]; |
|
113 | - |
|
114 | - list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false); |
|
115 | - $response = new Google_Http_Request(""); |
|
116 | - $response->setResponseHttpCode($status); |
|
117 | - $response->setResponseHeaders($partHeaders); |
|
118 | - $response->setResponseBody($partBody); |
|
119 | - |
|
120 | - // Need content id. |
|
121 | - $key = $metaHeaders['content-id']; |
|
122 | - |
|
123 | - if (isset($this->expected_classes[$key]) && |
|
124 | - strlen($this->expected_classes[$key]) > 0) { |
|
125 | - $class = $this->expected_classes[$key]; |
|
126 | - $response->setExpectedClass($class); |
|
127 | - } |
|
128 | - |
|
129 | - try { |
|
130 | - $response = Google_Http_REST::decodeHttpResponse($response, $this->client); |
|
131 | - $responses[$key] = $response; |
|
132 | - } catch (Google_Service_Exception $e) { |
|
133 | - // Store the exception as the response, so successful responses |
|
134 | - // can be processed. |
|
135 | - $responses[$key] = $e; |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $responses; |
|
141 | - } |
|
142 | - |
|
143 | - return null; |
|
88 | + $contentType = $response->getResponseHeader('content-type'); |
|
89 | + $contentType = explode(';', $contentType); |
|
90 | + $boundary = false; |
|
91 | + foreach ($contentType as $part) { |
|
92 | + $part = (explode('=', $part, 2)); |
|
93 | + if (isset($part[0]) && 'boundary' == trim($part[0])) { |
|
94 | + $boundary = $part[1]; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + $body = $response->getResponseBody(); |
|
99 | + if ($body) { |
|
100 | + $body = str_replace("--$boundary--", "--$boundary", $body); |
|
101 | + $parts = explode("--$boundary", $body); |
|
102 | + $responses = array(); |
|
103 | + |
|
104 | + foreach ($parts as $part) { |
|
105 | + $part = trim($part); |
|
106 | + if (!empty($part)) { |
|
107 | + list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2); |
|
108 | + $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders); |
|
109 | + |
|
110 | + $status = substr($part, 0, strpos($part, "\n")); |
|
111 | + $status = explode(" ", $status); |
|
112 | + $status = $status[1]; |
|
113 | + |
|
114 | + list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false); |
|
115 | + $response = new Google_Http_Request(""); |
|
116 | + $response->setResponseHttpCode($status); |
|
117 | + $response->setResponseHeaders($partHeaders); |
|
118 | + $response->setResponseBody($partBody); |
|
119 | + |
|
120 | + // Need content id. |
|
121 | + $key = $metaHeaders['content-id']; |
|
122 | + |
|
123 | + if (isset($this->expected_classes[$key]) && |
|
124 | + strlen($this->expected_classes[$key]) > 0) { |
|
125 | + $class = $this->expected_classes[$key]; |
|
126 | + $response->setExpectedClass($class); |
|
127 | + } |
|
128 | + |
|
129 | + try { |
|
130 | + $response = Google_Http_REST::decodeHttpResponse($response, $this->client); |
|
131 | + $responses[$key] = $response; |
|
132 | + } catch (Google_Service_Exception $e) { |
|
133 | + // Store the exception as the response, so successful responses |
|
134 | + // can be processed. |
|
135 | + $responses[$key] = $e; |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $responses; |
|
141 | + } |
|
142 | + |
|
143 | + return null; |
|
144 | 144 | } |
145 | 145 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | /** @var Google_Http_Request $req */ |
66 | 66 | foreach ($this->requests as $key => $req) { |
67 | 67 | $body .= "--{$this->boundary}\n"; |
68 | - $body .= $req->toBatchString($key) . "\n\n"; |
|
69 | - $this->expected_classes["response-" . $key] = $req->getExpectedClass(); |
|
68 | + $body .= $req->toBatchString($key)."\n\n"; |
|
69 | + $this->expected_classes["response-".$key] = $req->getExpectedClass(); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $body .= "--{$this->boundary}--"; |
73 | 73 | |
74 | - $url = $this->root_url . '/' . $this->batch_path; |
|
74 | + $url = $this->root_url.'/'.$this->batch_path; |
|
75 | 75 | $httpRequest = new Google_Http_Request($url, 'POST'); |
76 | 76 | $httpRequest->setRequestHeaders( |
77 | - array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary) |
|
77 | + array('Content-Type' => 'multipart/mixed; boundary='.$this->boundary) |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | $httpRequest->setPostBody($body); |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public static function execute(Google_Client $client, Google_Http_Request $req) |
38 | 38 | { |
39 | - $runner = new Google_Task_Runner( |
|
40 | - $client, |
|
41 | - sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()), |
|
42 | - array(get_class(), 'doExecute'), |
|
43 | - array($client, $req) |
|
44 | - ); |
|
39 | + $runner = new Google_Task_Runner( |
|
40 | + $client, |
|
41 | + sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()), |
|
42 | + array(get_class(), 'doExecute'), |
|
43 | + array($client, $req) |
|
44 | + ); |
|
45 | 45 | |
46 | - return $runner->run(); |
|
46 | + return $runner->run(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public static function doExecute(Google_Client $client, Google_Http_Request $req) |
59 | 59 | { |
60 | - $httpRequest = $client->getIo()->makeRequest($req); |
|
61 | - $httpRequest->setExpectedClass($req->getExpectedClass()); |
|
62 | - return self::decodeHttpResponse($httpRequest, $client); |
|
60 | + $httpRequest = $client->getIo()->makeRequest($req); |
|
61 | + $httpRequest->setExpectedClass($req->getExpectedClass()); |
|
62 | + return self::decodeHttpResponse($httpRequest, $client); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -72,65 +72,65 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public static function decodeHttpResponse($response, Google_Client $client = null) |
74 | 74 | { |
75 | - $code = $response->getResponseHttpCode(); |
|
76 | - $body = $response->getResponseBody(); |
|
77 | - $decoded = null; |
|
75 | + $code = $response->getResponseHttpCode(); |
|
76 | + $body = $response->getResponseBody(); |
|
77 | + $decoded = null; |
|
78 | 78 | |
79 | - if ((intVal($code)) >= 300) { |
|
80 | - $decoded = json_decode($body, true); |
|
81 | - $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl(); |
|
82 | - if (isset($decoded['error']) && |
|
83 | - isset($decoded['error']['message']) && |
|
84 | - isset($decoded['error']['code'])) { |
|
85 | - // if we're getting a json encoded error definition, use that instead of the raw response |
|
86 | - // body for improved readability |
|
87 | - $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}"; |
|
88 | - } else { |
|
89 | - $err .= ": ($code) $body"; |
|
90 | - } |
|
79 | + if ((intVal($code)) >= 300) { |
|
80 | + $decoded = json_decode($body, true); |
|
81 | + $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl(); |
|
82 | + if (isset($decoded['error']) && |
|
83 | + isset($decoded['error']['message']) && |
|
84 | + isset($decoded['error']['code'])) { |
|
85 | + // if we're getting a json encoded error definition, use that instead of the raw response |
|
86 | + // body for improved readability |
|
87 | + $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}"; |
|
88 | + } else { |
|
89 | + $err .= ": ($code) $body"; |
|
90 | + } |
|
91 | 91 | |
92 | - $errors = null; |
|
93 | - // Specific check for APIs which don't return error details, such as Blogger. |
|
94 | - if (isset($decoded['error']) && isset($decoded['error']['errors'])) { |
|
95 | - $errors = $decoded['error']['errors']; |
|
96 | - } |
|
92 | + $errors = null; |
|
93 | + // Specific check for APIs which don't return error details, such as Blogger. |
|
94 | + if (isset($decoded['error']) && isset($decoded['error']['errors'])) { |
|
95 | + $errors = $decoded['error']['errors']; |
|
96 | + } |
|
97 | 97 | |
98 | - $map = null; |
|
99 | - if ($client) { |
|
100 | - $client->getLogger()->error( |
|
101 | - $err, |
|
102 | - array('code' => $code, 'errors' => $errors) |
|
103 | - ); |
|
98 | + $map = null; |
|
99 | + if ($client) { |
|
100 | + $client->getLogger()->error( |
|
101 | + $err, |
|
102 | + array('code' => $code, 'errors' => $errors) |
|
103 | + ); |
|
104 | 104 | |
105 | - $map = $client->getClassConfig( |
|
106 | - 'Google_Service_Exception', |
|
107 | - 'retry_map' |
|
108 | - ); |
|
109 | - } |
|
110 | - throw new Google_Service_Exception($err, $code, null, $errors, $map); |
|
111 | - } |
|
105 | + $map = $client->getClassConfig( |
|
106 | + 'Google_Service_Exception', |
|
107 | + 'retry_map' |
|
108 | + ); |
|
109 | + } |
|
110 | + throw new Google_Service_Exception($err, $code, null, $errors, $map); |
|
111 | + } |
|
112 | 112 | |
113 | - // Only attempt to decode the response, if the response code wasn't (204) 'no content' |
|
114 | - if ($code != '204') { |
|
115 | - if ($response->getExpectedRaw()) { |
|
116 | - return $body; |
|
117 | - } |
|
113 | + // Only attempt to decode the response, if the response code wasn't (204) 'no content' |
|
114 | + if ($code != '204') { |
|
115 | + if ($response->getExpectedRaw()) { |
|
116 | + return $body; |
|
117 | + } |
|
118 | 118 | |
119 | - $decoded = json_decode($body, true); |
|
120 | - if ($decoded === null || $decoded === "") { |
|
121 | - $error = "Invalid json in service response: $body"; |
|
122 | - if ($client) { |
|
123 | - $client->getLogger()->error($error); |
|
124 | - } |
|
125 | - throw new Google_Service_Exception($error); |
|
126 | - } |
|
119 | + $decoded = json_decode($body, true); |
|
120 | + if ($decoded === null || $decoded === "") { |
|
121 | + $error = "Invalid json in service response: $body"; |
|
122 | + if ($client) { |
|
123 | + $client->getLogger()->error($error); |
|
124 | + } |
|
125 | + throw new Google_Service_Exception($error); |
|
126 | + } |
|
127 | 127 | |
128 | - if ($response->getExpectedClass()) { |
|
129 | - $class = $response->getExpectedClass(); |
|
130 | - $decoded = new $class($decoded); |
|
131 | - } |
|
132 | - } |
|
133 | - return $decoded; |
|
128 | + if ($response->getExpectedClass()) { |
|
129 | + $class = $response->getExpectedClass(); |
|
130 | + $decoded = new $class($decoded); |
|
131 | + } |
|
132 | + } |
|
133 | + return $decoded; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -144,35 +144,35 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function createRequestUri($servicePath, $restPath, $params) |
146 | 146 | { |
147 | - $requestUrl = $servicePath . $restPath; |
|
148 | - $uriTemplateVars = array(); |
|
149 | - $queryVars = array(); |
|
150 | - foreach ($params as $paramName => $paramSpec) { |
|
151 | - if ($paramSpec['type'] == 'boolean') { |
|
152 | - $paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false'; |
|
153 | - } |
|
154 | - if ($paramSpec['location'] == 'path') { |
|
155 | - $uriTemplateVars[$paramName] = $paramSpec['value']; |
|
156 | - } else if ($paramSpec['location'] == 'query') { |
|
157 | - if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) { |
|
158 | - foreach ($paramSpec['value'] as $value) { |
|
159 | - $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value)); |
|
160 | - } |
|
161 | - } else { |
|
162 | - $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value'])); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
147 | + $requestUrl = $servicePath . $restPath; |
|
148 | + $uriTemplateVars = array(); |
|
149 | + $queryVars = array(); |
|
150 | + foreach ($params as $paramName => $paramSpec) { |
|
151 | + if ($paramSpec['type'] == 'boolean') { |
|
152 | + $paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false'; |
|
153 | + } |
|
154 | + if ($paramSpec['location'] == 'path') { |
|
155 | + $uriTemplateVars[$paramName] = $paramSpec['value']; |
|
156 | + } else if ($paramSpec['location'] == 'query') { |
|
157 | + if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) { |
|
158 | + foreach ($paramSpec['value'] as $value) { |
|
159 | + $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value)); |
|
160 | + } |
|
161 | + } else { |
|
162 | + $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value'])); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - if (count($uriTemplateVars)) { |
|
168 | - $uriTemplateParser = new Google_Utils_URITemplate(); |
|
169 | - $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars); |
|
170 | - } |
|
167 | + if (count($uriTemplateVars)) { |
|
168 | + $uriTemplateParser = new Google_Utils_URITemplate(); |
|
169 | + $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars); |
|
170 | + } |
|
171 | 171 | |
172 | - if (count($queryVars)) { |
|
173 | - $requestUrl .= '?' . implode($queryVars, '&'); |
|
174 | - } |
|
172 | + if (count($queryVars)) { |
|
173 | + $requestUrl .= '?' . implode($queryVars, '&'); |
|
174 | + } |
|
175 | 175 | |
176 | - return $requestUrl; |
|
176 | + return $requestUrl; |
|
177 | 177 | } |
178 | 178 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | |
79 | 79 | if ((intVal($code)) >= 300) { |
80 | 80 | $decoded = json_decode($body, true); |
81 | - $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl(); |
|
81 | + $err = 'Error calling '.$response->getRequestMethod().' '.$response->getUrl(); |
|
82 | 82 | if (isset($decoded['error']) && |
83 | - isset($decoded['error']['message']) && |
|
83 | + isset($decoded['error']['message']) && |
|
84 | 84 | isset($decoded['error']['code'])) { |
85 | 85 | // if we're getting a json encoded error definition, use that instead of the raw response |
86 | 86 | // body for improved readability |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function createRequestUri($servicePath, $restPath, $params) |
146 | 146 | { |
147 | - $requestUrl = $servicePath . $restPath; |
|
147 | + $requestUrl = $servicePath.$restPath; |
|
148 | 148 | $uriTemplateVars = array(); |
149 | 149 | $queryVars = array(); |
150 | 150 | foreach ($params as $paramName => $paramSpec) { |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | } else if ($paramSpec['location'] == 'query') { |
157 | 157 | if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) { |
158 | 158 | foreach ($paramSpec['value'] as $value) { |
159 | - $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value)); |
|
159 | + $queryVars[] = $paramName.'='.rawurlencode(rawurldecode($value)); |
|
160 | 160 | } |
161 | 161 | } else { |
162 | - $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value'])); |
|
162 | + $queryVars[] = $paramName.'='.rawurlencode(rawurldecode($paramSpec['value'])); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | if (count($queryVars)) { |
173 | - $requestUrl .= '?' . implode($queryVars, '&'); |
|
173 | + $requestUrl .= '?'.implode($queryVars, '&'); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $requestUrl; |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct(Google_Client $client) |
36 | 36 | { |
37 | - if (!extension_loaded('curl')) { |
|
38 | - $error = 'The cURL IO handler requires the cURL extension to be enabled'; |
|
39 | - $client->getLogger()->critical($error); |
|
40 | - throw new Google_IO_Exception($error); |
|
41 | - } |
|
37 | + if (!extension_loaded('curl')) { |
|
38 | + $error = 'The cURL IO handler requires the cURL extension to be enabled'; |
|
39 | + $client->getLogger()->critical($error); |
|
40 | + throw new Google_IO_Exception($error); |
|
41 | + } |
|
42 | 42 | |
43 | - parent::__construct($client); |
|
43 | + parent::__construct($client); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -52,83 +52,83 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function executeRequest(Google_Http_Request $request) |
54 | 54 | { |
55 | - $curl = curl_init(); |
|
56 | - |
|
57 | - if ($request->getPostBody()) { |
|
58 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody()); |
|
59 | - } |
|
60 | - |
|
61 | - $requestHeaders = $request->getRequestHeaders(); |
|
62 | - if ($requestHeaders && is_array($requestHeaders)) { |
|
63 | - $curlHeaders = array(); |
|
64 | - foreach ($requestHeaders as $k => $v) { |
|
65 | - $curlHeaders[] = "$k: $v"; |
|
66 | - } |
|
67 | - curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders); |
|
68 | - } |
|
69 | - curl_setopt($curl, CURLOPT_URL, $request->getUrl()); |
|
70 | - |
|
71 | - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod()); |
|
72 | - curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent()); |
|
73 | - |
|
74 | - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); |
|
75 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); |
|
76 | - // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP. |
|
77 | - curl_setopt($curl, CURLOPT_SSLVERSION, 1); |
|
78 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
79 | - curl_setopt($curl, CURLOPT_HEADER, true); |
|
80 | - |
|
81 | - if ($request->canGzip()) { |
|
82 | - curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); |
|
83 | - } |
|
55 | + $curl = curl_init(); |
|
56 | + |
|
57 | + if ($request->getPostBody()) { |
|
58 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody()); |
|
59 | + } |
|
60 | + |
|
61 | + $requestHeaders = $request->getRequestHeaders(); |
|
62 | + if ($requestHeaders && is_array($requestHeaders)) { |
|
63 | + $curlHeaders = array(); |
|
64 | + foreach ($requestHeaders as $k => $v) { |
|
65 | + $curlHeaders[] = "$k: $v"; |
|
66 | + } |
|
67 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders); |
|
68 | + } |
|
69 | + curl_setopt($curl, CURLOPT_URL, $request->getUrl()); |
|
70 | + |
|
71 | + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod()); |
|
72 | + curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent()); |
|
73 | + |
|
74 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); |
|
75 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); |
|
76 | + // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP. |
|
77 | + curl_setopt($curl, CURLOPT_SSLVERSION, 1); |
|
78 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
79 | + curl_setopt($curl, CURLOPT_HEADER, true); |
|
80 | + |
|
81 | + if ($request->canGzip()) { |
|
82 | + curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); |
|
83 | + } |
|
84 | 84 | |
85 | - $options = $this->client->getClassConfig('Google_IO_Curl', 'options'); |
|
86 | - if (is_array($options)) { |
|
87 | - $this->setOptions($options); |
|
88 | - } |
|
85 | + $options = $this->client->getClassConfig('Google_IO_Curl', 'options'); |
|
86 | + if (is_array($options)) { |
|
87 | + $this->setOptions($options); |
|
88 | + } |
|
89 | 89 | |
90 | - foreach ($this->options as $key => $var) { |
|
91 | - curl_setopt($curl, $key, $var); |
|
92 | - } |
|
93 | - |
|
94 | - if (!isset($this->options[CURLOPT_CAINFO])) { |
|
95 | - curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem'); |
|
96 | - } |
|
97 | - |
|
98 | - $this->client->getLogger()->debug( |
|
99 | - 'cURL request', |
|
100 | - array( |
|
101 | - 'url' => $request->getUrl(), |
|
102 | - 'method' => $request->getRequestMethod(), |
|
103 | - 'headers' => $requestHeaders, |
|
104 | - 'body' => $request->getPostBody() |
|
105 | - ) |
|
106 | - ); |
|
107 | - |
|
108 | - $response = curl_exec($curl); |
|
109 | - if ($response === false) { |
|
110 | - $error = curl_error($curl); |
|
111 | - $code = curl_errno($curl); |
|
112 | - $map = $this->client->getClassConfig('Google_IO_Exception', 'retry_map'); |
|
113 | - |
|
114 | - $this->client->getLogger()->error('cURL ' . $error); |
|
115 | - throw new Google_IO_Exception($error, $code, null, $map); |
|
116 | - } |
|
117 | - $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
|
118 | - |
|
119 | - list($responseHeaders, $responseBody) = $this->parseHttpResponse($response, $headerSize); |
|
120 | - $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
121 | - |
|
122 | - $this->client->getLogger()->debug( |
|
123 | - 'cURL response', |
|
124 | - array( |
|
125 | - 'code' => $responseCode, |
|
126 | - 'headers' => $responseHeaders, |
|
127 | - 'body' => $responseBody, |
|
128 | - ) |
|
129 | - ); |
|
130 | - |
|
131 | - return array($responseBody, $responseHeaders, $responseCode); |
|
90 | + foreach ($this->options as $key => $var) { |
|
91 | + curl_setopt($curl, $key, $var); |
|
92 | + } |
|
93 | + |
|
94 | + if (!isset($this->options[CURLOPT_CAINFO])) { |
|
95 | + curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem'); |
|
96 | + } |
|
97 | + |
|
98 | + $this->client->getLogger()->debug( |
|
99 | + 'cURL request', |
|
100 | + array( |
|
101 | + 'url' => $request->getUrl(), |
|
102 | + 'method' => $request->getRequestMethod(), |
|
103 | + 'headers' => $requestHeaders, |
|
104 | + 'body' => $request->getPostBody() |
|
105 | + ) |
|
106 | + ); |
|
107 | + |
|
108 | + $response = curl_exec($curl); |
|
109 | + if ($response === false) { |
|
110 | + $error = curl_error($curl); |
|
111 | + $code = curl_errno($curl); |
|
112 | + $map = $this->client->getClassConfig('Google_IO_Exception', 'retry_map'); |
|
113 | + |
|
114 | + $this->client->getLogger()->error('cURL ' . $error); |
|
115 | + throw new Google_IO_Exception($error, $code, null, $map); |
|
116 | + } |
|
117 | + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
|
118 | + |
|
119 | + list($responseHeaders, $responseBody) = $this->parseHttpResponse($response, $headerSize); |
|
120 | + $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
121 | + |
|
122 | + $this->client->getLogger()->debug( |
|
123 | + 'cURL response', |
|
124 | + array( |
|
125 | + 'code' => $responseCode, |
|
126 | + 'headers' => $responseHeaders, |
|
127 | + 'body' => $responseBody, |
|
128 | + ) |
|
129 | + ); |
|
130 | + |
|
131 | + return array($responseBody, $responseHeaders, $responseCode); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function setOptions($options) |
139 | 139 | { |
140 | - $this->options = $options + $this->options; |
|
140 | + $this->options = $options + $this->options; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function setTimeout($timeout) |
148 | 148 | { |
149 | - // Since this timeout is really for putting a bound on the time |
|
150 | - // we'll set them both to the same. If you need to specify a longer |
|
151 | - // CURLOPT_TIMEOUT, or a higher CONNECTTIMEOUT, the best thing to |
|
152 | - // do is use the setOptions method for the values individually. |
|
153 | - $this->options[CURLOPT_CONNECTTIMEOUT] = $timeout; |
|
154 | - $this->options[CURLOPT_TIMEOUT] = $timeout; |
|
149 | + // Since this timeout is really for putting a bound on the time |
|
150 | + // we'll set them both to the same. If you need to specify a longer |
|
151 | + // CURLOPT_TIMEOUT, or a higher CONNECTTIMEOUT, the best thing to |
|
152 | + // do is use the setOptions method for the values individually. |
|
153 | + $this->options[CURLOPT_CONNECTTIMEOUT] = $timeout; |
|
154 | + $this->options[CURLOPT_TIMEOUT] = $timeout; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function getTimeout() |
162 | 162 | { |
163 | - return $this->options[CURLOPT_TIMEOUT]; |
|
163 | + return $this->options[CURLOPT_TIMEOUT]; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function needsQuirk() |
174 | 174 | { |
175 | - $ver = curl_version(); |
|
176 | - $versionNum = $ver['version_number']; |
|
177 | - return $versionNum < Google_IO_Curl::NO_QUIRK_VERSION; |
|
175 | + $ver = curl_version(); |
|
176 | + $versionNum = $ver['version_number']; |
|
177 | + return $versionNum < Google_IO_Curl::NO_QUIRK_VERSION; |
|
178 | 178 | } |
179 | 179 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | if (!class_exists('Google_Client')) { |
25 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
25 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Google_IO_Curl extends Google_IO_Abstract |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | if (!isset($this->options[CURLOPT_CAINFO])) { |
95 | - curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem'); |
|
95 | + curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__).'/cacerts.pem'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $this->client->getLogger()->debug( |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $code = curl_errno($curl); |
112 | 112 | $map = $this->client->getClassConfig('Google_IO_Exception', 'retry_map'); |
113 | 113 | |
114 | - $this->client->getLogger()->error('cURL ' . $error); |
|
114 | + $this->client->getLogger()->error('cURL '.$error); |
|
115 | 115 | throw new Google_IO_Exception($error, $code, null, $map); |
116 | 116 | } |
117 | 117 | $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
@@ -34,24 +34,24 @@ discard block |
||
34 | 34 | private $trappedErrorString; |
35 | 35 | |
36 | 36 | private static $DEFAULT_HTTP_CONTEXT = array( |
37 | - "follow_location" => 0, |
|
38 | - "ignore_errors" => 1, |
|
37 | + "follow_location" => 0, |
|
38 | + "ignore_errors" => 1, |
|
39 | 39 | ); |
40 | 40 | |
41 | 41 | private static $DEFAULT_SSL_CONTEXT = array( |
42 | - "verify_peer" => true, |
|
42 | + "verify_peer" => true, |
|
43 | 43 | ); |
44 | 44 | |
45 | 45 | public function __construct(Google_Client $client) |
46 | 46 | { |
47 | - if (!ini_get('allow_url_fopen')) { |
|
48 | - $error = 'The stream IO handler requires the allow_url_fopen runtime ' . |
|
49 | - 'configuration to be enabled'; |
|
50 | - $client->getLogger()->critical($error); |
|
51 | - throw new Google_IO_Exception($error); |
|
52 | - } |
|
53 | - |
|
54 | - parent::__construct($client); |
|
47 | + if (!ini_get('allow_url_fopen')) { |
|
48 | + $error = 'The stream IO handler requires the allow_url_fopen runtime ' . |
|
49 | + 'configuration to be enabled'; |
|
50 | + $client->getLogger()->critical($error); |
|
51 | + throw new Google_IO_Exception($error); |
|
52 | + } |
|
53 | + |
|
54 | + parent::__construct($client); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -63,119 +63,119 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function executeRequest(Google_Http_Request $request) |
65 | 65 | { |
66 | - $default_options = stream_context_get_options(stream_context_get_default()); |
|
67 | - |
|
68 | - $requestHttpContext = array_key_exists('http', $default_options) ? |
|
69 | - $default_options['http'] : array(); |
|
70 | - |
|
71 | - if ($request->getPostBody()) { |
|
72 | - $requestHttpContext["content"] = $request->getPostBody(); |
|
73 | - } |
|
74 | - |
|
75 | - $requestHeaders = $request->getRequestHeaders(); |
|
76 | - if ($requestHeaders && is_array($requestHeaders)) { |
|
77 | - $headers = ""; |
|
78 | - foreach ($requestHeaders as $k => $v) { |
|
79 | - $headers .= "$k: $v\r\n"; |
|
80 | - } |
|
81 | - $requestHttpContext["header"] = $headers; |
|
82 | - } |
|
83 | - |
|
84 | - $requestHttpContext["method"] = $request->getRequestMethod(); |
|
85 | - $requestHttpContext["user_agent"] = $request->getUserAgent(); |
|
86 | - |
|
87 | - $requestSslContext = array_key_exists('ssl', $default_options) ? |
|
88 | - $default_options['ssl'] : array(); |
|
89 | - |
|
90 | - if (!array_key_exists("cafile", $requestSslContext)) { |
|
91 | - $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
92 | - } |
|
93 | - |
|
94 | - $options = array( |
|
95 | - "http" => array_merge( |
|
96 | - self::$DEFAULT_HTTP_CONTEXT, |
|
97 | - $requestHttpContext |
|
98 | - ), |
|
99 | - "ssl" => array_merge( |
|
100 | - self::$DEFAULT_SSL_CONTEXT, |
|
101 | - $requestSslContext |
|
102 | - ) |
|
103 | - ); |
|
104 | - |
|
105 | - $context = stream_context_create($options); |
|
106 | - |
|
107 | - $url = $request->getUrl(); |
|
108 | - |
|
109 | - if ($request->canGzip()) { |
|
110 | - $url = self::ZLIB . $url; |
|
111 | - } |
|
112 | - |
|
113 | - $this->client->getLogger()->debug( |
|
114 | - 'Stream request', |
|
115 | - array( |
|
116 | - 'url' => $url, |
|
117 | - 'method' => $request->getRequestMethod(), |
|
118 | - 'headers' => $requestHeaders, |
|
119 | - 'body' => $request->getPostBody() |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - // We are trapping any thrown errors in this method only and |
|
124 | - // throwing an exception. |
|
125 | - $this->trappedErrorNumber = null; |
|
126 | - $this->trappedErrorString = null; |
|
127 | - |
|
128 | - // START - error trap. |
|
129 | - set_error_handler(array($this, 'trapError')); |
|
130 | - $fh = fopen($url, 'r', false, $context); |
|
131 | - restore_error_handler(); |
|
132 | - // END - error trap. |
|
133 | - |
|
134 | - if ($this->trappedErrorNumber) { |
|
135 | - $error = sprintf( |
|
136 | - "HTTP Error: Unable to connect: '%s'", |
|
137 | - $this->trappedErrorString |
|
138 | - ); |
|
139 | - |
|
140 | - $this->client->getLogger()->error('Stream ' . $error); |
|
141 | - throw new Google_IO_Exception($error, $this->trappedErrorNumber); |
|
142 | - } |
|
143 | - |
|
144 | - $response_data = false; |
|
145 | - $respHttpCode = self::UNKNOWN_CODE; |
|
146 | - if ($fh) { |
|
147 | - if (isset($this->options[self::TIMEOUT])) { |
|
148 | - stream_set_timeout($fh, $this->options[self::TIMEOUT]); |
|
149 | - } |
|
150 | - |
|
151 | - $response_data = stream_get_contents($fh); |
|
152 | - fclose($fh); |
|
153 | - |
|
154 | - $respHttpCode = $this->getHttpResponseCode($http_response_header); |
|
155 | - } |
|
156 | - |
|
157 | - if (false === $response_data) { |
|
158 | - $error = sprintf( |
|
159 | - "HTTP Error: Unable to connect: '%s'", |
|
160 | - $respHttpCode |
|
161 | - ); |
|
162 | - |
|
163 | - $this->client->getLogger()->error('Stream ' . $error); |
|
164 | - throw new Google_IO_Exception($error, $respHttpCode); |
|
165 | - } |
|
166 | - |
|
167 | - $responseHeaders = $this->getHttpResponseHeaders($http_response_header); |
|
168 | - |
|
169 | - $this->client->getLogger()->debug( |
|
170 | - 'Stream response', |
|
171 | - array( |
|
172 | - 'code' => $respHttpCode, |
|
173 | - 'headers' => $responseHeaders, |
|
174 | - 'body' => $response_data, |
|
175 | - ) |
|
176 | - ); |
|
177 | - |
|
178 | - return array($response_data, $responseHeaders, $respHttpCode); |
|
66 | + $default_options = stream_context_get_options(stream_context_get_default()); |
|
67 | + |
|
68 | + $requestHttpContext = array_key_exists('http', $default_options) ? |
|
69 | + $default_options['http'] : array(); |
|
70 | + |
|
71 | + if ($request->getPostBody()) { |
|
72 | + $requestHttpContext["content"] = $request->getPostBody(); |
|
73 | + } |
|
74 | + |
|
75 | + $requestHeaders = $request->getRequestHeaders(); |
|
76 | + if ($requestHeaders && is_array($requestHeaders)) { |
|
77 | + $headers = ""; |
|
78 | + foreach ($requestHeaders as $k => $v) { |
|
79 | + $headers .= "$k: $v\r\n"; |
|
80 | + } |
|
81 | + $requestHttpContext["header"] = $headers; |
|
82 | + } |
|
83 | + |
|
84 | + $requestHttpContext["method"] = $request->getRequestMethod(); |
|
85 | + $requestHttpContext["user_agent"] = $request->getUserAgent(); |
|
86 | + |
|
87 | + $requestSslContext = array_key_exists('ssl', $default_options) ? |
|
88 | + $default_options['ssl'] : array(); |
|
89 | + |
|
90 | + if (!array_key_exists("cafile", $requestSslContext)) { |
|
91 | + $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
92 | + } |
|
93 | + |
|
94 | + $options = array( |
|
95 | + "http" => array_merge( |
|
96 | + self::$DEFAULT_HTTP_CONTEXT, |
|
97 | + $requestHttpContext |
|
98 | + ), |
|
99 | + "ssl" => array_merge( |
|
100 | + self::$DEFAULT_SSL_CONTEXT, |
|
101 | + $requestSslContext |
|
102 | + ) |
|
103 | + ); |
|
104 | + |
|
105 | + $context = stream_context_create($options); |
|
106 | + |
|
107 | + $url = $request->getUrl(); |
|
108 | + |
|
109 | + if ($request->canGzip()) { |
|
110 | + $url = self::ZLIB . $url; |
|
111 | + } |
|
112 | + |
|
113 | + $this->client->getLogger()->debug( |
|
114 | + 'Stream request', |
|
115 | + array( |
|
116 | + 'url' => $url, |
|
117 | + 'method' => $request->getRequestMethod(), |
|
118 | + 'headers' => $requestHeaders, |
|
119 | + 'body' => $request->getPostBody() |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + // We are trapping any thrown errors in this method only and |
|
124 | + // throwing an exception. |
|
125 | + $this->trappedErrorNumber = null; |
|
126 | + $this->trappedErrorString = null; |
|
127 | + |
|
128 | + // START - error trap. |
|
129 | + set_error_handler(array($this, 'trapError')); |
|
130 | + $fh = fopen($url, 'r', false, $context); |
|
131 | + restore_error_handler(); |
|
132 | + // END - error trap. |
|
133 | + |
|
134 | + if ($this->trappedErrorNumber) { |
|
135 | + $error = sprintf( |
|
136 | + "HTTP Error: Unable to connect: '%s'", |
|
137 | + $this->trappedErrorString |
|
138 | + ); |
|
139 | + |
|
140 | + $this->client->getLogger()->error('Stream ' . $error); |
|
141 | + throw new Google_IO_Exception($error, $this->trappedErrorNumber); |
|
142 | + } |
|
143 | + |
|
144 | + $response_data = false; |
|
145 | + $respHttpCode = self::UNKNOWN_CODE; |
|
146 | + if ($fh) { |
|
147 | + if (isset($this->options[self::TIMEOUT])) { |
|
148 | + stream_set_timeout($fh, $this->options[self::TIMEOUT]); |
|
149 | + } |
|
150 | + |
|
151 | + $response_data = stream_get_contents($fh); |
|
152 | + fclose($fh); |
|
153 | + |
|
154 | + $respHttpCode = $this->getHttpResponseCode($http_response_header); |
|
155 | + } |
|
156 | + |
|
157 | + if (false === $response_data) { |
|
158 | + $error = sprintf( |
|
159 | + "HTTP Error: Unable to connect: '%s'", |
|
160 | + $respHttpCode |
|
161 | + ); |
|
162 | + |
|
163 | + $this->client->getLogger()->error('Stream ' . $error); |
|
164 | + throw new Google_IO_Exception($error, $respHttpCode); |
|
165 | + } |
|
166 | + |
|
167 | + $responseHeaders = $this->getHttpResponseHeaders($http_response_header); |
|
168 | + |
|
169 | + $this->client->getLogger()->debug( |
|
170 | + 'Stream response', |
|
171 | + array( |
|
172 | + 'code' => $respHttpCode, |
|
173 | + 'headers' => $responseHeaders, |
|
174 | + 'body' => $response_data, |
|
175 | + ) |
|
176 | + ); |
|
177 | + |
|
178 | + return array($response_data, $responseHeaders, $respHttpCode); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function setOptions($options) |
186 | 186 | { |
187 | - $this->options = $options + $this->options; |
|
187 | + $this->options = $options + $this->options; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function trapError($errno, $errstr) |
195 | 195 | { |
196 | - $this->trappedErrorNumber = $errno; |
|
197 | - $this->trappedErrorString = $errstr; |
|
196 | + $this->trappedErrorNumber = $errno; |
|
197 | + $this->trappedErrorString = $errstr; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function setTimeout($timeout) |
205 | 205 | { |
206 | - $this->options[self::TIMEOUT] = $timeout; |
|
206 | + $this->options[self::TIMEOUT] = $timeout; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function getTimeout() |
214 | 214 | { |
215 | - return $this->options[self::TIMEOUT]; |
|
215 | + return $this->options[self::TIMEOUT]; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -224,20 +224,20 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function needsQuirk() |
226 | 226 | { |
227 | - return false; |
|
227 | + return false; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | protected function getHttpResponseCode($response_headers) |
231 | 231 | { |
232 | - $header_count = count($response_headers); |
|
233 | - |
|
234 | - for ($i = 0; $i < $header_count; $i++) { |
|
235 | - $header = $response_headers[$i]; |
|
236 | - if (strncasecmp("HTTP", $header, strlen("HTTP")) == 0) { |
|
237 | - $response = explode(' ', $header); |
|
238 | - return $response[1]; |
|
239 | - } |
|
240 | - } |
|
241 | - return self::UNKNOWN_CODE; |
|
232 | + $header_count = count($response_headers); |
|
233 | + |
|
234 | + for ($i = 0; $i < $header_count; $i++) { |
|
235 | + $header = $response_headers[$i]; |
|
236 | + if (strncasecmp("HTTP", $header, strlen("HTTP")) == 0) { |
|
237 | + $response = explode(' ', $header); |
|
238 | + return $response[1]; |
|
239 | + } |
|
240 | + } |
|
241 | + return self::UNKNOWN_CODE; |
|
242 | 242 | } |
243 | 243 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | if (!class_exists('Google_Client')) { |
25 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
25 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Google_IO_Stream extends Google_IO_Abstract |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function __construct(Google_Client $client) |
46 | 46 | { |
47 | 47 | if (!ini_get('allow_url_fopen')) { |
48 | - $error = 'The stream IO handler requires the allow_url_fopen runtime ' . |
|
48 | + $error = 'The stream IO handler requires the allow_url_fopen runtime '. |
|
49 | 49 | 'configuration to be enabled'; |
50 | 50 | $client->getLogger()->critical($error); |
51 | 51 | throw new Google_IO_Exception($error); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $default_options['ssl'] : array(); |
89 | 89 | |
90 | 90 | if (!array_key_exists("cafile", $requestSslContext)) { |
91 | - $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
|
91 | + $requestSslContext["cafile"] = dirname(__FILE__).'/cacerts.pem'; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $options = array( |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $url = $request->getUrl(); |
108 | 108 | |
109 | 109 | if ($request->canGzip()) { |
110 | - $url = self::ZLIB . $url; |
|
110 | + $url = self::ZLIB.$url; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->client->getLogger()->debug( |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->trappedErrorString |
138 | 138 | ); |
139 | 139 | |
140 | - $this->client->getLogger()->error('Stream ' . $error); |
|
140 | + $this->client->getLogger()->error('Stream '.$error); |
|
141 | 141 | throw new Google_IO_Exception($error, $this->trappedErrorNumber); |
142 | 142 | } |
143 | 143 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $respHttpCode |
161 | 161 | ); |
162 | 162 | |
163 | - $this->client->getLogger()->error('Stream ' . $error); |
|
163 | + $this->client->getLogger()->error('Stream '.$error); |
|
164 | 164 | throw new Google_IO_Exception($error, $respHttpCode); |
165 | 165 | } |
166 | 166 |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | * @param array|null $retryMap Map of errors with retry counts. |
36 | 36 | */ |
37 | 37 | public function __construct( |
38 | - $message, |
|
39 | - $code = 0, |
|
40 | - Exception $previous = null, |
|
41 | - array $retryMap = null |
|
38 | + $message, |
|
39 | + $code = 0, |
|
40 | + Exception $previous = null, |
|
41 | + array $retryMap = null |
|
42 | 42 | ) { |
43 | - if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
44 | - parent::__construct($message, $code, $previous); |
|
45 | - } else { |
|
46 | - parent::__construct($message, $code); |
|
47 | - } |
|
43 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
44 | + parent::__construct($message, $code, $previous); |
|
45 | + } else { |
|
46 | + parent::__construct($message, $code); |
|
47 | + } |
|
48 | 48 | |
49 | - if (is_array($retryMap)) { |
|
50 | - $this->retryMap = $retryMap; |
|
51 | - } |
|
49 | + if (is_array($retryMap)) { |
|
50 | + $this->retryMap = $retryMap; |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function allowedRetries() |
62 | 62 | { |
63 | - if (isset($this->retryMap[$this->code])) { |
|
64 | - return $this->retryMap[$this->code]; |
|
65 | - } |
|
63 | + if (isset($this->retryMap[$this->code])) { |
|
64 | + return $this->retryMap[$this->code]; |
|
65 | + } |
|
66 | 66 | |
67 | - return 0; |
|
67 | + return 0; |
|
68 | 68 | } |
69 | 69 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class Google_IO_Exception extends Google_Exception implements Google_Task_Retryable |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | const UNKNOWN_CODE = 0; |
29 | 29 | const FORM_URLENCODED = 'application/x-www-form-urlencoded'; |
30 | 30 | private static $CONNECTION_ESTABLISHED_HEADERS = array( |
31 | - "HTTP/1.0 200 Connection established\r\n\r\n", |
|
32 | - "HTTP/1.1 200 Connection established\r\n\r\n", |
|
31 | + "HTTP/1.0 200 Connection established\r\n\r\n", |
|
32 | + "HTTP/1.1 200 Connection established\r\n\r\n", |
|
33 | 33 | ); |
34 | 34 | private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null); |
35 | 35 | private static $HOP_BY_HOP = array( |
36 | - 'connection' => true, |
|
37 | - 'keep-alive' => true, |
|
38 | - 'proxy-authenticate' => true, |
|
39 | - 'proxy-authorization' => true, |
|
40 | - 'te' => true, |
|
41 | - 'trailers' => true, |
|
42 | - 'transfer-encoding' => true, |
|
43 | - 'upgrade' => true |
|
36 | + 'connection' => true, |
|
37 | + 'keep-alive' => true, |
|
38 | + 'proxy-authenticate' => true, |
|
39 | + 'proxy-authorization' => true, |
|
40 | + 'te' => true, |
|
41 | + 'trailers' => true, |
|
42 | + 'transfer-encoding' => true, |
|
43 | + 'upgrade' => true |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | |
50 | 50 | public function __construct(Google_Client $client) |
51 | 51 | { |
52 | - $this->client = $client; |
|
53 | - $timeout = $client->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds'); |
|
54 | - if ($timeout > 0) { |
|
55 | - $this->setTimeout($timeout); |
|
56 | - } |
|
52 | + $this->client = $client; |
|
53 | + $timeout = $client->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds'); |
|
54 | + if ($timeout > 0) { |
|
55 | + $this->setTimeout($timeout); |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function setCachedRequest(Google_Http_Request $request) |
104 | 104 | { |
105 | - // Determine if the request is cacheable. |
|
106 | - if (Google_Http_CacheParser::isResponseCacheable($request)) { |
|
107 | - $this->client->getCache()->set($request->getCacheKey(), $request); |
|
108 | - return true; |
|
109 | - } |
|
105 | + // Determine if the request is cacheable. |
|
106 | + if (Google_Http_CacheParser::isResponseCacheable($request)) { |
|
107 | + $this->client->getCache()->set($request->getCacheKey(), $request); |
|
108 | + return true; |
|
109 | + } |
|
110 | 110 | |
111 | - return false; |
|
111 | + return false; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -121,37 +121,37 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function makeRequest(Google_Http_Request $request) |
123 | 123 | { |
124 | - // First, check to see if we have a valid cached version. |
|
125 | - $cached = $this->getCachedRequest($request); |
|
126 | - if ($cached !== false && $cached instanceof Google_Http_Request) { |
|
127 | - if (!$this->checkMustRevalidateCachedRequest($cached, $request)) { |
|
128 | - return $cached; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - if (array_key_exists($request->getRequestMethod(), self::$ENTITY_HTTP_METHODS)) { |
|
133 | - $request = $this->processEntityRequest($request); |
|
134 | - } |
|
135 | - |
|
136 | - list($responseData, $responseHeaders, $respHttpCode) = $this->executeRequest($request); |
|
137 | - |
|
138 | - if ($respHttpCode == 304 && $cached) { |
|
139 | - // If the server responded NOT_MODIFIED, return the cached request. |
|
140 | - $this->updateCachedRequest($cached, $responseHeaders); |
|
141 | - return $cached; |
|
142 | - } |
|
143 | - |
|
144 | - if (!isset($responseHeaders['Date']) && !isset($responseHeaders['date'])) { |
|
145 | - $responseHeaders['date'] = date("r"); |
|
146 | - } |
|
147 | - |
|
148 | - $request->setResponseHttpCode($respHttpCode); |
|
149 | - $request->setResponseHeaders($responseHeaders); |
|
150 | - $request->setResponseBody($responseData); |
|
151 | - // Store the request in cache (the function checks to see if the request |
|
152 | - // can actually be cached) |
|
153 | - $this->setCachedRequest($request); |
|
154 | - return $request; |
|
124 | + // First, check to see if we have a valid cached version. |
|
125 | + $cached = $this->getCachedRequest($request); |
|
126 | + if ($cached !== false && $cached instanceof Google_Http_Request) { |
|
127 | + if (!$this->checkMustRevalidateCachedRequest($cached, $request)) { |
|
128 | + return $cached; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + if (array_key_exists($request->getRequestMethod(), self::$ENTITY_HTTP_METHODS)) { |
|
133 | + $request = $this->processEntityRequest($request); |
|
134 | + } |
|
135 | + |
|
136 | + list($responseData, $responseHeaders, $respHttpCode) = $this->executeRequest($request); |
|
137 | + |
|
138 | + if ($respHttpCode == 304 && $cached) { |
|
139 | + // If the server responded NOT_MODIFIED, return the cached request. |
|
140 | + $this->updateCachedRequest($cached, $responseHeaders); |
|
141 | + return $cached; |
|
142 | + } |
|
143 | + |
|
144 | + if (!isset($responseHeaders['Date']) && !isset($responseHeaders['date'])) { |
|
145 | + $responseHeaders['date'] = date("r"); |
|
146 | + } |
|
147 | + |
|
148 | + $request->setResponseHttpCode($respHttpCode); |
|
149 | + $request->setResponseHeaders($responseHeaders); |
|
150 | + $request->setResponseBody($responseData); |
|
151 | + // Store the request in cache (the function checks to see if the request |
|
152 | + // can actually be cached) |
|
153 | + $this->setCachedRequest($request); |
|
154 | + return $request; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getCachedRequest(Google_Http_Request $request) |
164 | 164 | { |
165 | - if (false === Google_Http_CacheParser::isRequestCacheable($request)) { |
|
166 | - return false; |
|
167 | - } |
|
165 | + if (false === Google_Http_CacheParser::isRequestCacheable($request)) { |
|
166 | + return false; |
|
167 | + } |
|
168 | 168 | |
169 | - return $this->client->getCache()->get($request->getCacheKey()); |
|
169 | + return $this->client->getCache()->get($request->getCacheKey()); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -177,28 +177,28 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function processEntityRequest(Google_Http_Request $request) |
179 | 179 | { |
180 | - $postBody = $request->getPostBody(); |
|
181 | - $contentType = $request->getRequestHeader("content-type"); |
|
182 | - |
|
183 | - // Set the default content-type as application/x-www-form-urlencoded. |
|
184 | - if (false == $contentType) { |
|
185 | - $contentType = self::FORM_URLENCODED; |
|
186 | - $request->setRequestHeaders(array('content-type' => $contentType)); |
|
187 | - } |
|
188 | - |
|
189 | - // Force the payload to match the content-type asserted in the header. |
|
190 | - if ($contentType == self::FORM_URLENCODED && is_array($postBody)) { |
|
191 | - $postBody = http_build_query($postBody, '', '&'); |
|
192 | - $request->setPostBody($postBody); |
|
193 | - } |
|
194 | - |
|
195 | - // Make sure the content-length header is set. |
|
196 | - if (!$postBody || is_string($postBody)) { |
|
197 | - $postsLength = strlen($postBody); |
|
198 | - $request->setRequestHeaders(array('content-length' => $postsLength)); |
|
199 | - } |
|
200 | - |
|
201 | - return $request; |
|
180 | + $postBody = $request->getPostBody(); |
|
181 | + $contentType = $request->getRequestHeader("content-type"); |
|
182 | + |
|
183 | + // Set the default content-type as application/x-www-form-urlencoded. |
|
184 | + if (false == $contentType) { |
|
185 | + $contentType = self::FORM_URLENCODED; |
|
186 | + $request->setRequestHeaders(array('content-type' => $contentType)); |
|
187 | + } |
|
188 | + |
|
189 | + // Force the payload to match the content-type asserted in the header. |
|
190 | + if ($contentType == self::FORM_URLENCODED && is_array($postBody)) { |
|
191 | + $postBody = http_build_query($postBody, '', '&'); |
|
192 | + $request->setPostBody($postBody); |
|
193 | + } |
|
194 | + |
|
195 | + // Make sure the content-length header is set. |
|
196 | + if (!$postBody || is_string($postBody)) { |
|
197 | + $postsLength = strlen($postBody); |
|
198 | + $request->setRequestHeaders(array('content-length' => $postsLength)); |
|
199 | + } |
|
200 | + |
|
201 | + return $request; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -211,21 +211,21 @@ discard block |
||
211 | 211 | */ |
212 | 212 | protected function checkMustRevalidateCachedRequest($cached, $request) |
213 | 213 | { |
214 | - if (Google_Http_CacheParser::mustRevalidate($cached)) { |
|
215 | - $addHeaders = array(); |
|
216 | - if ($cached->getResponseHeader('etag')) { |
|
217 | - // [13.3.4] If an entity tag has been provided by the origin server, |
|
218 | - // we must use that entity tag in any cache-conditional request. |
|
219 | - $addHeaders['If-None-Match'] = $cached->getResponseHeader('etag'); |
|
220 | - } elseif ($cached->getResponseHeader('date')) { |
|
221 | - $addHeaders['If-Modified-Since'] = $cached->getResponseHeader('date'); |
|
222 | - } |
|
223 | - |
|
224 | - $request->setRequestHeaders($addHeaders); |
|
225 | - return true; |
|
226 | - } else { |
|
227 | - return false; |
|
228 | - } |
|
214 | + if (Google_Http_CacheParser::mustRevalidate($cached)) { |
|
215 | + $addHeaders = array(); |
|
216 | + if ($cached->getResponseHeader('etag')) { |
|
217 | + // [13.3.4] If an entity tag has been provided by the origin server, |
|
218 | + // we must use that entity tag in any cache-conditional request. |
|
219 | + $addHeaders['If-None-Match'] = $cached->getResponseHeader('etag'); |
|
220 | + } elseif ($cached->getResponseHeader('date')) { |
|
221 | + $addHeaders['If-Modified-Since'] = $cached->getResponseHeader('date'); |
|
222 | + } |
|
223 | + |
|
224 | + $request->setRequestHeaders($addHeaders); |
|
225 | + return true; |
|
226 | + } else { |
|
227 | + return false; |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function updateCachedRequest($cached, $responseHeaders) |
237 | 237 | { |
238 | - $hopByHop = self::$HOP_BY_HOP; |
|
239 | - if (!empty($responseHeaders['connection'])) { |
|
240 | - $connectionHeaders = array_map( |
|
241 | - 'strtolower', |
|
242 | - array_filter( |
|
243 | - array_map('trim', explode(',', $responseHeaders['connection'])) |
|
244 | - ) |
|
245 | - ); |
|
246 | - $hopByHop += array_fill_keys($connectionHeaders, true); |
|
247 | - } |
|
248 | - |
|
249 | - $endToEnd = array_diff_key($responseHeaders, $hopByHop); |
|
250 | - $cached->setResponseHeaders($endToEnd); |
|
238 | + $hopByHop = self::$HOP_BY_HOP; |
|
239 | + if (!empty($responseHeaders['connection'])) { |
|
240 | + $connectionHeaders = array_map( |
|
241 | + 'strtolower', |
|
242 | + array_filter( |
|
243 | + array_map('trim', explode(',', $responseHeaders['connection'])) |
|
244 | + ) |
|
245 | + ); |
|
246 | + $hopByHop += array_fill_keys($connectionHeaders, true); |
|
247 | + } |
|
248 | + |
|
249 | + $endToEnd = array_diff_key($responseHeaders, $hopByHop); |
|
250 | + $cached->setResponseHeaders($endToEnd); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -259,33 +259,33 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function parseHttpResponse($respData, $headerSize) |
261 | 261 | { |
262 | - // check proxy header |
|
263 | - foreach (self::$CONNECTION_ESTABLISHED_HEADERS as $established_header) { |
|
264 | - if (stripos($respData, $established_header) !== false) { |
|
265 | - // existed, remove it |
|
266 | - $respData = str_ireplace($established_header, '', $respData); |
|
267 | - // Subtract the proxy header size unless the cURL bug prior to 7.30.0 |
|
268 | - // is present which prevented the proxy header size from being taken into |
|
269 | - // account. |
|
270 | - if (!$this->needsQuirk()) { |
|
271 | - $headerSize -= strlen($established_header); |
|
272 | - } |
|
273 | - break; |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - if ($headerSize) { |
|
278 | - $responseBody = substr($respData, $headerSize); |
|
279 | - $responseHeaders = substr($respData, 0, $headerSize); |
|
280 | - } else { |
|
281 | - $responseSegments = explode("\r\n\r\n", $respData, 2); |
|
282 | - $responseHeaders = $responseSegments[0]; |
|
283 | - $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : |
|
284 | - null; |
|
285 | - } |
|
286 | - |
|
287 | - $responseHeaders = $this->getHttpResponseHeaders($responseHeaders); |
|
288 | - return array($responseHeaders, $responseBody); |
|
262 | + // check proxy header |
|
263 | + foreach (self::$CONNECTION_ESTABLISHED_HEADERS as $established_header) { |
|
264 | + if (stripos($respData, $established_header) !== false) { |
|
265 | + // existed, remove it |
|
266 | + $respData = str_ireplace($established_header, '', $respData); |
|
267 | + // Subtract the proxy header size unless the cURL bug prior to 7.30.0 |
|
268 | + // is present which prevented the proxy header size from being taken into |
|
269 | + // account. |
|
270 | + if (!$this->needsQuirk()) { |
|
271 | + $headerSize -= strlen($established_header); |
|
272 | + } |
|
273 | + break; |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + if ($headerSize) { |
|
278 | + $responseBody = substr($respData, $headerSize); |
|
279 | + $responseHeaders = substr($respData, 0, $headerSize); |
|
280 | + } else { |
|
281 | + $responseSegments = explode("\r\n\r\n", $respData, 2); |
|
282 | + $responseHeaders = $responseSegments[0]; |
|
283 | + $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : |
|
284 | + null; |
|
285 | + } |
|
286 | + |
|
287 | + $responseHeaders = $this->getHttpResponseHeaders($responseHeaders); |
|
288 | + return array($responseHeaders, $responseBody); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -295,45 +295,45 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function getHttpResponseHeaders($rawHeaders) |
297 | 297 | { |
298 | - if (is_array($rawHeaders)) { |
|
299 | - return $this->parseArrayHeaders($rawHeaders); |
|
300 | - } else { |
|
301 | - return $this->parseStringHeaders($rawHeaders); |
|
302 | - } |
|
298 | + if (is_array($rawHeaders)) { |
|
299 | + return $this->parseArrayHeaders($rawHeaders); |
|
300 | + } else { |
|
301 | + return $this->parseStringHeaders($rawHeaders); |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | private function parseStringHeaders($rawHeaders) |
306 | 306 | { |
307 | - $headers = array(); |
|
308 | - $responseHeaderLines = explode("\r\n", $rawHeaders); |
|
309 | - foreach ($responseHeaderLines as $headerLine) { |
|
310 | - if ($headerLine && strpos($headerLine, ':') !== false) { |
|
311 | - list($header, $value) = explode(': ', $headerLine, 2); |
|
312 | - $header = strtolower($header); |
|
313 | - if (isset($headers[$header])) { |
|
314 | - $headers[$header] .= "\n" . $value; |
|
315 | - } else { |
|
316 | - $headers[$header] = $value; |
|
317 | - } |
|
318 | - } |
|
319 | - } |
|
320 | - return $headers; |
|
307 | + $headers = array(); |
|
308 | + $responseHeaderLines = explode("\r\n", $rawHeaders); |
|
309 | + foreach ($responseHeaderLines as $headerLine) { |
|
310 | + if ($headerLine && strpos($headerLine, ':') !== false) { |
|
311 | + list($header, $value) = explode(': ', $headerLine, 2); |
|
312 | + $header = strtolower($header); |
|
313 | + if (isset($headers[$header])) { |
|
314 | + $headers[$header] .= "\n" . $value; |
|
315 | + } else { |
|
316 | + $headers[$header] = $value; |
|
317 | + } |
|
318 | + } |
|
319 | + } |
|
320 | + return $headers; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | private function parseArrayHeaders($rawHeaders) |
324 | 324 | { |
325 | - $header_count = count($rawHeaders); |
|
326 | - $headers = array(); |
|
327 | - |
|
328 | - for ($i = 0; $i < $header_count; $i++) { |
|
329 | - $header = $rawHeaders[$i]; |
|
330 | - // Times will have colons in - so we just want the first match. |
|
331 | - $header_parts = explode(': ', $header, 2); |
|
332 | - if (count($header_parts) == 2) { |
|
333 | - $headers[strtolower($header_parts[0])] = $header_parts[1]; |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - return $headers; |
|
325 | + $header_count = count($rawHeaders); |
|
326 | + $headers = array(); |
|
327 | + |
|
328 | + for ($i = 0; $i < $header_count; $i++) { |
|
329 | + $header = $rawHeaders[$i]; |
|
330 | + // Times will have colons in - so we just want the first match. |
|
331 | + $header_parts = explode(': ', $header, 2); |
|
332 | + if (count($header_parts) == 2) { |
|
333 | + $headers[strtolower($header_parts[0])] = $header_parts[1]; |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + return $headers; |
|
338 | 338 | } |
339 | 339 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | |
22 | 22 | if (!class_exists('Google_Client')) { |
23 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
23 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | abstract class Google_IO_Abstract |
@@ -280,8 +280,7 @@ discard block |
||
280 | 280 | } else { |
281 | 281 | $responseSegments = explode("\r\n\r\n", $respData, 2); |
282 | 282 | $responseHeaders = $responseSegments[0]; |
283 | - $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : |
|
284 | - null; |
|
283 | + $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : null; |
|
285 | 284 | } |
286 | 285 | |
287 | 286 | $responseHeaders = $this->getHttpResponseHeaders($responseHeaders); |
@@ -311,7 +310,7 @@ discard block |
||
311 | 310 | list($header, $value) = explode(': ', $headerLine, 2); |
312 | 311 | $header = strtolower($header); |
313 | 312 | if (isset($headers[$header])) { |
314 | - $headers[$header] .= "\n" . $value; |
|
313 | + $headers[$header] .= "\n".$value; |
|
315 | 314 | } else { |
316 | 315 | $headers[$header] = $value; |
317 | 316 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | |
4 | -add_filter('post_thumbnail_html','geodir_2017_remove_header',10,5); |
|
5 | -function geodir_2017_remove_header($html, $post_ID, $post_thumbnail_id, $size, $attr){ |
|
6 | - if($size=='twentyseventeen-featured-image'){ |
|
4 | +add_filter('post_thumbnail_html', 'geodir_2017_remove_header', 10, 5); |
|
5 | +function geodir_2017_remove_header($html, $post_ID, $post_thumbnail_id, $size, $attr) { |
|
6 | + if ($size == 'twentyseventeen-featured-image') { |
|
7 | 7 | |
8 | - if(geodir_is_page('detail') || geodir_is_page('add-listing')){ |
|
9 | - $html = '';// nothing up top |
|
8 | + if (geodir_is_page('detail') || geodir_is_page('add-listing')) { |
|
9 | + $html = ''; // nothing up top |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | } |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | |
64 | 64 | } |
65 | 65 | |
66 | -function geodir_twentyseventeen_body_classes($classes){ |
|
66 | +function geodir_twentyseventeen_body_classes($classes) { |
|
67 | 67 | |
68 | - if(geodir_is_page('add-listing') |
|
68 | + if (geodir_is_page('add-listing') |
|
69 | 69 | || geodir_is_page('preview') |
70 | 70 | || geodir_is_page('home') |
71 | 71 | || geodir_is_page('location') |
72 | 72 | || geodir_is_page('listing') |
73 | 73 | || geodir_is_page('search') |
74 | 74 | || geodir_is_page('author') |
75 | - ){ |
|
75 | + ) { |
|
76 | 76 | $classes[] = 'has-sidebar'; |
77 | 77 | } |
78 | 78 | return $classes; |
79 | 79 | } |
80 | -add_filter( 'body_class', 'geodir_twentyseventeen_body_classes' ); |
|
80 | +add_filter('body_class', 'geodir_twentyseventeen_body_classes'); |
|
81 | 81 |
@@ -46,17 +46,13 @@ |
||
46 | 46 | |
47 | 47 | if (is_page_geodir_home() || geodir_is_page('location')) { |
48 | 48 | add_action('geodir_wrapper_open', 'geodir_action_geodir_sidebar_home_top', 8); |
49 | - } |
|
50 | - elseif (geodir_is_page('listing')) { |
|
49 | + } elseif (geodir_is_page('listing')) { |
|
51 | 50 | add_action('geodir_wrapper_open', 'geodir_action_geodir_sidebar_listings_top', 8); |
52 | - } |
|
53 | - elseif (geodir_is_page('detail')) { |
|
51 | + } elseif (geodir_is_page('detail')) { |
|
54 | 52 | add_action('geodir_wrapper_open', 'geodir_action_geodir_sidebar_detail_top', 8); |
55 | - } |
|
56 | - elseif (geodir_is_page('search')) { |
|
53 | + } elseif (geodir_is_page('search')) { |
|
57 | 54 | add_action('geodir_wrapper_open', 'geodir_action_geodir_sidebar_search_top', 8); |
58 | - } |
|
59 | - elseif (geodir_is_page('author')) { |
|
55 | + } elseif (geodir_is_page('author')) { |
|
60 | 56 | add_action('geodir_wrapper_open', 'geodir_action_geodir_sidebar_author_top', 8); |
61 | 57 | } |
62 | 58 |
@@ -16,100 +16,100 @@ |
||
16 | 16 | |
17 | 17 | $field_ids = array(); |
18 | 18 | if (!empty($_REQUEST['licontainer']) && is_array($_REQUEST['licontainer'])) { |
19 | - foreach ($_REQUEST['licontainer'] as $lic_id) { |
|
20 | - $field_ids[] = sanitize_text_field($lic_id); |
|
21 | - } |
|
19 | + foreach ($_REQUEST['licontainer'] as $lic_id) { |
|
20 | + $field_ids[] = sanitize_text_field($lic_id); |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /* ------- check nonce field ------- */ |
25 | 25 | if (isset($_REQUEST['update']) && $_REQUEST['update'] == "update" && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
26 | - echo godir_set_field_order($field_ids); |
|
26 | + echo godir_set_field_order($field_ids); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | if (isset($_REQUEST['update']) && $_REQUEST['update'] == "update" && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
30 | - $response = godir_set_sort_field_order($field_ids); |
|
31 | - if (is_array($response)) { |
|
32 | - wp_send_json($response); |
|
33 | - } else { |
|
34 | - echo $response; |
|
35 | - } |
|
30 | + $response = godir_set_sort_field_order($field_ids); |
|
31 | + if (is_array($response)) { |
|
32 | + wp_send_json($response); |
|
33 | + } else { |
|
34 | + echo $response; |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /* ---- Show field form in admin ---- */ |
39 | 39 | if ($field_type != '' && $field_id != '' && $field_action == 'new' && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
40 | - geodir_custom_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
40 | + geodir_custom_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | if ($field_type != '' && $field_id != '' && $field_action == 'new' && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
44 | - geodir_custom_sort_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
44 | + geodir_custom_sort_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /* ---- Delete field ---- */ |
48 | 48 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
49 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
50 | - return; |
|
49 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
50 | + return; |
|
51 | 51 | |
52 | - echo geodir_custom_field_delete($field_id); |
|
52 | + echo geodir_custom_field_delete($field_id); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
56 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
57 | - return; |
|
56 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
57 | + return; |
|
58 | 58 | |
59 | - echo geodir_custom_sort_field_delete($field_id); |
|
59 | + echo geodir_custom_sort_field_delete($field_id); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /* ---- Save field ---- */ |
63 | 63 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
64 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
65 | - return; |
|
66 | - |
|
67 | - foreach ($_REQUEST as $pkey => $pval) { |
|
68 | - if (is_array($_REQUEST[$pkey]) || $pkey=='default_value') { |
|
69 | - $tags = 'skip_field'; |
|
70 | - } else { |
|
71 | - $tags = ''; |
|
72 | - } |
|
73 | - |
|
74 | - if ($tags != 'skip_field') { |
|
75 | - $_REQUEST[$pkey] = strip_tags($_REQUEST[$pkey], $tags); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - $return = geodir_custom_field_save($_REQUEST); |
|
80 | - |
|
81 | - if (is_int($return)) { |
|
82 | - $lastid = $return; |
|
83 | - geodir_custom_field_adminhtml($field_type, $lastid, 'submit',$field_type_key); |
|
84 | - } else { |
|
85 | - echo $return; |
|
86 | - } |
|
64 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
65 | + return; |
|
66 | + |
|
67 | + foreach ($_REQUEST as $pkey => $pval) { |
|
68 | + if (is_array($_REQUEST[$pkey]) || $pkey=='default_value') { |
|
69 | + $tags = 'skip_field'; |
|
70 | + } else { |
|
71 | + $tags = ''; |
|
72 | + } |
|
73 | + |
|
74 | + if ($tags != 'skip_field') { |
|
75 | + $_REQUEST[$pkey] = strip_tags($_REQUEST[$pkey], $tags); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + $return = geodir_custom_field_save($_REQUEST); |
|
80 | + |
|
81 | + if (is_int($return)) { |
|
82 | + $lastid = $return; |
|
83 | + geodir_custom_field_adminhtml($field_type, $lastid, 'submit',$field_type_key); |
|
84 | + } else { |
|
85 | + echo $return; |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /* ---- Save sort field ---- */ |
90 | 90 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
91 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
92 | - return; |
|
93 | - |
|
94 | - foreach ($_REQUEST as $pkey => $pval) { |
|
95 | - if (is_array($_REQUEST[$pkey])) { |
|
96 | - $tags = 'skip_field'; |
|
97 | - } else { |
|
98 | - $tags = ''; |
|
99 | - } |
|
100 | - |
|
101 | - if ($tags != 'skip_field') { |
|
102 | - $_REQUEST[$pkey] = strip_tags($_REQUEST[$pkey], $tags); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - $return = geodir_custom_sort_field_save($_REQUEST); |
|
107 | - |
|
108 | - if (is_int($return)) { |
|
109 | - $lastid = $return; |
|
110 | - $default = false; |
|
111 | - geodir_custom_sort_field_adminhtml($field_type, $lastid, 'submit', $default); |
|
112 | - } else { |
|
113 | - echo $return; |
|
114 | - } |
|
91 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
92 | + return; |
|
93 | + |
|
94 | + foreach ($_REQUEST as $pkey => $pval) { |
|
95 | + if (is_array($_REQUEST[$pkey])) { |
|
96 | + $tags = 'skip_field'; |
|
97 | + } else { |
|
98 | + $tags = ''; |
|
99 | + } |
|
100 | + |
|
101 | + if ($tags != 'skip_field') { |
|
102 | + $_REQUEST[$pkey] = strip_tags($_REQUEST[$pkey], $tags); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + $return = geodir_custom_sort_field_save($_REQUEST); |
|
107 | + |
|
108 | + if (is_int($return)) { |
|
109 | + $lastid = $return; |
|
110 | + $default = false; |
|
111 | + geodir_custom_sort_field_adminhtml($field_type, $lastid, 'submit', $default); |
|
112 | + } else { |
|
113 | + echo $return; |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -37,23 +37,23 @@ discard block |
||
37 | 37 | |
38 | 38 | /* ---- Show field form in admin ---- */ |
39 | 39 | if ($field_type != '' && $field_id != '' && $field_action == 'new' && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
40 | - geodir_custom_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
40 | + geodir_custom_field_adminhtml($field_type, $field_id, $field_action, $field_type_key); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | if ($field_type != '' && $field_id != '' && $field_action == 'new' && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
44 | - geodir_custom_sort_field_adminhtml($field_type, $field_id, $field_action,$field_type_key); |
|
44 | + geodir_custom_sort_field_adminhtml($field_type, $field_id, $field_action, $field_type_key); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /* ---- Delete field ---- */ |
48 | 48 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
49 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
49 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_'.$field_id)) |
|
50 | 50 | return; |
51 | 51 | |
52 | 52 | echo geodir_custom_field_delete($field_id); |
53 | 53 | } |
54 | 54 | |
55 | 55 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
56 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
56 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_'.$field_id)) |
|
57 | 57 | return; |
58 | 58 | |
59 | 59 | echo geodir_custom_sort_field_delete($field_id); |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | |
62 | 62 | /* ---- Save field ---- */ |
63 | 63 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
64 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
64 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_'.$field_id)) |
|
65 | 65 | return; |
66 | 66 | |
67 | 67 | foreach ($_REQUEST as $pkey => $pval) { |
68 | - if (is_array($_REQUEST[$pkey]) || $pkey=='default_value') { |
|
68 | + if (is_array($_REQUEST[$pkey]) || $pkey == 'default_value') { |
|
69 | 69 | $tags = 'skip_field'; |
70 | 70 | } else { |
71 | 71 | $tags = ''; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | if (is_int($return)) { |
82 | 82 | $lastid = $return; |
83 | - geodir_custom_field_adminhtml($field_type, $lastid, 'submit',$field_type_key); |
|
83 | + geodir_custom_field_adminhtml($field_type, $lastid, 'submit', $field_type_key); |
|
84 | 84 | } else { |
85 | 85 | echo $return; |
86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | /* ---- Save sort field ---- */ |
90 | 90 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
91 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
91 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_'.$field_id)) |
|
92 | 92 | return; |
93 | 93 | |
94 | 94 | foreach ($_REQUEST as $pkey => $pval) { |
@@ -46,23 +46,26 @@ discard block |
||
46 | 46 | |
47 | 47 | /* ---- Delete field ---- */ |
48 | 48 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
49 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
50 | - return; |
|
49 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) { |
|
50 | + return; |
|
51 | + } |
|
51 | 52 | |
52 | 53 | echo geodir_custom_field_delete($field_id); |
53 | 54 | } |
54 | 55 | |
55 | 56 | if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
56 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
57 | - return; |
|
57 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) { |
|
58 | + return; |
|
59 | + } |
|
58 | 60 | |
59 | 61 | echo geodir_custom_sort_field_delete($field_id); |
60 | 62 | } |
61 | 63 | |
62 | 64 | /* ---- Save field ---- */ |
63 | 65 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
64 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
65 | - return; |
|
66 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) { |
|
67 | + return; |
|
68 | + } |
|
66 | 69 | |
67 | 70 | foreach ($_REQUEST as $pkey => $pval) { |
68 | 71 | if (is_array($_REQUEST[$pkey]) || $pkey=='default_value') { |
@@ -88,8 +91,9 @@ discard block |
||
88 | 91 | |
89 | 92 | /* ---- Save sort field ---- */ |
90 | 93 | if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'sorting_options') { |
91 | - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
|
92 | - return; |
|
94 | + if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) { |
|
95 | + return; |
|
96 | + } |
|
93 | 97 | |
94 | 98 | foreach ($_REQUEST as $pkey => $pval) { |
95 | 99 | if (is_array($_REQUEST[$pkey])) { |