This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
* THE SOFTWARE. | ||
* | ||
* @author Jaka Jancar <[email protected]> <http://jaka.kubje.org/> | ||
* @version 1.1.17 | ||
* @version 1.1.19 | ||
* @license MIT <http://spdx.org/licenses/MIT> | ||
*/ | ||
final class DropboxUploader { | ||
|
@@ -46,8 +46,9 @@ final class DropboxUploader { | |
const DROPBOX_UPLOAD_LIMIT_IN_BYTES = 314572800; | ||
const HTTPS_DROPBOX_COM_HOME = 'https://www.dropbox.com/home'; | ||
const HTTPS_DROPBOX_COM_LOGIN = 'https://www.dropbox.com/login'; | ||
const HTTPS_DROPBOX_COM_AJAX_LOGIN = 'https://www.dropbox.com/ajax_login'; | ||
const HTTPS_DROPBOX_COM_LOGINACTION = 'https://www.dropbox.com/ajax_login'; | ||
const HTTPS_DROPBOX_COM_UPLOAD = 'https://dl-web.dropbox.com/upload'; | ||
const HTTPS_DROPBOX_COM_LOGOUT = 'https://www.dropbox.com/logout'; | ||
/** | ||
* DropboxUploader Error Flags and Codes | ||
*/ | ||
|
@@ -135,6 +136,7 @@ public function upload($source, $remoteDir = '/', $remoteName = NULL) { | |
'dest' => $remoteDir, | ||
't' => $token, | ||
'_subject_uid' => $subjectUid, | ||
'mtime_utc' => filemtime($source), | ||
); | ||
|
||
$data = $this->request(self::HTTPS_DROPBOX_COM_UPLOAD, $postData); | ||
|
@@ -188,14 +190,22 @@ private function login() { | |
'login_password' => (string) $this->password, | ||
't' => $token | ||
); | ||
$data = $this->request(self::HTTPS_DROPBOX_COM_AJAX_LOGIN, http_build_query($postData)); | ||
$data = $this->request(self::HTTPS_DROPBOX_COM_LOGINACTION, http_build_query($postData)); | ||
|
||
//if (stripos($data, 'location: /home') === FALSE) | ||
// throw new Exception('Login unsuccessful.', self::CODE_LOGIN_ERROR); | ||
if (stripos($data, '{"status": "OK", "csrf_token": "') === FALSE) | ||
throw new Exception('Login unsuccessful.', self::CODE_LOGIN_ERROR); | ||
|
||
$this->loggedIn = TRUE; | ||
} | ||
|
||
private function logout() { | ||
$data = $this->request(self::HTTPS_DROPBOX_COM_LOGOUT); | ||
|
||
if (!empty($data) && strpos($data, 'HTTP/1.1 302 FOUND') !== FALSE) { | ||
$this->loggedIn = FALSE; | ||
} | ||
} | ||
|
||
private function request($url, $postData = NULL) { | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, (string) $url); | ||
|
@@ -258,4 +268,10 @@ private function extractTokenFromLoginForm($html) { | |
return $matches[1]; | ||
} | ||
|
||
} | ||
public function __destruct() { | ||
if ($this->loggedIn) { | ||
$this->logout(); | ||
} | ||
} | ||
|
||
} |