From 0e61528d31d3ef06df9a7ba575705fc17b747b05 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Tue, 9 Nov 2010 09:11:28 +0000 Subject: [PATCH] MDL-19168, dropbox plugin now have full access --- .../dropbox/lang/en/repository_dropbox.php | 2 +- repository/dropbox/lib.php | 3 +- repository/dropbox/locallib.php | 31 +++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/repository/dropbox/lang/en/repository_dropbox.php b/repository/dropbox/lang/en/repository_dropbox.php index ec2341aa8c7..71f4433d6e4 100755 --- a/repository/dropbox/lang/en/repository_dropbox.php +++ b/repository/dropbox/lang/en/repository_dropbox.php @@ -28,7 +28,7 @@ $string['notitle'] = 'notitle'; $string['remember'] = 'Remember me'; $string['pluginname'] = 'Dropbox'; $string['apikey'] = 'Dropbox API Key'; -$string['sandbox'] = 'Dropbox sandbox'; +$string['dropbox'] = 'Dropbox'; $string['secret'] = 'Dropbox Secret'; $string['instruction'] = 'You can get your API Key and secret from Dropbox developers'; $string['dropbox:view'] = 'View a Dropbox folder'; diff --git a/repository/dropbox/lib.php b/repository/dropbox/lib.php index de9e398e84c..f7d7e88a024 100644 --- a/repository/dropbox/lib.php +++ b/repository/dropbox/lib.php @@ -138,10 +138,11 @@ class repository_dropbox extends repository { $list['nosearch'] = true; // process breacrumb trail $list['path'] = array( - array('name'=>get_string('sandbox', 'repository_dropbox'), 'path'=>'/') + array('name'=>get_string('dropbox', 'repository_dropbox'), 'path'=>'/') ); $result = $this->dropbox->get_listing($path, $this->access_key, $this->access_secret); + if (!is_object($result) || empty($result)) { return $list; } diff --git a/repository/dropbox/locallib.php b/repository/dropbox/locallib.php index b0c55d6ef11..36228930ed1 100644 --- a/repository/dropbox/locallib.php +++ b/repository/dropbox/locallib.php @@ -32,27 +32,54 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once($CFG->libdir.'/oauthlib.php'); class dropbox extends oauth_helper { - private $mode = 'sandbox'; + /** dropbox access type, can be dropbox or sandbox */ + private $mode = 'dropbox'; + /** dropbox api url*/ private $dropbox_api = 'http://api.dropbox.com/0'; + /** dropbox content api url*/ private $dropbox_content_api = 'http://api-content.dropbox.com/0'; + function __construct($args) { parent::__construct($args); } + /** + * Get file listing from dropbox + */ public function get_listing($path='/', $token='', $secret='') { $url = $this->dropbox_api.'/metadata/'.$this->mode.$path; $content = $this->get($url, array(), $token, $secret); $data = json_decode($content); return $data; } + + /** + * Get user account info + */ public function get_account_info($token, $secret) { $url = $this->dropbox_api.'/account/info'; $content = $this->get($url, array(), $token, $secret); return $content; } + + /** + * Download a file + */ public function get_file($filepath, $saveas) { - $url = 'http://api-content.dropbox.com/0/files/sandbox'.$filepath; + $info = pathinfo($filepath); + $dirname = $info['dirname']; + $basename = $info['basename']; + $filepath = $dirname . rawurlencode($basename); + if ($dirname != '/') { + $filepath = $dirname . '/' . rawurlencode($basename); + } + + $url = $this->dropbox_content_api.'/files/'.$this->mode.$filepath; $content = $this->get($url, array()); file_put_contents($saveas, $content); return array('path'=>$saveas, 'url'=>$url); } + + public function set_mode($mode) { + $this->mode = $mode; + } }