Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Fix Dropbox fail
Browse files Browse the repository at this point in the history
  • Loading branch information
dizda committed Sep 13, 2014
1 parent 41b0cbc commit 94f769b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Clients/DropboxUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -258,4 +268,10 @@ private function extractTokenFromLoginForm($html) {
return $matches[1];
}

}
public function __destruct() {
if ($this->loggedIn) {
$this->logout();
}
}

}

0 comments on commit 94f769b

Please sign in to comment.