From: dongsheng Date: Mon, 18 May 2009 03:51:09 +0000 (+0000) Subject: "MDL-19180, repository url plugin, download file into moodle by inputing url directly" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=da2946c98433910995fb1a009146075df48b4436;p=moodle.git "MDL-19180, repository url plugin, download file into moodle by inputing url directly" --- diff --git a/lang/en_utf8/repository_url.php b/lang/en_utf8/repository_url.php new file mode 100644 index 0000000000..f9023da5b6 --- /dev/null +++ b/lang/en_utf8/repository_url.php @@ -0,0 +1,5 @@ + -repository_listing['$id'] = {}; +repository_listing['$id'] = []; EOD; foreach ($repos as $repo) { $info = $repo->ajax_info(); $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 .= "\r\n"; diff --git a/repository/repository.src.js b/repository/repository.src.js index 160e2f0695..bd5e7c87c9 100644 --- a/repository/repository.src.js +++ b/repository/repository.src.js @@ -314,8 +314,8 @@ repository_client.print_login = function(id, data) { var login = data.login; var panel = new YAHOO.util.Element('panel-'+id); var action = 'login'; - if (data['login_search_form']) { - action='search'; + if (data['login_btn_action']) { + action=data['login_btn_action']; } var str = '
'; var has_pop = false; @@ -354,15 +354,17 @@ repository_client.print_login = function(id, data) { } str += ''; }else{ - str += ''; + str += ''; } } str +=''; } str +=''; 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 += '

'; + } else if(data['login_btn_action'] == 'download') { + str += '

'; } else { if(!has_pop) { str += '

'; @@ -403,6 +405,8 @@ repository_client.login_keypress = function(evt,action) { if(key == 13 || key == 10){ if(action=='search'){ repository_client.search(cached_id, cached_repo_id); + } else if (action=='download') { + repository_client.download(cached_id, cached_repo_id); } else { repository_client.login(cached_id, cached_repo_id); } diff --git a/repository/url/icon.png b/repository/url/icon.png new file mode 100755 index 0000000000..33c3817ab4 Binary files /dev/null and b/repository/url/icon.png differ diff --git a/repository/url/repository.class.php b/repository/url/repository.class.php new file mode 100755 index 0000000000..7df80e0728 --- /dev/null +++ b/repository/url/repository.class.php @@ -0,0 +1,85 @@ +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');; + } +} +?> diff --git a/repository/url/version.php b/repository/url/version.php new file mode 100644 index 0000000000..b5721016d8 --- /dev/null +++ b/repository/url/version.php @@ -0,0 +1,2 @@ +version = 2009051800; diff --git a/repository/ws.php b/repository/ws.php index e64a8c536f..d99e13d4b2 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -99,7 +99,7 @@ require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php'); $classname = 'repository_' . $type; 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){ $err->e = $e->getMessage(); die(json_encode($err)); diff --git a/repository/youtube/repository.class.php b/repository/youtube/repository.class.php index 44d6705481..c69275086a 100644 --- a/repository/youtube/repository.class.php +++ b/repository/youtube/repository.class.php @@ -78,7 +78,7 @@ class repository_youtube extends repository { $search->label = get_string('search', 'repository_youtube').': '; $ret['login'] = array($search); $ret['login_btn_label'] = get_string('search'); - $ret['login_search_form'] = true; + $ret['login_btn_action'] = 'search'; return $ret; } public function supported_return_value() {