Passed
Branch master (e94900)
by judicael
03:54
created
bundles/ext/facebook/base_facebook.php 1 patch
Indentation   +739 added lines, -739 removed lines patch added patch discarded remove patch
@@ -40,24 +40,24 @@  discard block
 block discarded – undo
40 40
    * @param array $result The result from the API server
41 41
    */
42 42
   public function __construct($result) {
43
-    $this->result = $result;
44
-
45
-    $code = isset($result['error_code']) ? $result['error_code'] : 0;
46
-
47
-    if (isset($result['error_description'])) {
48
-      // OAuth 2.0 Draft 10 style
49
-      $msg = $result['error_description'];
50
-    } else if (isset($result['error']) && is_array($result['error'])) {
51
-      // OAuth 2.0 Draft 00 style
52
-      $msg = $result['error']['message'];
53
-    } else if (isset($result['error_msg'])) {
54
-      // Rest server style
55
-      $msg = $result['error_msg'];
56
-    } else {
57
-      $msg = 'Unknown Error. Check getResult()';
58
-    }
59
-
60
-    parent::__construct($msg, $code);
43
+	$this->result = $result;
44
+
45
+	$code = isset($result['error_code']) ? $result['error_code'] : 0;
46
+
47
+	if (isset($result['error_description'])) {
48
+	  // OAuth 2.0 Draft 10 style
49
+	  $msg = $result['error_description'];
50
+	} else if (isset($result['error']) && is_array($result['error'])) {
51
+	  // OAuth 2.0 Draft 00 style
52
+	  $msg = $result['error']['message'];
53
+	} else if (isset($result['error_msg'])) {
54
+	  // Rest server style
55
+	  $msg = $result['error_msg'];
56
+	} else {
57
+	  $msg = 'Unknown Error. Check getResult()';
58
+	}
59
+
60
+	parent::__construct($msg, $code);
61 61
   }
62 62
 
63 63
   /**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
    * @return array The result from the API server
67 67
    */
68 68
   public function getResult() {
69
-    return $this->result;
69
+	return $this->result;
70 70
   }
71 71
 
72 72
   /**
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
    * @return string
77 77
    */
78 78
   public function getType() {
79
-    if (isset($this->result['error'])) {
80
-      $error = $this->result['error'];
81
-      if (is_string($error)) {
82
-        // OAuth 2.0 Draft 10 style
83
-        return $error;
84
-      } else if (is_array($error)) {
85
-        // OAuth 2.0 Draft 00 style
86
-        if (isset($error['type'])) {
87
-          return $error['type'];
88
-        }
89
-      }
90
-    }
91
-
92
-    return 'Exception';
79
+	if (isset($this->result['error'])) {
80
+	  $error = $this->result['error'];
81
+	  if (is_string($error)) {
82
+		// OAuth 2.0 Draft 10 style
83
+		return $error;
84
+	  } else if (is_array($error)) {
85
+		// OAuth 2.0 Draft 00 style
86
+		if (isset($error['type'])) {
87
+		  return $error['type'];
88
+		}
89
+	  }
90
+	}
91
+
92
+	return 'Exception';
93 93
   }
94 94
 
95 95
   /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
    * @return string The string representation of the error
99 99
    */
100 100
   public function __toString() {
101
-    $str = $this->getType() . ': ';
102
-    if ($this->code != 0) {
103
-      $str .= $this->code . ': ';
104
-    }
105
-    return $str . $this->message;
101
+	$str = $this->getType() . ': ';
102
+	if ($this->code != 0) {
103
+	  $str .= $this->code . ': ';
104
+	}
105
+	return $str . $this->message;
106 106
   }
107 107
 }
108 108
 
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
    * Default options for curl.
132 132
    */
133 133
   public static $CURL_OPTS = array(
134
-    CURLOPT_CONNECTTIMEOUT => 10,
135
-    CURLOPT_RETURNTRANSFER => true,
136
-    CURLOPT_TIMEOUT        => 60,
137
-    CURLOPT_USERAGENT      => 'facebook-php-3.2',
134
+	CURLOPT_CONNECTTIMEOUT => 10,
135
+	CURLOPT_RETURNTRANSFER => true,
136
+	CURLOPT_TIMEOUT        => 60,
137
+	CURLOPT_USERAGENT      => 'facebook-php-3.2',
138 138
   );
139 139
 
140 140
   /**
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
    * the current URL.
143 143
    */
144 144
   protected static $DROP_QUERY_PARAMS = array(
145
-    'code',
146
-    'state',
147
-    'signed_request',
145
+	'code',
146
+	'state',
147
+	'signed_request',
148 148
   );
149 149
 
150 150
   /**
151 151
    * Maps aliases to Facebook domains.
152 152
    */
153 153
   public static $DOMAIN_MAP = array(
154
-    'api'         => 'https://api.facebook.com/',
155
-    'api_video'   => 'https://api-video.facebook.com/',
156
-    'api_read'    => 'https://api-read.facebook.com/',
157
-    'graph'       => 'https://graph.facebook.com/',
158
-    'graph_video' => 'https://graph-video.facebook.com/',
159
-    'www'         => 'https://www.facebook.com/',
154
+	'api'         => 'https://api.facebook.com/',
155
+	'api_video'   => 'https://api-video.facebook.com/',
156
+	'api_read'    => 'https://api-read.facebook.com/',
157
+	'graph'       => 'https://graph.facebook.com/',
158
+	'graph_video' => 'https://graph-video.facebook.com/',
159
+	'www'         => 'https://www.facebook.com/',
160 160
   );
161 161
 
162 162
   /**
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
    * @param array $config The application configuration
224 224
    */
225 225
   public function __construct($config) {
226
-    $this->setAppId($config['appId']);
227
-    $this->setAppSecret($config['secret']);
228
-    if (isset($config['fileUpload'])) {
229
-      $this->setFileUploadSupport($config['fileUpload']);
230
-    }
231
-    if (isset($config['trustForwarded']) && $config['trustForwarded']) {
232
-      $this->trustForwarded = true;
233
-    }
234
-    $state = $this->getPersistentData('state');
235
-    if (!empty($state)) {
236
-      $this->state = $state;
237
-    }
226
+	$this->setAppId($config['appId']);
227
+	$this->setAppSecret($config['secret']);
228
+	if (isset($config['fileUpload'])) {
229
+	  $this->setFileUploadSupport($config['fileUpload']);
230
+	}
231
+	if (isset($config['trustForwarded']) && $config['trustForwarded']) {
232
+	  $this->trustForwarded = true;
233
+	}
234
+	$state = $this->getPersistentData('state');
235
+	if (!empty($state)) {
236
+	  $this->state = $state;
237
+	}
238 238
   }
239 239
 
240 240
   /**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
    * @return BaseFacebook
245 245
    */
246 246
   public function setAppId($appId) {
247
-    $this->appId = $appId;
248
-    return $this;
247
+	$this->appId = $appId;
248
+	return $this;
249 249
   }
250 250
 
251 251
   /**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
    * @return string the Application ID
255 255
    */
256 256
   public function getAppId() {
257
-    return $this->appId;
257
+	return $this->appId;
258 258
   }
259 259
 
260 260
   /**
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
    * @deprecated
266 266
    */
267 267
   public function setApiSecret($apiSecret) {
268
-    $this->setAppSecret($apiSecret);
269
-    return $this;
268
+	$this->setAppSecret($apiSecret);
269
+	return $this;
270 270
   }
271 271
 
272 272
   /**
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
    * @return BaseFacebook
277 277
    */
278 278
   public function setAppSecret($appSecret) {
279
-    $this->appSecret = $appSecret;
280
-    return $this;
279
+	$this->appSecret = $appSecret;
280
+	return $this;
281 281
   }
282 282
 
283 283
   /**
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
    * @deprecated
288 288
    */
289 289
   public function getApiSecret() {
290
-    return $this->getAppSecret();
290
+	return $this->getAppSecret();
291 291
   }
292 292
 
293 293
   /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
    * @return string the App Secret
297 297
    */
298 298
   public function getAppSecret() {
299
-    return $this->appSecret;
299
+	return $this->appSecret;
300 300
   }
301 301
 
302 302
   /**
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
    * @return BaseFacebook
307 307
    */
308 308
   public function setFileUploadSupport($fileUploadSupport) {
309
-    $this->fileUploadSupport = $fileUploadSupport;
310
-    return $this;
309
+	$this->fileUploadSupport = $fileUploadSupport;
310
+	return $this;
311 311
   }
312 312
 
313 313
   /**
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
    * @return boolean true if and only if the server supports file upload.
317 317
    */
318 318
   public function getFileUploadSupport() {
319
-    return $this->fileUploadSupport;
319
+	return $this->fileUploadSupport;
320 320
   }
321 321
 
322 322
   /**
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
    * @return boolean true if and only if the server supports file upload.
328 328
    */
329 329
   public function useFileUploadSupport() {
330
-    return $this->getFileUploadSupport();
330
+	return $this->getFileUploadSupport();
331 331
   }
332 332
 
333 333
   /**
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
    * @return BaseFacebook
340 340
    */
341 341
   public function setAccessToken($access_token) {
342
-    $this->accessToken = $access_token;
343
-    return $this;
342
+	$this->accessToken = $access_token;
343
+	return $this;
344 344
   }
345 345
 
346 346
   /**
@@ -349,41 +349,41 @@  discard block
 block discarded – undo
349 349
    * for the workaround.
350 350
    */
