mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 14:35:29 +02:00
"MDL-16908, webdav plugin for repository module"
This commit is contained in:
parent
a0a88627cc
commit
934ff62cfe
6
lang/en_utf8/repository_webdav.php
Normal file
6
lang/en_utf8/repository_webdav.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$string['repositoryname'] = 'WebDAV repository';
|
||||
$string['webdav_server'] = 'WebDAV server';
|
||||
$string['webdav_port'] = 'WebDAV server port';
|
||||
$string['webdav_user'] = 'WebDAV server user';
|
||||
$string['webdav_password'] = 'WebDAV server password';
|
1612
lib/webdavlib.php
Normal file
1612
lib/webdavlib.php
Normal file
File diff suppressed because it is too large
Load Diff
BIN
repository/webdav/icon.png
Normal file
BIN
repository/webdav/icon.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.5 KiB |
116
repository/webdav/repository.class.php
Normal file
116
repository/webdav/repository.class.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* repository_webdav class
|
||||
*
|
||||
* @author Dongsheng Cai
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
|
||||
require_once($CFG->libdir.'/webdavlib.php');
|
||||
|
||||
class repository_webdav extends repository {
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()) {
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
$this->wd = new webdav_client();
|
||||
$this->wd->set_server($this->webdav_server);
|
||||
if (empty($this->webdav_port)) {
|
||||
$this->wd->set_port(80);
|
||||
} else {
|
||||
$this->wd->set_port($this->webdav_port);
|
||||
}
|
||||
if(!empty($this->webdav_user)){
|
||||
$this->wd->set_user($this->webdav_user);
|
||||
}
|
||||
if(!empty($this->webdav_password)) {
|
||||
$this->wd->set_pass($this->webdav_password);
|
||||
}
|
||||
$this->wd->set_protocol(1);
|
||||
$this->wd->set_debug(false);
|
||||
}
|
||||
public function check_login() {
|
||||
global $SESSION;
|
||||
return true;
|
||||
}
|
||||
public function get_file($url, $title) {
|
||||
global $CFG;
|
||||
if (!file_exists($CFG->dataroot.'/temp/download')) {
|
||||
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
|
||||
}
|
||||
if (is_dir($CFG->dataroot.'/temp/download')) {
|
||||
$dir = $CFG->dataroot.'/temp/download/';
|
||||
}
|
||||
if (empty($file)) {
|
||||
$file = uniqid('repo').'_'.time().'.tmp';
|
||||
}
|
||||
if (file_exists($dir.$file)) {
|
||||
$file = uniqid('m').$file;
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
$this->wd->open();
|
||||
$this->wd->get($url, $buffer);
|
||||
$fp = fopen($dir.$file, 'w');
|
||||
fwrite($fp, $buffer);
|
||||
return $dir.$file;
|
||||
}
|
||||
public function global_search() {
|
||||
return false;
|
||||
}
|
||||
public function get_listing($path='') {
|
||||
global $CFG;
|
||||
$list = array();
|
||||
$ret = array();
|
||||
$ret['dynload'] = true;
|
||||
$ret['list'] = array();
|
||||
$ret['path'] = array(array('name'=>'Root', 'path'=>0));
|
||||
$this->wd->open();
|
||||
if (empty($path)) {
|
||||
$dir = $this->wd->ls('/');
|
||||
$path = '/';
|
||||
} else {
|
||||
$dir = $this->wd->ls($path);
|
||||
}
|
||||
if (!is_array($dir)) {
|
||||
return $ret;
|
||||
}
|
||||
foreach ($dir as $v) {
|
||||
$ts = $this->wd->iso8601totime($v['creationdate']);
|
||||
$filedate = userdate($ts);
|
||||
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
|
||||
if ($path != $v['href']) {
|
||||
$title = urldecode(substr($v['href'], strpos($v['href'], $path)+strlen($path)));
|
||||
$ret['list'][] = array(
|
||||
'title'=>$title,
|
||||
'thumbnail'=>$CFG->pixpath.'/f/folder.gif',
|
||||
'children'=>array(),
|
||||
'date'=>$filedate,
|
||||
'size'=>0,
|
||||
'path'=>$v['href']
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$title = urldecode(substr($v['href'], strpos($v['href'], $path)+strlen($path)));
|
||||
$ret['list'][] = array(
|
||||
'title'=>$title,
|
||||
'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo("icon", $title),
|
||||
'size'=>$v['getcontentlength'],
|
||||
'date'=>$filedate,
|
||||
'source'=>$v['href']
|
||||
);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public static function get_instance_option_names() {
|
||||
return array('webdav_server', 'webdav_port', 'webdav_user', 'webdav_password');
|
||||
}
|
||||
|
||||
public function instance_config_form(&$mform) {
|
||||
$mform->addElement('text', 'webdav_server', get_string('webdav_server', 'repository_webdav'), array('size' => '40'));
|
||||
$mform->addRule('webdav_server', get_string('required'), 'required', null, 'client');
|
||||
$mform->addElement('text', 'webdav_port', get_string('webdav_port', 'repository_webdav'), array('size' => '40'));
|
||||
$mform->addElement('text', 'webdav_user', get_string('webdav_user', 'repository_webdav'), array('size' => '40'));
|
||||
$mform->addElement('text', 'webdav_password', get_string('webdav_password', 'repository_webdav'), array('size' => '40'));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user