InfiniteWP Client - Version 1.2.13

Version Description

  • Fix: Google library conflict issues are fixed.
Download this release

Release Info

Developer infinitewp
Plugin Icon 128x128 InfiniteWP Client
Version 1.2.13
Comparing to
See all releases

Code changes from version 1.2.12 to 1.2.13

backup.class.php CHANGED
@@ -2307,7 +2307,7 @@ function ftp_backup($args)
2307
$fileSizeUploaded = 0;
2308
$resumeURI = false;
2309
2310
- $client = new Google_Client();
2311
$client->setClientId($args['clientID']);
2312
$client->setClientSecret($args['clientSecretKey']);
2313
$client->setRedirectUri($args['redirectURL']);
@@ -2331,7 +2331,7 @@ function ftp_backup($args)
2331
return array("error" => $e->getMessage());
2332
}
2333
2334
- $service = new Google_Service_Drive($client);
2335
2336
//create folder if not present
2337
try
@@ -2345,7 +2345,7 @@ function ftp_backup($args)
2345
2346
if(empty($list_result))
2347
{
2348
- $file = new Google_Service_Drive_DriveFile();
2349
$file->setTitle('infinitewp');
2350
$file->setMimeType('application/vnd.google-apps.folder');
2351
@@ -2380,12 +2380,12 @@ function ftp_backup($args)
2380
2381
if(empty($list_result))
2382
{
2383
- $file = new Google_Service_Drive_DriveFile();
2384
$file->setTitle($sub_folder_name);
2385
$file->setMimeType('application/vnd.google-apps.folder');
2386
2387
//setting parent as infinitewpFolder
2388
- $parent = new Google_Service_Drive_ParentReference();
2389
$parent->setId($iwp_folder_id);
2390
$file->setParents(array($parent));
2391
@@ -2407,12 +2407,12 @@ function ftp_backup($args)
2407
2408
2409
//Insert a file
2410
- $file = new Google_Service_Drive_DriveFile();
2411
$file->setTitle(basename($backup_file));
2412
$file->setMimeType('binary/octet-stream');
2413
2414
// Set the Parent Folder on Google Drive
2415
- $parent = new Google_Service_Drive_ParentReference();
2416
if(empty($sub_folder_id))
2417
{
2418
$parent->setId($iwp_folder_id);
@@ -2446,7 +2446,7 @@ function ftp_backup($args)
2446
$request = $service->files->insert($file);
2447
2448
// Create a media file upload to represent our upload process.
2449
- $media = new Google_Http_MediaFileUpload($client, $request, 'application/zip', null, true, $upload_file_block_size);
2450
$media->setFileSize(filesize($backup_file));
2451
2452
$status = false;
@@ -2546,7 +2546,7 @@ function ftp_backup($args)
2546
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Service/Drive.php');
2547
2548
//refresh token
2549
- $client = new Google_Client();
2550
$client->setClientId($args['clientID']);
2551
$client->setClientSecret($args['clientSecretKey']);
2552
$client->setRedirectUri($args['redirectURL']);
@@ -2571,7 +2571,7 @@ function ftp_backup($args)
2571
}
2572
2573
//downloading the file
2574
- $service = new Google_Service_Drive($client);
2575
2576
$file = $service->files->get($args['backup_file']);
2577
@@ -2583,7 +2583,7 @@ function ftp_backup($args)
2583
{
2584
if ($downloadUrl)
2585
{
2586
- $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
2587
2588
$signHttpRequest = $client->getAuth()->sign($request);
2589
$httpRequest = $client->getIo()->makeRequest($signHttpRequest);
@@ -2617,7 +2617,7 @@ function ftp_backup($args)
2617
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Client.php');
2618
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Service/Drive.php');
2619
2620
- $client = new Google_Client();
2621
$client->setClientId($args['clientID']);
2622
$client->setClientSecret($args['clientSecretKey']);
2623
$client->setRedirectUri($args['redirectURL']);
@@ -2641,7 +2641,7 @@ function ftp_backup($args)
2641
return array("error" => $e->getMessage());
2642
}
2643
2644
- $service = new Google_Service_Drive($client);
2645
2646
try
2647
{
2307
$fileSizeUploaded = 0;
2308
$resumeURI = false;
2309
2310
+ $client = new IWP_google_Client();
2311
$client->setClientId($args['clientID']);
2312
$client->setClientSecret($args['clientSecretKey']);
2313
$client->setRedirectUri($args['redirectURL']);
2331
return array("error" => $e->getMessage());
2332
}
2333
2334
+ $service = new IWP_google_Service_Drive($client);
2335
2336
//create folder if not present
2337
try
2345
2346
if(empty($list_result))
2347
{
2348
+ $file = new IWP_google_Service_Drive_DriveFile();
2349
$file->setTitle('infinitewp');
2350
$file->setMimeType('application/vnd.google-apps.folder');
2351
2380
2381
if(empty($list_result))
2382
{
2383
+ $file = new IWP_google_Service_Drive_DriveFile();
2384
$file->setTitle($sub_folder_name);
2385
$file->setMimeType('application/vnd.google-apps.folder');
2386
2387
//setting parent as infinitewpFolder
2388
+ $parent = new IWP_google_Service_Drive_ParentReference();
2389
$parent->setId($iwp_folder_id);
2390
$file->setParents(array($parent));
2391
2407
2408
2409
//Insert a file
2410
+ $file = new IWP_google_Service_Drive_DriveFile();
2411
$file->setTitle(basename($backup_file));
2412
$file->setMimeType('binary/octet-stream');
2413
2414
// Set the Parent Folder on Google Drive
2415
+ $parent = new IWP_google_Service_Drive_ParentReference();
2416
if(empty($sub_folder_id))
2417
{
2418
$parent->setId($iwp_folder_id);
2446
$request = $service->files->insert($file);
2447
2448
// Create a media file upload to represent our upload process.
2449
+ $media = new IWP_google_Http_MediaFileUpload($client, $request, 'application/zip', null, true, $upload_file_block_size);
2450
$media->setFileSize(filesize($backup_file));
2451
2452
$status = false;
2546
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Service/Drive.php');
2547
2548
//refresh token
2549
+ $client = new IWP_google_Client();
2550
$client->setClientId($args['clientID']);
2551
$client->setClientSecret($args['clientSecretKey']);
2552
$client->setRedirectUri($args['redirectURL']);
2571
}
2572
2573
//downloading the file
2574
+ $service = new IWP_google_Service_Drive($client);
2575
2576
$file = $service->files->get($args['backup_file']);
2577
2583
{
2584
if ($downloadUrl)
2585
{
2586
+ $request = new IWP_google_Http_Request($downloadUrl, 'GET', null, null);
2587
2588
$signHttpRequest = $client->getAuth()->sign($request);
2589
$httpRequest = $client->getIo()->makeRequest($signHttpRequest);
2617
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Client.php');
2618
require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Service/Drive.php');
2619
2620
+ $client = new IWP_google_Client();
2621
$client->setClientId($args['clientID']);
2622
$client->setClientSecret($args['clientSecretKey']);
2623
$client->setRedirectUri($args['redirectURL']);
2641
return array("error" => $e->getMessage());
2642
}
2643
2644
+ $service = new IWP_google_Service_Drive($client);
2645
2646
try
2647
{
init.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: InfiniteWP - Client
4
Plugin URI: http://infinitewp.com/
5
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6
Author: Revmakx
7
- Version: 1.2.12
8
Author URI: http://www.revmakx.com
9
*/
10
/************************************************************
@@ -26,7 +26,7 @@ Author URI: http://www.revmakx.com
26
**************************************************************/
27
28
if(!defined('IWP_MMB_CLIENT_VERSION'))
29
- define('IWP_MMB_CLIENT_VERSION', '1.2.12');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
4
Plugin URI: http://infinitewp.com/
5
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6
Author: Revmakx
7
+ Version: 1.2.13
8
Author URI: http://www.revmakx.com
9
*/
10
/************************************************************
26
**************************************************************/
27
28
if(!defined('IWP_MMB_CLIENT_VERSION'))
29
+ define('IWP_MMB_CLIENT_VERSION', '1.2.13');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
lib/Google/Auth/Abstract.php CHANGED
@@ -21,19 +21,19 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Http/Request.php";
21
* @author Chris Chabot <chabotc@google.com>
22
*
23
*/
24
- abstract class Google_Auth_Abstract
25
{
26
/**
27
* An utility function that first calls $this->auth->sign($request) and then
28
* executes makeRequest() on that signed request. Used for when a request
29
* should be authenticated
30
- * @param Google_Http_Request $request
31
- * @return Google_Http_Request $request
32
*/
33
- abstract public function authenticatedRequest(Google_Http_Request $request);
34
35
abstract public function authenticate($code);
36
- abstract public function sign(Google_Http_Request $request);
37
abstract public function createAuthUrl($scope);
38
39
abstract public function refreshToken($refreshToken);
21
* @author Chris Chabot <chabotc@google.com>
22
*
23
*/
24
+ abstract class IWP_google_Auth_Abstract
25
{
26
/**
27
* An utility function that first calls $this->auth->sign($request) and then
28
* executes makeRequest() on that signed request. Used for when a request
29
* should be authenticated
30
+ * @param IWP_google_Http_Request $request
31
+ * @return IWP_google_Http_Request $request
32
*/
33
+ abstract public function authenticatedRequest(IWP_google_Http_Request $request);
34
35
abstract public function authenticate($code);
36
+ abstract public function sign(IWP_google_Http_Request $request);
37
abstract public function createAuthUrl($scope);
38
39
abstract public function refreshToken($refreshToken);
lib/Google/Auth/AssertionCredentials.php CHANGED
@@ -24,7 +24,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Utils.php";
24
*
25
* @author Chirag Shah <chirags@google.com>
26
*/
27
- class Google_Auth_AssertionCredentials
28
{
29
const MAX_TOKEN_LIFETIME_SECS = 3600;
30
@@ -93,7 +93,7 @@ class Google_Auth_AssertionCredentials
93
$now = time();
94
95
$jwtParams = array(
96
- 'aud' => Google_Auth_OAuth2::OAUTH2_TOKEN_URI,
97
'scope' => $this->scopes,
98
'iat' => $now,
99
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
@@ -119,14 +119,14 @@ class Google_Auth_AssertionCredentials
119
$header = array('typ' => 'JWT', 'alg' => 'RS256');
120
121
$segments = array(
122
- Google_Utils::urlSafeB64Encode(json_encode($header)),
123
- Google_Utils::urlSafeB64Encode(json_encode($payload))
124
);
125
126
$signingInput = implode('.', $segments);
127
- $signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword);
128
$signature = $signer->sign($signingInput);
129
- $segments[] = Google_Utils::urlSafeB64Encode($signature);
130
131
return implode(".", $segments);
132
}
24
*
25
* @author Chirag Shah <chirags@google.com>
26
*/
27
+ class IWP_google_Auth_AssertionCredentials
28
{
29
const MAX_TOKEN_LIFETIME_SECS = 3600;
30
93
$now = time();
94
95
$jwtParams = array(
96
+ 'aud' => IWP_google_Auth_OAuth2::OAUTH2_TOKEN_URI,
97
'scope' => $this->scopes,
98
'iat' => $now,
99
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
119
$header = array('typ' => 'JWT', 'alg' => 'RS256');
120
121
$segments = array(
122
+ IWP_google_Utils::urlSafeB64Encode(json_encode($header)),
123
+ IWP_google_Utils::urlSafeB64Encode(json_encode($payload))
124
);
125
126
$signingInput = implode('.', $segments);
127
+ $signer = new IWP_google_Signer_P12($this->privateKey, $this->privateKeyPassword);
128
$signature = $signer->sign($signingInput);
129
+ $segments[] = IWP_google_Utils::urlSafeB64Encode($signature);
130
131
return implode(".", $segments);
132
}
lib/Google/Auth/Exception.php CHANGED
@@ -17,6 +17,6 @@
17
18
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Exception.php";
19
20
- class Google_Auth_Exception extends Google_Exception
21
{
22
}
17
18
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Exception.php";
19
20
+ class IWP_google_Auth_Exception extends IWP_google_Exception
21
{
22
}
lib/Google/Auth/LoginTicket.php CHANGED
@@ -22,7 +22,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Auth/Exception.php";
22
*
23
* @author Brian Eaton <beaton@google.com>
24
*/
25
- class Google_Auth_LoginTicket
26
{
27
const USER_ATTR = "sub";
28
@@ -46,7 +46,7 @@ class Google_Auth_LoginTicket
46
47
/**
48
* Returns the numeric identifier for the user.
49
- * @throws Google_Auth_Exception
50
* @return
51
*/
52
public function getUserId()
@@ -54,7 +54,7 @@ class Google_Auth_LoginTicket
54
if (array_key_exists(self::USER_ATTR, $this->payload)) {
55
return $this->payload[self::USER_ATTR];
56
}
57
- throw new Google_Auth_Exception("No user_id in token");
58
}
59
60
/**
22
*
23
* @author Brian Eaton <beaton@google.com>
24
*/
25
+ class IWP_google_Auth_LoginTicket
26
{
27
const USER_ATTR = "sub";
28
46
47
/**
48
* Returns the numeric identifier for the user.
49
+ * @throws IWP_google_Auth_Exception
50
* @return
51
*/
52
public function getUserId()
54
if (array_key_exists(self::USER_ATTR, $this->payload)) {
55
return $this->payload[self::USER_ATTR];
56
}
57
+ throw new IWP_google_Auth_Exception("No user_id in token");
58
}
59
60
/**
lib/Google/Auth/OAuth2.php CHANGED
@@ -31,7 +31,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Verifier/Pem.php";
31
* @author Chirag Shah <chirags@google.com>
32
*
33
*/
34
- class Google_Auth_OAuth2 extends Google_Auth_Abstract
35
{
36
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
37
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
@@ -41,7 +41,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
41
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
42
const OAUTH2_ISSUER = 'accounts.google.com';
43
44
- /** @var Google_Auth_AssertionCredentials $assertionCredentials */
45
private $assertionCredentials;
46
47
/**
@@ -55,7 +55,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
55
private $token = array();
56
57
/**
58
- * @var Google_Client the base client
59
*/
60
private $client;
61
@@ -63,7 +63,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
63
* Instantiates the class, but does not initiate the login flow, leaving it
64
* to the discretion of the caller.
65
*/
66
- public function __construct(Google_Client $client)
67
{
68
$this->client = $client;
69
}
@@ -74,11 +74,11 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
74
* (which can modify the request in what ever way fits the auth mechanism)
75
* and then calls apiCurlIO::makeRequest on the signed request
76
*
77
- * @param Google_Http_Request $request
78
- * @return Google_Http_Request The resulting HTTP response including the
79
* responseHttpCode, responseHeaders and responseBody.
80
*/
81
- public function authenticatedRequest(Google_Http_Request $request)
82
{
83
$request = $this->sign($request);
84
return $this->client->getIo()->makeRequest($request);
@@ -86,18 +86,18 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
86
87
/**
88
* @param string $code
89
- * @throws Google_Auth_Exception
90
* @return string
91
*/
92
public function authenticate($code)
93
{
94
if (strlen($code) == 0) {
95
- throw new Google_Auth_Exception("Invalid code");
96
}
97
98
// We got here from the redirect from a successful authorization grant,
99
// fetch the access token
100
- $request = new Google_Http_Request(
101
self::OAUTH2_TOKEN_URI,
102
'POST',
103
array(),
@@ -121,7 +121,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
121
if ($decodedResponse != null && $decodedResponse['error']) {
122
$decodedResponse = $decodedResponse['error'];
123
}
124
- throw new Google_Auth_Exception(
125
sprintf(
126
"Error fetching OAuth2 access token, message: '%s'",
127
$decodedResponse
@@ -165,16 +165,16 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
165
166
/**
167
* @param string $token
168
- * @throws Google_Auth_Exception
169
*/
170
public function setAccessToken($token)
171
{
172
$token = json_decode($token, true);
173
if ($token == null) {
174
- throw new Google_Auth_Exception('Could not json decode the token');
175
}
176
if (! isset($token['access_token'])) {
177
- throw new Google_Auth_Exception("Invalid token format");
178
}
179
$this->token = $token;
180
}
@@ -189,18 +189,18 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
189
$this->state = $state;
190
}
191
192
- public function setAssertionCredentials(Google_Auth_AssertionCredentials $creds)
193
{
194
$this->assertionCredentials = $creds;
195
}
196
197
/**
198
* Include an accessToken in a given apiHttpRequest.
199
- * @param Google_Http_Request $request
200
- * @return Google_Http_Request
201
- * @throws Google_Auth_Exception
202
*/
203
- public function sign(Google_Http_Request $request)
204
{
205
// add the developer key to the request before signing it
206
if ($this->client->getClassConfig($this, 'developer_key')) {
@@ -219,7 +219,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
219
$this->refreshTokenWithAssertion();
220
} else {
221
if (! array_key_exists('refresh_token', $this->token)) {
222
- throw new Google_Auth_Exception(
223
"The OAuth 2.0 access token has expired,"
224
." and a refresh token is not available. Refresh tokens"
225
." are not returned for responses that were auto-approved."
@@ -256,7 +256,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
256
257
/**
258
* Fetches a fresh access token with a given assertion token.
259
- * @param Google_Auth_AssertionCredentials $assertionCredentials optional.
260
* @return void
261
*/
262
public function refreshTokenWithAssertion($assertionCredentials = null)
@@ -299,7 +299,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
299
300
private function refreshTokenRequest($params)
301
{
302
- $http = new Google_Http_Request(
303
self::OAUTH2_TOKEN_URI,
304
'POST',
305
array(),
@@ -313,25 +313,25 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
313
if (200 == $code) {
314
$token = json_decode($body, true);
315
if ($token == null) {
316
- throw new Google_Auth_Exception("Could not json decode the access token");
317
}
318
319
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
320
- throw new Google_Auth_Exception("Invalid token format");
321
}
322
323
$this->token['access_token'] = $token['access_token'];
324
$this->token['expires_in'] = $token['expires_in'];
325
$this->token['created'] = time();
326
} else {
327
- throw new Google_Auth_Exception("Error refreshing the OAuth2 token, message: '$body'", $code);
328
}
329
}
330
331
/**
332
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
333
* token, if a token isn't provided.
334
- * @throws Google_Auth_Exception
335
* @param string|null $token The token (access token or a refresh token) that should be revoked.
336
* @return boolean Returns True if the revocation was successful, otherwise False.
337
*/
@@ -347,7 +347,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
347
$token = $this->token['access_token'];
348
}
349
}
350
- $request = new Google_Http_Request(
351
self::OAUTH2_REVOKE_URI,
352
'POST',
353
array(),
@@ -404,7 +404,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
404
if ($file) {
405
return json_decode($file, true);
406
} else {
407
- throw new Google_Auth_Exception(
408
"Failed to retrieve verification certificates: '" .
409
$url . "'."
410
);
@@ -413,7 +413,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
413
414
// This relies on makeRequest caching certificate responses.
415
$request = $this->client->getIo()->makeRequest(
416
- new Google_Http_Request(
417
$url
418
)
419
);
@@ -423,7 +423,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
423
return $certs;
424
}
425
}
426
- throw new Google_Auth_Exception(
427
"Failed to retrieve verification certificates: '" .
428
$request->getResponseBody() . "'.",
429
$request->getResponseHttpCode()
@@ -438,7 +438,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
438
*
439
* @param $id_token
440
* @param $audience
441
- * @return Google_Auth_LoginTicket
442
*/
443
public function verifyIdToken($id_token = null, $audience = null)
444
{
@@ -477,28 +477,28 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
477
478
$segments = explode(".", $jwt);
479
if (count($segments) != 3) {
480
- throw new Google_Auth_Exception("Wrong number of segments in token: $jwt");
481
}
482
$signed = $segments[0] . "." . $segments[1];
483
- $signature = Google_Utils::urlSafeB64Decode($segments[2]);
484
485
// Parse envelope.
486
- $envelope = json_decode(Google_Utils::urlSafeB64Decode($segments[0]), true);
487
if (!$envelope) {
488
- throw new Google_Auth_Exception("Can't parse token envelope: " . $segments[0]);
489
}
490
491
// Parse token
492
- $json_body = Google_Utils::urlSafeB64Decode($segments[1]);
493
$payload = json_decode($json_body, true);
494
if (!$payload) {
495
- throw new Google_Auth_Exception("Can't parse token payload: " . $segments[1]);
496
}
497
498
// Check signature
499
$verified = false;
500
foreach ($certs as $keyName => $pem) {
501
- $public_key = new Google_Verifier_Pem($pem);
502
if ($public_key->verify($signed, $signature)) {
503
$verified = true;
504
break;
@@ -506,7 +506,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
506
}
507
508
if (!$verified) {
509
- throw new Google_Auth_Exception("Invalid token signature: $jwt");
510
}
511
512
// Check issued-at timestamp
@@ -515,7 +515,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
515
$iat = $payload["iat"];
516
}
517
if (!$iat) {
518
- throw new Google_Auth_Exception("No issue time in token: $json_body");
519
}
520
$earliest = $iat - self::CLOCK_SKEW_SECS;
521
@@ -526,17 +526,17 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
526
$exp = $payload["exp"];
527
}
528
if (!$exp) {
529
- throw new Google_Auth_Exception("No expiration time in token: $json_body");
530
}
531
if ($exp >= $now + $max_expiry) {
532
- throw new Google_Auth_Exception(
533
sprintf("Expiration time too far in future: %s", $json_body)
534
);
535
}
536
537
$latest = $exp + self::CLOCK_SKEW_SECS;
538
if ($now < $earliest) {
539
- throw new Google_Auth_Exception(
540
sprintf(
541
"Token used too early, %s < %s: %s",
542
$now,
@@ -546,7 +546,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
546
);
547
}
548
if ($now > $latest) {
549
- throw new Google_Auth_Exception(
550
sprintf(
551
"Token used too late, %s > %s: %s",
552
$now,
@@ -558,7 +558,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
558
559
$iss = $payload['iss'];
560
if ($issuer && $iss != $issuer) {
561
- throw new Google_Auth_Exception(
562
sprintf(
563
"Invalid issuer, %s != %s: %s",
564
$iss,
@@ -571,7 +571,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
571
// Check audience
572
$aud = $payload["aud"];
573
if ($aud != $required_audience) {
574
- throw new Google_Auth_Exception(
575
sprintf(
576
"Wrong recipient, %s != %s:",
577
$aud,
@@ -582,6 +582,6 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
582
}
583
584
// All good.
585
- return new Google_Auth_LoginTicket($envelope, $payload);
586
}
587
}
31
* @author Chirag Shah <chirags@google.com>
32
*
33
*/
34
+ class IWP_google_Auth_OAuth2 extends IWP_google_Auth_Abstract
35
{
36
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
37
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
41
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
42
const OAUTH2_ISSUER = 'accounts.google.com';
43
44
+ /** @var IWP_google_Auth_AssertionCredentials $assertionCredentials */
45
private $assertionCredentials;
46
47
/**
55
private $token = array();
56
57
/**
58
+ * @var IWP_google_Client the base client
59
*/
60
private $client;
61
63
* Instantiates the class, but does not initiate the login flow, leaving it
64
* to the discretion of the caller.
65
*/
66
+ public function __construct(IWP_google_Client $client)
67
{
68
$this->client = $client;
69
}
74
* (which can modify the request in what ever way fits the auth mechanism)
75
* and then calls apiCurlIO::makeRequest on the signed request
76
*
77
+ * @param IWP_google_Http_Request $request
78
+ * @return IWP_google_Http_Request The resulting HTTP response including the
79
* responseHttpCode, responseHeaders and responseBody.
80
*/
81
+ public function authenticatedRequest(IWP_google_Http_Request $request)
82
{
83
$request = $this->sign($request);
84
return $this->client->getIo()->makeRequest($request);
86
87
/**
88
* @param string $code
89
+ * @throws IWP_google_Auth_Exception
90
* @return string
91
*/
92
public function authenticate($code)
93
{
94
if (strlen($code) == 0) {
95
+ throw new IWP_google_Auth_Exception("Invalid code");
96
}
97
98
// We got here from the redirect from a successful authorization grant,
99
// fetch the access token
100
+ $request = new IWP_google_Http_Request(
101
self::OAUTH2_TOKEN_URI,
102
'POST',
103
array(),
121
if ($decodedResponse != null && $decodedResponse['error']) {
122
$decodedResponse = $decodedResponse['error'];
123
}
124
+ throw new IWP_google_Auth_Exception(
125
sprintf(
126
"Error fetching OAuth2 access token, message: '%s'",
127
$decodedResponse
165
166
/**
167
* @param string $token
168
+ * @throws IWP_google_Auth_Exception
169
*/
170
public function setAccessToken($token)
171
{
172
$token = json_decode($token, true);
173
if ($token == null) {
174
+ throw new IWP_google_Auth_Exception('Could not json decode the token');
175
}
176
if (! isset($token['access_token'])) {
177
+ throw new IWP_google_Auth_Exception("Invalid token format");
178
}
179
$this->token = $token;
180
}
189
$this->state = $state;
190
}
191
192
+ public function setAssertionCredentials(IWP_google_Auth_AssertionCredentials $creds)
193
{
194
$this->assertionCredentials = $creds;
195
}
196
197
/**
198
* Include an accessToken in a given apiHttpRequest.
199
+ * @param IWP_google_Http_Request $request
200
+ * @return IWP_google_Http_Request
201
+ * @throws IWP_google_Auth_Exception
202
*/
203
+ public function sign(IWP_google_Http_Request $request)
204
{
205
// add the developer key to the request before signing it
206
if ($this->client->getClassConfig($this, 'developer_key')) {
219
$this->refreshTokenWithAssertion();
220
} else {
221
if (! array_key_exists('refresh_token', $this->token)) {
222
+ throw new IWP_google_Auth_Exception(
223
"The OAuth 2.0 access token has expired,"
224
." and a refresh token is not available. Refresh tokens"
225
." are not returned for responses that were auto-approved."
256
257
/**
258
* Fetches a fresh access token with a given assertion token.
259
+ * @param IWP_google_Auth_AssertionCredentials $assertionCredentials optional.
260
* @return void
261
*/
262
public function refreshTokenWithAssertion($assertionCredentials = null)
299
300
private function refreshTokenRequest($params)
301
{
302
+ $http = new IWP_google_Http_Request(
303
self::OAUTH2_TOKEN_URI,
304
'POST',
305
array(),
313
if (200 == $code) {
314
$token = json_decode($body, true);
315
if ($token == null) {
316
+ throw new IWP_google_Auth_Exception("Could not json decode the access token");
317
}
318
319
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
320
+ throw new IWP_google_Auth_Exception("Invalid token format");
321
}
322
323
$this->token['access_token'] = $token['access_token'];
324
$this->token['expires_in'] = $token['expires_in'];
325
$this->token['created'] = time();
326
} else {
327
+ throw new IWP_google_Auth_Exception("Error refreshing the OAuth2 token, message: '$body'", $code);
328
}
329
}
330
331
/**
332
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
333
* token, if a token isn't provided.
334
+ * @throws IWP_google_Auth_Exception
335
* @param string|null $token The token (access token or a refresh token) that should be revoked.
336
* @return boolean Returns True if the revocation was successful, otherwise False.
337
*/
347
$token = $this->token['access_token'];
348
}
349
}
350
+ $request = new IWP_google_Http_Request(
351
self::OAUTH2_REVOKE_URI,
352
'POST',
353
array(),
404
if ($file) {
405
return json_decode($file, true);
406
} else {
407
+ throw new IWP_google_Auth_Exception(
408
"Failed to retrieve verification certificates: '" .
409
$url . "'."
410
);
413
414
// This relies on makeRequest caching certificate responses.
415
$request = $this->client->getIo()->makeRequest(
416
+ new IWP_google_Http_Request(
417
$url
418
)
419
);
423
return $certs;
424
}
425
}
426
+ throw new IWP_google_Auth_Exception(
427
"Failed to retrieve verification certificates: '" .
428
$request->getResponseBody() . "'.",
429
$request->getResponseHttpCode()
438
*
439
* @param $id_token
440
* @param $audience
441
+ * @return IWP_google_Auth_LoginTicket
442
*/
443
public function verifyIdToken($id_token = null, $audience = null)
444
{
477
478
$segments = explode(".", $jwt);
479
if (count($segments) != 3) {
480
+ throw new IWP_google_Auth_Exception("Wrong number of segments in token: $jwt");
481
}
482
$signed = $segments[0] . "." . $segments[1];
483
+ $signature = IWP_google_Utils::urlSafeB64Decode($segments[2]);
484
485
// Parse envelope.
486
+ $envelope = json_decode(IWP_google_Utils::urlSafeB64Decode($segments[0]), true);
487
if (!$envelope) {
488
+ throw new IWP_google_Auth_Exception("Can't parse token envelope: " . $segments[0]);
489
}
490
491
// Parse token
492
+ $json_body = IWP_google_Utils::urlSafeB64Decode($segments[1]);
493
$payload = json_decode($json_body, true);
494
if (!$payload) {
495
+ throw new IWP_google_Auth_Exception("Can't parse token payload: " . $segments[1]);
496
}
497
498
// Check signature
499
$verified = false;
500
foreach ($certs as $keyName => $pem) {
501
+ $public_key = new IWP_google_Verifier_Pem($pem);
502
if ($public_key->verify($signed, $signature)) {
503
$verified = true;
504
break;
506
}
507
508
if (!$verified) {
509
+ throw new IWP_google_Auth_Exception("Invalid token signature: $jwt");
510
}
511
512
// Check issued-at timestamp
515
$iat = $payload["iat"];
516
}
517
if (!$iat) {
518
+ throw new IWP_google_Auth_Exception("No issue time in token: $json_body");
519
}
520
$earliest = $iat - self::CLOCK_SKEW_SECS;
521
526
$exp = $payload["exp"];
527
}
528
if (!$exp) {
529
+ throw new IWP_google_Auth_Exception("No expiration time in token: $json_body");
530
}
531
if ($exp >= $now + $max_expiry) {
532
+ throw new IWP_google_Auth_Exception(
533
sprintf("Expiration time too far in future: %s", $json_body)
534
);
535
}
536
537
$latest = $exp + self::CLOCK_SKEW_SECS;
538
if ($now < $earliest) {
539
+ throw new IWP_google_Auth_Exception(
540
sprintf(
541
"Token used too early, %s < %s: %s",
542
$now,
546
);
547
}
548
if ($now > $latest) {
549
+ throw new IWP_google_Auth_Exception(
550
sprintf(
551
"Token used too late, %s > %s: %s",
552
$now,
558
559
$iss = $payload['iss'];
560
if ($issuer && $iss != $issuer) {
561
+ throw new IWP_google_Auth_Exception(
562
sprintf(
563
"Invalid issuer, %s != %s: %s",
564
$iss,
571
// Check audience
572
$aud = $payload["aud"];
573
if ($aud != $required_audience) {
574
+ throw new IWP_google_Auth_Exception(
575
sprintf(
576
"Wrong recipient, %s != %s:",
577
$aud,
582
}
583
584
// All good.
585
+ return new IWP_google_Auth_LoginTicket($envelope, $payload);
586
}
587
}
lib/Google/Auth/Simple.php CHANGED
@@ -25,12 +25,12 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Http/Request.php";
25
* @author Chris Chabot <chabotc@google.com>
26
* @author Chirag Shah <chirags@google.com>
27
*/
28
- class Google_Auth_Simple extends Google_Auth_Abstract
29
{
30
private $key = null;
31
private $client;
32
33
- public function __construct(Google_Client $client, $config = null)
34
{
35
$this->client = $client;
36
}
@@ -41,11 +41,11 @@ class Google_Auth_Simple extends Google_Auth_Abstract
41
* (which can modify the request in what ever way fits the auth mechanism)
42
* and then calls apiCurlIO::makeRequest on the signed request
43
*
44
- * @param Google_Http_Request $request
45
- * @return Google_Http_Request The resulting HTTP response including the
46
* responseHttpCode, responseHeaders and responseBody.
47
*/
48
- public function authenticatedRequest(Google_Http_Request $request)
49
{
50
$request = $this->sign($request);
51
return $this->io->makeRequest($request);
@@ -53,7 +53,7 @@ class Google_Auth_Simple extends Google_Auth_Abstract
53
54
public function authenticate($code)
55
{
56
- throw new Google_Auth_Exception("Simple auth does not exchange tokens.");
57
}
58
59
public function setAccessToken($accessToken)
@@ -81,7 +81,7 @@ class Google_Auth_Simple extends Google_Auth_Abstract
81
/* noop*/
82
}
83
84
- public function sign(Google_Http_Request $request)
85
{
86
$key = $this->client->getClassConfig($this, 'developer_key');
87
if ($key) {
25
* @author Chris Chabot <chabotc@google.com>
26
* @author Chirag Shah <chirags@google.com>
27
*/
28
+ class IWP_google_Auth_Simple extends IWP_google_Auth_Abstract
29
{
30
private $key = null;
31
private $client;
32
33
+ public function __construct(IWP_google_Client $client, $config = null)
34
{
35
$this->client = $client;
36
}
41
* (which can modify the request in what ever way fits the auth mechanism)
42
* and then calls apiCurlIO::makeRequest on the signed request
43
*
44
+ * @param IWP_google_Http_Request $request
45
+ * @return IWP_google_Http_Request The resulting HTTP response including the
46
* responseHttpCode, responseHeaders and responseBody.
47
*/
48
+ public function authenticatedRequest(IWP_google_Http_Request $request)
49
{
50
$request = $this->sign($request);
51
return $this->io->makeRequest($request);
53
54
public function authenticate($code)
55
{
56
+ throw new IWP_google_Auth_Exception("Simple auth does not exchange tokens.");
57
}
58
59
public function setAccessToken($accessToken)
81
/* noop*/
82
}
83
84
+ public function sign(IWP_google_Http_Request $request)
85
{
86
$key = $this->client->getClassConfig($this, 'developer_key');
87
if ($key) {
lib/Google/Cache/Abstract.php CHANGED
@@ -20,10 +20,10 @@
20
*
21
* @author Chris Chabot <chabotc@google.com>
22
*/
23
- abstract class Google_Cache_Abstract
24
{
25
26
- abstract public function __construct(Google_Client $client);
27
28
/**
29
* Retrieves the data for the given key, or false if they
20
*
21
* @author Chris Chabot <chabotc@google.com>
22
*/
23
+ abstract class IWP_google_Cache_Abstract
24
{
25
26
+ abstract public function __construct(IWP_google_Client $client);
27
28
/**
29
* Retrieves the data for the given key, or false if they
lib/Google/Cache/Apc.php CHANGED
@@ -26,12 +26,12 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Cache/Exception.php";
26
*
27
* @author Chris Chabot <chabotc@google.com>
28
*/
29
- class Google_Cache_Apc extends Google_Cache_Abstract
30
{
31
- public function __construct(Google_Client $client)
32
{
33
if (! function_exists('apc_add') ) {
34
- throw new Google_Cache_Exception("Apc functions not available");
35
}
36
}
37
@@ -58,7 +58,7 @@ class Google_Cache_Apc extends Google_Cache_Abstract
58
{
59
$rc = apc_store($key, array('time' => time(), 'data' => $value));
60
if ($rc == false) {
61
- throw new Google_Cache_Exception("Couldn't store data");
62
}
63
}
64
26
*
27
* @author Chris Chabot <chabotc@google.com>
28
*/
29
+ class IWP_google_Cache_Apc extends IWP_google_Cache_Abstract
30
{
31
+ public function __construct(IWP_google_Client $client)
32
{
33
if (! function_exists('apc_add') ) {
34
+ throw new IWP_google_Cache_Exception("Apc functions not available");
35
}
36
}
37
58
{
59
$rc = apc_store($key, array('time' => time(), 'data' => $value));
60
if ($rc == false) {
61
+ throw new IWP_google_Cache_Exception("Couldn't store data");
62
}
63
}
64
lib/Google/Cache/Exception.php CHANGED
@@ -16,6 +16,6 @@
16
*/
17
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Exception.php";
18
19
- class Google_Cache_Exception extends Google_Exception
20
{
21
}
16
*/
17
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Exception.php";
18
19
+ class IWP_google_Cache_Exception extends IWP_google_Exception
20
{
21
}
lib/Google/Cache/File.php CHANGED
@@ -26,13 +26,13 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Cache/Exception.php";
26
*
27
* @author Chris Chabot <chabotc@google.com>
28
*/
29
- class Google_Cache_File extends Google_Cache_Abstract
30
{
31
const MAX_LOCK_RETRIES = 10;
32
private $path;
33
private $fh;
34
35
- public function __construct(Google_Client $client)
36
{
37
$this->path = $client->getClassConfig($this, 'directory');
38
}
@@ -79,7 +79,7 @@ class Google_Cache_File extends Google_Cache_Abstract
79
{
80
$file = $this->getCacheFile($key);
81
if (file_exists($file) && !unlink($file)) {
82
- throw new Google_Cache_Exception("Cache file could not be deleted");
83
}
84
}
85
@@ -101,7 +101,7 @@ class Google_Cache_File extends Google_Cache_Abstract
101
$storageDir = $this->path . '/' . substr(md5($file), 0, 2);
102
if ($forWrite && ! is_dir($storageDir)) {
103
if (! mkdir($storageDir, 0755, true)) {
104
- throw new Google_Cache_Exception("Could not create storage directory: $storageDir");
105
}
106
}
107
return $storageDir;
26
*
27
* @author Chris Chabot <chabotc@google.com>
28
*/
29
+ class IWP_google_Cache_File extends IWP_google_Cache_Abstract
30
{
31
const MAX_LOCK_RETRIES = 10;
32
private $path;
33
private $fh;
34
35
+ public function __construct(IWP_google_Client $client)
36
{
37
$this->path = $client->getClassConfig($this, 'directory');
38
}
79
{
80
$file = $this->getCacheFile($key);
81
if (file_exists($file) && !unlink($file)) {
82
+ throw new IWP_google_Cache_Exception("Cache file could not be deleted");
83
}
84
}
85
101
$storageDir = $this->path . '/' . substr(md5($file), 0, 2);
102
if ($forWrite && ! is_dir($storageDir)) {
103
if (! mkdir($storageDir, 0755, true)) {
104
+ throw new IWP_google_Cache_Exception("Could not create storage directory: $storageDir");
105
}
106
}
107
return $storageDir;
lib/Google/Cache/Memcache.php CHANGED
@@ -28,17 +28,17 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Cache/Exception.php";
28
*
29
* @author Chris Chabot <chabotc@google.com>
30
*/
31
- class Google_Cache_Memcache extends Google_Cache_Abstract
32
{
33
private $connection = false;
34
private $mc = false;
35
private $host;
36
private $port;
37
38
- public function __construct(Google_Client $client)
39
{
40
if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
41
- throw new Google_Cache_Exception("Memcache functions not available");
42
}
43
if ($client->isAppEngine()) {
44
// No credentials needed for GAE.
@@ -48,7 +48,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
48
$this->host = $client->getClassConfig($this, 'host');
49
$this->port = $client->getClassConfig($this, 'port');
50
if (empty($this->host) || empty($this->port)) {
51
- throw new Google_Cache_Exception("You need to supply a valid memcache host and port");
52
}
53
}
54
}
@@ -79,7 +79,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
79
* @inheritDoc
80
* @param string $key
81
* @param string $value
82
- * @throws Google_Cache_Exception
83
*/
84
public function set($key, $value)
85
{
@@ -94,7 +94,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
94
$rc = memcache_set($this->connection, $key, $data, false);
95
}
96
if ($rc == false) {
97
- throw new Google_Cache_Exception("Couldn't store data in cache");
98
}
99
}
100
@@ -131,7 +131,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
131
}
132
133
if (! $this->connection) {
134
- throw new Google_Cache_Exception("Couldn't connect to memcache server");
135
}
136
}
137
}
28
*
29
* @author Chris Chabot <chabotc@google.com>
30
*/
31
+ class IWP_google_Cache_Memcache extends IWP_google_Cache_Abstract
32
{
33
private $connection = false;
34
private $mc = false;
35
private $host;
36
private $port;
37
38
+ public function __construct(IWP_google_Client $client)
39
{
40
if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
41
+ throw new IWP_google_Cache_Exception("Memcache functions not available");
42
}
43
if ($client->isAppEngine()) {
44
// No credentials needed for GAE.
48
$this->host = $client->getClassConfig($this, 'host');
49
$this->port = $client->getClassConfig($this, 'port');
50
if (empty($this->host) || empty($this->port)) {
51
+ throw new IWP_google_Cache_Exception("You need to supply a valid memcache host and port");
52
}
53
}
54
}
79
* @inheritDoc
80
* @param string $key
81
* @param string $value
82
+ * @throws IWP_google_Cache_Exception
83
*/
84
public function set($key, $value)
85
{
94
$rc = memcache_set($this->connection, $key, $data, false);
95
}
96
if ($rc == false) {
97
+ throw new IWP_google_Cache_Exception("Couldn't store data in cache");
98
}
99
}
100
131
}
132
133
if (! $this->connection) {
134
+ throw new IWP_google_Cache_Exception("Couldn't connect to memcache server");
135
}
136
}
137
}
lib/Google/Cache/Null.php CHANGED
@@ -22,9 +22,9 @@ require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Cache/Exception.php";
22
* A blank storage class, for cases where caching is not
23
* required.
24
*/
25
- class Google_Cache_Null extends Google_Cache_Abstract
26
{
27
- public function __construct(Google_Client $client)
28
{
29
30
}
22
* A blank storage class, for cases where caching is not
23
* required.
24
*/
25
+ class IWP_google_Cache_Null extends IWP_google_Cache_Abstract
26
{
27
+ public function __construct(IWP_google_Client $client)
28
{
29
30
}
lib/Google/Client.php CHANGED
@@ -34,27 +34,27 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Service/Resource.php';
34
* @author Chris Chabot <chabotc@google.com>
35
* @author Chirag Shah <chirags@google.com>
36
*/
37
- class Google_Client
38
{
39
const LIBVER = "1.0.5-beta";
40
const USER_AGENT_SUFFIX = "google-api-php-client/";
41
/**
42
- * @var Google_Auth_Abstract $auth
43
*/
44
private $auth;
45
46
/**
47
- * @var Google_IO_Abstract $io
48
*/
49
private $io;
50
51
/**
52
- * @var Google_Cache_Abstract $cache
53
*/
54
private $cache;
55
56
/**
57
- * @var Google_Config $config
58
*/
59
private $config;
60
@@ -76,7 +76,7 @@ class Google_Client
76
/**
77
* Construct the Google Client.
78
*
79
- * @param $config Google_Config or string for the ini file to load
80
*/
81
public function __construct($config = null)
82
{
@@ -86,26 +86,26 @@ class Google_Client
86
}
87
88
if (is_string($config) && strlen($config)) {
89
- $config = new Google_Config($config);
90
- } else if ( !($config instanceof Google_Config)) {
91
- $config = new Google_Config();
92
93
if ($this->isAppEngine()) {
94
// Automatically use Memcache if we're in AppEngine.
95
- $config->setCacheClass('Google_Cache_Memcache');
96
}
97
98
if (version_compare(phpversion(), "5.3.4", "<=") || $this->isAppEngine()) {
99
// Automatically disable compress.zlib, as currently unsupported.
100
- $config->setClassConfig('Google_Http_Request', 'disable_gzip', true);
101
}
102
}
103
104
- if ($config->getIoClass() == Google_Config::USE_AUTO_IO_SELECTION) {
105
if (function_exists('curl_version') && function_exists('curl_exec')) {
106
- $config->setIoClass("Google_Io_Curl");
107
} else {
108
- $config->setIoClass("Google_Io_Stream");
109
}
110
}
111
@@ -147,7 +147,7 @@ class Google_Client
147
$data = json_decode($json);
148
$key = isset($data->installed) ? 'installed' : 'web';
149
if (!isset($data->$key)) {
150
- throw new Google_Exception("Invalid client secret JSON file.");
151
}
152
$this->setClientId($data->$key->client_id);
153
$this->setClientSecret($data->$key->client_secret);
@@ -175,7 +175,7 @@ class Google_Client
175
public function prepareScopes()
176
{
177
if (empty($this->requestedScopes)) {
178
- throw new Google_Auth_Exception("No scopes specified");
179
}
180
$scopes = implode(' ', $this->requestedScopes);
181
return $scopes;
@@ -183,7 +183,7 @@ class Google_Client
183
184
/**
185
* Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl()
186
- * or Google_Client#getAccessToken().
187
* @param string $accessToken JSON encoded string containing in the following format:
188
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
189
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
@@ -200,9 +200,9 @@ class Google_Client
200
201
/**
202
* Set the authenticator object
203
- * @param Google_Auth_Abstract $auth
204
*/
205
- public function setAuth(Google_Auth_Abstract $auth)
206
{
207
$this->config->setAuthClass(get_class($auth));
208
$this->auth = $auth;
@@ -210,9 +210,9 @@ class Google_Client
210
211
/**
212
* Set the IO object
213
- * @param Google_Io_Abstract $auth
214
*/
215
- public function setIo(Google_Io_Abstract $io)
216
{
217
$this->config->setIoClass(get_class($io));
218
$this->io = $io;
@@ -220,9 +220,9 @@ class Google_Client
220
221
/**
222
* Set the Cache object
223
- * @param Google_Cache_Abstract $auth
224
*/
225
- public function setCache(Google_Cache_Abstract $cache)
226
{
227
$this->config->setCacheClass(get_class($cache));
228
$this->cache = $cache;
@@ -367,7 +367,7 @@ class Google_Client
367
/**
368
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
369
* token, if a token isn't provided.
370
- * @throws Google_Auth_Exception
371
* @param string|null $token The token (access token or a refresh token) that should be revoked.
372
* @return boolean Returns True if the revocation was successful, otherwise False.
373
*/
@@ -379,9 +379,9 @@ class Google_Client
379
/**
380
* Verify an id_token. This method will verify the current id_token, if one
381
* isn't provided.
382
- * @throws Google_Auth_Exception
383
* @param string|null $token The token (id_token) that should be verified.
384
- * @return Google_Auth_LoginTicket Returns an apiLoginTicket if the verification was
385
* successful.
386
*/
387
public function verifyIdToken($token = null)
@@ -401,16 +401,16 @@ class Google_Client
401
*/
402
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
403
{
404
- $auth = new Google_Auth_OAuth2($this);
405
$certs = $auth->retrieveCertsFromLocation($cert_location);
406
return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry);
407
}
408
409
/**
410
- * @param Google_Auth_AssertionCredentials $creds
411
* @return void
412
*/
413
- public function setAssertionCredentials(Google_Auth_AssertionCredentials $creds)
414
{
415
$this->getAuth()->setAssertionCredentials($creds);
416
}
@@ -486,21 +486,21 @@ class Google_Client
486
*/
487
public function execute($request)
488
{
489
- if ($request instanceof Google_Http_Request) {
490
$request->setUserAgent(
491
$this->getApplicationName()
492
. " " . self::USER_AGENT_SUFFIX
493
. $this->getLibraryVersion()
494
);
495
- if (!$this->getClassConfig("Google_Http_Request", "disable_gzip")) {
496
$request->enableGzip();
497
}
498
$request->maybeMoveParametersToBody();
499
- return Google_Http_REST::execute($this, $request);
500
- } else if ($request instanceof Google_Http_Batch) {
501
return $request->execute();
502
} else {
503
- throw new Google_Exception("Do not know how to execute this type of object.");
504
}
505
}
506
@@ -514,7 +514,7 @@ class Google_Client
514
}
515
516
/**
517
- * @return Google_Auth_Abstract Authentication implementation
518
*/
519
public function getAuth()
520
{
@@ -526,7 +526,7 @@ class Google_Client
526
}
527
528
/**
529
- * @return Google_IO_Abstract IO implementation
530
*/
531
public function getIo()
532
{
@@ -538,7 +538,7 @@ class Google_Client
538
}
539
540
/**
541
- * @return Google_Cache_Abstract Cache implementation
542
*/
543
public function getCache()
544
{
@@ -564,7 +564,7 @@ class Google_Client
564
565
/**
566
* Set configuration specific to a given class.
567
- * $config->setClassConfig('Google_Cache_File',
568
* array('directory' => '/tmp/cache'));
569
* @param $class The class name for the configuration
570
* @param $config string key or an array of configuration values
34
* @author Chris Chabot <chabotc@google.com>
35
* @author Chirag Shah <chirags@google.com>
36
*/
37
+ class IWP_google_Client
38
{
39
const LIBVER = "1.0.5-beta";
40
const USER_AGENT_SUFFIX = "google-api-php-client/";
41
/**
42
+ * @var IWP_google_Auth_Abstract $auth
43
*/
44
private $auth;
45
46
/**
47
+ * @var IWP_google_IO_Abstract $io
48
*/
49
private $io;
50
51
/**
52
+ * @var IWP_google_Cache_Abstract $cache
53
*/
54
private $cache;
55
56
/**
57
+ * @var IWP_google_Config $config
58
*/
59
private $config;
60
76
/**
77
* Construct the Google Client.
78
*
79
+ * @param $config IWP_google_Config or string for the ini file to load
80
*/
81
public function __construct($config = null)
82
{
86
}
87
88
if (is_string($config) && strlen($config)) {
89
+ $config = new IWP_google_Config($config);
90
+ } else if ( !($config instanceof IWP_google_Config)) {
91
+ $config = new IWP_google_Config();
92
93
if ($this->isAppEngine()) {
94
// Automatically use Memcache if we're in AppEngine.
95
+ $config->setCacheClass('IWP_google_Cache_Memcache');
96
}
97
98
if (version_compare(phpversion(), "5.3.4", "<=") || $this->isAppEngine()) {
99
// Automatically disable compress.zlib, as currently unsupported.
100
+ $config->setClassConfig('IWP_google_Http_Request', 'disable_gzip', true);
101
}
102
}
103
104
+ if ($config->getIoClass() == IWP_google_Config::USE_AUTO_IO_SELECTION) {
105
if (function_exists('curl_version') && function_exists('curl_exec')) {
106
+ $config->setIoClass("IWP_google_Io_Curl");
107
} else {
108
+ $config->setIoClass("IWP_google_Io_Stream");
109
}
110
}
111
147
$data = json_decode($json);
148
$key = isset($data->installed) ? 'installed' : 'web';
149
if (!isset($data->$key)) {
150
+ throw new IWP_google_Exception("Invalid client secret JSON file.");
151
}
152
$this->setClientId($data->$key->client_id);
153
$this->setClientSecret($data->$key->client_secret);
175
public function prepareScopes()
176
{
177
if (empty($this->requestedScopes)) {
178
+ throw new IWP_google_Auth_Exception("No scopes specified");
179
}
180
$scopes = implode(' ', $this->requestedScopes);
181
return $scopes;
183
184
/**
185
* Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl()
186
+ * or IWP_google_Client#getAccessToken().
187
* @param string $accessToken JSON encoded string containing in the following format:
188
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
189
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
200
201
/**
202
* Set the authenticator object
203
+ * @param IWP_google_Auth_Abstract $auth
204
*/
205
+ public function setAuth(IWP_google_Auth_Abstract $auth)
206
{
207
$this->config->setAuthClass(get_class($auth));
208
$this->auth = $auth;
210
211
/**
212
* Set the IO object
213
+ * @param IWP_google_Io_Abstract $auth
214
*/
215
+ public function setIo(IWP_google_Io_Abstract $io)
216
{
217
$this->config->setIoClass(get_class($io));
218
$this->io = $io;
220
221
/**
222
* Set the Cache object
223
+ * @param IWP_google_Cache_Abstract $auth
224
*/
225
+ public function setCache(IWP_google_Cache_Abstract $cache)
226
{
227
$this->config->setCacheClass(get_class($cache));
228
$this->cache = $cache;
367
/**
368
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
369
* token, if a token isn't provided.
370
+ * @throws IWP_google_Auth_Exception
371
* @param string|null $token The token (access token or a refresh token) that should be revoked.
372
* @return boolean Returns True if the revocation was successful, otherwise False.
373
*/
379
/**
380
* Verify an id_token. This method will verify the current id_token, if one
381
* isn't provided.
382
+ * @throws IWP_google_Auth_Exception
383
* @param string|null $token The token (id_token) that should be verified.
384
+ * @return IWP_google_Auth_LoginTicket Returns an apiLoginTicket if the verification was
385
* successful.
386
*/
387
public function verifyIdToken($token = null)
401
*/
402
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
403
{
404
+ $auth = new IWP_google_Auth_OAuth2($this);
405
$certs = $auth->retrieveCertsFromLocation($cert_location);
406
return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry);
407
}
408
409
/**
410
+ * @param IWP_google_Auth_AssertionCredentials $creds
411
* @return void
412
*/
413
+ public function setAssertionCredentials(IWP_google_Auth_AssertionCredentials $creds)
414
{
415
$this->getAuth()->setAssertionCredentials($creds);
416
}
486
*/
487
public function execute($request)
488
{
489
+ if ($request instanceof IWP_google_Http_Request) {
490
$request->setUserAgent(
491
$this->getApplicationName()
492
. " " . self::USER_AGENT_SUFFIX
493
. $this->getLibraryVersion()
494
);
495
+ if (!$this->getClassConfig("IWP_google_Http_Request", "disable_gzip")) {
496
$request->enableGzip();
497
}
498
$request->maybeMoveParametersToBody();
499
+ return IWP_google_Http_REST::execute($this, $request);
500
+ } else if ($request instanceof IWP_google_Http_Batch) {
501
return $request->execute();
502
} else {
503
+ throw new IWP_google_Exception("Do not know how to execute this type of object.");
504
}
505
}
506
514
}
515
516
/**
517
+ * @return IWP_google_Auth_Abstract Authentication implementation
518
*/
519
public function getAuth()
520
{
526
}
527
528
/**
529
+ * @return IWP_google_IO_Abstract IO implementation
530
*/
531
public function getIo()
532
{
538
}
539
540
/**
541
+ * @return IWP_google_Cache_Abstract Cache implementation
542
*/
543
public function getCache()
544
{
564
565
/**
566
* Set configuration specific to a given class.
567
+ * $config->setClassConfig('IWP_google_Cache_File',
568
* array('directory' => '/tmp/cache'));
569
* @param $class The class name for the configuration
570
* @param $config string key or an array of configuration values
lib/Google/Collection.php CHANGED
@@ -3,11 +3,11 @@
3
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Model.php";
4
5
/**
6
- * Extension to the regular Google_Model that automatically
7
* exposes the items array for iteration, so you can just
8
* iterate over the object rather than a reference inside.
9
*/
10
- class Google_Collection extends Google_Model implements Iterator, Countable
11
{
12
protected $collection_key = 'items';
13
3
require_once $GLOBALS['iwp_mmb_plugin_dir']."/lib/Google/Model.php";
4
5
/**
6
+ * Extension to the regular IWP_google_Model that automatically
7
* exposes the items array for iteration, so you can just
8
* iterate over the object rather than a reference inside.
9
*/
10
+ class IWP_google_Collection extends IWP_google_Model implements Iterator, Countable
11
{
12
protected $collection_key = 'items';
13
lib/Google/Config.php CHANGED
@@ -18,7 +18,7 @@
18
/**
19
* A class to contain the library configuration for the Google API client.
20
*/
21
- class Google_Config
22
{
23
const GZIP_DISABLED = true;
24
const GZIP_ENABLED = false;
@@ -28,7 +28,7 @@ class Google_Config
28
private $configuration;
29
30
/**
31
- * Create a new Google_Config. Can accept an ini file location with the
32
* local configuration. For example:
33
* application_name: "My App";
34
*
@@ -41,9 +41,9 @@ class Google_Config
41
'application_name' => '',
42
43
// Which Authentication, Storage and HTTP IO classes to use.
44
- 'auth_class' => 'Google_Auth_OAuth2',
45
'io_class' => self::USE_AUTO_IO_SELECTION,
46
- 'cache_class' => 'Google_Cache_File',
47
48
// Don't change these unless you're working against a special development
49
// or testing environment.
@@ -51,10 +51,10 @@ class Google_Config
51
52
// Definition of class specific values, like file paths and so on.
53
'classes' => array(
54
- 'Google_IO_Abstract' => array(
55
'request_timeout_seconds' => 100,
56
),
57
- 'Google_Http_Request' => array(
58
// Disable the use of gzip on calls if set to true. Defaults to false.
59
'disable_gzip' => self::GZIP_ENABLED,
60
@@ -66,7 +66,7 @@ class Google_Config
66
),
67
// If you want to pass in OAuth 2.0 settings, they will need to be
68
// structured like this.
69
- 'Google_Auth_OAuth2' => array(
70
// Keys for OAuth 2.0 access, see the API console at
71
// https://developers.google.com/console
72
'client_id' => '',
@@ -85,8 +85,8 @@ class Google_Config
85
'https://www.googleapis.com/oauth2/v1/certs',
86
),
87
// Set a default directory for the file cache.
88
- 'Google_Cache_File' => array(
89
- 'directory' => sys_get_temp_dir() . '/Google_Client'
90
)
91
),
92
@@ -105,7 +105,7 @@ class Google_Config
105
106
/**
107
* Set configuration specific to a given class.
108
- * $config->setClassConfig('Google_Cache_File',
109
* array('directory' => '/tmp/cache'));
110
* @param $class The class name for the configuration
111
* @param $config string key or an array of configuration values
18
/**
19
* A class to contain the library configuration for the Google API client.
20
*/
21
+ class IWP_google_Config
22
{
23
const GZIP_DISABLED = true;
24
const GZIP_ENABLED = false;
28
private $configuration;
29
30
/**
31
+ * Create a new IWP_google_Config. Can accept an ini file location with the
32
* local configuration. For example:
33
* application_name: "My App";
34
*
41
'application_name' => '',
42
43
// Which Authentication, Storage and HTTP IO classes to use.
44
+ 'auth_class' => 'IWP_google_Auth_OAuth2',
45
'io_class' => self::USE_AUTO_IO_SELECTION,
46
+ 'cache_class' => 'IWP_google_Cache_File',
47
48
// Don't change these unless you're working against a special development
49
// or testing environment.
51
52
// Definition of class specific values, like file paths and so on.
53
'classes' => array(
54
+ 'IWP_google_IO_Abstract' => array(
55
'request_timeout_seconds' => 100,
56
),
57
+ 'IWP_google_Http_Request' => array(
58
// Disable the use of gzip on calls if set to true. Defaults to false.
59
'disable_gzip' => self::GZIP_ENABLED,
60
66
),
67
// If you want to pass in OAuth 2.0 settings, they will need to be
68
// structured like this.
69
+ 'IWP_google_Auth_OAuth2' => array(
70
// Keys for OAuth 2.0 access, see the API console at
71
// https://developers.google.com/console
72
'client_id' => '',
85
'https://www.googleapis.com/oauth2/v1/certs',
86
),
87
// Set a default directory for the file cache.
88
+ 'IWP_google_Cache_File' => array(
89
+ 'directory' => sys_get_temp_dir() . '/IWP_google_Client'
90
)
91
),
92
105
106
/**
107
* Set configuration specific to a given class.
108
+ * $config->setClassConfig('IWP_google_Cache_File',
109
* array('directory' => '/tmp/cache'));
110
* @param $class The class name for the configuration
111
* @param $config string key or an array of configuration values
lib/Google/Exception.php CHANGED
@@ -15,6 +15,6 @@
15
* limitations under the License.
16
*/
17
18
- class Google_Exception extends Exception
19
{
20
}
15
* limitations under the License.
16
*/
17
18
+ class IWP_google_Exception extends Exception
19
{
20
}
lib/Google/Http/Batch.php CHANGED
@@ -22,7 +22,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/REST.php';
22
/**
23
* @author Chirag Shah <chirags@google.com>
24
*/
25
- class Google_Http_Batch
26
{
27
/** @var string Multipart Boundary. */
28
private $boundary;
@@ -30,14 +30,14 @@ class Google_Http_Batch
30
/** @var array service requests to be executed. */
31
private $requests = array();
32
33
- /** @var Google_Client */
34
private $client;
35
36
private $expected_classes = array();
37
38
private $base_path;
39
40
- public function __construct(Google_Client $client, $boundary = false)
41
{
42
$this->client = $client;
43
$this->base_path = $this->client->getBasePath();
@@ -46,7 +46,7 @@ class Google_Http_Batch
46
$this->boundary = str_replace('"', '', $boundary);
47
}
48
49
- public function add(Google_Http_Request $request, $key = false)
50
{
51
if (false == $key) {
52
$key = mt_rand();
@@ -59,7 +59,7 @@ class Google_Http_Batch
59
{
60
$body = '';
61
62
- /** @var Google_Http_Request $req */
63
foreach ($this->requests as $key => $req) {
64
$body .= "--{$this->boundary}\n";
65
$body .= $req->toBatchString($key) . "\n";
@@ -70,7 +70,7 @@ class Google_Http_Batch
70
$body .= "\n--{$this->boundary}--";
71
72
$url = $this->base_path . '/batch';
73
- $httpRequest = new Google_Http_Request($url, 'POST');
74
$httpRequest->setRequestHeaders(
75
array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
76
);
@@ -81,7 +81,7 @@ class Google_Http_Batch
81
return $this->parseResponse($response);
82
}
83
84
- public function parseResponse(Google_Http_Request $response)
85
{
86
$contentType = $response->getResponseHeader('content-type');
87
$contentType = explode(';', $contentType);
@@ -110,7 +110,7 @@ class Google_Http_Batch
110
$status = $status[1];
111
112
list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
113
- $response = new Google_Http_Request("");
114
$response->setResponseHttpCode($status);
115
$response->setResponseHeaders($partHeaders);
116
$response->setResponseBody($partBody);
@@ -125,9 +125,9 @@ class Google_Http_Batch
125
}
126
127
try {
128
- $response = Google_Http_REST::decodeHttpResponse($response);
129
$responses[$key] = $response;
130
- } catch (Google_Service_Exception $e) {
131
// Store the exception as the response, so succesful responses
132
// can be processed.
133
$responses[$key] = $e;
22
/**
23
* @author Chirag Shah <chirags@google.com>
24
*/
25
+ class IWP_google_Http_Batch
26
{
27
/** @var string Multipart Boundary. */
28
private $boundary;
30
/** @var array service requests to be executed. */
31
private $requests = array();
32
33
+ /** @var IWP_google_Client */
34
private $client;
35
36
private $expected_classes = array();
37
38
private $base_path;
39
40
+ public function __construct(IWP_google_Client $client, $boundary = false)
41
{
42
$this->client = $client;
43
$this->base_path = $this->client->getBasePath();
46
$this->boundary = str_replace('"', '', $boundary);
47
}
48
49
+ public function add(IWP_google_Http_Request $request, $key = false)
50
{
51
if (false == $key) {
52
$key = mt_rand();
59
{
60
$body = '';
61
62
+ /** @var IWP_google_Http_Request $req */
63
foreach ($this->requests as $key => $req) {
64
$body .= "--{$this->boundary}\n";
65
$body .= $req->toBatchString($key) . "\n";
70
$body .= "\n--{$this->boundary}--";
71
72
$url = $this->base_path . '/batch';
73
+ $httpRequest = new IWP_google_Http_Request($url, 'POST');
74
$httpRequest->setRequestHeaders(
75
array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
76
);
81
return $this->parseResponse($response);
82
}
83
84
+ public function parseResponse(IWP_google_Http_Request $response)
85
{
86
$contentType = $response->getResponseHeader('content-type');
87
$contentType = explode(';', $contentType);
110
$status = $status[1];
111
112
list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
113
+ $response = new IWP_google_Http_Request("");
114
$response->setResponseHttpCode($status);
115
$response->setResponseHeaders($partHeaders);
116
$response->setResponseBody($partBody);
125
}
126
127
try {
128
+ $response = IWP_google_Http_REST::decodeHttpResponse($response);
129
$responses[$key] = $response;
130
+ } catch (IWP_google_Service_Exception $e) {
131
// Store the exception as the response, so succesful responses
132
// can be processed.
133
$responses[$key] = $e;
lib/Google/Http/CacheParser.php CHANGED
@@ -22,7 +22,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/Request.php';
22
* implementation is guided by the guidance offered in rfc2616-sec13.
23
* @author Chirag Shah <chirags@google.com>
24
*/
25
- class Google_Http_CacheParser
26
{
27
public static $CACHEABLE_HTTP_METHODS = array('GET', 'HEAD');
28
public static $CACHEABLE_STATUS_CODES = array('200', '203', '300', '301');
@@ -31,11 +31,11 @@ class Google_Http_CacheParser
31
* Check if an HTTP request can be cached by a private local cache.
32
*
33
* @static
34
- * @param Google_Http_Request $resp
35
* @return bool True if the request is cacheable.
36
* False if the request is uncacheable.
37
*/
38
- public static function isRequestCacheable(Google_Http_Request $resp)
39
{
40
$method = $resp->getRequestMethod();
41
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
@@ -57,11 +57,11 @@ class Google_Http_CacheParser
57
* Check if an HTTP response can be cached by a private local cache.
58
*
59
* @static
60
- * @param Google_Http_Request $resp
61
* @return bool True if the response is cacheable.
62
* False if the response is un-cacheable.
63
*/
64
- public static function isResponseCacheable(Google_Http_Request $resp)
65
{
66
// First, check if the HTTP request was cacheable before inspecting the
67
// HTTP response.
@@ -109,11 +109,11 @@ class Google_Http_CacheParser
109
110
/**
111
* @static
112
- * @param Google_Http_Request $resp
113
* @return bool True if the HTTP response is considered to be expired.
114
* False if it is considered to be fresh.
115
*/
116
- public static function isExpired(Google_Http_Request $resp)
117
{
118
// HTTP/1.1 clients and caches MUST treat other invalid date formats,
119
// especially including the value “0”, as in the past.
@@ -148,7 +148,7 @@ class Google_Http_CacheParser
148
// We can't default this to now, as that means future cache reads
149
// will always pass with the logic below, so we will require a
150
// date be injected if not supplied.
151
- throw new Google_Exception("All cacheable requests must have creation dates.");
152
}
153
154
if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
@@ -171,10 +171,10 @@ class Google_Http_CacheParser
171
/**
172
* Determine if a cache entry should be revalidated with by the origin.
173
*
174
- * @param Google_Http_Request $response
175
* @return bool True if the entry is expired, else return false.
176
*/
177
- public static function mustRevalidate(Google_Http_Request $response)
178
{
179
// [13.3] When a cache has a stale entry that it would like to use as a
180
// response to a client's request, it first has to check with the origin
22
* implementation is guided by the guidance offered in rfc2616-sec13.
23
* @author Chirag Shah <chirags@google.com>
24
*/
25
+ class IWP_google_Http_CacheParser
26
{
27
public static $CACHEABLE_HTTP_METHODS = array('GET', 'HEAD');
28
public static $CACHEABLE_STATUS_CODES = array('200', '203', '300', '301');
31
* Check if an HTTP request can be cached by a private local cache.
32
*
33
* @static
34
+ * @param IWP_google_Http_Request $resp
35
* @return bool True if the request is cacheable.
36
* False if the request is uncacheable.
37
*/
38
+ public static function isRequestCacheable(IWP_google_Http_Request $resp)
39
{
40
$method = $resp->getRequestMethod();
41
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
57
* Check if an HTTP response can be cached by a private local cache.
58
*
59
* @static
60
+ * @param IWP_google_Http_Request $resp
61
* @return bool True if the response is cacheable.
62
* False if the response is un-cacheable.
63
*/
64
+ public static function isResponseCacheable(IWP_google_Http_Request $resp)
65
{
66
// First, check if the HTTP request was cacheable before inspecting the
67
// HTTP response.
109
110
/**
111
* @static
112
+ * @param IWP_google_Http_Request $resp
113
* @return bool True if the HTTP response is considered to be expired.
114
* False if it is considered to be fresh.
115
*/
116
+ public static function isExpired(IWP_google_Http_Request $resp)
117
{
118
// HTTP/1.1 clients and caches MUST treat other invalid date formats,
119
// especially including the value “0”, as in the past.
148
// We can't default this to now, as that means future cache reads
149
// will always pass with the logic below, so we will require a
150
// date be injected if not supplied.
151
+ throw new IWP_google_Exception("All cacheable requests must have creation dates.");
152
}
153
154
if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
171
/**
172
* Determine if a cache entry should be revalidated with by the origin.
173
*
174
+ * @param IWP_google_Http_Request $response
175
* @return bool True if the entry is expired, else return false.
176
*/
177
+ public static function mustRevalidate(IWP_google_Http_Request $response)
178
{
179
// [13.3] When a cache has a stale entry that it would like to use as a
180
// response to a client's request, it first has to check with the origin
lib/Google/Http/MediaFileUpload.php CHANGED
@@ -25,7 +25,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Utils.php';
25
* @author Chirag Shah <chirags@google.com>
26
*
27
*/
28
- class Google_Http_MediaFileUpload
29
{
30
const UPLOAD_MEDIA_TYPE = 'media';
31
const UPLOAD_MULTIPART_TYPE = 'multipart';
@@ -52,10 +52,10 @@ class Google_Http_MediaFileUpload
52
/** @var int $progress */
53
private $progress;
54
55
- /** @var Google_Client */
56
private $client;
57
58
- /** @var Google_Http_Request */
59
private $request;
60
61
/** @var string */
@@ -75,8 +75,8 @@ class Google_Http_MediaFileUpload
75
* only used if resumable=True
76
*/
77
public function __construct(
78
- Google_Client $client,
79
- Google_Http_Request $request,
80
$mimeType,
81
$data,
82
$resumable = false,
@@ -141,6 +141,8 @@ class Google_Http_MediaFileUpload
141
$this->resumeUri = $this->getResumeUri();
142
}
143
144
if (false == $chunk) {
145
$chunk = substr($this->data, $this->progress, $this->chunkSize);
146
}
@@ -153,14 +155,14 @@ class Google_Http_MediaFileUpload
153
'expect' => '',
154
);
155
156
- $httpRequest = new Google_Http_Request(
157
$this->resumeUri,
158
'PUT',
159
$headers,
160
$chunk
161
);
162
163
- if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) {
164
$httpRequest->enableGzip();
165
} else {
166
$httpRequest->disableGzip();
@@ -189,9 +191,9 @@ class Google_Http_MediaFileUpload
189
return $status;
190
} else {
191
$status['progress'] = $this->progress;
192
- $status['status'] = Google_Http_REST::decodeHttpResponse($response);
193
return $status;
194
- //return Google_Http_REST::decodeHttpResponse($response);
195
}
196
}
197
@@ -283,7 +285,7 @@ class Google_Http_MediaFileUpload
283
if ($body) {
284
$headers = array(
285
'content-type' => 'application/json; charset=UTF-8',
286
- 'content-length' => Google_Utils::getStrLen($body),
287
'x-upload-content-type' => $this->mimeType,
288
'x-upload-content-length' => $this->size,
289
'expect' => '',
@@ -298,6 +300,6 @@ class Google_Http_MediaFileUpload
298
if (200 == $code && true == $location) {
299
return $location;
300
}
301
- throw new Google_Exception("Failed to start the resumable upload");
302
}
303
}
25
* @author Chirag Shah <chirags@google.com>
26
*
27
*/
28
+ class IWP_google_Http_MediaFileUpload
29
{
30
const UPLOAD_MEDIA_TYPE = 'media';
31
const UPLOAD_MULTIPART_TYPE = 'multipart';
52
/** @var int $progress */
53
private $progress;
54
55
+ /** @var IWP_google_Client */
56
private $client;
57
58
+ /** @var IWP_google_Http_Request */
59
private $request;
60
61
/** @var string */
75
* only used if resumable=True
76
*/
77
public function __construct(
78
+ IWP_google_Client $client,
79
+ IWP_google_Http_Request $request,
80
$mimeType,
81
$data,
82
$resumable = false,
141
$this->resumeUri = $this->getResumeUri();
142
}
143
144
+ file_put_contents(WP_CONTENT_DIR .'/DE_clientPluginSIde.php',"\n ------ resumeURI-------- ".var_export($this->resumeUri,true)."\n",FILE_APPEND);
145
+
146
if (false == $chunk) {
147
$chunk = substr($this->data, $this->progress, $this->chunkSize);
148
}
155
'expect' => '',
156
);
157
158
+ $httpRequest = new IWP_google_Http_Request(
159
$this->resumeUri,
160
'PUT',
161
$headers,
162
$chunk
163
);
164
165
+ if ($this->client->getClassConfig("IWP_google_Http_Request", "enable_gzip_for_uploads")) {
166
$httpRequest->enableGzip();
167
} else {
168
$httpRequest->disableGzip();
191
return $status;
192
} else {
193
$status['progress'] = $this->progress;
194
+ $status['status'] = IWP_google_Http_REST::decodeHttpResponse($response);
195
return $status;
196
+ //return IWP_google_Http_REST::decodeHttpResponse($response);
197
}
198
}
199
285
if ($body) {
286
$headers = array(
287
'content-type' => 'application/json; charset=UTF-8',
288
+ 'content-length' => IWP_google_Utils::getStrLen($body),
289
'x-upload-content-type' => $this->mimeType,
290
'x-upload-content-length' => $this->size,
291
'expect' => '',
300
if (200 == $code && true == $location) {
301
return $location;
302
}
303
+ throw new IWP_google_Exception("Failed to start the resumable upload");
304
}
305
}
lib/Google/Http/REST.php CHANGED
@@ -26,18 +26,18 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Utils/URITemplate.php';
26
* @author Chris Chabot <chabotc@google.com>
27
* @author Chirag Shah <chirags@google.com>
28
*/
29
- class Google_Http_REST
30
{
31
/**
32
- * Executes a Google_Http_Request
33
*
34
- * @param Google_Client $client
35
- * @param Google_Http_Request $req
36
* @return array decoded result
37
- * @throws Google_Service_Exception on server side error (ie: not authenticated,
38
* invalid or malformed post body, invalid url)
39
*/
40
- public static function execute(Google_Client $client, Google_Http_Request $req)
41
{
42
$httpRequest = $client->getIo()->makeRequest($req);
43
$httpRequest->setExpectedClass($req->getExpectedClass());
@@ -47,8 +47,8 @@ class Google_Http_REST
47
/**
48
* Decode an HTTP Response.
49
* @static
50
- * @throws Google_Service_Exception
51
- * @param Google_Http_Request $response The http response to be decoded.
52
* @return mixed|null
53
*/
54
public static function decodeHttpResponse($response)
@@ -76,14 +76,14 @@ class Google_Http_REST
76
$errors = $decoded['error']['errors'];
77
}
78
79
- throw new Google_Service_Exception($err, $code, null, $errors);
80
}
81
82
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
83
if ($code != '204') {
84
$decoded = json_decode($body, true);
85
if ($decoded === null || $decoded === "") {
86
- throw new Google_Service_Exception("Invalid json in service response: $body");
87
}
88
89
if ($response->getExpectedClass()) {
@@ -126,7 +126,7 @@ class Google_Http_REST
126
}
127
128
if (count($uriTemplateVars)) {
129
- $uriTemplateParser = new Google_Utils_URITemplate();
130
$requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
131
}
132
26
* @author Chris Chabot <chabotc@google.com>
27
* @author Chirag Shah <chirags@google.com>
28
*/
29
+ class IWP_google_Http_REST
30
{
31
/**
32
+ * Executes a IWP_google_Http_Request
33
*
34
+ * @param IWP_google_Client $client
35
+ * @param IWP_google_Http_Request $req
36
* @return array decoded result
37
+ * @throws IWP_google_Service_Exception on server side error (ie: not authenticated,
38
* invalid or malformed post body, invalid url)
39
*/
40
+ public static function execute(IWP_google_Client $client, IWP_google_Http_Request $req)
41
{
42
$httpRequest = $client->getIo()->makeRequest($req);
43
$httpRequest->setExpectedClass($req->getExpectedClass());
47
/**
48
* Decode an HTTP Response.
49
* @static
50
+ * @throws IWP_google_Service_Exception
51
+ * @param IWP_google_Http_Request $response The http response to be decoded.
52
* @return mixed|null
53
*/
54
public static function decodeHttpResponse($response)
76
$errors = $decoded['error']['errors'];
77
}
78
79
+ throw new IWP_google_Service_Exception($err, $code, null, $errors);
80
}
81
82
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
83
if ($code != '204') {
84
$decoded = json_decode($body, true);
85
if ($decoded === null || $decoded === "") {
86
+ throw new IWP_google_Service_Exception("Invalid json in service response: $body");
87
}
88
89
if ($response->getExpectedClass()) {
126
}
127
128
if (count($uriTemplateVars)) {
129
+ $uriTemplateParser = new IWP_google_Utils_URITemplate();
130
$requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
131
}
132
lib/Google/Http/Request.php CHANGED
@@ -25,7 +25,7 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Utils.php';
25
* @author Chirag Shah <chirags@google.com>
26
*
27
*/
28
- class Google_Http_Request
29
{
30
const GZIP_UA = " (gzip)";
31
@@ -194,7 +194,7 @@ class Google_Http_Request
194
*/
195
public function setResponseHeaders($headers)
196
{
197
- $headers = Google_Utils::normalize($headers);
198
if ($this->responseHeaders) {
199
$headers = array_merge($this->responseHeaders, $headers);
200
}
@@ -312,7 +312,7 @@ class Google_Http_Request
312
*/
313
public function setRequestHeaders($headers)
314
{
315
- $headers = Google_Utils::normalize($headers);
316
if ($this->requestHeaders) {
317
$headers = array_merge($this->requestHeaders, $headers);
318
}
25
* @author Chirag Shah <chirags@google.com>
26
*
27
*/
28
+ class IWP_google_Http_Request
29
{
30
const GZIP_UA = " (gzip)";
31
194
*/
195
public function setResponseHeaders($headers)
196
{
197
+ $headers = IWP_google_Utils::normalize($headers);
198
if ($this->responseHeaders) {
199
$headers = array_merge($this->responseHeaders, $headers);
200
}
312
*/
313
public function setRequestHeaders($headers)
314
{
315
+ $headers = IWP_google_Utils::normalize($headers);
316
if ($this->requestHeaders) {
317
$headers = array_merge($this->requestHeaders, $headers);
318
}
lib/Google/IO/Abstract.php CHANGED
@@ -24,31 +24,31 @@ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/IO/Exception.php';
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/CacheParser.php';
25
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/Request.php';
26
27
- abstract class Google_IO_Abstract
28
{
29
const UNKNOWN_CODE = 0;
30
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
31
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
32
private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
33
34
- /** @var Google_Client */
35
protected $client;
36
37
- public function __construct(Google_Client $client)
38
{
39
$this->client = $client;
40
- $timeout = $client->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds');
41
if ($timeout > 0) {
42
$this->setTimeout($timeout);
43
}
44
}
45
46
/**
47
- * Executes a Google_Http_Request and returns the resulting populated Google_Http_Request
48
- * @param Google_Http_Request $request
49
- * @return Google_Http_Request $request
50
*/
51
- abstract public function executeRequest(Google_Http_Request $request);
52
53
/**
54
* Set options that update the transport implementation's behavior.
@@ -77,14 +77,14 @@ abstract class Google_IO_Abstract
77
/**
78
* @visible for testing.
79
* Cache the response to an HTTP request if it is cacheable.
80
- * @param Google_Http_Request $request
81
* @return bool Returns true if the insertion was successful.
82
* Otherwise, return false.
83
*/
84
- public function setCachedRequest(Google_Http_Request $request)
85
{
86
// Determine if the request is cacheable.
87
- if (Google_Http_CacheParser::isResponseCacheable($request)) {
88
$this->client->getCache()->set($request->getCacheKey(), $request);
89
return true;
90
}
@@ -95,16 +95,16 @@ abstract class Google_IO_Abstract
95
/**
96
* Execute an HTTP Request
97
*
98
- * @param Google_HttpRequest $request the http request to be executed
99
- * @return Google_HttpRequest http request with the response http code,
100
* response headers and response body filled in
101
- * @throws Google_IO_Exception on curl or IO error
102
*/
103
- public function makeRequest(Google_Http_Request $request)
104
{
105
// First, check to see if we have a valid cached version.
106
$cached = $this->getCachedRequest($request);
107
- if ($cached !== false && $cached instanceof Google_Http_Request) {
108
if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
109
return $cached;
110
}
@@ -137,13 +137,13 @@ abstract class Google_IO_Abstract
137
138
/**
139
* @visible for testing.
140
- * @param Google_Http_Request $request
141
- * @return Google_Http_Request|bool Returns the cached object or
142
* false if the operation was unsuccessful.
143
*/
144
- public function getCachedRequest(Google_Http_Request $request)
145
{
146
- if (false === Google_Http_CacheParser::isRequestCacheable($request)) {
147
return false;
148
}
149
@@ -153,10 +153,10 @@ abstract class Google_IO_Abstract
153
/**
154
* @visible for testing
155
* Process an http request that contains an enclosed entity.
156
- * @param Google_Http_Request $request
157
- * @return Google_Http_Request Processed request with the enclosed entity.
158
*/
159
- public function processEntityRequest(Google_Http_Request $request)
160
{
161
$postBody = $request->getPostBody();
162
$contentType = $request->getRequestHeader("content-type");
@@ -185,14 +185,14 @@ abstract class Google_IO_Abstract
185
/**
186
* Check if an already cached request must be revalidated, and if so update
187
* the request with the correct ETag headers.
188
- * @param Google_Http_Request $cached A previously cached response.
189
- * @param Google_Http_Request $request The outbound request.
190
* return bool If the cached object needs to be revalidated, false if it is
191
* still current and can be re-used.
192
*/
193
protected function checkMustRevalidateCachedRequest($cached, $request)
194
{
195
- if (Google_Http_CacheParser::mustRevalidate($cached)) {
196
$addHeaders = array();
197
if ($cached->getResponseHeader('etag')) {
198
// [13.3.4] If an entity tag has been provided by the origin server,
@@ -211,7 +211,7 @@ abstract class Google_IO_Abstract
211
212
/**
213
* Update a cached request, using the headers from the last response.
214
- * @param Google_HttpRequest $cached A previously cached response.
215
* @param mixed Associative array of response headers from the last request.
216
*/
217
protected function updateCachedRequest($cached, $responseHeaders)
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/CacheParser.php';
25
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Http/Request.php';
26
27
+ abstract class IWP_google_IO_Abstract
28
{
29
const UNKNOWN_CODE = 0;
30
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
31
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
32
private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
33
34
+ /** @var IWP_google_Client */
35
protected $client;
36
37
+ public function __construct(IWP_google_Client $client)
38
{
39
$this->client = $client;
40
+ $timeout = $client->getClassConfig('IWP_google_IO_Abstract', 'request_timeout_seconds');
41
if ($timeout > 0) {
42
$this->setTimeout($timeout);
43
}
44
}
45
46
/**
47
+ * Executes a IWP_google_Http_Request and returns the resulting populated IWP_google_Http_Request
48
+ * @param IWP_google_Http_Request $request
49
+ * @return IWP_google_Http_Request $request
50
*/
51
+ abstract public function executeRequest(IWP_google_Http_Request $request);
52
53
/**
54
* Set options that update the transport implementation's behavior.
77
/**
78
* @visible for testing.
79
* Cache the response to an HTTP request if it is cacheable.
80
+ * @param IWP_google_Http_Request $request
81
* @return bool Returns true if the insertion was successful.
82
* Otherwise, return false.
83
*/
84
+ public function setCachedRequest(IWP_google_Http_Request $request)
85
{
86
// Determine if the request is cacheable.
87
+ if (IWP_google_Http_CacheParser::isResponseCacheable($request)) {
88
$this->client->getCache()->set($request->getCacheKey(), $request);
89
return true;
90
}
95
/**
96
* Execute an HTTP Request
97
*
98
+ * @param IWP_google_HttpRequest $request the http request to be executed
99
+ * @return IWP_google_HttpRequest http request with the response http code,
100
* response headers and response body filled in
101
+ * @throws IWP_google_IO_Exception on curl or IO error
102
*/
103
+ public function makeRequest(IWP_google_Http_Request $request)
104
{
105
// First, check to see if we have a valid cached version.
106
$cached = $this->getCachedRequest($request);
107
+ if ($cached !== false && $cached instanceof IWP_google_Http_Request) {
108
if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
109
return $cached;
110
}
137
138
/**
139
* @visible for testing.
140
+ * @param IWP_google_Http_Request $request
141
+ * @return IWP_google_Http_Request|bool Returns the cached object or
142
* false if the operation was unsuccessful.
143
*/
144
+ public function getCachedRequest(IWP_google_Http_Request $request)
145
{
146
+ if (false === IWP_google_Http_CacheParser::isRequestCacheable($request)) {
147
return false;
148
}
149
153
/**
154
* @visible for testing
155
* Process an http request that contains an enclosed entity.
156
+ * @param IWP_google_Http_Request $request
157
+ * @return IWP_google_Http_Request Processed request with the enclosed entity.
158
*/
159
+ public function processEntityRequest(IWP_google_Http_Request $request)
160
{
161
$postBody = $request->getPostBody();
162
$contentType = $request->getRequestHeader("content-type");
185
/**
186
* Check if an already cached request must be revalidated, and if so update
187
* the request with the correct ETag headers.
188
+ * @param IWP_google_Http_Request $cached A previously cached response.
189
+ * @param IWP_google_Http_Request $request The outbound request.
190
* return bool If the cached object needs to be revalidated, false if it is
191
* still current and can be re-used.
192
*/
193
protected function checkMustRevalidateCachedRequest($cached, $request)
194
{
195
+ if (IWP_google_Http_CacheParser::mustRevalidate($cached)) {
196
$addHeaders = array();
197
if ($cached->getResponseHeader('etag')) {
198
// [13.3.4] If an entity tag has been provided by the origin server,
211
212
/**
213
* Update a cached request, using the headers from the last response.
214
+ * @param IWP_google_HttpRequest $cached A previously cached response.
215
* @param mixed Associative array of response headers from the last request.
216
*/
217
protected function updateCachedRequest($cached, $responseHeaders)
lib/Google/IO/Curl.php CHANGED
@@ -16,14 +16,14 @@
16
*/
17
18
/**
19
- * Curl based implementation of Google_IO.
20
*
21
* @author Stuart Langley <slangley@google.com>
22
*/
23
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/IO/Abstract.php';
25
26
- class Google_IO_Curl extends Google_IO_Abstract
27
{
28
// hex for version 7.31.0
29
const NO_QUIRK_VERSION = 0x071F00;
@@ -32,12 +32,12 @@ class Google_IO_Curl extends Google_IO_Abstract
32
/**
33
* Execute an HTTP Request
34
*
35
- * @param Google_HttpRequest $request the http request to be executed
36
- * @return Google_HttpRequest http request with the response http code,
37
* response headers and response body filled in
38
- * @throws Google_IO_Exception on curl or IO error
39
*/
40
- public function executeRequest(Google_Http_Request $request)
41
{
42
$curl = curl_init();
43
@@ -78,7 +78,7 @@ class Google_IO_Curl extends Google_IO_Abstract
78
79
$response = curl_exec($curl);
80
if ($response === false) {
81
- throw new Google_IO_Exception(curl_error($curl));
82
}
83
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
84
@@ -130,6 +130,6 @@ class Google_IO_Curl extends Google_IO_Abstract
130
{
131
$ver = curl_version();
132
$versionNum = $ver['version_number'];
133
- return $versionNum < Google_IO_Curl::NO_QUIRK_VERSION;
134
}
135
}
16
*/
17
18
/**
19
+ * Curl based implementation of IWP_google_IO.
20
*
21
* @author Stuart Langley <slangley@google.com>
22
*/
23
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/IO/Abstract.php';
25
26
+ class IWP_google_IO_Curl extends IWP_google_IO_Abstract
27
{
28
// hex for version 7.31.0
29
const NO_QUIRK_VERSION = 0x071F00;
32
/**
33
* Execute an HTTP Request
34
*
35
+ * @param IWP_google_HttpRequest $request the http request to be executed
36
+ * @return IWP_google_HttpRequest http request with the response http code,
37
* response headers and response body filled in
38
+ * @throws IWP_google_IO_Exception on curl or IO error
39
*/
40
+ public function executeRequest(IWP_google_Http_Request $request)
41
{
42
$curl = curl_init();
43
78
79
$response = curl_exec($curl);
80
if ($response === false) {
81
+ throw new IWP_google_IO_Exception(curl_error($curl));
82
}
83
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
84
130
{
131
$ver = curl_version();
132
$versionNum = $ver['version_number'];
133
+ return $versionNum < IWP_google_IO_Curl::NO_QUIRK_VERSION;
134
}
135
}
lib/Google/IO/Exception.php CHANGED
@@ -17,6 +17,6 @@
17
18
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Exception.php';
19
20
- class Google_IO_Exception extends Google_Exception
21
{
22
}
17
18
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/Exception.php';
19
20
+ class IWP_google_IO_Exception extends IWP_google_Exception
21
{
22
}
lib/Google/IO/Stream.php CHANGED
@@ -16,14 +16,14 @@
16
*/
17
18
/**
19
- * Http Streams based implementation of Google_IO.
20
*
21
* @author Stuart Langley <slangley@google.com>
22
*/
23
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/IO/Abstract.php';
25
26
- class Google_IO_Stream extends Google_IO_Abstract
27
{
28
const TIMEOUT = "timeout";
29
const ZLIB = "compress.zlib://";
@@ -41,12 +41,12 @@ class Google_IO_Stream extends Google_IO_Abstract
41
/**
42
* Execute an HTTP Request
43
*
44
- * @param Google_HttpRequest $request the http request to be executed
45
- * @return Google_HttpRequest http request with the response http code,
46
* response headers and response body filled in
47
- * @throws Google_IO_Exception on curl or IO error
48
*/
49
- public function executeRequest(Google_Http_Request $request)
50
{
51
$default_options = stream_context_get_options(stream_context_get_default());
52
@@ -115,7 +115,7 @@ class Google_IO_Stream extends Google_IO_Abstract
115
}
116
117
if (false === $response_data) {
118
- throw new Google_IO_Exception(
119
sprintf(
120
"HTTP Error: Unable to connect: '%s'",
121
$respHttpCode
16
*/
17
18
/**
19
+ * Http Streams based implementation of IWP_google_IO.
20
*
21
* @author Stuart Langley <slangley@google.com>
22
*/
23
24
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Google/IO/Abstract.php';
25
26
+ class IWP_google_IO_Stream extends IWP_google_IO_Abstract
27
{
28
const TIMEOUT = "timeout";
29
const ZLIB = "compress.zlib://";
41
/**
42
* Execute an HTTP Request
43
*
44
+ * @param IWP_google_HttpRequest $request the http request to be executed
45
+ * @return IWP_google_HttpRequest http request with the response http code,
46
* response headers and response body filled in
47
+ * @throws IWP_google_IO_Exception on curl or IO error
48
*/
49
+ public function executeRequest(IWP_google_Http_Request $request)
50
{
51
$default_options = stream_context_get_options(stream_context_get_default());
52
115
}
116
117
if (false === $response_data) {
118
+ throw new IWP_google_IO_Exception(
119
sprintf(
120
"HTTP Error: Unable to connect: '%s'",
121
$respHttpCode
lib/Google/Model.php CHANGED
@@ -23,7 +23,7 @@
23
* @author Chirag Shah <chirags@google.com>
24
*
25
*/
26
- class Google_Model implements ArrayAccess
27
{
28
protected $modelData = array();
29
protected $processed = array();
@@ -92,7 +92,7 @@ class Google_Model implements ArrayAccess
92
property_exists($this, $key)) {
93
$this->$key = $val;
94
unset($array[$key]);
95
- } elseif (property_exists($this, $camelKey = Google_Utils::camelCase($key))) {
96
// This checks if property exists as camelCase, leaving it in array as snake_case
97
// in case of backwards compatibility issues.
98
$this->$camelKey = $val;
@@ -139,7 +139,7 @@ class Google_Model implements ArrayAccess
139
*/
140
private function getSimpleValue($value)
141
{
142
- if ($value instanceof Google_Model) {
143
return $value->toSimpleObject();
144
} else if (is_array($value)) {
145
$return = array();
@@ -188,14 +188,14 @@ class Google_Model implements ArrayAccess
188
189
/**
190
* Verify if $obj is an array.
191
- * @throws Google_Exception Thrown if $obj isn't an array.
192
* @param array $obj Items that should be validated.
193
* @param string $method Method expecting an array as an argument.
194
*/
195
public function assertIsArray($obj, $method)
196
{
197
if ($obj && !is_array($obj)) {
198
- throw new Google_Exception(
199
"Incorrect parameter type passed to $method(). Expected an array."
200
);
201
}
23
* @author Chirag Shah <chirags@google.com>
24
*
25
*/
26
+ class IWP_google_Model implements ArrayAccess
27
{
28
protected $modelData = array();
29
protected $processed = array();
92
property_exists($this, $key)) {
93
$this->$key = $val;
94
unset($array[$key]);
95
+ } elseif (property_exists($this, $camelKey = IWP_google_Utils::camelCase($key))) {
96
// This checks if property exists as camelCase, leaving it in array as snake_case
97
// in case of backwards compatibility issues.
98
$this->$camelKey = $val;
139
*/
140
private function getSimpleValue($value)
141
{
142
+ if ($value instanceof IWP_google_Model) {
143
return $value->toSimpleObject();
144
} else if (is_array($value)) {
145
$return = array();
188
189
/**
190
* Verify if $obj is an array.
191
+ * @throws IWP_google_Exception Thrown if $obj isn't an array.
192
* @param array $obj Items that should be validated.
193
* @param string $method Method expecting an array as an argument.
194
*/
195
public function assertIsArray($obj, $method)
196
{
197
if ($obj && !is_array($obj)) {
198
+ throw new IWP_google_Exception(
199
"Incorrect parameter type passed to $method(). Expected an array."
200
);
201
}
lib/Google/Service.php CHANGED
@@ -15,7 +15,7 @@
15
* limitations under the License.
16
*/
17
18
- class Google_Service
19
{
20
public $version;
21
public $servicePath;
@@ -23,14 +23,14 @@ class Google_Service
23
public $resource;
24
private $client;
25
26
- public function __construct(Google_Client $client)
27
{
28
$this->client = $client;
29
}
30
31
/**
32
- * Return the associated Google_Client class.
33
- * @return Google_Client
34
*/
35
public function getClient()
36
{
15
* limitations under the License.
16
*/
17
18
+ class IWP_google_Service
19
{
20
public $version;
21
public $servicePath;
23
public $resource;
24
private $client;
25
26
+ public function __construct(IWP_google_Client $client)
27
{
28
$this->client = $client;
29
}
30
31
/**
32
+ * Return the associated IWP_google_Client class.
33
+ * @return IWP_google_Client
34
*/
35
public function getClient()
36
{
lib/Google/Service/Drive.php CHANGED
@@ -29,7 +29,7 @@
29
*
30
* @author Google, Inc.
31
*/
32
- class Google_Service_Drive extends Google_Service
33
{
34
/** View and manage the files and documents in your Google Drive. */
35
const DRIVE = "https://www.googleapis.com/auth/drive";
@@ -64,16 +64,16 @@ class Google_Service_Drive extends Google_Service
64
/**
65
* Constructs the internal representation of the Drive service.
66
*
67
- * @param Google_Client $client
68
*/
69
- public function __construct(Google_Client $client)
70
{
71
parent::__construct($client);
72
$this->servicePath = 'drive/v2/';
73
$this->version = 'v2';
74
$this->serviceName = 'drive';
75
76
- $this->about = new Google_Service_Drive_About_Resource(
77
$this,
78
$this->serviceName,
79
'about',
@@ -100,7 +100,7 @@ class Google_Service_Drive extends Google_Service
100
)
101
)
102
);
103
- $this->apps = new Google_Service_Drive_Apps_Resource(
104
$this,
105
$this->serviceName,
106
'apps',
@@ -124,7 +124,7 @@ class Google_Service_Drive extends Google_Service
124
)
125
)
126
);
127
- $this->changes = new Google_Service_Drive_Changes_Resource(
128
$this,
129
$this->serviceName,
130
'changes',
@@ -194,7 +194,7 @@ class Google_Service_Drive extends Google_Service
194
)
195
)
196
);
197
- $this->channels = new Google_Service_Drive_Channels_Resource(
198
$this,
199
$this->serviceName,
200
'channels',
@@ -208,7 +208,7 @@ class Google_Service_Drive extends Google_Service
208
)
209
)
210
);
211
- $this->children = new Google_Service_Drive_Children_Resource(
212
$this,
213
$this->serviceName,
214
'children',
@@ -280,7 +280,7 @@ class Google_Service_Drive extends Google_Service
280
)
281
)
282
);
283
- $this->comments = new Google_Service_Drive_Comments_Resource(
284
$this,
285
$this->serviceName,
286
'comments',
@@ -390,7 +390,7 @@ class Google_Service_Drive extends Google_Service
390
)
391
)
392
);
393
- $this->files = new Google_Service_Drive_Files_Resource(
394
$this,
395
$this->serviceName,
396
'files',
@@ -672,7 +672,7 @@ class Google_Service_Drive extends Google_Service
672
)
673
)
674
);
675
- $this->parents = new Google_Service_Drive_Parents_Resource(
676
$this,
677
$this->serviceName,
678
'parents',
@@ -732,7 +732,7 @@ class Google_Service_Drive extends Google_Service
732
)
733
)
734
);
735
- $this->permissions = new Google_Service_Drive_Permissions_Resource(
736
$this,
737