351 351
   public function setExtendedAccessToken() {
352
-    try {
353
-      // need to circumvent json_decode by calling _oauthRequest
354
-      // directly, since response isn't JSON format.
355
-      $access_token_response = $this->_oauthRequest(
356
-        $this->getUrl('graph', '/oauth/access_token'),
357
-        $params = array(
358
-          'client_id' => $this->getAppId(),
359
-          'client_secret' => $this->getAppSecret(),
360
-          'grant_type' => 'fb_exchange_token',
361
-          'fb_exchange_token' => $this->getAccessToken(),
362
-        )
363
-      );
364
-    }
365
-    catch (FacebookApiException $e) {
366
-      // most likely that user very recently revoked authorization.
367
-      // In any event, we don't have an access token, so say so.
368
-      return false;
369
-    }
370
-
371
-    if (empty($access_token_response)) {
372
-      return false;
373
-    }
374
-
375
-    $response_params = array();
376
-    parse_str($access_token_response, $response_params);
377
-
378
-    if (!isset($response_params['access_token'])) {
379
-      return false;
380
-    }
381
-
382
-    $this->destroySession();
383
-
384
-    $this->setPersistentData(
385
-      'access_token', $response_params['access_token']
386
-    );
352
+	try {
353
+	  // need to circumvent json_decode by calling _oauthRequest
354
+	  // directly, since response isn't JSON format.
355
+	  $access_token_response = $this->_oauthRequest(
356
+		$this->getUrl('graph', '/oauth/access_token'),
357
+		$params = array(
358
+		  'client_id' => $this->getAppId(),
359
+		  'client_secret' => $this->getAppSecret(),
360
+		  'grant_type' => 'fb_exchange_token',
361
+		  'fb_exchange_token' => $this->getAccessToken(),
362
+		)
363
+	  );
364
+	}
365
+	catch (FacebookApiException $e) {
366
+	  // most likely that user very recently revoked authorization.
367
+	  // In any event, we don't have an access token, so say so.
368
+	  return false;
369
+	}
370
+
371
+	if (empty($access_token_response)) {
372
+	  return false;
373
+	}
374
+
375
+	$response_params = array();
376
+	parse_str($access_token_response, $response_params);
377
+
378
+	if (!isset($response_params['access_token'])) {
379
+	  return false;
380
+	}
381
+
382
+	$this->destroySession();
383
+
384
+	$this->setPersistentData(
385
+	  'access_token', $response_params['access_token']
386
+	);
387 387
   }
388 388
 
389 389
   /**
@@ -396,21 +396,21 @@  discard block
 block discarded – undo
396 396
    * @return string The access token
397 397
    */
398 398
   public function getAccessToken() {
399
-    if ($this->accessToken !== null) {
400
-      // we've done this already and cached it.  Just return.
401
-      return $this->accessToken;
402
-    }
403
-
404
-    // first establish access token to be the application
405
-    // access token, in case we navigate to the /oauth/access_token
406
-    // endpoint, where SOME access token is required.
407
-    $this->setAccessToken($this->getApplicationAccessToken());
408
-    $user_access_token = $this->getUserAccessToken();
409
-    if ($user_access_token) {
410
-      $this->setAccessToken($user_access_token);
411
-    }
412
-
413
-    return $this->accessToken;
399
+	if ($this->accessToken !== null) {
400
+	  // we've done this already and cached it.  Just return.
401
+	  return $this->accessToken;
402
+	}
403
+
404
+	// first establish access token to be the application
405
+	// access token, in case we navigate to the /oauth/access_token
406
+	// endpoint, where SOME access token is required.
407
+	$this->setAccessToken($this->getApplicationAccessToken());
408
+	$user_access_token = $this->getUserAccessToken();
409
+	if ($user_access_token) {
410
+	  $this->setAccessToken($user_access_token);
411
+	}
412
+
413
+	return $this->accessToken;
414 414
   }
415 415
 
416 416
   /**
@@ -424,60 +424,60 @@  discard block
 block discarded – undo
424 424
    *                could not be determined.
425 425
    */
426 426
   protected function getUserAccessToken() {
427
-    // first, consider a signed request if it's supplied.
428
-    // if there is a signed request, then it alone determines
429
-    // the access token.
430
-    $signed_request = $this->getSignedRequest();
431
-    if ($signed_request) {
432
-      // apps.facebook.com hands the access_token in the signed_request
433
-      if (array_key_exists('oauth_token', $signed_request)) {
434
-        $access_token = $signed_request['oauth_token'];
435
-        $this->setPersistentData('access_token', $access_token);
436
-        return $access_token;
437
-      }
438
-
439
-      // the JS SDK puts a code in with the redirect_uri of ''
440
-      if (array_key_exists('code', $signed_request)) {
441
-        $code = $signed_request['code'];
442
-        if ($code && $code == $this->getPersistentData('code')) {
443
-          // short-circuit if the code we have is the same as the one presented
444
-          return $this->getPersistentData('access_token');
445
-        }
446
-
447
-        $access_token = $this->getAccessTokenFromCode($code, '');
448
-        if ($access_token) {
449
-          $this->setPersistentData('code', $code);
450
-          $this->setPersistentData('access_token', $access_token);
451
-          return $access_token;
452
-        }
453
-      }
454
-
455
-      // signed request states there's no access token, so anything
456
-      // stored should be cleared.
457
-      $this->clearAllPersistentData();
458
-      return false; // respect the signed request's data, even
459
-                    // if there's an authorization code or something else
460
-    }
461
-
462
-    $code = $this->getCode();
463
-    if ($code && $code != $this->getPersistentData('code')) {
464
-      $access_token = $this->getAccessTokenFromCode($code);
465
-      if ($access_token) {
466
-        $this->setPersistentData('code', $code);
467
-        $this->setPersistentData('access_token', $access_token);
468
-        return $access_token;
469
-      }
470
-
471
-      // code was bogus, so everything based on it should be invalidated.
472
-      $this->clearAllPersistentData();
473
-      return false;
474
-    }
475
-
476
-    // as a fallback, just return whatever is in the persistent
477
-    // store, knowing nothing explicit (signed request, authorization
478
-    // code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
479
-    // but it's the same as what's in the persistent store)
480
-    return $this->getPersistentData('access_token');
427
+	// first, consider a signed request if it's supplied.
428
+	// if there is a signed request, then it alone determines
429
+	// the access token.
430
+	$signed_request = $this->getSignedRequest();
431
+	if ($signed_request) {
432
+	  // apps.facebook.com hands the access_token in the signed_request
433
+	  if (array_key_exists('oauth_token', $signed_request)) {
434
+		$access_token = $signed_request['oauth_token'];
435
+		$this->setPersistentData('access_token', $access_token);
436
+		return $access_token;
437
+	  }
438
+
439
+	  // the JS SDK puts a code in with the redirect_uri of ''
440
+	  if (array_key_exists('code', $signed_request)) {
441
+		$code = $signed_request['code'];
442
+		if ($code && $code == $this->getPersistentData('code')) {
443
+		  // short-circuit if the code we have is the same as the one presented
444
+		  return $this->getPersistentData('access_token');
445
+		}
446
+
447
+		$access_token = $this->getAccessTokenFromCode($code, '');
448
+		if ($access_token) {
449
+		  $this->setPersistentData('code', $code);
450
+		  $this->setPersistentData('access_token', $access_token);
451
+		  return $access_token;
452
+		}
453
+	  }
454
+
455
+	  // signed request states there's no access token, so anything
456
+	  // stored should be cleared.
457
+	  $this->clearAllPersistentData();
458
+	  return false; // respect the signed request's data, even
459
+					// if there's an authorization code or something else
460
+	}
461
+
462
+	$code = $this->getCode();
463
+	if ($code && $code != $this->getPersistentData('code')) {
464
+	  $access_token = $this->getAccessTokenFromCode($code);
465
+	  if ($access_token) {
466
+		$this->setPersistentData('code', $code);
467
+		$this->setPersistentData('access_token', $access_token);
468
+		return $access_token;
469
+	  }
470
+
471
+	  // code was bogus, so everything based on it should be invalidated.
472
+	  $this->clearAllPersistentData();
473
+	  return false;
474
+	}
475
+
476
+	// as a fallback, just return whatever is in the persistent
477
+	// store, knowing nothing explicit (signed request, authorization
478
+	// code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
479
+	// but it's the same as what's in the persistent store)
480
+	return $this->getPersistentData('access_token');
481 481
   }
482 482
 
483 483
   /**
@@ -487,16 +487,16 @@  discard block
 block discarded – undo
487 487
    * @return string the signed request, if available, or null otherwise.
488 488
    */
489 489
   public function getSignedRequest() {
490
-    if (!$this->signedRequest) {
491
-      if (!empty($_REQUEST['signed_request'])) {
492
-        $this->signedRequest = $this->parseSignedRequest(
493
-          $_REQUEST['signed_request']);
494
-      } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
495
-        $this->signedRequest = $this->parseSignedRequest(
496
-          $_COOKIE[$this->getSignedRequestCookieName()]);
497
-      }
498
-    }
499
-    return $this->signedRequest;
490
+	if (!$this->signedRequest) {
491
+	  if (!empty($_REQUEST['signed_request'])) {
492
+		$this->signedRequest = $this->parseSignedRequest(
493
+		  $_REQUEST['signed_request']);
494
+	  } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
495
+		$this->signedRequest = $this->parseSignedRequest(
496
+		  $_COOKIE[$this->getSignedRequestCookieName()]);
497
+	  }
498
+	}
499
+	return $this->signedRequest;
500 500
   }
501 501
 
502 502
   /**
@@ -506,12 +506,12 @@  discard block
 block discarded – undo
506 506
    * @return string the UID if available.
507 507
    */
508 508
   public function getUser() {
509
-    if ($this->user !== null) {
510
-      // we've already determined this and cached the value.
511
-      return $this->user;
512
-    }
509
+	if ($this->user !== null) {
510
+	  // we've already determined this and cached the value.
511
+	  return $this->user;
512
+	}
513 513
 
514
-    return $this->user = $this->getUserFromAvailableData();
514
+	return $this->user = $this->getUserFromAvailableData();
515 515
   }
516 516
 
517 517
   /**
@@ -523,45 +523,45 @@  discard block
 block discarded – undo
523 523
    *                 or 0 if no such user exists.
524 524
    */
