Просмотр исходного кода

#1222 Facebook SDK was updated up to 5.6.2 version

Alex Trofimov 8 лет назад
Родитель
Сommit
586eb09e8f

+ 1 - 1
plugins/facebook-php-sdk/LICENSE

@@ -1,4 +1,4 @@
-Copyright 2016 Facebook, Inc.
+Copyright 2017 Facebook, Inc.
 
 You are hereby granted a non-exclusive, worldwide, royalty-free license to
 use, copy, modify, and distribute this software in source code or binary

+ 4 - 3
plugins/facebook-php-sdk/composer.json

@@ -1,14 +1,14 @@
 {
-    "name": "facebook/php-sdk-v4",
+    "name": "facebook/graph-sdk",
     "description": "Facebook SDK for PHP",
     "keywords": ["facebook", "sdk"],
     "type": "library",
-    "homepage": "https://github.com/facebook/facebook-php-sdk-v4",
+    "homepage": "https://github.com/facebook/php-graph-sdk",
     "license": "Facebook Platform",
     "authors": [
         {
             "name": "Facebook",
-            "homepage": "https://github.com/facebook/facebook-php-sdk-v4/contributors"
+            "homepage": "https://github.com/facebook/php-graph-sdk/contributors"
         }
     ],
     "require": {
@@ -20,6 +20,7 @@
         "guzzlehttp/guzzle": "~5.0"
     },
     "suggest": {
+        "paragonie/random_compat": "Provides a better CSPRNG option in PHP 5",
         "guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client"
     },
     "autoload": {

+ 1 - 1
plugins/facebook-php-sdk/src/Facebook/Authentication/OAuth2Client.php

@@ -125,8 +125,8 @@ class OAuth2Client
      * Generates an authorization URL to begin the process of authenticating a user.
      *
      * @param string $redirectUrl The callback URL to redirect to.
-     * @param array  $scope       An array of permissions to request.
      * @param string $state       The CSPRNG-generated CSRF value.
+     * @param array  $scope       An array of permissions to request.
      * @param array  $params      An array of parameters to generate URL.
      * @param string $separator   The separator to use in http_build_query().
      *

+ 2 - 0
plugins/facebook-php-sdk/src/Facebook/Exceptions/FacebookResponseException.php

@@ -113,7 +113,9 @@ class FacebookResponseException extends FacebookSDKException
             // API Throttling
             case 4:
             case 17:
+            case 32:
             case 341:
+            case 613:
                 return new static($response, new FacebookThrottleException($message, $code));
 
             // Duplicate Post

+ 23 - 2
plugins/facebook-php-sdk/src/Facebook/Facebook.php

@@ -53,12 +53,12 @@ class Facebook
     /**
      * @const string Version number of the Facebook PHP SDK.
      */
-    const VERSION = '5.4.4';
+    const VERSION = '5.6.2';
 
     /**
      * @const string Default Graph API version for requests.
      */
-    const DEFAULT_GRAPH_VERSION = 'v2.8';
+    const DEFAULT_GRAPH_VERSION = 'v2.10';
 
     /**
      * @const string The name of the environment variable that contains the app ID.
@@ -494,6 +494,27 @@ class Facebook
         return $this->lastResponse = $this->client->sendBatchRequest($batchRequest);
     }
 
+    /**
+     * Instantiates an empty FacebookBatchRequest entity.
+     *
+     * @param  AccessToken|string|null $accessToken  The top-level access token. Requests with no access token
+     *                                               will fallback to this.
+     * @param  string|null             $graphVersion The Graph API version to use.
+     * @return FacebookBatchRequest
+     */
+    public function newBatchRequest($accessToken = null, $graphVersion = null)
+    {
+        $accessToken = $accessToken ?: $this->defaultAccessToken;
+        $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
+
+        return new FacebookBatchRequest(
+            $this->app,
+            [],
+            $accessToken,
+            $graphVersion
+        );
+    }
+
     /**
      * Instantiates a new FacebookRequest entity.
      *

+ 43 - 22
plugins/facebook-php-sdk/src/Facebook/FacebookBatchRequest.php

@@ -62,16 +62,17 @@ class FacebookBatchRequest extends FacebookRequest implements IteratorAggregate,
     }
 
     /**
-     * A a new request to the array.
+     * Adds a new request to the array.
      *
      * @param FacebookRequest|array $request
-     * @param string|null           $name
+     * @param string|null|array     $options Array of batch request options e.g. 'name', 'omit_response_on_success'.
+     *                                       If a string is given, it is the value of the 'name' option.
      *
      * @return FacebookBatchRequest
      *
      * @throws \InvalidArgumentException
      */
-    public function add($request, $name = null)
+    public function add($request, $options = null)
     {
         if (is_array($request)) {
             foreach ($request as $key => $req) {
@@ -85,17 +86,28 @@ class FacebookBatchRequest extends FacebookRequest implements IteratorAggregate,
             throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
         }
 
+        if (null === $options) {
+            $options = [];
+        } elseif (!is_array($options)) {
+            $options = ['name' => $options];
+        }
+
         $this->addFallbackDefaults($request);
+
+        // File uploads
+        $attachedFiles = $this->extractFileAttachments($request);
+
+        $name = isset($options['name']) ? $options['name'] : null;
+
+        unset($options['name']);
+
         $requestToAdd = [
             'name' => $name,
             'request' => $request,
+            'options' => $options,
+            'attached_files' => $attachedFiles,
         ];
 
-        // File uploads
-        $attachedFiles = $this->extractFileAttachments($request);
-        if ($attachedFiles) {
-            $requestToAdd['attached_files'] = $attachedFiles;
-        }
         $this->requests[] = $requestToAdd;
 
         return $this;
@@ -189,8 +201,15 @@ class FacebookBatchRequest extends FacebookRequest implements IteratorAggregate,
     {
         $requests = [];
         foreach ($this->requests as $request) {
-            $attachedFiles = isset($request['attached_files']) ? $request['attached_files'] : null;
-            $requests[] = $this->requestEntityToBatchArray($request['request'], $request['name'], $attachedFiles);
+            $options = [];
+
+            if (null !== $request['name']) {
+                $options['name'] = $request['name'];
+            }
+
+            $options += $request['options'];
+
+            $requests[] = $this->requestEntityToBatchArray($request['request'], $options, $request['attached_files']);
         }
 
         return json_encode($requests);
@@ -215,14 +234,22 @@ class FacebookBatchRequest extends FacebookRequest implements IteratorAggregate,
     /**
      * Converts a Request entity into an array that is batch-friendly.
      *
-     * @param FacebookRequest $request       The request entity to convert.
-     * @param string|null     $requestName   The name of the request.
-     * @param string|null     $attachedFiles Names of files associated with the request.
+     * @param FacebookRequest   $request       The request entity to convert.
+     * @param string|null|array $options       Array of batch request options e.g. 'name', 'omit_response_on_success'.
+     *                                         If a string is given, it is the value of the 'name' option.
+     * @param string|null       $attachedFiles Names of files associated with the request.
      *
      * @return array
      */
-    public function requestEntityToBatchArray(FacebookRequest $request, $requestName = null, $attachedFiles = null)
+    public function requestEntityToBatchArray(FacebookRequest $request, $options = null, $attachedFiles = null)
     {
+
+        if (null === $options) {
+            $options = [];
+        } elseif (!is_array($options)) {
+            $options = ['name' => $options];
+        }
+
         $compiledHeaders = [];
         $headers = $request->getHeaders();
         foreach ($headers as $name => $value) {
@@ -242,18 +269,12 @@ class FacebookBatchRequest extends FacebookRequest implements IteratorAggregate,
             $batch['body'] = $body;
         }
 
-        if (isset($requestName)) {
-            $batch['name'] = $requestName;
-        }
+        $batch += $options;
 
-        if (isset($attachedFiles)) {
+        if (null !== $attachedFiles) {
             $batch['attached_files'] = $attachedFiles;
         }
 
-        // @TODO Add support for "omit_response_on_success"
-        // @TODO Add support for "depends_on"
-        // @TODO Add support for JSONP with "callback"
-
         return $batch;
     }
 

+ 1 - 1
plugins/facebook-php-sdk/src/Facebook/FacebookRequest.php

@@ -108,7 +108,7 @@ class FacebookRequest
     /**
      * Set the access token for this request.
      *
-     * @param AccessToken|string
+     * @param AccessToken|string|null
      *
      * @return FacebookRequest
      */

+ 1 - 1
plugins/facebook-php-sdk/src/Facebook/GraphNodes/GraphUser.php

@@ -123,7 +123,7 @@ class GraphUser extends GraphNode
     /**
      * Returns the users birthday, if available.
      *
-     * @return \DateTime|null
+     * @return Birthday|null
      */
     public function getBirthday()
     {

+ 2 - 2
plugins/facebook-php-sdk/src/Facebook/Helpers/FacebookRedirectLoginHelper.php

@@ -222,8 +222,8 @@ class FacebookRedirectLoginHelper
         $this->resetCsrf();
 
         $redirectUrl = $redirectUrl ?: $this->urlDetectionHandler->getCurrentUrl();
-        // At minimum we need to remove the state param
-        $redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['state']);
+        // At minimum we need to remove the 'state' and 'code' params
+        $redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['code', 'state']);
 
         return $this->oAuth2Client->getAccessTokenFromCode($code, $redirectUrl);
     }

+ 1 - 1
plugins/facebook-php-sdk/src/Facebook/HttpClients/FacebookCurlHttpClient.php

@@ -98,7 +98,7 @@ class FacebookCurlHttpClient implements FacebookHttpClientInterface
             CURLOPT_URL => $url,
             CURLOPT_CONNECTTIMEOUT => 10,
             CURLOPT_TIMEOUT => $timeOut,
-            CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects
+            CURLOPT_RETURNTRANSFER => true, // Return response as string
             CURLOPT_HEADER => true, // Enable header processing
             CURLOPT_SSL_VERIFYHOST => 2,
             CURLOPT_SSL_VERIFYPEER => true,

+ 3 - 3
plugins/facebook-php-sdk/src/Facebook/SignedRequest.php

@@ -164,7 +164,7 @@ class SignedRequest
     /**
      * Splits a raw signed request into signature and payload.
      *
-     * @returns array
+     * @return array
      *
      * @throws FacebookSDKException
      */
@@ -182,7 +182,7 @@ class SignedRequest
      *
      * @param string $encodedSig
      *
-     * @returns string
+     * @return string
      *
      * @throws FacebookSDKException
      */
@@ -202,7 +202,7 @@ class SignedRequest
      *
      * @param string $encodedPayload
      *
-     * @returns array
+     * @return array
      *
      * @throws FacebookSDKException
      */