"REPOSITORY/MDL-16910, amazon s3 plugin for repository"

This commit is contained in:
dongsheng 2009-01-09 03:19:13 +00:00
parent e476804cdb
commit 2e1cfc6eb8
4 changed files with 1384 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<?php // $Id$
$string['repositoryname'] = 'Amazon S3';
$string['configplugin'] = 'Amazon S3 settings';
$string['access_key'] = 'Access key';
$string['secret_key'] = 'Secret key';
$string['needaccesskey'] = 'Access key must be provided';

1288
repository/s3/S3.php Normal file

File diff suppressed because it is too large Load Diff

BIN
repository/s3/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

View File

@ -0,0 +1,89 @@
<?php // $Id$
require_once('S3.php');
class repository_s3 extends repository {
public function __construct($repositoryid, $context = SITEID, $options = array()) {
parent::__construct($repositoryid, $context, $options);
$this->access_key = get_config('s3', 'access_key');
$this->secret_key = get_config('s3', 'secret_key');
if (empty($this->access_key)) {
die(json_encode(array('e'=>get_string('repository_s3', 'needaccesskey'))));
}
$this->s = new S3($this->access_key, $this->secret_key);
}
public function get_listing($path = '') {
global $CFG;
$list = array();
$list['list'] = array();
// the management interface url
$list['manage'] = false;
// dynamically loading
$list['dynload'] = true;
// the current path of this list.
// set to true, the login link will be removed
$list['nologin'] = true;
// set to true, the search button will be removed
$list['nosearch'] = true;
$tree = array();
if (empty($path)) {
$buckets = $this->s->listBuckets();
foreach ($buckets as $bucket) {
$folder = array(
'title' => $bucket,
'children' => array(),
'thumbnail'=>$CFG->pixpath.'/f/folder.gif',
'path'=>$bucket
);
$tree[] = $folder;
}
} else {
$contents = $this->s->getBucket($path);
foreach ($contents as $file) {
$info = $this->s->getObjectInfo($path, baseName($file['name']));
$tree[] = array(
'title'=>$file['name'],
'size'=>$file['size'],
'date'=>userdate($file['time']),
'source'=>$path.'/'.$file['name'],
'thumbnail'=>$CFG->pixpath.'/f/'.mimeinfo('icon', $file['name'])
);
}
}
$list['list'] = $tree;
return $list;
}
public function get_file($filepath, $file) {
global $CFG;
$arr = explode('/', $filepath);
$bucket = $arr[0];
$filename = $arr[1];
if (!file_exists($CFG->dataroot.'/repository/download')) {
mkdir($CFG->dataroot.'/repository/download/', 0777, true);
}
if(is_dir($CFG->dataroot.'/repository/download')) {
$dir = $CFG->dataroot.'/repository/download/';
}
$this->s->getObject($bucket, $filename, $dir.$file);
return $dir.$file;
}
// login
public function check_login() {
return true;
}
public function global_search() {
return false;
}
public static function get_type_option_names() {
return array('access_key', 'secret_key');
}
public function type_config_form(&$mform) {
$strrequired = get_string('required');
$mform->addElement('text', 'access_key', get_string('access_key', 'repository_s3'));
$mform->addElement('text', 'secret_key', get_string('secret_key', 'repository_s3'));
$mform->addRule('access_key', $strrequired, 'required', null, 'client');
$mform->addRule('secret_key', $strrequired, 'required', null, 'client');
return true;
}
}