525 525
   protected function getUserFromAvailableData() {
526
-    // if a signed request is supplied, then it solely determines
527
-    // who the user is.
528
-    $signed_request = $this->getSignedRequest();
529
-    if ($signed_request) {
530
-      if (array_key_exists('user_id', $signed_request)) {
531
-        $user = $signed_request['user_id'];
532
-
533
-        if($user != $this->getPersistentData('user_id')){
534
-          $this->clearAllPersistentData();
535
-        }
536
-
537
-        $this->setPersistentData('user_id', $signed_request['user_id']);
538
-        return $user;
539
-      }
540
-
541
-      // if the signed request didn't present a user id, then invalidate
542
-      // all entries in any persistent store.
543
-      $this->clearAllPersistentData();
544
-      return 0;
545
-    }
546
-
547
-    $user = $this->getPersistentData('user_id', $default = 0);
548
-    $persisted_access_token = $this->getPersistentData('access_token');
549
-
550
-    // use access_token to fetch user id if we have a user access_token, or if
551
-    // the cached access token has changed.
552
-    $access_token = $this->getAccessToken();
553
-    if ($access_token &&
554
-        $access_token != $this->getApplicationAccessToken() &&
555
-        !($user && $persisted_access_token == $access_token)) {
556
-      $user = $this->getUserFromAccessToken();
557
-      if ($user) {
558
-        $this->setPersistentData('user_id', $user);
559
-      } else {
560
-        $this->clearAllPersistentData();
561
-      }
562
-    }
563
-
564
-    return $user;
526
+	// if a signed request is supplied, then it solely determines
527
+	// who the user is.
528
+	$signed_request = $this->getSignedRequest();
529
+	if ($signed_request) {
530
+	  if (array_key_exists('user_id', $signed_request)) {
531
+		$user = $signed_request['user_id'];
532
+
533
+		if($user != $this->getPersistentData('user_id')){
534
+		  $this->clearAllPersistentData();
535
+		}
536
+
537
+		$this->setPersistentData('user_id', $signed_request['user_id']);
538
+		return $user;
539
+	  }
540
+
541
+	  // if the signed request didn't present a user id, then invalidate
542
+	  // all entries in any persistent store.
543
+	  $this->clearAllPersistentData();
544
+	  return 0;
545
+	}
546
+
547
+	$user = $this->getPersistentData('user_id', $default = 0);
548
+	$persisted_access_token = $this->getPersistentData('access_token');
549
+
550
+	// use access_token to fetch user id if we have a user access_token, or if
551
+	// the cached access token has changed.
552
+	$access_token = $this->getAccessToken();
553
+	if ($access_token &&
554
+		$access_token != $this->getApplicationAccessToken() &&
555
+		!($user && $persisted_access_token == $access_token)) {
556
+	  $user = $this->getUserFromAccessToken();
557
+	  if ($user) {
558
+		$this->setPersistentData('user_id', $user);
559
+	  } else {
560
+		$this->clearAllPersistentData();
561
+	  }
562
+	}
563
+
564
+	return $user;
565 565
   }
566 566
 
567 567
   /**
@@ -577,23 +577,23 @@  discard block
 block discarded – undo
577 577
    * @return string The URL for the login flow
578 578
    */
579 579
   public function getLoginUrl($params=array()) {
580
-    $this->establishCSRFTokenState();
581
-    $currentUrl = $this->getCurrentUrl();
582
-
583
-    // if 'scope' is passed as an array, convert to comma separated list
584
-    $scopeParams = isset($params['scope']) ? $params['scope'] : null;
585
-    if ($scopeParams && is_array($scopeParams)) {
586
-      $params['scope'] = implode(',', $scopeParams);
587
-    }
588
-
589
-    return $this->getUrl(
590
-      'www',
591
-      'dialog/oauth',
592
-      array_merge(array(
593
-                    'client_id' => $this->getAppId(),
594
-                    'redirect_uri' => $currentUrl, // possibly overwritten
595
-                    'state' => $this->state),
596
-                  $params));
580
+	$this->establishCSRFTokenState();
581
+	$currentUrl = $this->getCurrentUrl();
582
+
583
+	// if 'scope' is passed as an array, convert to comma separated list
584
+	$scopeParams = isset($params['scope']) ? $params['scope'] : null;
585
+	if ($scopeParams && is_array($scopeParams)) {
586
+	  $params['scope'] = implode(',', $scopeParams);
587
+	}
588
+
589
+	return $this->getUrl(
590
+	  'www',
591
+	  'dialog/oauth',
592
+	  array_merge(array(
593
+					'client_id' => $this->getAppId(),
594
+					'redirect_uri' => $currentUrl, // possibly overwritten
595
+					'state' => $this->state),
596
+				  $params));
597 597
   }
598 598
 
599 599
   /**
@@ -606,14 +606,14 @@  discard block
 block discarded – undo
606 606
    * @return string The URL for the logout flow
607 607
    */
608 608
   public function getLogoutUrl($params=array()) {
609
-    return $this->getUrl(
610
-      'www',
611
-      'logout.php',
612
-      array_merge(array(
613
-        'next' => $this->getCurrentUrl(),
614
-        'access_token' => $this->getUserAccessToken(),
615
-      ), $params)
616
-    );
609
+	return $this->getUrl(
610
+	  'www',
611
+	  'logout.php',
612
+	  array_merge(array(
613
+		'next' => $this->getCurrentUrl(),
614
+		'access_token' => $this->getUserAccessToken(),
615
+	  ), $params)
616
+	);
617 617
   }
618 618
 
619 619
   /**
@@ -628,17 +628,17 @@  discard block
 block discarded – undo
628 628
    * @return string The URL for the logout flow
629 629
    */
630 630
   public function getLoginStatusUrl($params=array()) {
631
-    return $this->getUrl(
632
-      'www',
633
-      'extern/login_status.php',
634
-      array_merge(array(
635
-        'api_key' => $this->getAppId(),
636
-        'no_session' => $this->getCurrentUrl(),
637
-        'no_user' => $this->getCurrentUrl(),
638
-        'ok_session' => $this->getCurrentUrl(),
639
-        'session_version' => 3,
640
-      ), $params)
641
-    );
631
+	return $this->getUrl(
632
+	  'www',
633
+	  'extern/login_status.php',
634
+	  array_merge(array(
635
+		'api_key' => $this->getAppId(),
636
+		'no_session' => $this->getCurrentUrl(),
637
+		'no_user' => $this->getCurrentUrl(),
638
+		'ok_session' => $this->getCurrentUrl(),
639
+		'session_version' => 3,
640
+	  ), $params)
641
+	);
642 642
   }
643 643
 
644 644
   /**
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
    * @return mixed The decoded response
648 648
    */
649 649
   public function api(/* polymorphic */) {
650
-    $args = func_get_args();
651
-    if (is_array($args[0])) {
652
-      return $this->_restserver($args[0]);
653
-    } else {
654
-      return call_user_func_array(array($this, '_graph'), $args);
655
-    }
650
+	$args = func_get_args();
651
+	if (is_array($args[0])) {
652
+	  return $this->_restserver($args[0]);
653
+	} else {
654
+	  return call_user_func_array(array($this, '_graph'), $args);
655
+	}
656 656
   }
657 657
 
658 658
   /**
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
    *         the signed request value.
666 666
    */
667 667
   protected function getSignedRequestCookieName() {
668
-    return 'fbsr_'.$this->getAppId();
668
+	return 'fbsr_'.$this->getAppId();
669 669
   }
670 670
 
671 671
   /**
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
    * @return string the name of the cookie that would house metadata.
677 677
    */
678 678
   protected function getMetadataCookieName() {
679
-    return 'fbm_'.$this->getAppId();
679
+	return 'fbm_'.$this->getAppId();
680 680
   }
681 681
 
682 682
   /**
@@ -688,22 +688,22 @@  discard block
 block discarded – undo
688 688
    *               code could not be determined.
689 689
    */
690 690
   protected function getCode() {
691
-    if (isset($_REQUEST['code'])) {
692
-      if ($this->state !== null &&
693
-          isset($_REQUEST['state']) &&
694
-          $this->state === $_REQUEST['state']) {
695
-
696
-        // CSRF state has done its job, so clear it
697
-        $this->state = null;
698
-        $this->clearPersistentData('state');
699
-        return $_REQUEST['code'];
700
-      } else {
701
-        self::errorLog('CSRF state token does not match one provided.');
702
-        return false;
703
-      }
704
-    }
705
-
706
-    return false;
691
+	if (isset($_REQUEST['code'])) {
692
+	  if ($this->state !== null &&
693
+		  isset($_REQUEST['state']) &&
694
+		  $this->state === $_REQUEST['state']) {
695
+
696
+		// CSRF state has done its job, so clear it
697
+		$this->state = null;
698
+		$this->clearPersistentData('state');
699
+		return $_REQUEST['code'];
700
+	  } else {
701
+		self::errorLog('CSRF state token does not match one provided.');
702
+		return false;
703
+	  }
704
+	}
705
+
706
+	return false;
707 707
   }
708 708
 
709 709
   /**
@@ -717,12 +717,12 @@  discard block
 block discarded – undo
717 717
    *                 if the Facebook user could not be determined.
718 718
    */
719 719
   protected function getUserFromAccessToken() {
720
-    try {
721
-      $user_info = $this->api('/me');
722
-      return $user_info['id'];
723
-    } catch (FacebookApiException $e) {
724
-      return 0;
725
-    }
720
+	try {
721
+	  $user_info = $this->api('/me');
722
+	  return $user_info['id'];
723
+	} catch (FacebookApiException $e) {
724
+	  return 0;
725
+	}
726 726
   }
727 727
 
728 728
   /**
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
    *                public information about users and applications.
734 734
    */
735 735
   protected function getApplicationAccessToken() {
736
-    return $this->appId.'|'.$this->appSecret;
736
+	return $this->appId.'|'.$this->appSecret;
737 737
   }
738 738
 
739 739
   /**
@@ -742,10 +742,10 @@  discard block
 block discarded – undo
742 742
    * @return void
743 743
    */
744 744
   protected function establishCSRFTokenState() {
745
-    if ($this->state === null) {
746
-      $this->state = md5(uniqid(mt_rand(), true));
747
-      $this->setPersistentData('state', $this->state);
748
-    }
745
+	if ($this->state === null) {
746
+	  $this->state = md5(uniqid(mt_rand(), true));
747
+	  $this->setPersistentData('state', $this->state);
748
+	}
749 749
   }
750 750
 
751 751
   /**
@@ -761,41 +761,41 @@  discard block
 block discarded – undo
761 761
    *               false if an access token could not be generated.
762 762
    */
