mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
"MDL-19180, repository url plugin, download file into moodle by inputing url directly"
This commit is contained in:
parent
d3080510e4
commit
da2946c984
9 changed files with 105 additions and 9 deletions
5
lang/en_utf8/repository_url.php
Normal file
5
lang/en_utf8/repository_url.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php // $Id$
|
||||||
|
$string['repositoryname'] = 'URL Downloader';
|
||||||
|
$string['url'] = 'URL';
|
||||||
|
$string['rename'] = 'Name';
|
||||||
|
$string['download'] = 'Download';
|
|
@ -151,7 +151,7 @@ class repository_flickr_public extends repository {
|
||||||
|
|
||||||
$ret['login'] = array($fulltext, $tag, $email_field, $license);
|
$ret['login'] = array($fulltext, $tag, $email_field, $license);
|
||||||
$ret['login_btn_label'] = get_string('search');
|
$ret['login_btn_label'] = get_string('search');
|
||||||
$ret['login_search_form'] = true;
|
$ret['login_btn_action'] = 'search';
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1960,12 +1960,12 @@ EOD;
|
||||||
// print repository instances listing
|
// print repository instances listing
|
||||||
$js .= <<<EOD
|
$js .= <<<EOD
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
repository_listing['$id'] = {};
|
repository_listing['$id'] = [];
|
||||||
EOD;
|
EOD;
|
||||||
foreach ($repos as $repo) {
|
foreach ($repos as $repo) {
|
||||||
$info = $repo->ajax_info();
|
$info = $repo->ajax_info();
|
||||||
$js .= "\r\n";
|
$js .= "\r\n";
|
||||||
$js .= 'repository_listing[\''.$id.'\'][\''.$info->id.'\']='.json_encode($repo->ajax_info()).';';
|
$js .= 'repository_listing[\''.$id.'\']['.$info->id.']='.json_encode($repo->ajax_info()).';';
|
||||||
$js .= "\n";
|
$js .= "\n";
|
||||||
}
|
}
|
||||||
$js .= "\r\n";
|
$js .= "\r\n";
|
||||||
|
|
|
@ -314,8 +314,8 @@ repository_client.print_login = function(id, data) {
|
||||||
var login = data.login;
|
var login = data.login;
|
||||||
var panel = new YAHOO.util.Element('panel-'+id);
|
var panel = new YAHOO.util.Element('panel-'+id);
|
||||||
var action = 'login';
|
var action = 'login';
|
||||||
if (data['login_search_form']) {
|
if (data['login_btn_action']) {
|
||||||
action='search';
|
action=data['login_btn_action'];
|
||||||
}
|
}
|
||||||
var str = '<div class="fp-login-form" onkeypress="repository_client.login_keypress(event,\''+action+'\')">';
|
var str = '<div class="fp-login-form" onkeypress="repository_client.login_keypress(event,\''+action+'\')">';
|
||||||
var has_pop = false;
|
var has_pop = false;
|
||||||
|
@ -354,15 +354,17 @@ repository_client.print_login = function(id, data) {
|
||||||
}
|
}
|
||||||
str += '</td>';
|
str += '</td>';
|
||||||
}else{
|
}else{
|
||||||
str += '<td align="left"><input type="'+login[k].type+'"'+' name="'+login[k].name+'"'+field_value+' /></td>';
|
str += '<td align="left"><input type="'+login[k].type+'"'+' name="'+login[k].name+'"'+field_value+' '+field_id+' /></td>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str +='</tr>';
|
str +='</tr>';
|
||||||
}
|
}
|
||||||
str +='</table>';
|
str +='</table>';
|
||||||
var btn_label = data['login_btn_label']?data['login_btn_label']:fp_lang.submit;
|
var btn_label = data['login_btn_label']?data['login_btn_label']:fp_lang.submit;
|
||||||
if (data['login_search_form']) {
|
if (data['login_btn_action'] == 'search') {
|
||||||
str += '<p><input type="button" onclick="repository_client.search(\''+id+'\', \''+data.repo_id+'\')" value="'+btn_label+'" /></p>';
|
str += '<p><input type="button" onclick="repository_client.search(\''+id+'\', \''+data.repo_id+'\')" value="'+btn_label+'" /></p>';
|
||||||
|
} else if(data['login_btn_action'] == 'download') {
|
||||||
|
str += '<p><input type="button" onclick="repository_client.download(\''+id+'\', \''+data.repo_id+'\')" value="'+btn_label+'" /></p>';
|
||||||
} else {
|
} else {
|
||||||
if(!has_pop) {
|
if(!has_pop) {
|
||||||
str += '<p><input type="button" onclick="repository_client.login(\''+id+'\', \''+data.repo_id+'\')" value="'+btn_label+'" /></p>';
|
str += '<p><input type="button" onclick="repository_client.login(\''+id+'\', \''+data.repo_id+'\')" value="'+btn_label+'" /></p>';
|
||||||
|
@ -403,6 +405,8 @@ repository_client.login_keypress = function(evt,action) {
|
||||||
if(key == 13 || key == 10){
|
if(key == 13 || key == 10){
|
||||||
if(action=='search'){
|
if(action=='search'){
|
||||||
repository_client.search(cached_id, cached_repo_id);
|
repository_client.search(cached_id, cached_repo_id);
|
||||||
|
} else if (action=='download') {
|
||||||
|
repository_client.download(cached_id, cached_repo_id);
|
||||||
} else {
|
} else {
|
||||||
repository_client.login(cached_id, cached_repo_id);
|
repository_client.login(cached_id, cached_repo_id);
|
||||||
}
|
}
|
||||||
|
|
BIN
repository/url/icon.png
Executable file
BIN
repository/url/icon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
85
repository/url/repository.class.php
Executable file
85
repository/url/repository.class.php
Executable file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* repository_url class
|
||||||
|
* A subclass of repository, which is used to download a file from a specific url
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
class repository_url extends repository {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global object $SESSION
|
||||||
|
* @global string $action
|
||||||
|
* @global object $CFG
|
||||||
|
* @param int $repositoryid
|
||||||
|
* @param object $context
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
public function __construct($repositoryid, $context = SITEID, $options = array()){
|
||||||
|
global $SESSION, $action, $CFG;
|
||||||
|
parent::__construct($repositoryid, $context, $options);
|
||||||
|
$this->client_id = $options['client_id'];
|
||||||
|
$this->file_url = optional_param('download_from', '', PARAM_RAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_file($url, $file = '') {
|
||||||
|
global $CFG;
|
||||||
|
$path = $this->prepare_file($file);
|
||||||
|
$fp = fopen($path, 'w');
|
||||||
|
$c = new curl;
|
||||||
|
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_login() {
|
||||||
|
global $action;
|
||||||
|
if (!empty($this->file_url)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global object $SESSION
|
||||||
|
* @param boolean $ajax
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function print_login($ajax = true) {
|
||||||
|
$url = new stdclass;
|
||||||
|
$url->label = get_string('url', 'repository_url').': ';
|
||||||
|
$url->id = 'fileurl-'.$this->client_id;
|
||||||
|
$url->type = 'text';
|
||||||
|
$url->name = 'fileiii';
|
||||||
|
|
||||||
|
$title = new stdclass;
|
||||||
|
$title->label = get_string('rename', 'repository_url').': ';
|
||||||
|
$title->id = 'newname-'.$this->client_id;
|
||||||
|
$title->type = 'text';
|
||||||
|
$title->name = 'file';
|
||||||
|
|
||||||
|
$ret['login'] = array($url, $title);
|
||||||
|
$ret['login_btn_label'] = get_string('download', 'repository_url');
|
||||||
|
$ret['login_btn_action'] = 'download';
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param mixed $path
|
||||||
|
* @param string $search
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_listing($path='', $page='') {
|
||||||
|
$this->print_login();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_name(){
|
||||||
|
return get_string('repositoryname', 'repository_url');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
2
repository/url/version.php
Normal file
2
repository/url/version.php
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?php
|
||||||
|
$plugin->version = 2009051800;
|
|
@ -99,7 +99,7 @@
|
||||||
require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php');
|
require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php');
|
||||||
$classname = 'repository_' . $type;
|
$classname = 'repository_' . $type;
|
||||||
try {
|
try {
|
||||||
$repo = new $classname($repo_id, $ctx_id, array('ajax'=>true, 'name'=>$repository->name));
|
$repo = new $classname($repo_id, $ctx_id, array('ajax'=>true, 'name'=>$repository->name, 'client_id'=>$client_id));
|
||||||
} catch (repository_exception $e){
|
} catch (repository_exception $e){
|
||||||
$err->e = $e->getMessage();
|
$err->e = $e->getMessage();
|
||||||
die(json_encode($err));
|
die(json_encode($err));
|
||||||
|
|
|
@ -78,7 +78,7 @@ class repository_youtube extends repository {
|
||||||
$search->label = get_string('search', 'repository_youtube').': ';
|
$search->label = get_string('search', 'repository_youtube').': ';
|
||||||
$ret['login'] = array($search);
|
$ret['login'] = array($search);
|
||||||
$ret['login_btn_label'] = get_string('search');
|
$ret['login_btn_label'] = get_string('search');
|
||||||
$ret['login_search_form'] = true;
|
$ret['login_btn_action'] = 'search';
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
public function supported_return_value() {
|
public function supported_return_value() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue