mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
"REPOSITORY/MDL-16910, amazon s3 plugin for repository"
This commit is contained in:
parent
e476804cdb
commit
2e1cfc6eb8
7
lang/en_utf8/repository_s3.php
Normal file
7
lang/en_utf8/repository_s3.php
Normal 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
1288
repository/s3/S3.php
Normal file
File diff suppressed because it is too large
Load Diff
BIN
repository/s3/icon.png
Normal file
BIN
repository/s3/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 444 B |
89
repository/s3/repository.class.php
Normal file
89
repository/s3/repository.class.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user