763 763
   protected function getAccessTokenFromCode($code, $redirect_uri = null) {
764
-    if (empty($code)) {
765
-      return false;
766
-    }
767
-
768
-    if ($redirect_uri === null) {
769
-      $redirect_uri = $this->getCurrentUrl();
770
-    }
771
-
772
-    try {
773
-      // need to circumvent json_decode by calling _oauthRequest
774
-      // directly, since response isn't JSON format.
775
-      $access_token_response =
776
-        $this->_oauthRequest(
777
-          $this->getUrl('graph', '/oauth/access_token'),
778
-          $params = array('client_id' => $this->getAppId(),
779
-                          'client_secret' => $this->getAppSecret(),
780
-                          'redirect_uri' => $redirect_uri,
781
-                          'code' => $code));
782
-    } catch (FacebookApiException $e) {
783
-      // most likely that user very recently revoked authorization.
784
-      // In any event, we don't have an access token, so say so.
785
-      return false;
786
-    }
787
-
788
-    if (empty($access_token_response)) {
789
-      return false;
790
-    }
791
-
792
-    $response_params = array();
793
-    parse_str($access_token_response, $response_params);
794
-    if (!isset($response_params['access_token'])) {
795
-      return false;
796
-    }
797
-
798
-    return $response_params['access_token'];
764
+	if (empty($code)) {
765
+	  return false;
766
+	}
767
+
768
+	if ($redirect_uri === null) {
769
+	  $redirect_uri = $this->getCurrentUrl();
770
+	}
771
+
772
+	try {
773
+	  // need to circumvent json_decode by calling _oauthRequest
774
+	  // directly, since response isn't JSON format.
775
+	  $access_token_response =
776
+		$this->_oauthRequest(
777
+		  $this->getUrl('graph', '/oauth/access_token'),
778
+		  $params = array('client_id' => $this->getAppId(),
779
+						  'client_secret' => $this->getAppSecret(),
780
+						  'redirect_uri' => $redirect_uri,
781
+						  'code' => $code));
782
+	} catch (FacebookApiException $e) {
783
+	  // most likely that user very recently revoked authorization.
784
+	  // In any event, we don't have an access token, so say so.
785
+	  return false;
786
+	}
787
+
788
+	if (empty($access_token_response)) {
789
+	  return false;
790
+	}
791
+
792
+	$response_params = array();
793
+	parse_str($access_token_response, $response_params);
794
+	if (!isset($response_params['access_token'])) {
795
+	  return false;
796
+	}
797
+
798
+	return $response_params['access_token'];
799 799
   }
800 800
 
801 801
   /**
@@ -807,29 +807,29 @@  discard block
 block discarded – undo
807 807
    * @throws FacebookApiException
808 808
    */
809 809
   protected function _restserver($params) {
810
-    // generic application level parameters
811
-    $params['api_key'] = $this->getAppId();
812
-    $params['format'] = 'json-strings';
813
-
814
-    $result = json_decode($this->_oauthRequest(
815
-      $this->getApiUrl($params['method']),
816
-      $params
817
-    ), true);
818
-
819
-    // results are returned, errors are thrown
820
-    if (is_array($result) && isset($result['error_code'])) {
821
-      $this->throwAPIException($result);
822
-      // @codeCoverageIgnoreStart
823
-    }
824
-    // @codeCoverageIgnoreEnd
825
-
826
-    $method = strtolower($params['method']);
827
-    if ($method === 'auth.expiresession' ||
828
-        $method === 'auth.revokeauthorization') {
829
-      $this->destroySession();
830
-    }
831
-
832
-    return $result;
810
+	// generic application level parameters
811
+	$params['api_key'] = $this->getAppId();
812
+	$params['format'] = 'json-strings';
813
+
814
+	$result = json_decode($this->_oauthRequest(
815
+	  $this->getApiUrl($params['method']),
816
+	  $params
817
+	), true);
818
+
819
+	// results are returned, errors are thrown
820
+	if (is_array($result) && isset($result['error_code'])) {
821
+	  $this->throwAPIException($result);
822
+	  // @codeCoverageIgnoreStart
823
+	}
824
+	// @codeCoverageIgnoreEnd
825
+
826
+	$method = strtolower($params['method']);
827
+	if ($method === 'auth.expiresession' ||
828
+		$method === 'auth.revokeauthorization') {
829
+	  $this->destroySession();
830
+	}
831
+
832
+	return $result;
833 833
   }
834 834
 
835 835
   /**
@@ -841,10 +841,10 @@  discard block
 block discarded – undo
841 841
    * @return boolean true if this is video post
842 842
    */
843 843
   protected function isVideoPost($path, $method = 'GET') {
844
-    if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
845
-      return true;
846
-    }
847
-    return false;
844
+	if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
845
+	  return true;
846
+	}
847
+	return false;
848 848
   }
849 849
 
850 850
   /**
@@ -858,31 +858,31 @@  discard block
 block discarded – undo
858 858
    * @throws FacebookApiException
859 859
    */
860 860
   protected function _graph($path, $method = 'GET', $params = array()) {
861
-    if (is_array($method) && empty($params)) {
862
-      $params = $method;
863
-      $method = 'GET';
864
-    }
865
-    $params['method'] = $method; // method override as we always do a POST
866
-
867
-    if ($this->isVideoPost($path, $method)) {
868
-      $domainKey = 'graph_video';
869
-    } else {
870
-      $domainKey = 'graph';
871
-    }
872
-
873
-    $result = json_decode($this->_oauthRequest(
874
-      $this->getUrl($domainKey, $path),
875
-      $params
876
-    ), true);
877
-
878
-    // results are returned, errors are thrown
879
-    if (is_array($result) && isset($result['error'])) {
880
-      $this->throwAPIException($result);
881
-      // @codeCoverageIgnoreStart
882
-    }
883
-    // @codeCoverageIgnoreEnd
884
-
885
-    return $result;
861
+	if (is_array($method) && empty($params)) {
862
+	  $params = $method;
863
+	  $method = 'GET';
864
+	}
865
+	$params['method'] = $method; // method override as we always do a POST
866
+
867
+	if ($this->isVideoPost($path, $method)) {
868
+	  $domainKey = 'graph_video';
869
+	} else {
870
+	  $domainKey = 'graph';
871
+	}
872
+
873
+	$result = json_decode($this->_oauthRequest(
874
+	  $this->getUrl($domainKey, $path),
875
+	  $params
876
+	), true);
877
+
878
+	// results are returned, errors are thrown
879
+	if (is_array($result) && isset($result['error'])) {
880
+	  $this->throwAPIException($result);
881
+	  // @codeCoverageIgnoreStart
882
+	}
883
+	// @codeCoverageIgnoreEnd
884
+
885
+	return $result;
886 886
   }
887 887
 
888 888
   /**
@@ -895,22 +895,22 @@  discard block
 block discarded – undo
895 895
    * @throws FacebookApiException
896 896
    */
897 897
   protected function _oauthRequest($url, $params) {
898
-    if (!isset($params['access_token'])) {
899
-      $params['access_token'] = $this->getAccessToken();
900
-    }
901
-
902
-    if (isset($params['access_token'])) {
903
-      $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']);
904
-    }
905
-
906
-    // json_encode all params values that are not strings
907
-    foreach ($params as $key => $value) {
908
-      if (!is_string($value)) {
909
-        $params[$key] = json_encode($value);
910
-      }
911
-    }
912
-
913
-    return $this->makeRequest($url, $params);
898
+	if (!isset($params['access_token'])) {
899
+	  $params['access_token'] = $this->getAccessToken();
900
+	}
901
+
902
+	if (isset($params['access_token'])) {
903
+	  $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']);
904
+	}
905
+
906
+	// json_encode all params values that are not strings
907
+	foreach ($params as $key => $value) {
908
+	  if (!is_string($value)) {
909
+		$params[$key] = json_encode($value);
910
+	  }
911
+	}
912
+
913
+	return $this->makeRequest($url, $params);
914 914
   }
915 915
 
916 916
   /**
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
    * @return string The sha256 hash of the access_token
924 924
    */
925 925
   protected function getAppSecretProof($access_token) {
926
-    return hash_hmac('sha256', $access_token, $this->getAppSecret());
926
+	return hash_hmac('sha256', $access_token, $this->getAppSecret());
927 927
   }
928 928
 
929 929
   /**
@@ -938,71 +938,71 @@  discard block
 block discarded – undo
938 938
    * @return string The response text
939 939
    */
940 940
   protected function makeRequest($url, $params, $ch=null) {
941
-    if (!$ch) {
942
-      $ch = curl_init();
943
-    }
944
-
945
-    $opts = self::$CURL_OPTS;
946
-    if ($this->getFileUploadSupport()) {
947
-      $opts[CURLOPT_POSTFIELDS] = $params;
948
-    } else {
949
-      $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
950
-    }
951
-    $opts[CURLOPT_URL] = $url;
952
-
953
-    // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
954
-    // for 2 seconds if the server does not support this header.
955
-    if (isset($opts[CURLOPT_HTTPHEADER])) {
956
-      $existing_headers = $opts[CURLOPT_HTTPHEADER];
957
-      $existing_headers[] = 'Expect:';
958
-      $opts[CURLOPT_HTTPHEADER] = $existing_headers;
959
-    } else {
960
-      $opts[CURLOPT_HTTPHEADER] = array('Expect:');
961
-    }
962
-
963
-    curl_setopt_array($ch, $opts);
964
-    $result = curl_exec($ch);
965
-
966
-    if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
967
-      self::errorLog('Invalid or no certificate authority found, '.
968
-                     'using bundled information');
969
-      curl_setopt($ch, CURLOPT_CAINFO,
970
-                  dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
971
-      $result = curl_exec($ch);
972
-    }
973
-
974
-    // With dual stacked DNS responses, it's possible for a server to
975
-    // have IPv6 enabled but not have IPv6 connectivity.  If this is
976
-    // the case, curl will try IPv4 first and if that fails, then it will
977
-    // fall back to IPv6 and the error EHOSTUNREACH is returned by the
978
-    // operating system.
979
-    if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
980
-        $matches = array();
981
-        $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
982
-        if (preg_match($regex, curl_error($ch), $matches)) {
983
-          if (strlen(@inet_pton($matches[1])) === 16) {
984
-            self::errorLog('Invalid IPv6 configuration on server, '.
985
-                           'Please disable or get native IPv6 on your server.');
986
-            self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
987
-            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
988
-            $result = curl_exec($ch);
989
-          }
990
-        }
991
-    }
992
-
993
-    if ($result === false) {
994
-      $e = new FacebookApiException(array(
995
-        'error_code' => curl_errno($ch),
996
-        'error' => array(
997
-        'message' => curl_error($ch),
998
-        'type' => 'CurlException',
999
-        ),
1000
-      ));
1001
-      curl_close($ch);
1002
-      throw $e;
1003
-    }
1004
-    curl_close($ch);
1005
-    return $result;
941
+	if (!$ch) {
942
+	  $ch = curl_init();
943
+	}
944
+
945
+	$opts = self::$CURL_OPTS;
946
+	if ($this->getFileUploadSupport()) {
947
+	  $opts[CURLOPT_POSTFIELDS] = $params;
948
+	} else {
949
+	  $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
950
+	}
951
+	$opts[CURLOPT_URL] = $url;
952
+
953
+	// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
954
+	// for 2 seconds if the server does not support this header.
955
+	if (isset($opts[CURLOPT_HTTPHEADER])) {
956
+	  $existing_headers = $opts[CURLOPT_HTTPHEADER];
957
+	  $existing_headers[] = 'Expect:';
958
+	  $opts[CURLOPT_HTTPHEADER] = $existing_headers;
959
+	} else {
960
+	  $opts[CURLOPT_HTTPHEADER] = array('Expect:');
961
+	}
962
+
963
+	curl_setopt_array($ch, $opts);
964
+	$result = curl_exec($ch);
965
+
966
+	if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
967
+	  self::errorLog('Invalid or no certificate authority found, '.
968
+					 'using bundled information');
969
+	  curl_setopt($ch, CURLOPT_CAINFO,
970
+				  dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
971
+	  $result = curl_exec($ch);
972
+	}
973
+
974
+	// With dual stacked DNS responses, it's possible for a server to
975
+	// have IPv6 enabled but not have IPv6 connectivity.  If this is
976
+	// the case, curl will try IPv4 first and if that fails, then it will
977
+	// fall back to IPv6 and the error EHOSTUNREACH is returned by the
978
+	// operating system.
979
+	if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
980
+		$matches = array();
981
+		$regex = '/Failed to connect to ([^:].*): Network is unreachable/';
982
+		if (preg_match($regex, curl_error($ch), $matches)) {
983
+		  if (strlen(@inet_pton($matches[1])) === 16) {
984
+			self::errorLog('Invalid IPv6 configuration on server, '.
985
+						   'Please disable or get native IPv6 on your server.');
986
+			self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
987
+			curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
988
+			$result = curl_exec($ch);
989
+		  }
990
+		}
991
+	}
992
+
993
+	if ($result === false) {
994
+	  $e = new FacebookApiException(array(
995
+		'error_code' => curl_errno($ch),
996
+		'error' => array(
997
+		'message' => curl_error($ch),
998
+		'type' => 'CurlException',
999
+		),
1000
+	  ));
1001
+	  curl_close($ch);
1002
+	  throw $e;
1003
+	}
1004
+	curl_close($ch);
1005
+	return $result;
1006 1006
   }
