From 96e657e28bc4fcc834abb12655ebe4d57eaccf42 Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Mon, 4 Dec 2017 14:00:44 +0100 Subject: [PATCH 01/14] mcrypt_create_iv is deprecated in PHP7.1 Fixes #29 --- src/Dropbox/Security/RandomStringGeneratorFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dropbox/Security/RandomStringGeneratorFactory.php b/src/Dropbox/Security/RandomStringGeneratorFactory.php index 6bef9ec..bba746b 100644 --- a/src/Dropbox/Security/RandomStringGeneratorFactory.php +++ b/src/Dropbox/Security/RandomStringGeneratorFactory.php @@ -57,7 +57,7 @@ public static function makeRandomStringGenerator($generator = null) protected static function defaultRandomStringGenerator() { //Mcrypt - if (function_exists('mcrypt_create_iv')) { + if (function_exists('mcrypt_create_iv') && version_compare( PHP_VERSION, '7.1', '<' )) { return new McryptRandomStringGenerator(); } From b9aeeee0faef4176a442e2b41ae601df81c927f7 Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Fri, 29 Dec 2017 21:35:57 +0100 Subject: [PATCH 02/14] Fix issue with arg_separator.output set to & --- src/Dropbox/Authentication/OAuth2Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dropbox/Authentication/OAuth2Client.php b/src/Dropbox/Authentication/OAuth2Client.php index 0af7b2e..600e6fc 100644 --- a/src/Dropbox/Authentication/OAuth2Client.php +++ b/src/Dropbox/Authentication/OAuth2Client.php @@ -68,7 +68,7 @@ public function __construct(DropboxApp $app, DropboxClient $client, RandomString */ protected function buildUrl($endpoint = '', array $params = []) { - $queryParams = http_build_query($params); + $queryParams = http_build_query($params,'','&'); return static::BASE_URL . $endpoint . '?' . $queryParams; } @@ -142,7 +142,7 @@ public function getAccessToken($code, $redirectUri = null, $grant_type = 'author 'redirect_uri' => $redirectUri ]; - $params = http_build_query($params); + $params = http_build_query($params, '', '&'); $apiUrl = static::AUTH_TOKEN_URL; $uri = $apiUrl . "?" . $params; From 885aaaf164feac05bb98f92b4505934fff74c840 Mon Sep 17 00:00:00 2001 From: Bernard Joseph Jean Bruno Date: Sun, 6 Oct 2019 20:00:06 +0400 Subject: [PATCH 03/14] Added new Exceptions --- .../DropboxClientUnableToOpenTempFileException.php | 10 ++++++++++ .../DropboxClientUnableToWriteToTempException.php | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/Dropbox/Exceptions/DropboxClientUnableToOpenTempFileException.php create mode 100644 src/Dropbox/Exceptions/DropboxClientUnableToWriteToTempException.php diff --git a/src/Dropbox/Exceptions/DropboxClientUnableToOpenTempFileException.php b/src/Dropbox/Exceptions/DropboxClientUnableToOpenTempFileException.php new file mode 100644 index 0000000..0aeef28 --- /dev/null +++ b/src/Dropbox/Exceptions/DropboxClientUnableToOpenTempFileException.php @@ -0,0 +1,10 @@ + Date: Sun, 6 Oct 2019 20:00:27 +0400 Subject: [PATCH 04/14] Added feature to make DropBoxFile from string --- src/Dropbox/Dropbox.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b017c38..ce64a20 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -2,6 +2,7 @@ namespace Kunnu\Dropbox; +use Kunnu\Dropbox\Exceptions\DropboxClientUnableToWriteToTempException; use Kunnu\Dropbox\Models\DeletedMetadata; use Kunnu\Dropbox\Models\File; use Kunnu\Dropbox\Models\Account; @@ -50,6 +51,13 @@ class Dropbox */ const METADATA_HEADER = 'dropbox-api-result'; + /** + * Prefix for writable temporary file + * + * @const string + */ + const TMP_PREFIX = 'dropbox-temp-file'; + /** * The Dropbox App * @@ -792,6 +800,36 @@ public function upload($dropboxFile, $path, array $params = []) return $this->simpleUpload($dropboxFile, $path, $params); } + + /** + * Make DropboxFile Object using the given $data string as the file contents. + * @param $path + * @param $data + * @return DropboxFile + * @throws DropboxClientException + * @throws DropboxClientUnableToWriteToTempException + */ + public function makeDropboxFileFromString($path, $data) { + //create a temp file with a prefix + $tmpfname = tempnam(sys_get_temp_dir(), static::TMP_PREFIX); + + if (!is_writable($tmpfname)) { // Test if the file is writable + throw new DropboxClientUnableToWriteToTempException("Cannot write to {$tmpfname}"); + } + + $handle = fopen( $tmpfname, DropboxFile::MODE_WRITE); + + if (!is_resource($handle)) + { // Test if PHP could open the file + throw new DropboxClientUnableToWriteToTempException("Could not open {$tmpfname} on writing mode."); + + } + + fwrite($handle, $data); + + return DropboxFile::createByStream($path, $handle, DropboxFile::MODE_WRITE); + } + /** * Make DropboxFile Object * From 212e7a453caf66abeec72dddfd550d88a1467726 Mon Sep 17 00:00:00 2001 From: Bernard Joseph Jean Bruno Date: Sun, 6 Oct 2019 20:02:37 +0400 Subject: [PATCH 05/14] Updated new exception --- src/Dropbox/Dropbox.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index ce64a20..a4a86b5 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -2,6 +2,7 @@ namespace Kunnu\Dropbox; +use Kunnu\Dropbox\Exceptions\DropboxClientUnableToOpenTempFileException; use Kunnu\Dropbox\Exceptions\DropboxClientUnableToWriteToTempException; use Kunnu\Dropbox\Models\DeletedMetadata; use Kunnu\Dropbox\Models\File; @@ -821,7 +822,7 @@ public function makeDropboxFileFromString($path, $data) { if (!is_resource($handle)) { // Test if PHP could open the file - throw new DropboxClientUnableToWriteToTempException("Could not open {$tmpfname} on writing mode."); + throw new DropboxClientUnableToOpenTempFileException("Could not open {$tmpfname} on writing mode."); } From 8b1f456b37b46ee8e99ec367cbcd46f9f3fea3f0 Mon Sep 17 00:00:00 2001 From: Bernard Joseph Jean Bruno Date: Sun, 6 Oct 2019 20:03:19 +0400 Subject: [PATCH 06/14] fix cs --- src/Dropbox/Dropbox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index a4a86b5..19aa59b 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -814,7 +814,8 @@ public function makeDropboxFileFromString($path, $data) { //create a temp file with a prefix $tmpfname = tempnam(sys_get_temp_dir(), static::TMP_PREFIX); - if (!is_writable($tmpfname)) { // Test if the file is writable + if (!is_writable($tmpfname)) + { // Test if the file is writable throw new DropboxClientUnableToWriteToTempException("Cannot write to {$tmpfname}"); } @@ -823,7 +824,6 @@ public function makeDropboxFileFromString($path, $data) { if (!is_resource($handle)) { // Test if PHP could open the file throw new DropboxClientUnableToOpenTempFileException("Could not open {$tmpfname} on writing mode."); - } fwrite($handle, $data); From 3c1a957315564b3e157bf9d6f6e27a5cef82879c Mon Sep 17 00:00:00 2001 From: Bernard Joseph Jean Bruno Date: Sun, 6 Oct 2019 20:09:29 +0400 Subject: [PATCH 07/14] fix cs --- src/Dropbox/Dropbox.php | 201 +++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 97 deletions(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index 19aa59b..6e17b5a 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -210,8 +210,8 @@ public function getPersistentDataStore() /** * Get the Metadata for a file or folder * - * @param string $path Path of the file or folder - * @param array $params Additional Params + * @param string $path Path of the file or folder + * @param array $params Additional Params * * @return \Kunnu\Dropbox\Models\FileMetadata | \Kunnu\Dropbox\Models\FolderMetadata * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @@ -239,9 +239,9 @@ public function getMetadata($path, array $params = []) /** * Make a HTTP POST Request to the API endpoint type * - * @param string $endpoint API Endpoint to send Request to - * @param array $params Request Query Params - * @param string $accessToken Access Token to send with the Request + * @param string $endpoint API Endpoint to send Request to + * @param array $params Request Query Params + * @param string $accessToken Access Token to send with the Request * * @return \Kunnu\Dropbox\DropboxResponse */ @@ -253,19 +253,25 @@ public function postToAPI($endpoint, array $params = [], $accessToken = null) /** * Make Request to the API * - * @param string $method HTTP Request Method - * @param string $endpoint API Endpoint to send Request to - * @param string $endpointType Endpoint type ['api'|'content'] - * @param array $params Request Query Params - * @param string $accessToken Access Token to send with the Request - * @param DropboxFile $responseFile Save response to the file + * @param string $method HTTP Request Method + * @param string $endpoint API Endpoint to send Request to + * @param string $endpointType Endpoint type ['api'|'content'] + * @param array $params Request Query Params + * @param string $accessToken Access Token to send with the Request + * @param DropboxFile $responseFile Save response to the file * * @return \Kunnu\Dropbox\DropboxResponse * * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException */ - public function sendRequest($method, $endpoint, $endpointType = 'api', array $params = [], $accessToken = null, DropboxFile $responseFile = null) - { + public function sendRequest( + $method, + $endpoint, + $endpointType = 'api', + array $params = [], + $accessToken = null, + DropboxFile $responseFile = null + ) { //Access Token $accessToken = $this->getAccessToken() ? $this->getAccessToken() : $accessToken; @@ -307,7 +313,7 @@ public function setAccessToken($accessToken) /** * Make Model from DropboxResponse * - * @param DropboxResponse $response + * @param DropboxResponse $response * * @return \Kunnu\Dropbox\Models\ModelInterface * @@ -329,12 +335,12 @@ public function makeModelFromResponse(DropboxResponse $response) /** * Get the contents of a Folder * - * @param string $path Path to the folder. Defaults to root. - * @param array $params Additional Params + * @param string $path Path to the folder. Defaults to root. + * @param array $params Additional Params * + * @return \Kunnu\Dropbox\Models\MetadataCollection * @link https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder * - * @return \Kunnu\Dropbox\Models\MetadataCollection */ public function listFolder($path = null, array $params = []) { @@ -358,12 +364,12 @@ public function listFolder($path = null, array $params = []) * Paginate through all files and retrieve updates to the folder, * using the cursor retrieved from listFolder or listFolderContinue * - * @param string $cursor The cursor returned by your + * @param string $cursor The cursor returned by your * last call to listFolder or listFolderContinue * + * @return \Kunnu\Dropbox\Models\MetadataCollection * @link https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue * - * @return \Kunnu\Dropbox\Models\MetadataCollection */ public function listFolderContinue($cursor) { @@ -376,8 +382,8 @@ public function listFolderContinue($cursor) /** * Get a cursor for the folder's state. * - * @param string $path Path to the folder. Defaults to root. - * @param array $params Additional Params + * @param string $path Path to the folder. Defaults to root. + * @param array $params Additional Params * * @return string The Cursor for the folder's state * @@ -416,12 +422,12 @@ public function listFolderLatestCursor($path, array $params = []) /** * Get Revisions of a File * - * @param string $path Path to the file - * @param array $params Additional Params + * @param string $path Path to the file + * @param array $params Additional Params * + * @return \Kunnu\Dropbox\Models\ModelCollection * @link https://www.dropbox.com/developers/documentation/http/documentation#files-list_revisions * - * @return \Kunnu\Dropbox\Models\ModelCollection */ public function listRevisions($path, array $params = []) { @@ -451,13 +457,13 @@ public function listRevisions($path, array $params = []) /** * Search a folder for files/folders * - * @param string $path Path to search - * @param string $query Search Query - * @param array $params Additional Params + * @param string $path Path to search + * @param string $query Search Query + * @param array $params Additional Params * + * @return \Kunnu\Dropbox\Models\SearchResults * @link https://www.dropbox.com/developers/documentation/http/documentation#files-search * - * @return \Kunnu\Dropbox\Models\SearchResults */ public function search($path, $query, array $params = []) { @@ -481,8 +487,8 @@ public function search($path, $query, array $params = []) /** * Create a folder at the given path * - * @param string $path Path to create - * @param boolean $autorename Auto Rename File + * @param string $path Path to create + * @param boolean $autorename Auto Rename File * * @return \Kunnu\Dropbox\Models\FolderMetadata * @@ -511,7 +517,7 @@ public function createFolder($path, $autorename = false) /** * Delete a file or folder at the given path * - * @param string $path Path to file/folder to delete + * @param string $path Path to file/folder to delete * * @return \Kunnu\Dropbox\Models\DeletedMetadata * @@ -542,8 +548,8 @@ public function delete($path) /** * Move a file or folder to a different location * - * @param string $fromPath Path to be moved - * @param string $toPath Path to be moved to + * @param string $fromPath Path to be moved + * @param string $toPath Path to be moved to * * @return \Kunnu\Dropbox\Models\DeletedMetadata|\Kunnu\Dropbox\Models\FileMetadata * @@ -569,8 +575,8 @@ public function move($fromPath, $toPath) /** * Copy a file or folder to a different location * - * @param string $fromPath Path to be copied - * @param string $toPath Path to be copied to + * @param string $fromPath Path to be copied + * @param string $toPath Path to be copied to * * @return \Kunnu\Dropbox\Models\DeletedMetadata|\Kunnu\Dropbox\Models\FileMetadata * @@ -596,8 +602,8 @@ public function copy($fromPath, $toPath) /** * Restore a file to the specific version * - * @param string $path Path to the file to restore - * @param string $rev Revision to store for the file + * @param string $path Path to the file to restore + * @param string $rev Revision to store for the file * * @return \Kunnu\Dropbox\Models\DeletedMetadata|\Kunnu\Dropbox\Models\FileMetadata|\Kunnu\Dropbox\Models\FolderMetadata * @@ -626,7 +632,7 @@ public function restore($path, $rev) /** * Get Copy Reference * - * @param string $path Path to the file or folder to get a copy reference to + * @param string $path Path to the file or folder to get a copy reference to * * @return \Kunnu\Dropbox\Models\CopyReference * @@ -653,8 +659,8 @@ public function getCopyReference($path) /** * Save Copy Reference * - * @param string $path Path to the file or folder to get a copy reference to - * @param string $copyReference Copy reference returned by getCopyReference + * @param string $path Path to the file or folder to get a copy reference to + * @param string $copyReference Copy reference returned by getCopyReference * * @return \Kunnu\Dropbox\Models\FileMetadata|\Kunnu\Dropbox\Models\FolderMetadata * @@ -671,7 +677,8 @@ public function saveCopyReference($path, $copyReference) } //Save Copy Reference - $response = $this->postToAPI('/files/copy_reference/save', ['path' => $path, 'copy_reference' => $copyReference]); + $response = $this->postToAPI('/files/copy_reference/save', + ['path' => $path, 'copy_reference' => $copyReference]); $body = $response->getDecodedBody(); //Response doesn't have Metadata @@ -686,7 +693,7 @@ public function saveCopyReference($path, $copyReference) /** * Get a temporary link to stream contents of a file * - * @param string $path Path to the file you want a temporary link to + * @param string $path Path to the file you want a temporary link to * * https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link * @@ -711,8 +718,8 @@ public function getTemporaryLink($path) /** * Save a specified URL into a file in user's Dropbox * - * @param string $path Path where the URL will be saved - * @param string $url URL to be saved + * @param string $path Path where the URL will be saved + * @param string $url URL to be saved * * @return string Async Job ID * @@ -778,13 +785,13 @@ public function checkJobStatus($asyncJobId) /** * Upload a File to Dropbox * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param string $path Path to upload the file to - * @param array $params Additional Params + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param string $path Path to upload the file to + * @param array $params Additional Params * + * @return \Kunnu\Dropbox\Models\FileMetadata * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload * - * @return \Kunnu\Dropbox\Models\FileMetadata */ public function upload($dropboxFile, $path, array $params = []) { @@ -810,19 +817,18 @@ public function upload($dropboxFile, $path, array $params = []) * @throws DropboxClientException * @throws DropboxClientUnableToWriteToTempException */ - public function makeDropboxFileFromString($path, $data) { + public function makeDropboxFileFromString($path, $data) + { //create a temp file with a prefix $tmpfname = tempnam(sys_get_temp_dir(), static::TMP_PREFIX); - if (!is_writable($tmpfname)) - { // Test if the file is writable + if (!is_writable($tmpfname)) { // Test if the file is writable throw new DropboxClientUnableToWriteToTempException("Cannot write to {$tmpfname}"); } - $handle = fopen( $tmpfname, DropboxFile::MODE_WRITE); + $handle = fopen($tmpfname, DropboxFile::MODE_WRITE); - if (!is_resource($handle)) - { // Test if PHP could open the file + if (!is_resource($handle)) { // Test if PHP could open the file throw new DropboxClientUnableToOpenTempFileException("Could not open {$tmpfname} on writing mode."); } @@ -834,10 +840,10 @@ public function makeDropboxFileFromString($path, $data) { /** * Make DropboxFile Object * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param int $maxLength Max Bytes to read from the file - * @param int $offset Seek to specified offset before reading - * @param string $mode The type of access + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param int $maxLength Max Bytes to read from the file + * @param int $offset Seek to specified offset before reading + * @param string $mode The type of access * * @return \Kunnu\Dropbox\DropboxFile */ @@ -868,17 +874,17 @@ public function makeDropboxFile($dropboxFile, $maxLength = null, $offset = null, /** * Upload file in sessions/chunks * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param string $path Path to save the file to, on Dropbox - * @param int $fileSize The size of the file - * @param int $chunkSize The amount of data to upload in each chunk - * @param array $params Additional Params + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param string $path Path to save the file to, on Dropbox + * @param int $fileSize The size of the file + * @param int $chunkSize The amount of data to upload in each chunk + * @param array $params Additional Params * - * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start + * @return \Kunnu\Dropbox\Models\FileMetadata * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2 * - * @return \Kunnu\Dropbox\Models\FileMetadata + * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start */ public function uploadChunked($dropboxFile, $path, $fileSize = null, $chunkSize = null, array $params = array()) { @@ -933,9 +939,9 @@ public function uploadChunked($dropboxFile, $path, $fileSize = null, $chunkSize /** * Start an Upload Session * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param int $chunkSize Size of file chunk to upload - * @param boolean $close Closes the session for "appendUploadSession" + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param int $chunkSize Size of file chunk to upload + * @param boolean $close Closes the session for "appendUploadSession" * * @return string Unique identifier for the upload session * @@ -971,10 +977,10 @@ public function startUploadSession($dropboxFile, $chunkSize = -1, $close = false /** * Make a HTTP POST Request to the Content endpoint type * - * @param string $endpoint Content Endpoint to send Request to - * @param array $params Request Query Params - * @param string $accessToken Access Token to send with the Request - * @param DropboxFile $responseFile Save response to the file + * @param string $endpoint Content Endpoint to send Request to + * @param array $params Request Query Params + * @param string $accessToken Access Token to send with the Request + * @param DropboxFile $responseFile Save response to the file * * @return \Kunnu\Dropbox\DropboxResponse */ @@ -986,11 +992,11 @@ public function postToContent($endpoint, array $params = [], $accessToken = null /** * Append more data to an Upload Session * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param string $sessionId Session ID returned by `startUploadSession` - * @param int $offset The amount of data that has been uploaded so far - * @param int $chunkSize The amount of data to upload - * @param boolean $close Closes the session for futher "appendUploadSession" calls + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param string $sessionId Session ID returned by `startUploadSession` + * @param int $offset The amount of data that has been uploaded so far + * @param int $chunkSize The amount of data to upload + * @param boolean $close Closes the session for futher "appendUploadSession" calls * * @return string Unique identifier for the upload session * @@ -1035,12 +1041,12 @@ public function appendUploadSession($dropboxFile, $sessionId, $offset, $chunkSiz /** * Finish an upload session and save the uploaded data to the given file path * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param string $sessionId Session ID returned by `startUploadSession` - * @param int $offset The amount of data that has been uploaded so far - * @param int $remaining The amount of data that is remaining - * @param string $path Path to save the file to, on Dropbox - * @param array $params Additional Params + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param string $sessionId Session ID returned by `startUploadSession` + * @param int $offset The amount of data that has been uploaded so far + * @param int $remaining The amount of data that is remaining + * @param string $path Path to save the file to, on Dropbox + * @param array $params Additional Params * * @return \Kunnu\Dropbox\Models\FileMetadata * @@ -1083,13 +1089,13 @@ public function finishUploadSession($dropboxFile, $sessionId, $offset, $remainin /** * Upload a File to Dropbox in a single request * - * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file - * @param string $path Path to upload the file to - * @param array $params Additional Params + * @param string|DropboxFile $dropboxFile DropboxFile object or Path to file + * @param string $path Path to upload the file to + * @param array $params Additional Params * + * @return \Kunnu\Dropbox\Models\FileMetadata * @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload * - * @return \Kunnu\Dropbox\Models\FileMetadata */ public function simpleUpload($dropboxFile, $path, array $params = []) { @@ -1111,9 +1117,9 @@ public function simpleUpload($dropboxFile, $path, array $params = []) /** * Get a thumbnail for an image * - * @param string $path Path to the file you want a thumbnail to - * @param string $size Size for the thumbnail image ['thumb','small','medium','large','huge'] - * @param string $format Format for the thumbnail image ['jpeg'|'png'] + * @param string $path Path to the file you want a thumbnail to + * @param string $size Size for the thumbnail image ['thumb','small','medium','large','huge'] + * @param string $format Format for the thumbnail image ['jpeg'|'png'] * * @return \Kunnu\Dropbox\Models\Thumbnail * @@ -1138,7 +1144,8 @@ public function getThumbnail($path, $size = 'small', $format = 'jpeg') $size = $this->getThumbnailSize($size); //Get Thumbnail - $response = $this->postToContent('/files/get_thumbnail', ['path' => $path, 'format' => $format, 'size' => $size]); + $response = $this->postToContent('/files/get_thumbnail', + ['path' => $path, 'format' => $format, 'size' => $size]); //Get file metadata from response headers $metadata = $this->getMetadataFromResponseHeaders($response); @@ -1153,7 +1160,7 @@ public function getThumbnail($path, $size = 'small', $format = 'jpeg') /** * Get thumbnail size * - * @param string $size Thumbnail Size + * @param string $size Thumbnail Size * * @return string */ @@ -1173,7 +1180,7 @@ protected function getThumbnailSize($size) /** * Get metadata from response headers * - * @param DropboxResponse $response + * @param DropboxResponse $response * * @return array */ @@ -1209,8 +1216,8 @@ protected function getMetadataFromResponseHeaders(DropboxResponse $response) /** * Download a File * - * @param string $path Path to the file you want to download - * @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file + * @param string $path Path to the file you want to download + * @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file * * @return \Kunnu\Dropbox\Models\File * @@ -1264,9 +1271,9 @@ public function getCurrentAccount() * * @param string $account_id Account ID of the account to get details for * + * @return \Kunnu\Dropbox\Models\Account * @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_account * - * @return \Kunnu\Dropbox\Models\Account */ public function getAccount($account_id) { @@ -1283,9 +1290,9 @@ public function getAccount($account_id) * * @param array $account_ids IDs of the accounts to get details for * + * @return \Kunnu\Dropbox\Models\AccountList * @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_account_batch * - * @return \Kunnu\Dropbox\Models\AccountList */ public function getAccounts(array $account_ids = []) { From 610908dba8dcd7cac83dd11dfc166c8dda330e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Hansson?= Date: Thu, 19 Dec 2019 17:16:28 +0100 Subject: [PATCH 08/14] New: downloadZip --- src/Dropbox/Dropbox.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b017c38..c5a695a 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -1203,6 +1203,42 @@ public function download($path, $dropboxFile = null) return new File($metadata, $contents); } + /** + * Download a folder as a zip file + * + * @param string $path Path to the file you want to download + * @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file + * + * @return \Kunnu\Dropbox\Models\File + * + * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException + * + * @link https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip + * + */ + public function downloadZip($path, $dropboxFile = null) + { + //Path cannot be null + if (is_null($path)) { + throw new DropboxClientException("Path cannot be null."); + } + + //Make Dropbox File if target is specified + $dropboxFile = $dropboxFile ? $this->makeDropboxFile($dropboxFile, null, null, DropboxFile::MODE_WRITE) : null; + + //Download File + $response = $this->postToContent('/files/download_zip', ['path' => $path], null, $dropboxFile); + + //Get file metadata from response headers + $metadata = $this->getMetadataFromResponseHeaders($response); + + //File Contents + $contents = $dropboxFile ? $this->makeDropboxFile($dropboxFile) : $response->getBody(); + + //Make and return a File model + return new File($metadata, $contents); + } + /** * Get Current Account * From 22a713510975ca09fe18bdfa1b08ef41cb5eb02e Mon Sep 17 00:00:00 2001 From: Lito Date: Fri, 14 Feb 2020 17:12:13 +0100 Subject: [PATCH 09/14] Start Session if not started previously on SessionPersistentDataStore Related issues #115 #105 #85 --- src/Dropbox/Store/SessionPersistentDataStore.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Dropbox/Store/SessionPersistentDataStore.php b/src/Dropbox/Store/SessionPersistentDataStore.php index 5698acb..569db8a 100644 --- a/src/Dropbox/Store/SessionPersistentDataStore.php +++ b/src/Dropbox/Store/SessionPersistentDataStore.php @@ -16,9 +16,20 @@ class SessionPersistentDataStore implements PersistentDataStoreInterface * * @param string $prefix Session Variable Prefix */ - public function __construct($prefix = "DBAPI_") + public function __construct($prefix = 'DBAPI_') { $this->prefix = $prefix; + $this->start(); + } + + /** + * Start session if not started previously + */ + protected function start() + { + if (!isset($_SESSION)) { + session_start(); + } } /** From 4b5ea87d39dc7581c5f622796d7b6826f2b7e5af Mon Sep 17 00:00:00 2001 From: Lito Date: Wed, 26 Feb 2020 17:08:00 +0100 Subject: [PATCH 10/14] Minor code style on http_build_query --- src/Dropbox/Authentication/OAuth2Client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Dropbox/Authentication/OAuth2Client.php b/src/Dropbox/Authentication/OAuth2Client.php index 600e6fc..518465e 100644 --- a/src/Dropbox/Authentication/OAuth2Client.php +++ b/src/Dropbox/Authentication/OAuth2Client.php @@ -68,8 +68,7 @@ public function __construct(DropboxApp $app, DropboxClient $client, RandomString */ protected function buildUrl($endpoint = '', array $params = []) { - $queryParams = http_build_query($params,'','&'); - return static::BASE_URL . $endpoint . '?' . $queryParams; + return static::BASE_URL . $endpoint . '?' . http_build_query($params, '', '&'); } /** From 85f0f6f7369b8cac16de30212fc903d1deb85560 Mon Sep 17 00:00:00 2001 From: Lito Date: Wed, 26 Feb 2020 17:12:47 +0100 Subject: [PATCH 11/14] Updated code style --- src/Dropbox/Authentication/OAuth2Client.php | 48 ++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/Dropbox/Authentication/OAuth2Client.php b/src/Dropbox/Authentication/OAuth2Client.php index 518465e..d09bb75 100644 --- a/src/Dropbox/Authentication/OAuth2Client.php +++ b/src/Dropbox/Authentication/OAuth2Client.php @@ -14,14 +14,14 @@ class OAuth2Client * * @const string */ - const BASE_URL = "https://dropbox.com"; + const BASE_URL = 'https://dropbox.com'; /** * Auth Token URL * * @const string */ - const AUTH_TOKEN_URL = "https://api.dropboxapi.com/oauth2/token"; + const AUTH_TOKEN_URL = 'https://api.dropboxapi.com/oauth2/token'; /** * The Dropbox App @@ -107,12 +107,12 @@ public function getClient() */ public function getAuthorizationUrl($redirectUri = null, $state = null, array $params = []) { - //Request Parameters + // Request Parameters $params = array_merge([ 'client_id' => $this->getApp()->getClientId(), 'response_type' => 'code', 'state' => $state, - ], $params); + ], $params); if (!is_null($redirectUri)) { $params['redirect_uri'] = $redirectUri; @@ -132,31 +132,23 @@ public function getAuthorizationUrl($redirectUri = null, $state = null, array $p */ public function getAccessToken($code, $redirectUri = null, $grant_type = 'authorization_code') { - //Request Params + // Request Params $params = [ - 'code' => $code, - 'grant_type' => $grant_type, - 'client_id' => $this->getApp()->getClientId(), - 'client_secret' => $this->getApp()->getClientSecret(), - 'redirect_uri' => $redirectUri + 'code' => $code, + 'grant_type' => $grant_type, + 'client_id' => $this->getApp()->getClientId(), + 'client_secret' => $this->getApp()->getClientSecret(), + 'redirect_uri' => $redirectUri ]; - $params = http_build_query($params, '', '&'); - - $apiUrl = static::AUTH_TOKEN_URL; - $uri = $apiUrl . "?" . $params; - - //Send Request through the DropboxClient - //Fetch the Response (DropboxRawResponse) - $response = $this->getClient() - ->getHttpClient() - ->send($uri, "POST", null); + $uri = static::AUTH_TOKEN_URL . '?' . http_build_query($params, '', '&'); - //Fetch Response Body - $body = $response->getBody(); + // Send Request through the DropboxClient + // Fetch the Response (DropboxRawResponse) + $body = $this->getClient()->getHttpClient()->send($uri, 'POST', null)->getBody(); - //Decode the Response body to associative array - //and return + // Decode the Response body to associative array + // and return return json_decode((string) $body, true); } @@ -167,18 +159,16 @@ public function getAccessToken($code, $redirectUri = null, $grant_type = 'author */ public function revokeAccessToken() { - //Access Token - $accessToken = $this->getApp()->getAccessToken(); + // Request + $request = new DropboxRequest('POST', '/auth/token/revoke', $this->getApp()->getAccessToken()); - //Request - $request = new DropboxRequest("POST", "/auth/token/revoke", $accessToken); // Do not validate the response // since the /token/revoke endpoint // doesn't return anything in the response. // See: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke $request->setParams(['validateResponse' => false]); - //Revoke Access Token + // Revoke Access Token $this->getClient()->sendRequest($request); } } From 3bc733979279c2c6945fc800354d4f47bb0f8bbd Mon Sep 17 00:00:00 2001 From: Lito Date: Sat, 25 Apr 2020 21:22:39 +0200 Subject: [PATCH 12/14] Added headers sent check before session start --- src/Dropbox/Store/SessionPersistentDataStore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dropbox/Store/SessionPersistentDataStore.php b/src/Dropbox/Store/SessionPersistentDataStore.php index 569db8a..fd2650f 100644 --- a/src/Dropbox/Store/SessionPersistentDataStore.php +++ b/src/Dropbox/Store/SessionPersistentDataStore.php @@ -27,7 +27,7 @@ public function __construct($prefix = 'DBAPI_') */ protected function start() { - if (!isset($_SESSION)) { + if (!isset($_SESSION) && !headers_sent()) { session_start(); } } From 2223cd5ffa4c64726b21a13a84ea9aff5a4534ea Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Wed, 29 Apr 2020 15:28:31 -0600 Subject: [PATCH 13/14] Enable dropbox sdk search v2 Dropbox.php - created a new method "searchV2" to enable dropbox search version 2 since search version 1 is deprecated. --- .gitignore | 1 + src/Dropbox/Dropbox.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.gitignore b/.gitignore index 3938932..6724e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ index.php composer.lock /.idea .php_cs.cache +.DS_Store diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b017c38..d79565b 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -469,6 +469,39 @@ public function search($path, $query, array $params = []) return $this->makeModelFromResponse($response); } + /** + * Search a folder for files/folders + * + * @param string $path Path to search + * @param string $query Search Query + * @param array $params Additional Params + * + * @link https://www.dropbox.com/developers/documentation/http/documentation#files-search + * + * @return \Kunnu\Dropbox\Models\SearchResults + */ + public function searchV2($query, array $params = []) + { + //Specify the root folder as an + //empty string rather than as "/" + if ($path === '/') { + $path = ""; + } + + //Set the path and query + $params['query'] = $query; + + if( !array_key_exists( 'include_highlights', $params ) ){ + $params['include_highlights'] = false; + } + + //Fetch Search Results + $response = $this->postToAPI('/files/search_v2', $params); + + //Make and Return the Model + return $this->makeModelFromResponse($response); + } + /** * Create a folder at the given path * From 8a175ef62a5398d469ea5e25f1b2544ee4e7ee09 Mon Sep 17 00:00:00 2001 From: Lito Date: Tue, 8 Sep 2020 22:11:26 +0200 Subject: [PATCH 14/14] Allowed guzzle http 7.x --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d99cddf..802a171 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "guzzlehttp/guzzle": "~6.0", + "guzzlehttp/guzzle": ">=6.3", "tightenco/collect": "^5.2" }, "autoload": {