From 4e0969f0d335bc7abcd59df57cb6682e87f57706 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Wed, 7 Jul 2010 08:18:41 +0000 Subject: [PATCH] MDL-22982, fixed file browser renderer component --- files/filebrowser_ajax.php | 12 +----------- files/module.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/files/filebrowser_ajax.php b/files/filebrowser_ajax.php index 8e82d8b8a8c..659568cab66 100755 --- a/files/filebrowser_ajax.php +++ b/files/filebrowser_ajax.php @@ -34,7 +34,6 @@ $action = optional_param('action', 'list', PARAM_ALPHA); require_login(); $err = new stdclass; - if (isguestuser()) { $err->error = get_string('noguest'); die(json_encode($err)); @@ -43,7 +42,6 @@ if (isguestuser()) { switch ($action) { // used by course file tree viewer case 'getfiletree': - $contextid = required_param('contextid', PARAM_INT); $component = required_param('component', PARAM_ALPHAEXT); $filearea = required_param('filearea', PARAM_ALPHAEXT); @@ -51,13 +49,6 @@ switch ($action) { $filepath = required_param('filepath', PARAM_PATH); $browser = get_file_browser(); - $params = $url->params(); - // fix empty value - foreach ($params as $key=>$value) { - if ($value==='') { - $params[$key] = null; - } - } $fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid), $component, $filearea, $itemid, $filepath); $children = $fileinfo->get_children(); $tree = array(); @@ -75,14 +66,13 @@ switch ($action) { ); if ($child->is_directory()) { $fileitem['isdir'] = true; - $fileitem['url'] = $url->out(); + $fileitem['url'] = $url->out(false); } else { $fileitem['url'] = $child->get_url(); } $tree[] = $fileitem; } echo json_encode($tree); - break; default: diff --git a/files/module.js b/files/module.js index 266540541a8..6338053d660 100644 --- a/files/module.js +++ b/files/module.js @@ -6,7 +6,12 @@ M.core_filetree = { request: function(url, node, cb) { var api = this.api + '?action=getfiletree'; var params = []; - params['fileurl'] = url; + params['contextid'] = this.get_param(url, 'contextid', -1); + params['component'] = this.get_param(url, 'component', null); + params['filearea'] = this.get_param(url, 'filearea', null); + params['itemid'] = this.get_param(url, 'itemid', -1); + params['filepath'] = this.get_param(url, 'filepath', null); + params['filename'] = this.get_param(url, 'filename', null); var scope = this; params['sesskey']=M.cfg.sesskey; var cfg = { @@ -50,7 +55,7 @@ M.core_filetree = { }; this.y3.io(api, cfg); }, - init : function(Y, options){ + init : function(Y){ var tree = new YAHOO.widget.TreeView('course-file-tree-view'); tree.setDynamicLoad(this.dynload); tree.subscribe("clickEvent", this.onclick); @@ -71,5 +76,16 @@ M.core_filetree = { }, onclick: function(e) { YAHOO.util.Event.preventDefault(e); + }, + get_param: function(url, name, val) { + name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); + var regexS = "[\\?&]"+name+"=([^&#]*)"; + var regex = new RegExp( regexS ); + var results = regex.exec(url); + if( results == null ) { + return val; + } else { + return unescape(results[1]); + } } } -- 2.43.0