1007 1007
 
1008 1008
   /**
@@ -1012,27 +1012,27 @@  discard block
 block discarded – undo
1012 1012
    * @return array The payload inside it or null if the sig is wrong
1013 1013
    */
1014 1014
   protected function parseSignedRequest($signed_request) {
1015
-    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
1016
-
1017
-    // decode the data
1018
-    $sig = self::base64UrlDecode($encoded_sig);
1019
-    $data = json_decode(self::base64UrlDecode($payload), true);
1020
-
1021
-    if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
1022
-      self::errorLog(
1023
-        'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
1024
-      return null;
1025
-    }
1026
-
1027
-    // check sig
1028
-    $expected_sig = hash_hmac('sha256', $payload,
1029
-                              $this->getAppSecret(), $raw = true);
1030
-    if ($sig !== $expected_sig) {
1031
-      self::errorLog('Bad Signed JSON signature!');
1032
-      return null;
1033
-    }
1034
-
1035
-    return $data;
1015
+	list($encoded_sig, $payload) = explode('.', $signed_request, 2);
1016
+
1017
+	// decode the data
1018
+	$sig = self::base64UrlDecode($encoded_sig);
1019
+	$data = json_decode(self::base64UrlDecode($payload), true);
1020
+
1021
+	if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
1022
+	  self::errorLog(
1023
+		'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
1024
+	  return null;
1025
+	}
1026
+
1027
+	// check sig
1028
+	$expected_sig = hash_hmac('sha256', $payload,
1029
+							  $this->getAppSecret(), $raw = true);
1030
+	if ($sig !== $expected_sig) {
1031
+	  self::errorLog('Bad Signed JSON signature!');
1032
+	  return null;
1033
+	}
1034
+
1035
+	return $data;
1036 1036
   }
1037 1037
 
1038 1038
   /**
@@ -1042,17 +1042,17 @@  discard block
 block discarded – undo
1042 1042
    * @return string The signed request.
1043 1043
    */
1044 1044
   protected function makeSignedRequest($data) {
1045
-    if (!is_array($data)) {
1046
-      throw new InvalidArgumentException(
1047
-        'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1048
-    }
1049
-    $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1050
-    $data['issued_at'] = time();
1051
-    $json = json_encode($data);
1052
-    $b64 = self::base64UrlEncode($json);
1053
-    $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1054
-    $sig = self::base64UrlEncode($raw_sig);
1055
-    return $sig.'.'.$b64;
1045
+	if (!is_array($data)) {
1046
+	  throw new InvalidArgumentException(
1047
+		'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1048
+	}
1049
+	$data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1050
+	$data['issued_at'] = time();
1051
+	$json = json_encode($data);
1052
+	$b64 = self::base64UrlEncode($json);
1053
+	$raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1054
+	$sig = self::base64UrlEncode($raw_sig);
1055
+	return $sig.'.'.$b64;
1056 1056
   }
1057 1057
 
1058 1058
   /**
@@ -1062,74 +1062,74 @@  discard block
 block discarded – undo
1062 1062
    * @return string The URL for the given parameters
1063 1063
    */
1064 1064
   protected function getApiUrl($method) {
1065
-    static $READ_ONLY_CALLS =
1066
-      array('admin.getallocation' => 1,
1067
-            'admin.getappproperties' => 1,
1068
-            'admin.getbannedusers' => 1,
1069
-            'admin.getlivestreamvialink' => 1,
1070
-            'admin.getmetrics' => 1,
1071
-            'admin.getrestrictioninfo' => 1,
1072
-            'application.getpublicinfo' => 1,
1073
-            'auth.getapppublickey' => 1,
1074
-            'auth.getsession' => 1,
1075
-            'auth.getsignedpublicsessiondata' => 1,
1076
-            'comments.get' => 1,
1077
-            'connect.getunconnectedfriendscount' => 1,
1078
-            'dashboard.getactivity' => 1,
1079
-            'dashboard.getcount' => 1,
1080
-            'dashboard.getglobalnews' => 1,
1081
-            'dashboard.getnews' => 1,
1082
-            'dashboard.multigetcount' => 1,
1083
-            'dashboard.multigetnews' => 1,
1084
-            'data.getcookies' => 1,
1085
-            'events.get' => 1,
1086
-            'events.getmembers' => 1,
1087
-            'fbml.getcustomtags' => 1,
1088
-            'feed.getappfriendstories' => 1,
1089
-            'feed.getregisteredtemplatebundlebyid' => 1,
1090
-            'feed.getregisteredtemplatebundles' => 1,
1091
-            'fql.multiquery' => 1,
1092
-            'fql.query' => 1,
1093
-            'friends.arefriends' => 1,
1094
-            'friends.get' => 1,
1095
-            'friends.getappusers' => 1,
1096
-            'friends.getlists' => 1,
1097
-            'friends.getmutualfriends' => 1,
1098
-            'gifts.get' => 1,
1099
-            'groups.get' => 1,
1100
-            'groups.getmembers' => 1,
1101
-            'intl.gettranslations' => 1,
1102
-            'links.get' => 1,
1103
-            'notes.get' => 1,
1104
-            'notifications.get' => 1,
1105
-            'pages.getinfo' => 1,
1106
-            'pages.isadmin' => 1,
1107
-            'pages.isappadded' => 1,
1108
-            'pages.isfan' => 1,
1109
-            'permissions.checkavailableapiaccess' => 1,
1110
-            'permissions.checkgrantedapiaccess' => 1,
1111
-            'photos.get' => 1,
1112
-            'photos.getalbums' => 1,
1113
-            'photos.gettags' => 1,
1114
-            'profile.getinfo' => 1,
1115
-            'profile.getinfooptions' => 1,
1116
-            'stream.get' => 1,
1117
-            'stream.getcomments' => 1,
1118
-            'stream.getfilters' => 1,
1119
-            'users.getinfo' => 1,
1120
-            'users.getloggedinuser' => 1,
1121
-            'users.getstandardinfo' => 1,
1122
-            'users.hasapppermission' => 1,
1123
-            'users.isappuser' => 1,
1124
-            'users.isverified' => 1,
1125
-            'video.getuploadlimits' => 1);
1126
-    $name = 'api';
1127
-    if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1128
-      $name = 'api_read';
1129
-    } else if (strtolower($method) == 'video.upload') {
1130
-      $name = 'api_video';
1131
-    }
1132
-    return self::getUrl($name, 'restserver.php');
1065
+	static $READ_ONLY_CALLS =
1066
+	  array('admin.getallocation' => 1,
1067
+			'admin.getappproperties' => 1,
1068
+			'admin.getbannedusers' => 1,
1069
+			'admin.getlivestreamvialink' => 1,
1070
+			'admin.getmetrics' => 1,
1071
+			'admin.getrestrictioninfo' => 1,
1072
+			'application.getpublicinfo' => 1,
1073
+			'auth.getapppublickey' => 1,
1074
+			'auth.getsession' => 1,
1075
+			'auth.getsignedpublicsessiondata' => 1,
1076
+			'comments.get' => 1,
1077
+			'connect.getunconnectedfriendscount' => 1,
1078
+			'dashboard.getactivity' => 1,
1079
+			'dashboard.getcount' => 1,
1080
+			'dashboard.getglobalnews' => 1,
1081
+			'dashboard.getnews' => 1,
1082
+			'dashboard.multigetcount' => 1,
1083
+			'dashboard.multigetnews' => 1,
1084
+			'data.getcookies' => 1,
1085
+			'events.get' => 1,
1086
+			'events.getmembers' => 1,
1087
+			'fbml.getcustomtags' => 1,
1088
+			'feed.getappfriendstories' => 1,
1089
+			'feed.getregisteredtemplatebundlebyid' => 1,
1090
+			'feed.getregisteredtemplatebundles' => 1,
1091
+			'fql.multiquery' => 1,
1092
+			'fql.query' => 1,
1093
+			'friends.arefriends' => 1,
1094
+			'friends.get' => 1,
1095
+			'friends.getappusers' => 1,
1096
+			'friends.getlists' => 1,
1097
+			'friends.getmutualfriends' => 1,
1098
+			'gifts.get' => 1,
1099
+			'groups.get' => 1,
1100
+			'groups.getmembers' => 1,
1101
+			'intl.gettranslations' => 1,
1102
+			'links.get' => 1,
1103
+			'notes.get' => 1,
1104
+			'notifications.get' => 1,
1105
+			'pages.getinfo' => 1,
1106
+			'pages.isadmin' => 1,
1107
+			'pages.isappadded' => 1,
1108
+			'pages.isfan' => 1,
1109
+			'permissions.checkavailableapiaccess' => 1,
1110
+			'permissions.checkgrantedapiaccess' => 1,
1111
+			'photos.get' => 1,
1112
+			'photos.getalbums' => 1,
1113
+			'photos.gettags' => 1,
1114
+			'profile.getinfo' => 1,
1115
+			'profile.getinfooptions' => 1,
1116
+			'stream.get' => 1,
1117
+			'stream.getcomments' => 1,
1118
+			'stream.getfilters' => 1,
1119
+			'users.getinfo' => 1,
1120
+			'users.getloggedinuser' => 1,
1121
+			'users.getstandardinfo' => 1,
1122
+			'users.hasapppermission' => 1,
1123
+			'users.isappuser' => 1,
1124
+			'users.isverified' => 1,
1125
+			'video.getuploadlimits' => 1);
1126
+	$name = 'api';
1127
+	if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1128
+	  $name = 'api_read';
1129
+	} else if (strtolower($method) == 'video.upload') {
1130
+	  $name = 'api_video';
1131
+	}
1132
+	return self::getUrl($name, 'restserver.php');
1133 1133
   }
