Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/dropbox/README.txt,v retrieving revision 1.2 diff -u -r1.2 README.txt --- README.txt 20 May 2009 00:55:10 -0000 1.2 +++ README.txt 4 Jun 2009 15:58:42 -0000 @@ -14,8 +14,14 @@ Installation and Configuration ------------------------------ To install the Dropbox Integration module, extract the archive to your modules -folder. This is usually sites/all/modules. After enabling the module on the -Modules page, there are two permissions available: +folder. This is usually sites/all/modules. As well, the DropBoxUploader library +must be downloaded to the Dropbox module directory. The library can be obtained +at: + +http://jaka.kubje.org/software/dropboxuploader/ + +After enabling the module on the Modules page, there are two permissions +available: 1. **Configure Dropbox account**. This gives users access to enable Dropbox integration in their user account. It doesn't mean anything for anonymous Index: DropboxUploader.php =================================================================== RCS file: DropboxUploader.php diff -N DropboxUploader.php --- DropboxUploader.php 15 Mar 2009 15:59:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,155 +0,0 @@ -email = $emailOrHostId; - $this->password = $password; - } else { - $this->hostId = $emailOrHostId; - } - } - - public function setCaCertificateFile($file) - { - $this->caCertSourceType = self::CACERT_SOURCE_FILE; - $this->caCertSource = $file; - } - - public function setCaCertificateDir($dir) - { - $this->caCertSourceType = self::CACERT_SOURCE_DIR; - $this->caCertSource = $dir; - } - - public function upload($filename, $remoteDir='/') { - if (!file_exists($filename) or !is_file($filename) or !is_readable($filename)) - throw new Exception("File '$filename' does not exist or is not readable."); - - if (!is_string($remoteDir)) - throw new Exception("Remote directory must be a string, is ".gettype($remoteDir)." instead."); - - if (!$this->loggedIn) - $this->login(); - - $data = $this->request('https://www.getdropbox.com/upload?basic=1'); - $token = $this->extractToken($data, 'https://dl-web.getdropbox.com/upload'); - - $data = $this->request('https://dl-web.getdropbox.com/upload', true, array('plain'=>'yes', 'file'=>'@'.$filename, 'dest'=>$remoteDir, 't'=>$token)); - if (strpos($data, 'HTTP/1.1 302 FOUND') === false) - throw new Exception('Upload failed!'); - } - - protected function login() { - if (isset($this->hostId)) { - $data = $this->request('https://www.getdropbox.com/tray_login?host_id=' . $this->hostId); - } else { - $data = $this->request('https://www.getdropbox.com/login'); - $token = $this->extractToken($data, '/login'); - - $data = $this->request('https://www.getdropbox.com/login', true, array('email'=>$this->email, 'password'=>$this->password, 't'=>$token)); - } - - if (stripos($data, 'location: /home') === false) - throw new Exception('Login unsuccessful.'); - - $this->loggedIn = true; - } - - protected function request($url, $post=false, $postData=array()) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); - switch ($this->caCertSourceType) { - case self::CACERT_SOURCE_FILE: - curl_setopt($ch, CURLOPT_CAINFO, $this->caCertSource); - break; - case self::CACERT_SOURCE_DIR: - curl_setopt($ch, CURLOPT_CAPATH, $this->caCertSource); - break; - } - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - if ($post) { - curl_setopt($ch, CURLOPT_POST, $post); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - } - - // Send cookies - $rawCookies = array(); - foreach ($this->cookies as $k=>$v) - $rawCookies[] = "$k=$v"; - $rawCookies = implode(';', $rawCookies); - curl_setopt($ch, CURLOPT_COOKIE, $rawCookies); - - $data = curl_exec($ch); - - if ($data === false) - throw new Exception('Cannot execute request: '.curl_error($ch)); - - // Store received cookies - preg_match_all('/Set-Cookie: ([^=]+)=(.*?);/i', $data, $matches, PREG_SET_ORDER); - foreach ($matches as $match) - $this->cookies[$match[1]] = $match[2]; - - curl_close($ch); - - return $data; - } - - protected function extractToken($html, $formAction) { - if (!preg_match('/