@@ -8,20 +8,20 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | $this->_strings = array( |
| 11 | - CAS_STR_USING_SERVER |
|
| 12 | - => 'usando servidor', |
|
| 13 | - CAS_STR_AUTHENTICATION_WANTED |
|
| 14 | - => '¡Autentificación CAS necesaria!', |
|
| 15 | - CAS_STR_LOGOUT |
|
| 16 | - => '¡Salida CAS necesaria!', |
|
| 17 | - CAS_STR_SHOULD_HAVE_BEEN_REDIRECTED |
|
| 18 | - => 'Ya debería haber sido redireccionado al servidor CAS. Haga click <a href="%s">aquí</a> para continuar.', |
|
| 19 | - CAS_STR_AUTHENTICATION_FAILED |
|
| 20 | - => '¡Autentificación CAS fallida!', |
|
| 21 | - CAS_STR_YOU_WERE_NOT_AUTHENTICATED |
|
| 22 | - => '<p>No estás autentificado.</p><p>Puedes volver a intentarlo haciendo click <a href="%s">aquí</a>.</p><p>Si el problema persiste debería contactar con el <a href="mailto:%s">administrador de este sitio</a>.</p>', |
|
| 23 | - CAS_STR_SERVICE_UNAVAILABLE |
|
| 24 | - => 'El servicio `<b>%s</b>\' no está disponible (<b>%s</b>).' |
|
| 11 | + CAS_STR_USING_SERVER |
|
| 12 | + => 'usando servidor', |
|
| 13 | + CAS_STR_AUTHENTICATION_WANTED |
|
| 14 | + => '¡Autentificación CAS necesaria!', |
|
| 15 | + CAS_STR_LOGOUT |
|
| 16 | + => '¡Salida CAS necesaria!', |
|
| 17 | + CAS_STR_SHOULD_HAVE_BEEN_REDIRECTED |
|
| 18 | + => 'Ya debería haber sido redireccionado al servidor CAS. Haga click <a href="%s">aquí</a> para continuar.', |
|
| 19 | + CAS_STR_AUTHENTICATION_FAILED |
|
| 20 | + => '¡Autentificación CAS fallida!', |
|
| 21 | + CAS_STR_YOU_WERE_NOT_AUTHENTICATED |
|
| 22 | + => '<p>No estás autentificado.</p><p>Puedes volver a intentarlo haciendo click <a href="%s">aquí</a>.</p><p>Si el problema persiste debería contactar con el <a href="mailto:%s">administrador de este sitio</a>.</p>', |
|
| 23 | + CAS_STR_SERVICE_UNAVAILABLE |
|
| 24 | + => 'El servicio `<b>%s</b>\' no está disponible (<b>%s</b>).' |
|
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | 27 | ?> |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | $url = api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'; |
| 6 | 6 | |
| 7 | 7 | if (! isset($_SESSION['conditional_login']['uid'])) |
| 8 | - die("Not Authorised"); |
|
| 8 | + die("Not Authorised"); |
|
| 9 | 9 | ?> |
| 10 | 10 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 11 | 11 | <html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"> |
@@ -32,135 +32,135 @@ |
||
| 32 | 32 | abstract class FacebookSignedRequestFromInputHelper |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var \Facebook\Entities\SignedRequest|null |
|
| 37 | - */ |
|
| 38 | - protected $signedRequest; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string the app id |
|
| 42 | - */ |
|
| 43 | - protected $appId; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string the app secret |
|
| 47 | - */ |
|
| 48 | - protected $appSecret; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string|null Random string to prevent CSRF. |
|
| 52 | - */ |
|
| 53 | - public $state = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Initialize the helper and process available signed request data. |
|
| 57 | - * |
|
| 58 | - * @param string|null $appId |
|
| 59 | - * @param string|null $appSecret |
|
| 60 | - */ |
|
| 61 | - public function __construct($appId = null, $appSecret = null) |
|
| 62 | - { |
|
| 35 | + /** |
|
| 36 | + * @var \Facebook\Entities\SignedRequest|null |
|
| 37 | + */ |
|
| 38 | + protected $signedRequest; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string the app id |
|
| 42 | + */ |
|
| 43 | + protected $appId; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string the app secret |
|
| 47 | + */ |
|
| 48 | + protected $appSecret; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string|null Random string to prevent CSRF. |
|
| 52 | + */ |
|
| 53 | + public $state = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Initialize the helper and process available signed request data. |
|
| 57 | + * |
|
| 58 | + * @param string|null $appId |
|
| 59 | + * @param string|null $appSecret |
|
| 60 | + */ |
|
| 61 | + public function __construct($appId = null, $appSecret = null) |
|
| 62 | + { |
|
| 63 | 63 | $this->appId = FacebookSession::_getTargetAppId($appId); |
| 64 | 64 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); |
| 65 | 65 | |
| 66 | 66 | $this->instantiateSignedRequest(); |
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Instantiates a new SignedRequest entity. |
|
| 71 | - * |
|
| 72 | - * @param string|null |
|
| 73 | - */ |
|
| 74 | - public function instantiateSignedRequest($rawSignedRequest = null) |
|
| 75 | - { |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Instantiates a new SignedRequest entity. |
|
| 71 | + * |
|
| 72 | + * @param string|null |
|
| 73 | + */ |
|
| 74 | + public function instantiateSignedRequest($rawSignedRequest = null) |
|
| 75 | + { |
|
| 76 | 76 | $rawSignedRequest = $rawSignedRequest ?: $this->getRawSignedRequest(); |
| 77 | 77 | |
| 78 | 78 | if (!$rawSignedRequest) { |
| 79 | - return; |
|
| 79 | + return; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $this->signedRequest = new SignedRequest($rawSignedRequest, $this->state, $this->appSecret); |
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Instantiates a FacebookSession from the signed request from input. |
|
| 87 | - * |
|
| 88 | - * @return FacebookSession|null |
|
| 89 | - */ |
|
| 90 | - public function getSession() |
|
| 91 | - { |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Instantiates a FacebookSession from the signed request from input. |
|
| 87 | + * |
|
| 88 | + * @return FacebookSession|null |
|
| 89 | + */ |
|
| 90 | + public function getSession() |
|
| 91 | + { |
|
| 92 | 92 | if ($this->signedRequest && $this->signedRequest->hasOAuthData()) { |
| 93 | - return FacebookSession::newSessionFromSignedRequest($this->signedRequest); |
|
| 93 | + return FacebookSession::newSessionFromSignedRequest($this->signedRequest); |
|
| 94 | 94 | } |
| 95 | 95 | return null; |
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Returns the SignedRequest entity. |
|
| 100 | - * |
|
| 101 | - * @return \Facebook\Entities\SignedRequest|null |
|
| 102 | - */ |
|
| 103 | - public function getSignedRequest() |
|
| 104 | - { |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Returns the SignedRequest entity. |
|
| 100 | + * |
|
| 101 | + * @return \Facebook\Entities\SignedRequest|null |
|
| 102 | + */ |
|
| 103 | + public function getSignedRequest() |
|
| 104 | + { |
|
| 105 | 105 | return $this->signedRequest; |
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Returns the user_id if available. |
|
| 110 | - * |
|
| 111 | - * @return string|null |
|
| 112 | - */ |
|
| 113 | - public function getUserId() |
|
| 114 | - { |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Returns the user_id if available. |
|
| 110 | + * |
|
| 111 | + * @return string|null |
|
| 112 | + */ |
|
| 113 | + public function getUserId() |
|
| 114 | + { |
|
| 115 | 115 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; |
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Get raw signed request from input. |
|
| 120 | - * |
|
| 121 | - * @return string|null |
|
| 122 | - */ |
|
| 123 | - abstract public function getRawSignedRequest(); |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get raw signed request from GET input. |
|
| 127 | - * |
|
| 128 | - * @return string|null |
|
| 129 | - */ |
|
| 130 | - public function getRawSignedRequestFromGet() |
|
| 131 | - { |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Get raw signed request from input. |
|
| 120 | + * |
|
| 121 | + * @return string|null |
|
| 122 | + */ |
|
| 123 | + abstract public function getRawSignedRequest(); |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get raw signed request from GET input. |
|
| 127 | + * |
|
| 128 | + * @return string|null |
|
| 129 | + */ |
|
| 130 | + public function getRawSignedRequestFromGet() |
|
| 131 | + { |
|
| 132 | 132 | if (isset($_GET['signed_request'])) { |
| 133 | - return $_GET['signed_request']; |
|
| 133 | + return $_GET['signed_request']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return null; |
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Get raw signed request from POST input. |
|
| 141 | - * |
|
| 142 | - * @return string|null |
|
| 143 | - */ |
|
| 144 | - public function getRawSignedRequestFromPost() |
|
| 145 | - { |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Get raw signed request from POST input. |
|
| 141 | + * |
|
| 142 | + * @return string|null |
|
| 143 | + */ |
|
| 144 | + public function getRawSignedRequestFromPost() |
|
| 145 | + { |
|
| 146 | 146 | if (isset($_POST['signed_request'])) { |
| 147 | - return $_POST['signed_request']; |
|
| 147 | + return $_POST['signed_request']; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return null; |
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get raw signed request from cookie set from the Javascript SDK. |
|
| 155 | - * |
|
| 156 | - * @return string|null |
|
| 157 | - */ |
|
| 158 | - public function getRawSignedRequestFromCookie() |
|
| 159 | - { |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get raw signed request from cookie set from the Javascript SDK. |
|
| 155 | + * |
|
| 156 | + * @return string|null |
|
| 157 | + */ |
|
| 158 | + public function getRawSignedRequestFromCookie() |
|
| 159 | + { |
|
| 160 | 160 | if (isset($_COOKIE['fbsr_' . $this->appId])) { |
| 161 | - return $_COOKIE['fbsr_' . $this->appId]; |
|
| 161 | + return $_COOKIE['fbsr_' . $this->appId]; |
|
| 162 | 162 | } |
| 163 | 163 | return null; |
| 164 | - } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | } |
@@ -31,34 +31,34 @@ |
||
| 31 | 31 | class GraphPage extends GraphObject |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the ID for the user's page as a string if present. |
|
| 36 | - * |
|
| 37 | - * @return string|null |
|
| 38 | - */ |
|
| 39 | - public function getId() |
|
| 40 | - { |
|
| 34 | + /** |
|
| 35 | + * Returns the ID for the user's page as a string if present. |
|
| 36 | + * |
|
| 37 | + * @return string|null |
|
| 38 | + */ |
|
| 39 | + public function getId() |
|
| 40 | + { |
|
| 41 | 41 | return $this->getProperty('id'); |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Returns the Category for the user's page as a string if present. |
|
| 46 | - * |
|
| 47 | - * @return string|null |
|
| 48 | - */ |
|
| 49 | - public function getCategory() |
|
| 50 | - { |
|
| 44 | + /** |
|
| 45 | + * Returns the Category for the user's page as a string if present. |
|
| 46 | + * |
|
| 47 | + * @return string|null |
|
| 48 | + */ |
|
| 49 | + public function getCategory() |
|
| 50 | + { |
|
| 51 | 51 | return $this->getProperty('category'); |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Returns the Name of the user's page as a string if present. |
|
| 56 | - * |
|
| 57 | - * @return string|null |
|
| 58 | - */ |
|
| 59 | - public function getName() |
|
| 60 | - { |
|
| 54 | + /** |
|
| 55 | + * Returns the Name of the user's page as a string if present. |
|
| 56 | + * |
|
| 57 | + * @return string|null |
|
| 58 | + */ |
|
| 59 | + public function getName() |
|
| 60 | + { |
|
| 61 | 61 | return $this->getProperty('name'); |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -32,293 +32,293 @@ |
||
| 32 | 32 | class FacebookRedirectLoginHelper |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string The application id |
|
| 37 | - */ |
|
| 38 | - private $appId; |
|
| 35 | + /** |
|
| 36 | + * @var string The application id |
|
| 37 | + */ |
|
| 38 | + private $appId; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string The application secret |
|
| 42 | - */ |
|
| 43 | - private $appSecret; |
|
| 40 | + /** |
|
| 41 | + * @var string The application secret |
|
| 42 | + */ |
|
| 43 | + private $appSecret; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string The redirect URL for the application |
|
| 47 | - */ |
|
| 48 | - private $redirectUrl; |
|
| 45 | + /** |
|
| 46 | + * @var string The redirect URL for the application |
|
| 47 | + */ |
|
| 48 | + private $redirectUrl; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string Prefix to use for session variables |
|
| 52 | - */ |
|
| 53 | - private $sessionPrefix = 'FBRLH_'; |
|
| 50 | + /** |
|
| 51 | + * @var string Prefix to use for session variables |
|
| 52 | + */ |
|
| 53 | + private $sessionPrefix = 'FBRLH_'; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string State token for CSRF validation |
|
| 57 | - */ |
|
| 58 | - protected $state; |
|
| 55 | + /** |
|
| 56 | + * @var string State token for CSRF validation |
|
| 57 | + */ |
|
| 58 | + protected $state; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var boolean Toggle for PHP session status check |
|
| 62 | - */ |
|
| 63 | - protected $checkForSessionStatus = true; |
|
| 60 | + /** |
|
| 61 | + * @var boolean Toggle for PHP session status check |
|
| 62 | + */ |
|
| 63 | + protected $checkForSessionStatus = true; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Constructs a RedirectLoginHelper for a given appId and redirectUrl. |
|
| 67 | - * |
|
| 68 | - * @param string $redirectUrl The URL Facebook should redirect users to |
|
| 69 | - * after login |
|
| 70 | - * @param string $appId The application id |
|
| 71 | - * @param string $appSecret The application secret |
|
| 72 | - */ |
|
| 73 | - public function __construct($redirectUrl, $appId = null, $appSecret = null) |
|
| 74 | - { |
|
| 65 | + /** |
|
| 66 | + * Constructs a RedirectLoginHelper for a given appId and redirectUrl. |
|
| 67 | + * |
|
| 68 | + * @param string $redirectUrl The URL Facebook should redirect users to |
|
| 69 | + * after login |
|
| 70 | + * @param string $appId The application id |
|
| 71 | + * @param string $appSecret The application secret |
|
| 72 | + */ |
|
| 73 | + public function __construct($redirectUrl, $appId = null, $appSecret = null) |
|
| 74 | + { |
|
| 75 | 75 | $this->appId = FacebookSession::_getTargetAppId($appId); |
| 76 | 76 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); |
| 77 | 77 | $this->redirectUrl = $redirectUrl; |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Stores CSRF state and returns a URL to which the user should be sent to |
|
| 82 | - * in order to continue the login process with Facebook. The |
|
| 83 | - * provided redirectUrl should invoke the handleRedirect method. |
|
| 84 | - * |
|
| 85 | - * @param array $scope List of permissions to request during login |
|
| 86 | - * @param string $version Optional Graph API version if not default (v2.0) |
|
| 87 | - * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false) |
|
| 92 | - { |
|
| 80 | + /** |
|
| 81 | + * Stores CSRF state and returns a URL to which the user should be sent to |
|
| 82 | + * in order to continue the login process with Facebook. The |
|
| 83 | + * provided redirectUrl should invoke the handleRedirect method. |
|
| 84 | + * |
|
| 85 | + * @param array $scope List of permissions to request during login |
|
| 86 | + * @param string $version Optional Graph API version if not default (v2.0) |
|
| 87 | + * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false) |
|
| 92 | + { |
|
| 93 | 93 | |
| 94 | 94 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); |
| 95 | 95 | $this->state = $this->random(16); |
| 96 | 96 | $this->storeState($this->state); |
| 97 | 97 | |
| 98 | 98 | $params = array( |
| 99 | - 'client_id' => $this->appId, |
|
| 100 | - 'redirect_uri' => $this->redirectUrl, |
|
| 101 | - 'state' => $this->state, |
|
| 102 | - 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
| 103 | - 'scope' => implode(',', $scope) |
|
| 99 | + 'client_id' => $this->appId, |
|
| 100 | + 'redirect_uri' => $this->redirectUrl, |
|
| 101 | + 'state' => $this->state, |
|
| 102 | + 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
| 103 | + 'scope' => implode(',', $scope) |
|
| 104 | 104 | ); |
| 105 | 105 | |
| 106 | 106 | if ($displayAsPopup) |
| 107 | 107 | { |
| 108 | - $params['display'] = 'popup'; |
|
| 108 | + $params['display'] = 'popup'; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . |
| 112 | - http_build_query($params, null, '&'); |
|
| 113 | - } |
|
| 112 | + http_build_query($params, null, '&'); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Returns a URL to which the user should be sent to re-request permissions. |
|
| 117 | - * |
|
| 118 | - * @param array $scope List of permissions to re-request |
|
| 119 | - * @param string $version Optional Graph API version if not default (v2.0) |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getReRequestUrl($scope = array(), $version = null) |
|
| 124 | - { |
|
| 115 | + /** |
|
| 116 | + * Returns a URL to which the user should be sent to re-request permissions. |
|
| 117 | + * |
|
| 118 | + * @param array $scope List of permissions to re-request |
|
| 119 | + * @param string $version Optional Graph API version if not default (v2.0) |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getReRequestUrl($scope = array(), $version = null) |
|
| 124 | + { |
|
| 125 | 125 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); |
| 126 | 126 | $this->state = $this->random(16); |
| 127 | 127 | $this->storeState($this->state); |
| 128 | 128 | $params = array( |
| 129 | - 'client_id' => $this->appId, |
|
| 130 | - 'redirect_uri' => $this->redirectUrl, |
|
| 131 | - 'state' => $this->state, |
|
| 132 | - 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
| 133 | - 'auth_type' => 'rerequest', |
|
| 134 | - 'scope' => implode(',', $scope) |
|
| 129 | + 'client_id' => $this->appId, |
|
| 130 | + 'redirect_uri' => $this->redirectUrl, |
|
| 131 | + 'state' => $this->state, |
|
| 132 | + 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
| 133 | + 'auth_type' => 'rerequest', |
|
| 134 | + 'scope' => implode(',', $scope) |
|
| 135 | 135 | ); |
| 136 | 136 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . |
| 137 | - http_build_query($params, null, '&'); |
|
| 138 | - } |
|
| 137 | + http_build_query($params, null, '&'); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Returns the URL to send the user in order to log out of Facebook. |
|
| 142 | - * |
|
| 143 | - * @param FacebookSession $session The session that will be logged out |
|
| 144 | - * @param string $next The url Facebook should redirect the user to after |
|
| 145 | - * a successful logout |
|
| 146 | - * |
|
| 147 | - * @return string |
|
| 148 | - * |
|
| 149 | - * @throws FacebookSDKException |
|
| 150 | - */ |
|
| 151 | - public function getLogoutUrl(FacebookSession $session, $next) |
|
| 152 | - { |
|
| 140 | + /** |
|
| 141 | + * Returns the URL to send the user in order to log out of Facebook. |
|
| 142 | + * |
|
| 143 | + * @param FacebookSession $session The session that will be logged out |
|
| 144 | + * @param string $next The url Facebook should redirect the user to after |
|
| 145 | + * a successful logout |
|
| 146 | + * |
|
| 147 | + * @return string |
|
| 148 | + * |
|
| 149 | + * @throws FacebookSDKException |
|
| 150 | + */ |
|
| 151 | + public function getLogoutUrl(FacebookSession $session, $next) |
|
| 152 | + { |
|
| 153 | 153 | if ($session->getAccessToken()->isAppSession()) { |
| 154 | - throw new FacebookSDKException( |
|
| 154 | + throw new FacebookSDKException( |
|
| 155 | 155 | 'Cannot generate a Logout URL with an App Session.', 722 |
| 156 | - ); |
|
| 156 | + ); |
|
| 157 | 157 | } |
| 158 | 158 | $params = array( |
| 159 | - 'next' => $next, |
|
| 160 | - 'access_token' => $session->getToken() |
|
| 159 | + 'next' => $next, |
|
| 160 | + 'access_token' => $session->getToken() |
|
| 161 | 161 | ); |
| 162 | 162 | return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&'); |
| 163 | - } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Handles a response from Facebook, including a CSRF check, and returns a |
|
| 167 | - * FacebookSession. |
|
| 168 | - * |
|
| 169 | - * @return FacebookSession|null |
|
| 170 | - */ |
|
| 171 | - public function getSessionFromRedirect() |
|
| 172 | - { |
|
| 165 | + /** |
|
| 166 | + * Handles a response from Facebook, including a CSRF check, and returns a |
|
| 167 | + * FacebookSession. |
|
| 168 | + * |
|
| 169 | + * @return FacebookSession|null |
|
| 170 | + */ |
|
| 171 | + public function getSessionFromRedirect() |
|
| 172 | + { |
|
| 173 | 173 | $this->loadState(); |
| 174 | 174 | if ($this->isValidRedirect()) { |
| 175 | 175 | |
| 176 | - $params = array( |
|
| 176 | + $params = array( |
|
| 177 | 177 | 'client_id' => FacebookSession::_getTargetAppId($this->appId), |
| 178 | 178 | 'redirect_uri' => $this->redirectUrl, |
| 179 | 179 | 'client_secret' => |
| 180 | - FacebookSession::_getTargetAppSecret($this->appSecret), |
|
| 180 | + FacebookSession::_getTargetAppSecret($this->appSecret), |
|
| 181 | 181 | 'code' => $this->getCode() |
| 182 | - ); |
|
| 182 | + ); |
|
| 183 | 183 | |
| 184 | - $response = (new FacebookRequest( |
|
| 184 | + $response = (new FacebookRequest( |
|
| 185 | 185 | FacebookSession::newAppSession($this->appId, $this->appSecret), |
| 186 | 186 | 'GET', |
| 187 | 187 | '/oauth/access_token', |
| 188 | 188 | $params |
| 189 | - ))->execute()->getResponse(); |
|
| 189 | + ))->execute()->getResponse(); |
|
| 190 | 190 | |
| 191 | - if (isset($response['access_token'])) { |
|
| 191 | + if (isset($response['access_token'])) { |
|
| 192 | 192 | return new FacebookSession($response['access_token']); |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | } |
| 195 | 195 | return null; |
| 196 | - } |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Check if a redirect has a valid state. |
|
| 200 | - * |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - protected function isValidRedirect() |
|
| 204 | - { |
|
| 198 | + /** |
|
| 199 | + * Check if a redirect has a valid state. |
|
| 200 | + * |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + protected function isValidRedirect() |
|
| 204 | + { |
|
| 205 | 205 | return $this->getCode() && isset($_GET['state']) |
| 206 | 206 | && $_GET['state'] == $this->state; |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Return the code. |
|
| 211 | - * |
|
| 212 | - * @return string|null |
|
| 213 | - */ |
|
| 214 | - protected function getCode() |
|
| 215 | - { |
|
| 209 | + /** |
|
| 210 | + * Return the code. |
|
| 211 | + * |
|
| 212 | + * @return string|null |
|
| 213 | + */ |
|
| 214 | + protected function getCode() |
|
| 215 | + { |
|
| 216 | 216 | |
| 217 | 217 | return isset($_GET['code']) ? $_GET['code'] : null; |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Stores a state string in session storage for CSRF protection. |
|
| 222 | - * Developers should subclass and override this method if they want to store |
|
| 223 | - * this state in a different location. |
|
| 224 | - * |
|
| 225 | - * @param string $state |
|
| 226 | - * |
|
| 227 | - * @throws FacebookSDKException |
|
| 228 | - */ |
|
| 229 | - protected function storeState($state) |
|
| 230 | - { |
|
| 220 | + /** |
|
| 221 | + * Stores a state string in session storage for CSRF protection. |
|
| 222 | + * Developers should subclass and override this method if they want to store |
|
| 223 | + * this state in a different location. |
|
| 224 | + * |
|
| 225 | + * @param string $state |
|
| 226 | + * |
|
| 227 | + * @throws FacebookSDKException |
|
| 228 | + */ |
|
| 229 | + protected function storeState($state) |
|
| 230 | + { |
|
| 231 | 231 | if ($this->checkForSessionStatus === true |
| 232 | 232 | && session_status() !== PHP_SESSION_ACTIVE) { |
| 233 | - throw new FacebookSDKException( |
|
| 233 | + throw new FacebookSDKException( |
|
| 234 | 234 | 'Session not active, could not store state.', 720 |
| 235 | - ); |
|
| 235 | + ); |
|
| 236 | 236 | } |
| 237 | 237 | $_SESSION[$this->sessionPrefix . 'state'] = $state; |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * Loads a state string from session storage for CSRF validation. May return |
|
| 242 | - * null if no object exists. Developers should subclass and override this |
|
| 243 | - * method if they want to load the state from a different location. |
|
| 244 | - * |
|
| 245 | - * @return string|null |
|
| 246 | - * |
|
| 247 | - * @throws FacebookSDKException |
|
| 248 | - */ |
|
| 249 | - protected function loadState() |
|
| 250 | - { |
|
| 240 | + /** |
|
| 241 | + * Loads a state string from session storage for CSRF validation. May return |
|
| 242 | + * null if no object exists. Developers should subclass and override this |
|
| 243 | + * method if they want to load the state from a different location. |
|
| 244 | + * |
|
| 245 | + * @return string|null |
|
| 246 | + * |
|
| 247 | + * @throws FacebookSDKException |
|
| 248 | + */ |
|
| 249 | + protected function loadState() |
|
| 250 | + { |
|
| 251 | 251 | |
| 252 | 252 | if ($this->checkForSessionStatus === true |
| 253 | 253 | && session_status() !== PHP_SESSION_ACTIVE) { |
| 254 | - throw new FacebookSDKException( |
|
| 254 | + throw new FacebookSDKException( |
|
| 255 | 255 | 'Session not active, could not load state.', 721 |
| 256 | - ); |
|
| 256 | + ); |
|
| 257 | 257 | } |
| 258 | 258 | if (isset($_SESSION[$this->sessionPrefix . 'state'])) { |
| 259 | - $this->state = $_SESSION[$this->sessionPrefix . 'state']; |
|
| 260 | - return $this->state; |
|
| 259 | + $this->state = $_SESSION[$this->sessionPrefix . 'state']; |
|
| 260 | + return $this->state; |
|
| 261 | 261 | } |
| 262 | 262 | return null; |
| 263 | - } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Generate a cryptographically secure pseudrandom number |
|
| 267 | - * |
|
| 268 | - * @param integer $bytes - number of bytes to return |
|
| 269 | - * |
|
| 270 | - * @return string |
|
| 271 | - * |
|
| 272 | - * @throws FacebookSDKException |
|
| 273 | - * |
|
| 274 | - * @todo Support Windows platforms |
|
| 275 | - */ |
|
| 276 | - public function random($bytes) |
|
| 277 | - { |
|
| 265 | + /** |
|
| 266 | + * Generate a cryptographically secure pseudrandom number |
|
| 267 | + * |
|
| 268 | + * @param integer $bytes - number of bytes to return |
|
| 269 | + * |
|
| 270 | + * @return string |
|
| 271 | + * |
|
| 272 | + * @throws FacebookSDKException |
|
| 273 | + * |
|
| 274 | + * @todo Support Windows platforms |
|
| 275 | + */ |
|
| 276 | + public function random($bytes) |
|
| 277 | + { |
|
| 278 | 278 | if (!is_numeric($bytes)) { |
| 279 | - throw new FacebookSDKException( |
|
| 279 | + throw new FacebookSDKException( |
|
| 280 | 280 | "random() expects an integer" |
| 281 | - ); |
|
| 281 | + ); |
|
| 282 | 282 | } |
| 283 | 283 | if ($bytes < 1) { |
| 284 | - throw new FacebookSDKException( |
|
| 284 | + throw new FacebookSDKException( |
|
| 285 | 285 | "random() expects an integer greater than zero" |
| 286 | - ); |
|
| 286 | + ); |
|
| 287 | 287 | } |
| 288 | 288 | $buf = ''; |
| 289 | 289 | // http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ |
| 290 | 290 | if (!ini_get('open_basedir') |
| 291 | 291 | && is_readable('/dev/urandom')) { |
| 292 | - $fp = fopen('/dev/urandom', 'rb'); |
|
| 293 | - if ($fp !== FALSE) { |
|
| 292 | + $fp = fopen('/dev/urandom', 'rb'); |
|
| 293 | + if ($fp !== FALSE) { |
|
| 294 | 294 | $buf = fread($fp, $bytes); |
| 295 | 295 | fclose($fp); |
| 296 | 296 | if($buf !== FALSE) { |
| 297 | - return bin2hex($buf); |
|
| 297 | + return bin2hex($buf); |
|
| 298 | + } |
|
| 298 | 299 | } |
| 299 | - } |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | if (function_exists('mcrypt_create_iv')) { |
| 303 | 303 | $buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); |
| 304 | 304 | if ($buf !== FALSE) { |
| 305 | - return bin2hex($buf); |
|
| 305 | + return bin2hex($buf); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | while (strlen($buf) < $bytes) { |
| 310 | - $buf .= md5(uniqid(mt_rand(), true), true); |
|
| 311 | - // We are appending raw binary |
|
| 310 | + $buf .= md5(uniqid(mt_rand(), true), true); |
|
| 311 | + // We are appending raw binary |
|
| 312 | 312 | } |
| 313 | 313 | return bin2hex(substr($buf, 0, $bytes)); |
| 314 | - } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * Disables the session_status() check when using $_SESSION |
|
| 318 | - */ |
|
| 319 | - public function disableSessionStatusCheck() |
|
| 320 | - { |
|
| 316 | + /** |
|
| 317 | + * Disables the session_status() check when using $_SESSION |
|
| 318 | + */ |
|
| 319 | + public function disableSessionStatusCheck() |
|
| 320 | + { |
|
| 321 | 321 | $this->checkForSessionStatus = false; |
| 322 | - } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | 324 | } |
@@ -32,29 +32,29 @@ |
||
| 32 | 32 | class FacebookCanvasLoginHelper extends FacebookSignedRequestFromInputHelper |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Returns the app data value. |
|
| 37 | - * |
|
| 38 | - * @return mixed|null |
|
| 39 | - */ |
|
| 40 | - public function getAppData() |
|
| 41 | - { |
|
| 35 | + /** |
|
| 36 | + * Returns the app data value. |
|
| 37 | + * |
|
| 38 | + * @return mixed|null |
|
| 39 | + */ |
|
| 40 | + public function getAppData() |
|
| 41 | + { |
|
| 42 | 42 | return $this->signedRequest ? $this->signedRequest->get('app_data') : null; |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Get raw signed request from POST. |
|
| 47 | - * |
|
| 48 | - * @return string|null |
|
| 49 | - */ |
|
| 50 | - public function getRawSignedRequest() |
|
| 51 | - { |
|
| 45 | + /** |
|
| 46 | + * Get raw signed request from POST. |
|
| 47 | + * |
|
| 48 | + * @return string|null |
|
| 49 | + */ |
|
| 50 | + public function getRawSignedRequest() |
|
| 51 | + { |
|
| 52 | 52 | $rawSignedRequest = $this->getRawSignedRequestFromPost(); |
| 53 | 53 | if ($rawSignedRequest) { |
| 54 | - return $rawSignedRequest; |
|
| 54 | + return $rawSignedRequest; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return null; |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
@@ -31,72 +31,72 @@ |
||
| 31 | 31 | class FacebookPageTabHelper extends FacebookCanvasLoginHelper |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array|null |
|
| 36 | - */ |
|
| 37 | - protected $pageData; |
|
| 34 | + /** |
|
| 35 | + * @var array|null |
|
| 36 | + */ |
|
| 37 | + protected $pageData; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initialize the helper and process available signed request data. |
|
| 41 | - * |
|
| 42 | - * @param string|null $appId |
|
| 43 | - * @param string|null $appSecret |
|
| 44 | - */ |
|
| 45 | - public function __construct($appId = null, $appSecret = null) |
|
| 46 | - { |
|
| 39 | + /** |
|
| 40 | + * Initialize the helper and process available signed request data. |
|
| 41 | + * |
|
| 42 | + * @param string|null $appId |
|
| 43 | + * @param string|null $appSecret |
|
| 44 | + */ |
|
| 45 | + public function __construct($appId = null, $appSecret = null) |
|
| 46 | + { |
|
| 47 | 47 | parent::__construct($appId, $appSecret); |
| 48 | 48 | |
| 49 | 49 | if (!$this->signedRequest) { |
| 50 | - return; |
|
| 50 | + return; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->pageData = $this->signedRequest->get('page'); |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Returns a value from the page data. |
|
| 58 | - * |
|
| 59 | - * @param string $key |
|
| 60 | - * @param mixed|null $default |
|
| 61 | - * |
|
| 62 | - * @return mixed|null |
|
| 63 | - */ |
|
| 64 | - public function getPageData($key, $default = null) |
|
| 65 | - { |
|
| 56 | + /** |
|
| 57 | + * Returns a value from the page data. |
|
| 58 | + * |
|
| 59 | + * @param string $key |
|
| 60 | + * @param mixed|null $default |
|
| 61 | + * |
|
| 62 | + * @return mixed|null |
|
| 63 | + */ |
|
| 64 | + public function getPageData($key, $default = null) |
|
| 65 | + { |
|
| 66 | 66 | if (isset($this->pageData[$key])) { |
| 67 | - return $this->pageData[$key]; |
|
| 67 | + return $this->pageData[$key]; |
|
| 68 | 68 | } |
| 69 | 69 | return $default; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns true if the page is liked by the user. |
|
| 74 | - * |
|
| 75 | - * @return boolean |
|
| 76 | - */ |
|
| 77 | - public function isLiked() |
|
| 78 | - { |
|
| 72 | + /** |
|
| 73 | + * Returns true if the page is liked by the user. |
|
| 74 | + * |
|
| 75 | + * @return boolean |
|
| 76 | + */ |
|
| 77 | + public function isLiked() |
|
| 78 | + { |
|
| 79 | 79 | return $this->getPageData('liked') === true; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns true if the user is an admin. |
|
| 84 | - * |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - public function isAdmin() |
|
| 88 | - { |
|
| 82 | + /** |
|
| 83 | + * Returns true if the user is an admin. |
|
| 84 | + * |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + public function isAdmin() |
|
| 88 | + { |
|
| 89 | 89 | return $this->getPageData('admin') === true; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Returns the page id if available. |
|
| 94 | - * |
|
| 95 | - * @return string|null |
|
| 96 | - */ |
|
| 97 | - public function getPageId() |
|
| 98 | - { |
|
| 92 | + /** |
|
| 93 | + * Returns the page id if available. |
|
| 94 | + * |
|
| 95 | + * @return string|null |
|
| 96 | + */ |
|
| 97 | + public function getPageId() |
|
| 98 | + { |
|
| 99 | 99 | return $this->getPageData('id'); |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | } |
@@ -32,84 +32,84 @@ |
||
| 32 | 32 | class GraphSessionInfo extends GraphObject |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Returns the application id the token was issued for. |
|
| 37 | - * |
|
| 38 | - * @return string|null |
|
| 39 | - */ |
|
| 40 | - public function getAppId() |
|
| 41 | - { |
|
| 35 | + /** |
|
| 36 | + * Returns the application id the token was issued for. |
|
| 37 | + * |
|
| 38 | + * @return string|null |
|
| 39 | + */ |
|
| 40 | + public function getAppId() |
|
| 41 | + { |
|
| 42 | 42 | return $this->getProperty('app_id'); |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Returns the application name the token was issued for. |
|
| 47 | - * |
|
| 48 | - * @return string|null |
|
| 49 | - */ |
|
| 50 | - public function getApplication() |
|
| 51 | - { |
|
| 45 | + /** |
|
| 46 | + * Returns the application name the token was issued for. |
|
| 47 | + * |
|
| 48 | + * @return string|null |
|
| 49 | + */ |
|
| 50 | + public function getApplication() |
|
| 51 | + { |
|
| 52 | 52 | return $this->getProperty('application'); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns the date & time that the token expires. |
|
| 57 | - * |
|
| 58 | - * @return \DateTime|null |
|
| 59 | - */ |
|
| 60 | - public function getExpiresAt() |
|
| 61 | - { |
|
| 55 | + /** |
|
| 56 | + * Returns the date & time that the token expires. |
|
| 57 | + * |
|
| 58 | + * @return \DateTime|null |
|
| 59 | + */ |
|
| 60 | + public function getExpiresAt() |
|
| 61 | + { |
|
| 62 | 62 | $stamp = $this->getProperty('expires_at'); |
| 63 | 63 | if ($stamp) { |
| 64 | - return (new \DateTime())->setTimestamp($stamp); |
|
| 64 | + return (new \DateTime())->setTimestamp($stamp); |
|
| 65 | 65 | } else { |
| 66 | - return null; |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | - } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Returns whether the token is valid. |
|
| 72 | - * |
|
| 73 | - * @return boolean |
|
| 74 | - */ |
|
| 75 | - public function isValid() |
|
| 76 | - { |
|
| 70 | + /** |
|
| 71 | + * Returns whether the token is valid. |
|
| 72 | + * |
|
| 73 | + * @return boolean |
|
| 74 | + */ |
|
| 75 | + public function isValid() |
|
| 76 | + { |
|
| 77 | 77 | return $this->getProperty('is_valid'); |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Returns the date & time the token was issued at. |
|
| 82 | - * |
|
| 83 | - * @return \DateTime|null |
|
| 84 | - */ |
|
| 85 | - public function getIssuedAt() |
|
| 86 | - { |
|
| 80 | + /** |
|
| 81 | + * Returns the date & time the token was issued at. |
|
| 82 | + * |
|
| 83 | + * @return \DateTime|null |
|
| 84 | + */ |
|
| 85 | + public function getIssuedAt() |
|
| 86 | + { |
|
| 87 | 87 | $stamp = $this->getProperty('issued_at'); |
| 88 | 88 | if ($stamp) { |
| 89 | - return (new \DateTime())->setTimestamp($stamp); |
|
| 89 | + return (new \DateTime())->setTimestamp($stamp); |
|
| 90 | 90 | } else { |
| 91 | - return null; |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 92 | 93 | } |
| 93 | - } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Returns the scope permissions associated with the token. |
|
| 97 | - * |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getScopes() |
|
| 101 | - { |
|
| 95 | + /** |
|
| 96 | + * Returns the scope permissions associated with the token. |
|
| 97 | + * |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getScopes() |
|
| 101 | + { |
|
| 102 | 102 | return $this->getPropertyAsArray('scopes'); |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Returns the login id of the user associated with the token. |
|
| 107 | - * |
|
| 108 | - * @return string|null |
|
| 109 | - */ |
|
| 110 | - public function getId() |
|
| 111 | - { |
|
| 105 | + /** |
|
| 106 | + * Returns the login id of the user associated with the token. |
|
| 107 | + * |
|
| 108 | + * @return string|null |
|
| 109 | + */ |
|
| 110 | + public function getId() |
|
| 111 | + { |
|
| 112 | 112 | return $this->getProperty('user_id'); |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
| 116 | 116 | \ No newline at end of file |
@@ -32,175 +32,175 @@ |
||
| 32 | 32 | class FacebookResponse |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var FacebookRequest The request which produced this response |
|
| 37 | - */ |
|
| 38 | - private $request; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array The decoded response from the Graph API |
|
| 42 | - */ |
|
| 43 | - private $responseData; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string The raw response from the Graph API |
|
| 47 | - */ |
|
| 48 | - private $rawResponse; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var bool Indicates whether sent ETag matched the one on the FB side |
|
| 52 | - */ |
|
| 53 | - private $etagHit; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string ETag received with the response. `null` in case of ETag hit. |
|
| 57 | - */ |
|
| 58 | - private $etag; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Creates a FacebookResponse object for a given request and response. |
|
| 62 | - * |
|
| 63 | - * @param FacebookRequest $request |
|
| 64 | - * @param array $responseData JSON Decoded response data |
|
| 65 | - * @param string $rawResponse Raw string response |
|
| 66 | - * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side |
|
| 67 | - * @param string|null $etag ETag received with the response. `null` in case of ETag hit. |
|
| 68 | - */ |
|
| 69 | - public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) |
|
| 70 | - { |
|
| 35 | + /** |
|
| 36 | + * @var FacebookRequest The request which produced this response |
|
| 37 | + */ |
|
| 38 | + private $request; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array The decoded response from the Graph API |
|
| 42 | + */ |
|
| 43 | + private $responseData; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string The raw response from the Graph API |
|
| 47 | + */ |
|
| 48 | + private $rawResponse; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var bool Indicates whether sent ETag matched the one on the FB side |
|
| 52 | + */ |
|
| 53 | + private $etagHit; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string ETag received with the response. `null` in case of ETag hit. |
|
| 57 | + */ |
|
| 58 | + private $etag; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Creates a FacebookResponse object for a given request and response. |
|
| 62 | + * |
|
| 63 | + * @param FacebookRequest $request |
|
| 64 | + * @param array $responseData JSON Decoded response data |
|
| 65 | + * @param string $rawResponse Raw string response |
|
| 66 | + * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side |
|
| 67 | + * @param string|null $etag ETag received with the response. `null` in case of ETag hit. |
|
| 68 | + */ |
|
| 69 | + public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) |
|
| 70 | + { |
|
| 71 | 71 | $this->request = $request; |
| 72 | 72 | $this->responseData = $responseData; |
| 73 | 73 | $this->rawResponse = $rawResponse; |
| 74 | 74 | $this->etagHit = $etagHit; |
| 75 | 75 | $this->etag = $etag; |
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Returns the request which produced this response. |
|
| 80 | - * |
|
| 81 | - * @return FacebookRequest |
|
| 82 | - */ |
|
| 83 | - public function getRequest() |
|
| 84 | - { |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Returns the request which produced this response. |
|
| 80 | + * |
|
| 81 | + * @return FacebookRequest |
|
| 82 | + */ |
|
| 83 | + public function getRequest() |
|
| 84 | + { |
|
| 85 | 85 | return $this->request; |
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the decoded response data. |
|
| 90 | - * |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function getResponse() |
|
| 94 | - { |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the decoded response data. |
|
| 90 | + * |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function getResponse() |
|
| 94 | + { |
|
| 95 | 95 | return $this->responseData; |
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Returns the raw response |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getRawResponse() |
|
| 104 | - { |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Returns the raw response |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getRawResponse() |
|
| 104 | + { |
|
| 105 | 105 | return $this->rawResponse; |
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Returns true if ETag matched the one sent with a request |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function isETagHit() |
|
| 114 | - { |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Returns true if ETag matched the one sent with a request |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function isETagHit() |
|
| 114 | + { |
|
| 115 | 115 | return $this->etagHit; |
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Returns the ETag |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getETag() |
|
| 124 | - { |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Returns the ETag |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getETag() |
|
| 124 | + { |
|
| 125 | 125 | return $this->etag; |
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Gets the result as a GraphObject. If a type is specified, returns the |
|
| 130 | - * strongly-typed subclass of GraphObject for the data. |
|
| 131 | - * |
|
| 132 | - * @param string $type |
|
| 133 | - * |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function getGraphObject($type = 'Facebook\GraphObject') { |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Gets the result as a GraphObject. If a type is specified, returns the |
|
| 130 | + * strongly-typed subclass of GraphObject for the data. |
|
| 131 | + * |
|
| 132 | + * @param string $type |
|
| 133 | + * |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function getGraphObject($type = 'Facebook\GraphObject') { |
|
| 137 | 137 | return (new GraphObject($this->responseData))->cast($type); |
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of GraphObject returned by the request. If a type is |
|
| 142 | - * specified, returns the strongly-typed subclass of GraphObject for the data. |
|
| 143 | - * |
|
| 144 | - * @param string $type |
|
| 145 | - * |
|
| 146 | - * @return mixed |
|
| 147 | - */ |
|
| 148 | - public function getGraphObjectList($type = 'Facebook\GraphObject') { |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of GraphObject returned by the request. If a type is |
|
| 142 | + * specified, returns the strongly-typed subclass of GraphObject for the data. |
|
| 143 | + * |
|
| 144 | + * @param string $type |
|
| 145 | + * |
|
| 146 | + * @return mixed |
|
| 147 | + */ |
|
| 148 | + public function getGraphObjectList($type = 'Facebook\GraphObject') { |
|
| 149 | 149 | $out = array(); |
| 150 | 150 | $data = $this->responseData->data; |
| 151 | 151 | $dataLength = count($data); |
| 152 | 152 | for ($i = 0; $i < $dataLength; $i++) { |
| 153 | - $out[] = (new GraphObject($data[$i]))->cast($type); |
|
| 153 | + $out[] = (new GraphObject($data[$i]))->cast($type); |
|
| 154 | 154 | } |
| 155 | 155 | return $out; |
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * If this response has paginated data, returns the FacebookRequest for the |
|
| 160 | - * next page, or null. |
|
| 161 | - * |
|
| 162 | - * @return FacebookRequest|null |
|
| 163 | - */ |
|
| 164 | - public function getRequestForNextPage() |
|
| 165 | - { |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * If this response has paginated data, returns the FacebookRequest for the |
|
| 160 | + * next page, or null. |
|
| 161 | + * |
|
| 162 | + * @return FacebookRequest|null |
|
| 163 | + */ |
|
| 164 | + public function getRequestForNextPage() |
|
| 165 | + { |
|
| 166 | 166 | return $this->handlePagination('next'); |
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * If this response has paginated data, returns the FacebookRequest for the |
|
| 171 | - * previous page, or null. |
|
| 172 | - * |
|
| 173 | - * @return FacebookRequest|null |
|
| 174 | - */ |
|
| 175 | - public function getRequestForPreviousPage() |
|
| 176 | - { |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * If this response has paginated data, returns the FacebookRequest for the |
|
| 171 | + * previous page, or null. |
|
| 172 | + * |
|
| 173 | + * @return FacebookRequest|null |
|
| 174 | + */ |
|
| 175 | + public function getRequestForPreviousPage() |
|
| 176 | + { |
|
| 177 | 177 | return $this->handlePagination('previous'); |
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Returns the FacebookRequest for the previous or next page, or null. |
|
| 182 | - * |
|
| 183 | - * @param string $direction |
|
| 184 | - * |
|
| 185 | - * @return FacebookRequest|null |
|
| 186 | - */ |
|
| 187 | - private function handlePagination($direction) { |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Returns the FacebookRequest for the previous or next page, or null. |
|
| 182 | + * |
|
| 183 | + * @param string $direction |
|
| 184 | + * |
|
| 185 | + * @return FacebookRequest|null |
|
| 186 | + */ |
|
| 187 | + private function handlePagination($direction) { |
|
| 188 | 188 | if (isset($this->responseData->paging->$direction)) { |
| 189 | - $url = parse_url($this->responseData->paging->$direction); |
|
| 190 | - parse_str($url['query'], $params); |
|
| 189 | + $url = parse_url($this->responseData->paging->$direction); |
|
| 190 | + parse_str($url['query'], $params); |
|
| 191 | 191 | |
| 192 | - if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ |
|
| 192 | + if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ |
|
| 193 | 193 | unset($params['type']); |
| 194 | - } |
|
| 195 | - return new FacebookRequest( |
|
| 194 | + } |
|
| 195 | + return new FacebookRequest( |
|
| 196 | 196 | $this->request->getSession(), |
| 197 | 197 | $this->request->getMethod(), |
| 198 | 198 | $this->request->getPath(), |
| 199 | 199 | $params |
| 200 | - ); |
|
| 200 | + ); |
|
| 201 | 201 | } else { |
| 202 | - return null; |
|
| 202 | + return null; |
|
| 203 | + } |
|
| 203 | 204 | } |
| 204 | - } |
|
| 205 | 205 | |
| 206 | 206 | } |