1134 1134
 
1135 1135
   /**
@@ -1142,59 +1142,59 @@  discard block
 block discarded – undo
1142 1142
    * @return string The URL for the given parameters
1143 1143
    */
1144 1144
   protected function getUrl($name, $path='', $params=array()) {
1145
-    $url = self::$DOMAIN_MAP[$name];
1146
-    if ($path) {
1147
-      if ($path[0] === '/') {
1148
-        $path = substr($path, 1);
1149
-      }
1150
-      $url .= $path;
1151
-    }
1152
-    if ($params) {
1153
-      $url .= '?' . http_build_query($params, null, '&');
1154
-    }
1155
-
1156
-    return $url;
1145
+	$url = self::$DOMAIN_MAP[$name];
1146
+	if ($path) {
1147
+	  if ($path[0] === '/') {
1148
+		$path = substr($path, 1);
1149
+	  }
1150
+	  $url .= $path;
1151
+	}
1152
+	if ($params) {
1153
+	  $url .= '?' . http_build_query($params, null, '&');
1154
+	}
1155
+
1156
+	return $url;
1157 1157
   }
1158 1158
 
1159 1159
   protected function getHttpHost() {
1160
-    if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1161
-      return $_SERVER['HTTP_X_FORWARDED_HOST'];
1162
-    }
1163
-    return $_SERVER['HTTP_HOST'];
1160
+	if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1161
+	  return $_SERVER['HTTP_X_FORWARDED_HOST'];
1162
+	}
1163
+	return $_SERVER['HTTP_HOST'];
1164 1164
   }
1165 1165
 
1166 1166
   protected function getHttpProtocol() {
1167
-    if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1168
-      if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1169
-        return 'https';
1170
-      }
1171
-      return 'http';
1172
-    }
1173
-    /*apache + variants specific way of checking for https*/
1174
-    if (isset($_SERVER['HTTPS']) &&
1175
-        ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1176
-      return 'https';
1177
-    }
1178
-    /*nginx way of checking for https*/
1179
-    if (isset($_SERVER['SERVER_PORT']) &&
1180
-        ($_SERVER['SERVER_PORT'] === '443')) {
1181
-      return 'https';
1182
-    }
1183
-    return 'http';
1167
+	if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1168
+	  if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1169
+		return 'https';
1170
+	  }
1171
+	  return 'http';
1172
+	}
1173
+	/*apache + variants specific way of checking for https*/
1174
+	if (isset($_SERVER['HTTPS']) &&
1175
+		($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1176
+	  return 'https';
1177
+	}
1178
+	/*nginx way of checking for https*/
1179
+	if (isset($_SERVER['SERVER_PORT']) &&
1180
+		($_SERVER['SERVER_PORT'] === '443')) {
1181
+	  return 'https';
1182
+	}
1183
+	return 'http';
1184 1184
   }
1185 1185
 
1186 1186
   /**
1187 1187
    * Get the base domain used for the cookie.
1188 1188
    */
1189 1189
   protected function getBaseDomain() {
1190
-    // The base domain is stored in the metadata cookie if not we fallback
1191
-    // to the current hostname
1192
-    $metadata = $this->getMetadataCookie();
1193
-    if (array_key_exists('base_domain', $metadata) &&
1194
-        !empty($metadata['base_domain'])) {
1195
-      return trim($metadata['base_domain'], '.');
1196
-    }
1197
-    return $this->getHttpHost();
1190
+	// The base domain is stored in the metadata cookie if not we fallback
1191
+	// to the current hostname
1192
+	$metadata = $this->getMetadataCookie();
1193
+	if (array_key_exists('base_domain', $metadata) &&
1194
+		!empty($metadata['base_domain'])) {
1195
+	  return trim($metadata['base_domain'], '.');
1196
+	}
1197
+	return $this->getHttpHost();
1198 1198
   }
1199 1199
 
1200 1200
   /**
@@ -1206,36 +1206,36 @@  discard block
 block discarded – undo
1206 1206
    * @return string The current URL
1207 1207
    */
1208 1208
   protected function getCurrentUrl() {
1209
-    $protocol = $this->getHttpProtocol() . '://';
1210
-    $host = $this->getHttpHost();
1211
-    $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1212
-    $parts = parse_url($currentUrl);
1213
-
1214
-    $query = '';
1215
-    if (!empty($parts['query'])) {
1216
-      // drop known fb params
1217
-      $params = explode('&', $parts['query']);
1218
-      $retained_params = array();
1219
-      foreach ($params as $param) {
1220
-        if ($this->shouldRetainParam($param)) {
1221
-          $retained_params[] = $param;
1222
-        }
1223
-      }
1224
-
1225
-      if (!empty($retained_params)) {
1226
-        $query = '?'.implode($retained_params, '&');
1227
-      }
1228
-    }
1229
-
1230
-    // use port if non default
1231
-    $port =
1232
-      isset($parts['port']) &&
1233
-      (($protocol === 'http://' && $parts['port'] !== 80) ||
1234
-       ($protocol === 'https://' && $parts['port'] !== 443))
1235
-      ? ':' . $parts['port'] : '';
1236
-
1237
-    // rebuild
1238
-    return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1209
+	$protocol = $this->getHttpProtocol() . '://';
1210
+	$host = $this->getHttpHost();
1211
+	$currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1212
+	$parts = parse_url($currentUrl);
1213
+
1214
+	$query = '';
1215
+	if (!empty($parts['query'])) {
1216
+	  // drop known fb params
1217
+	  $params = explode('&', $parts['query']);
1218
+	  $retained_params = array();
1219
+	  foreach ($params as $param) {
1220
+		if ($this->shouldRetainParam($param)) {
1221
+		  $retained_params[] = $param;
1222
+		}
1223
+	  }
1224
+
1225
+	  if (!empty($retained_params)) {
1226
+		$query = '?'.implode($retained_params, '&');
1227
+	  }
1228
+	}
1229
+
1230
+	// use port if non default
1231
+	$port =
1232
+	  isset($parts['port']) &&
1233
+	  (($protocol === 'http://' && $parts['port'] !== 80) ||
1234
+	   ($protocol === 'https://' && $parts['port'] !== 443))
1235
+	  ? ':' . $parts['port'] : '';
1236
+
1237
+	// rebuild
1238
+	return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1239 1239
   }
1240 1240
 
1241 1241
   /**
@@ -1250,13 +1250,13 @@  discard block
 block discarded – undo
1250 1250
    * @return boolean
1251 1251
    */
1252 1252
   protected function shouldRetainParam($param) {
1253
-    foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1254
-      if (strpos($param, $drop_query_param.'=') === 0) {
1255
-        return false;
1256
-      }
1257
-    }
1253
+	foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1254
+	  if (strpos($param, $drop_query_param.'=') === 0) {
1255
+		return false;
1256
+	  }
1257
+	}
1258 1258
 
1259
-    return true;
1259
+	return true;
1260 1260
   }
1261 1261
 
1262 1262
   /**
@@ -1268,25 +1268,25 @@  discard block
 block discarded – undo
1268 1268
    *                      by a failed API call.
1269 1269
    */
1270 1270
   protected function throwAPIException($result) {
1271
-    $e = new FacebookApiException($result);
1272
-    switch ($e->getType()) {
1273
-      // OAuth 2.0 Draft 00 style
1274
-      case 'OAuthException':
1275
-        // OAuth 2.0 Draft 10 style
1276
-      case 'invalid_token':
1277
-        // REST server errors are just Exceptions
1278
-      case 'Exception':
1279
-        $message = $e->getMessage();
1280
-        if ((strpos($message, 'Error validating access token') !== false) ||
1281
-            (strpos($message, 'Invalid OAuth access token') !== false) ||
1282
-            (strpos($message, 'An active access token must be used') !== false)
1283
-        ) {
1284
-          $this->destroySession();
1285
-        }
1286
-        break;
1287
-    }
1288
-
1289
-    throw $e;
1271
+	$e = new FacebookApiException($result);
1272
+	switch ($e->getType()) {
1273
+	  // OAuth 2.0 Draft 00 style
1274
+	  case 'OAuthException':
1275
+		// OAuth 2.0 Draft 10 style
1276
+	  case 'invalid_token':
1277
+		// REST server errors are just Exceptions
1278
+	  case 'Exception':
1279
+		$message = $e->getMessage();
1280
+		if ((strpos($message, 'Error validating access token') !== false) ||
1281
+			(strpos($message, 'Invalid OAuth access token') !== false) ||
1282
+			(strpos($message, 'An active access token must be used') !== false)
1283
+		) {
1284
+		  $this->destroySession();
1285
+		}
1286
+		break;
1287
+	}
1288
+
1289
+	throw $e;
1290 1290
   }
1291 1291
 
1292 1292
 
@@ -1296,14 +1296,14 @@  discard block
 block discarded – undo
1296 1296
    * @param string $msg Log message
1297 1297
    */
1298 1298
   protected static function errorLog($msg) {
1299
-    // disable error log if we are running in a CLI environment
1300
-    // @codeCoverageIgnoreStart
1301
-    if (php_sapi_name() != 'cli') {
1302
-      error_log($msg);
1303
-    }
1304
-    // uncomment this if you want to see the errors on the page
1305
-    // print 'error_log: '.$msg."\n";
1306
-    // @codeCoverageIgnoreEnd
1299
+	// disable error log if we are running in a CLI environment
1300
+	// @codeCoverageIgnoreStart
1301
+	if (php_sapi_name() != 'cli') {
1302
+	  error_log($msg);
1303
+	}
1304
+	// uncomment this if you want to see the errors on the page
1305
+	// print 'error_log: '.$msg."\n";
1306
+	// @codeCoverageIgnoreEnd
1307 1307
   }
1308 1308
 
1309 1309
   /**
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
    * @return string
1318 1318
    */
1319 1319
   protected static function base64UrlDecode($input) {
1320
-    return base64_decode(strtr($input, '-_', '+/'));
1320
+	return base64_decode(strtr($input, '-_', '+/'));
1321 1321
   }
1322 1322
 
1323 1323
   /**
@@ -1330,38 +1330,38 @@  discard block
 block discarded – undo
1330 1330
    * @return string base64Url encoded string
1331 1331
    */
1332 1332
   protected static function base64UrlEncode($input) {
1333
-    $str = strtr(base64_encode($input), '+/', '-_');
1334
-    $str = str_replace('=', '', $str);
1335
-    return $str;
1333
+	$str = strtr(base64_encode($input), '+/', '-_');
1334
+	$str = str_replace('=', '', $str);
1335
+	return $str;
1336 1336
   }
1337 1337
 
1338 1338
   /**
1339 1339
    * Destroy the current session
1340 1340
    */
1341 1341
   public function destroySession() {
1342
-    $this->accessToken = null;
1343
-    $this->signedRequest = null;
1344
-    $this->user = null;
1345
-    $this->clearAllPersistentData();
1346
-
1347
-    // Javascript sets a cookie that will be used in getSignedRequest that we
1348
-    // need to clear if we can
1349
-    $cookie_name = $this->getSignedRequestCookieName();
1350
-    if (array_key_exists($cookie_name, $_COOKIE)) {
1351
-      unset($_COOKIE[$cookie_name]);
1352
-      if (!headers_sent()) {
1353
-        $base_domain = $this->getBaseDomain();
1354
-        setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1355
-      } else {
1356
-        // @codeCoverageIgnoreStart
1357
-        self::errorLog(
1358
-          'There exists a cookie that we wanted to clear that we couldn\'t '.
1359
-          'clear because headers was already sent. Make sure to do the first '.
1360
-          'API call before outputing anything.'
1361
-        );
1362
-        // @codeCoverageIgnoreEnd
1363
-      }
1364
-    }
1342
+	$this->accessToken = null;
1343
+	$this->signedRequest = null;
1344
+	$this->user = null;
1345
+	$this->clearAllPersistentData();
1346
+
1347
+	// Javascript sets a cookie that will be used in getSignedRequest that we
1348
+	// need to clear if we can
1349
+	$cookie_name = $this->getSignedRequestCookieName();
1350
+	if (array_key_exists($cookie_name, $_COOKIE)) {
1351
+	  unset($_COOKIE[$cookie_name]);
1352
+	  if (!headers_sent()) {
1353
+		$base_domain = $this->getBaseDomain();
1354
+		setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1355
+	  } else {
1356
+		// @codeCoverageIgnoreStart
1357
+		self::errorLog(
1358
+		  'There exists a cookie that we wanted to clear that we couldn\'t '.
1359
+		  'clear because headers was already sent. Make sure to do the first '.
1360
+		  'API call before outputing anything.'
1361
+		);
1362
+		// @codeCoverageIgnoreEnd
1363
+	  }
1364
+	}
1365 1365
   }
1366 1366
 
1367 1367
   /**
@@ -1370,44 +1370,44 @@  discard block
 block discarded – undo
1370 1370
    * @return  an array mapping key to value
1371 1371
    */
1372 1372
   protected function getMetadataCookie() {
1373
-    $cookie_name = $this->getMetadataCookieName();
1374
-    if (!array_key_exists($cookie_name, $_COOKIE)) {
1375
-      return array();
1376
-    }
1377
-
1378
-    // The cookie value can be wrapped in "-characters so remove them
1379
-    $cookie_value = trim($_COOKIE[$cookie_name], '"');
1380
-
1381
-    if (empty($cookie_value)) {
1382
-      return array();
1383
-    }
1384
-
1385
-    $parts = explode('&', $cookie_value);
1386
-    $metadata = array();
1387
-    foreach ($parts as $part) {
1388
-      $pair = explode('=', $part, 2);
1389
-      if (!empty($pair[0])) {
1390
-        $metadata[urldecode($pair[0])] =
1391
-          (count($pair) > 1) ? urldecode($pair[1]) : '';
1392
-      }
1393
-    }
1394
-
1395
-    return $metadata;
1373
+	$cookie_name = $this->getMetadataCookieName();
1374
+	if (!array_key_exists($cookie_name, $_COOKIE)) {
1375
+	  return array();
1376
+	}
1377
+
1378
+	// The cookie value can be wrapped in "-characters so remove them
1379
+	$cookie_value = trim($_COOKIE[$cookie_name], '"');
1380
+
1381
+	if (empty($cookie_value)) {
1382
+	  return array();
1383
+	}
1384
+
1385
+	$parts = explode('&', $cookie_value);
1386
+	$metadata = array();
1387
+	foreach ($parts as $part) {
1388
+	  $pair = explode('=', $part, 2);
1389
+	  if (!empty($pair[0])) {
1390
+		$metadata[urldecode($pair[0])] =
1391
+		  (count($pair) > 1) ? urldecode($pair[1]) : '';
1392
+	  }
1393
+	}
1394
+
1395
+	return $metadata;
1396 1396
   }
1397 1397
 
1398 1398
   protected static function isAllowedDomain($big, $small) {
1399
-    if ($big === $small) {
1400
-      return true;
1401
-    }
1402
-    return self::endsWith($big, '.'.$small);
1399
+	if ($big === $small) {
1400
+	  return true;
1401
+	}
1402
+	return self::endsWith($big, '.'.$small);
1403 1403
   }
1404 1404
 
1405 1405
   protected static function endsWith($big, $small) {
1406
-    $len = strlen($small);
1407
-    if ($len === 0) {
1408
-      return true;
1409
-    }
1410
-    return substr($big, -$len) === $small;
1406
+	$len = strlen($small);
1407
+	if ($len === 0) {
1408
+	  return true;
1409
+	}
1410
+	return substr($big, -$len) === $small;
1411 1411
   }
1412 1412
 
1413 1413
   /**
Please login to merge, or discard this patch.
bundles/ext/facebook/facebook.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -45,52 +45,52 @@  discard block
 block discarded – undo
45 45
    * @see BaseFacebook::__construct in facebook.php
46 46
    */
47 47
   public function __construct($config) {
48
-    if (!session_id()) {
49
-      session_start();
50
-    }
51
-    parent::__construct($config);
52
-    if (!empty($config['sharedSession'])) {
53
-      $this->initSharedSession();
54
-    }
48
+	if (!session_id()) {
49
+	  session_start();
50
+	}
51
+	parent::__construct($config);
52
+	if (!empty($config['sharedSession'])) {
53
+	  $this->initSharedSession();
54
+	}
55 55
   }
56 56
 
57 57
   protected static $kSupportedKeys =
58
-    array('state', 'code', 'access_token', 'user_id');
58
+	array('state', 'code', 'access_token', 'user_id');
59 59
 
60 60
   protected function initSharedSession() {
61
-    $cookie_name = $this->getSharedSessionCookieName();
62
-    if (isset($_COOKIE[$cookie_name])) {
63
-      $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
-      if ($data && !empty($data['domain']) &&
65
-          self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
-        // good case
67
-        $this->sharedSessionID = $data['id'];
68
-        return;
69
-      }
70
-      // ignoring potentially unreachable data
71
-    }
72
-    // evil/corrupt/missing case
73
-    $base_domain = $this->getBaseDomain();
74
-    $this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
-    $cookie_value = $this->makeSignedRequest(
76
-      array(
77
-        'domain' => $base_domain,
78
-        'id' => $this->sharedSessionID,
79
-      )
80
-    );
81
-    $_COOKIE[$cookie_name] = $cookie_value;
82
-    if (!headers_sent()) {
83
-      $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
-      setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
-    } else {
86
-      // @codeCoverageIgnoreStart
87
-      self::errorLog(
88
-        'Shared session ID cookie could not be set! You must ensure you '.
89
-        'create the Facebook instance before headers have been sent. This '.
90
-        'will cause authentication issues after the first request.'
91
-      );
92
-      // @codeCoverageIgnoreEnd
93
-    }
61
+	$cookie_name = $this->getSharedSessionCookieName();
62
+	if (isset($_COOKIE[$cookie_name])) {
63
+	  $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
+	  if ($data && !empty($data['domain']) &&
65
+		  self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
+		// good case
67
+		$this->sharedSessionID = $data['id'];
68
+		return;
69
+	  }
70
+	  // ignoring potentially unreachable data
71
+	}
72
+	// evil/corrupt/missing case
73
+	$base_domain = $this->getBaseDomain();
74
+	$this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
+	$cookie_value = $this->makeSignedRequest(
76
+	  array(
77
+		'domain' => $base_domain,
78
+		'id' => $this->sharedSessionID,
79
+	  )
80
+	);
81
+	$_COOKIE[$cookie_name] = $cookie_value;
82
+	if (!headers_sent()) {
83
+	  $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
+	  setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
+	} else {
86
+	  // @codeCoverageIgnoreStart
87
+	  self::errorLog(
88
+		'Shared session ID cookie could not be set! You must ensure you '.
89
+		'create the Facebook instance before headers have been sent. This '.
90
+		'will cause authentication issues after the first request.'
91
+	  );
92
+	  // @codeCoverageIgnoreEnd
93
+	}
94 94
   }
95 95
 
96 96
   /**
@@ -100,61 +100,61 @@  discard block
 block discarded – undo
100 100
    * access tokens.
101 101
    */
102 102
   protected function setPersistentData($key, $value) {
103
-    if (!in_array($key, self::$kSupportedKeys)) {
104
-      self::errorLog('Unsupported key passed to setPersistentData.');
105
-      return;
106
-    }
103
+	if (!in_array($key, self::$kSupportedKeys)) {
104
+	  self::errorLog('Unsupported key passed to setPersistentData.');
105
+	  return;
106
+	}
107 107
 
108
-    $session_var_name = $this->constructSessionVariableName($key);
109
-    $_SESSION[$session_var_name] = $value;
108
+	$session_var_name = $this->constructSessionVariableName($key);
109
+	$_SESSION[$session_var_name] = $value;
110 110
   }
111 111
 
112 112
   protected function getPersistentData($key, $default = false) {
113
-    if (!in_array($key, self::$kSupportedKeys)) {
114
-      self::errorLog('Unsupported key passed to getPersistentData.');
115
-      return $default;
116
-    }
117
-
118
-    $session_var_name = $this->constructSessionVariableName($key);
119
-    return isset($_SESSION[$session_var_name]) ?
120
-      $_SESSION[$session_var_name] : $default;
113
+	if (!in_array($key, self::$kSupportedKeys)) {
114
+	  self::errorLog('Unsupported key passed to getPersistentData.');
115
+	  return $default;
116
+	}
117
+
118
+	$session_var_name = $this->constructSessionVariableName($key);
119
+	return isset($_SESSION[$session_var_name]) ?
120
+	  $_SESSION[$session_var_name] : $default;
121 121
   }
122 122
 
123 123
   protected function clearPersistentData($key) {
124
-    if (!in_array($key, self::$kSupportedKeys)) {
125
-      self::errorLog('Unsupported key passed to clearPersistentData.');
126
-      return;
127
-    }
124
+	if (!in_array($key, self::$kSupportedKeys)) {
125
+	  self::errorLog('Unsupported key passed to clearPersistentData.');
126
+	  return;
127
+	}
128 128
 
129
-    $session_var_name = $this->constructSessionVariableName($key);
130
-    unset($_SESSION[$session_var_name]);
129
+	$session_var_name = $this->constructSessionVariableName($key);
130
+	unset($_SESSION[$session_var_name]);
131 131
   }
132 132
 
133 133
   protected function clearAllPersistentData() {
134
-    foreach (self::$kSupportedKeys as $key) {
135
-      $this->clearPersistentData($key);
136
-    }
137
-    if ($this->sharedSessionID) {
138
-      $this->deleteSharedSessionCookie();
139
-    }
134
+	foreach (self::$kSupportedKeys as $key) {
135
+	  $this->clearPersistentData($key);
136
+	}
137
+	if ($this->sharedSessionID) {
138
+	  $this->deleteSharedSessionCookie();
139
+	}
140 140
   }
141 141
 
142 142
   protected function deleteSharedSessionCookie() {
143
-    $cookie_name = $this->getSharedSessionCookieName();
144
-    unset($_COOKIE[$cookie_name]);
145
-    $base_domain = $this->getBaseDomain();
146
-    setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
143
+	$cookie_name = $this->getSharedSessionCookieName();
144
+	unset($_COOKIE[$cookie_name]);
145
+	$base_domain = $this->getBaseDomain();
146
+	setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
147 147
   }
148 148
 
149 149
   protected function getSharedSessionCookieName() {
150
-    return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
150
+	return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
151 151
   }
152 152
 
153 153
   protected function constructSessionVariableName($key) {
154
-    $parts = array('fb', $this->getAppId(), $key);
155
-    if ($this->sharedSessionID) {
156
-      array_unshift($parts, $this->sharedSessionID);
157
-    }
158
-    return implode('_', $parts);
154
+	$parts = array('fb', $this->getAppId(), $key);
155
+	if ($this->sharedSessionID) {
156
+	  array_unshift($parts, $this->sharedSessionID);
157
+	}
158
+	return implode('_', $parts);
159 159
   }
160 160
 }
Please login to merge, or discard this patch.
bundles/tests/Demo/app/Controller/Exemple1Test.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -39,31 +39,31 @@
 block discarded – undo
39 39
 	 *
40 40
 	 * @access public
41 41
 	 * @return void
42
-     * @test
42
+	 * @test
43 43
 	 */
44 44
 
45 45
 	public function testShow()
46
-    {
47
-	    try {
46
+	{
47
+		try {
48 48
 
49
-            ob_start();
50
-            $exemple1 = new Exemple1;
51
-            $exemple1->show();
52
-            $content = ob_get_clean();
49
+			ob_start();
50
+			$exemple1 = new Exemple1;
51
+			$exemple1->show();
52
+			$content = ob_get_clean();
53 53
 
54
-            //var_dump(debug_backtrace());
54
+			//var_dump(debug_backtrace());
55 55
 
56
-            if ($content) {
56
+			if ($content) {
57 57
 
58
-                $this->assertTrue(true);
59
-            }
60
-            else {
61
-                $this->assertTrue(false);
62
-            }
63
-        }
64
-        catch(\Exception $e) {
65
-            $this->assertTrue(false);
66
-        }
58
+				$this->assertTrue(true);
59
+			}
60
+			else {
61
+				$this->assertTrue(false);
62
+			}
63
+		}
64
+		catch(\Exception $e) {
65
+			$this->assertTrue(false);
66
+		}
67 67
 
68 68
 	}
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
bundles/lib/Ldap.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class Ldap
32 32
 {
33
-    /**
34
-     * connection at ldap server
35
-     * 
36
-     * @access private
37
-     * @var    resource
38
-     */
33
+	/**
34
+	 * connection at ldap server
35
+	 * 
36
+	 * @access private
37
+	 * @var    resource
38
+	 */
39 39
 	private $_rConnect;
40 40
 	
41 41
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function __construct()
64 64
 	{
65
-	    $oDbConf = Config::get('Ldap')->configuration;
65
+		$oDbConf = Config::get('Ldap')->configuration;
66 66
 
67 67
 		$this->_sBase = $oDbConf->base;
68 68
 
@@ -77,28 +77,28 @@  discard block
 block discarded – undo
77 77
 	 * @access public
78 78
 	 * @return array
79 79
 	 */
80
-    public function getGroups() : array
81
-    {
82
-        $rSearch = ldap_search( $this->_rConnect , $this->_sBase , "objectclass=group" , array("cn") );
83
-        $aEntries = ldap_get_entries($this->_rConnect, $rSearch);
84
-        $aGroups = array();
80
+	public function getGroups() : array
81
+	{
82
+		$rSearch = ldap_search( $this->_rConnect , $this->_sBase , "objectclass=group" , array("cn") );
83
+		$aEntries = ldap_get_entries($this->_rConnect, $rSearch);
84
+		$aGroups = array();
85 85
 
86
-        for ( $i = 0 ; $i < $aEntries["count"] ; $i++ ) {
86
+		for ( $i = 0 ; $i < $aEntries["count"] ; $i++ ) {
87 87
             
88
-            $aGroups[] = utf8_encode($aEntries[$i]["dn"]);
89
-        }
90
-
91
-        return $aGroups;
92
-    }
93
-
94
-    /**
95
-     * Authentification in Ldap
96
-     * 
97
-     * @access public
98
-     * @param  string $sUser
99
-     * @param  string $sPassword
100
-     * @return \Venus\lib\Ldap
101
-     */
88
+			$aGroups[] = utf8_encode($aEntries[$i]["dn"]);
89
+		}
90
+
91
+		return $aGroups;
92
+	}
93
+
94
+	/**
95
+	 * Authentification in Ldap
96
+	 * 
97
+	 * @access public
98
+	 * @param  string $sUser
99
+	 * @param  string $sPassword
100
+	 * @return \Venus\lib\Ldap
101
+	 */
102 102
 	public function bind($sUser, $sPassword) : Ldap
103 103
 	{
104 104
 		return $this->_bConnected = ldap_bind($this->_rConnect, $sUser, $sPassword);
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function unbind() : bool
115 115
 	{
116
-	    if ($this->_bConnected) { return $this->_bConnected = ldap_unbind($this->_rConnect); }
117
-	    else { return true; }
116
+		if ($this->_bConnected) { return $this->_bConnected = ldap_unbind($this->_rConnect); }
117
+		else { return true; }
118 118
 	}
119 119
 
120 120
 	/**
Please login to merge, or discard this patch.
bundles/lib/Cookie.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
   	public function set(string $sName, $mValue, int $iExpire = 0, string $sPath = '', string $sDomain = '', int $iSecure = false) : Cookie
40 40
 	{
41 41
   		$iExpire = time() + $iExpire;
42
-    	setcookie($sName, $mValue, $iExpire, $sPath, $sDomain, $iSecure);
43
-    	return $this;
42
+		setcookie($sName, $mValue, $iExpire, $sPath, $sDomain, $iSecure);
43
+		return $this;
44 44
   	}
45 45
 
46 46
   	/**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
   	 */
53 53
   	public function get(string $sName)
54 54
 	{
55
-    	return $_COOKIE[$sName];
55
+		return $_COOKIE[$sName];
56 56
   	}
57 57
 
58 58
   	/**
@@ -64,6 +64,6 @@  discard block
 block discarded – undo
64 64
   	 */
65 65
   	public function exists(string $sName) : bool
66 66
 	{
67
-    	return isset($_COOKIE[$sName]);
67
+		return isset($_COOKIE[$sName]);
68 68
   	}
69 69
 }
Please login to merge, or discard this patch.
bundles/lib/Response/ResponseInterface.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
  */
31 31
 interface ResponseInterface
32 32
 {
33
-    /**
33
+	/**
34 34
 	 * translate the content
35 35
 	 *
36 36
 	 * @access public
Please login to merge, or discard this patch.
bundles/lib/Response/Mock.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@
 block discarded – undo
40 40
 	 * @param  mixed $mContent content to translate
41 41
 	 * @return mixed
42 42
 	 */
43
-    public static function translate($mContent)
44
-    {
45
-        // TODO Auto-generated method stub
46
-        return $mContent;
47
-    }
43
+	public static function translate($mContent)
44
+	{
45
+		// TODO Auto-generated method stub
46
+		return $mContent;
47
+	}
48 48
 
49 49
 }
Please login to merge, or discard this patch.
bundles/lib/Response/Yaml.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@
 block discarded – undo
34 34
 {
35 35
 	/**
36 36
 	 * translate the content
37
-     * @see \Venus\lib\Response\ResponseInterface::translate()
37
+	 * @see \Venus\lib\Response\ResponseInterface::translate()
38 38
 	 *
39 39
 	 * @access public
40 40
 	 * @param  mixed $mContent content to translate
41 41
 	 * @return mixed
42 42
 	 */
43
-    public static function translate($mContent)
44
-    {
45
-        // TODO Auto-generated method stub
46
-        return yaml_emit($mContent);
47
-    }
43
+	public static function translate($mContent)
44
+	{
45
+		// TODO Auto-generated method stub
46
+		return yaml_emit($mContent);
47
+	}
48 48
 
49 49
 }
Please login to merge, or discard this patch.
bundles/lib/Response/Json.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@
 block discarded – undo
41 41
 	 * @param  mixed $mContent content to translate
42 42
 	 * @return mixed
43 43
 	 */
44
-    public static function translate($mContent)
45
-    {
46
-        return json_encode(Object::object_to_array($mContent));
47
-    }
44
+	public static function translate($mContent)
45
+	{
46
+		return json_encode(Object::object_to_array($mContent));
47
+	}
48 48
 
49 49
 }
Please login to merge, or discard this patch.