From 761265adabf36bb44ab844595205a922f7219ef0 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 8 Jun 2009 06:25:53 +0000 Subject: [PATCH] "MDL-17316, non-js file picker added" --- lang/en_utf8/repository.php | 1 + lib/form/filemanager.php | 2 + repository/alfresco/repository.class.php | 8 + repository/filepicker.php | 191 +++++++++++++++++++++++ 4 files changed, 202 insertions(+) create mode 100755 repository/filepicker.php diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 62a4c0213b..eae8f43e63 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -1,4 +1,5 @@ _options['filetypes'], $this->_options['returnvalue']); $html = $this->_get_draftfiles($draftitemid, $client_id); + $accessiblefp = get_string('accessiblefilepicker', 'repository'); $str = $this->_getTabs(); $str .= $html; @@ -174,6 +175,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
+ $accessiblefp
EOD; if (empty($CFG->filemanagerjsloaded)) { diff --git a/repository/alfresco/repository.class.php b/repository/alfresco/repository.class.php index 5df7f6d58f..cc3d9d512f 100755 --- a/repository/alfresco/repository.class.php +++ b/repository/alfresco/repository.class.php @@ -60,6 +60,14 @@ class repository_alfresco extends repository { $ret = array(); $ret['login'] = array($user_field, $passwd_field); return $ret; + } else { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + echo ''; } } diff --git a/repository/filepicker.php b/repository/filepicker.php new file mode 100755 index 0000000000..d8cb4359d5 --- /dev/null +++ b/repository/filepicker.php @@ -0,0 +1,191 @@ +. +// + +require_once('../config.php'); +require_once($CFG->libdir.'/filelib.php'); +require_once('lib.php'); + +$page = optional_param('page', '', PARAM_RAW); // page +$client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID +$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform +$file = optional_param('file', '', PARAM_RAW); // file to download +$title = optional_param('title', '', PARAM_FILE); // new file name +$itemid = optional_param('itemid', '', PARAM_INT); +$icon = optional_param('icon', '', PARAM_RAW); +$action = optional_param('action', '', PARAM_ALPHA); +$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID +$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID +$req_path = optional_param('p', '', PARAM_RAW); // path +$callback = optional_param('callback', '', PARAM_CLEANHTML); +$search_text = optional_param('s', '', PARAM_CLEANHTML); + +// init repository plugin +$sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '. + 'WHERE i.id=? AND i.typeid=r.id'; +if (!$repository = $DB->get_record_sql($sql, array($repo_id))) { + $err->e = get_string('invalidrepositoryid', 'repository'); + die(json_encode($err)); +} else { + $type = $repository->type; +} +$url = $CFG->httpswwwroot."/repository/filepicker.php?ctx_id=$ctx_id&itemid=$itemid"; + +if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) { + require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php'); + $classname = 'repository_' . $type; + try { + $repo = new $classname($repo_id, $ctx_id, array('ajax'=>false, 'name'=>$repository->name, 'client_id'=>$client_id)); + } catch (repository_exception $e){ + $err->e = $e->getMessage(); + die(json_encode($err)); + } +} else { + $err->e = get_string('invalidplugin', 'repository', $type); + die(json_encode($err)); +} + +if ($action == 'download') { + $filepath = $repo->get_file($file, $title, $itemid); + if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) { + // youtube plugin return a url instead a file path + $url = $filepath; + echo json_encode(array( + /* File picker need to know this is a link + * in order to attach title to url + */ + 'type'=>'link', + 'client_id'=>$client_id, + 'url'=>$url, + 'id'=>$url, + 'file'=>$url + ) + ); + } else if (is_array($filepath)) { + // file api don't have real file path, so we need more file api specific info for "local" plugin + $fileinfo = $filepath; + $info = array(); + $info['file'] = $fileinfo['title']; + $info['id'] = $itemid; + $info['url'] = $CFG->httpswwwroot.'/draftfile.php/'.$fileinfo['contextid'].'/user_draft/'.$itemid.'/'.$fileinfo['title']; + echo json_encode($info); + } else { + // normal file path name + $info = repository::move_to_filepool($filepath, $title, $itemid); + //echo json_encode($info); + redirect($url, get_string('downloadsucc','repository')); + } + echo $filepath; +} else if ($action == 'confirm') { + print_header(get_string('download', 'repository'), get_string('download', 'repository')); + echo ''; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo ''; + echo '
'; + echo '
'; + print_footer('empty'); + +} else if ($action == 'list' or $action == 'sign') { + $navlinks = array(); + $navlinks[] = array('name' => 'filepicker', 'link' => $url, 'type' => 'activityinstance'); + $navlinks[] = array('name' => $repo->get_name()); + + $navigation = build_navigation($navlinks); + print_header(get_string('accessiblefilepicker', 'repository'), get_string('accessiblefilepicker', 'repository'), $navigation); + if ($repo->check_login()) { + $list = $repo->get_listing($req_path); + $dynload = !empty($list['dynload'])?true:false; + if (!empty($list['upload'])) { + echo '
'; + echo ''; + echo '
'; + echo ''; + echo '
'; + } else { + foreach ($list['path'] as $p) { + echo '
'; + echo ''; + echo '
'; + echo ' / '; + } + echo ''; + foreach ($list['list'] as $item) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'; + echo ''; + if (!empty($item['url'])) { + echo ''.$item['title'].''; + } else { + echo $item['title']; + } + echo ''; + if (!isset($item['children'])) { + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + } else { + echo '
'; + echo ''; + echo ''; + echo '
'; + } + echo '
'; + echo '
'; + } + } else { + echo '
'; + $repo->print_login(); + echo ''; + echo ''; + echo '
'; + } + print_footer('empty'); +} else { + $user_context = get_context_instance(CONTEXT_USER, $USER->id); + $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); + $navlinks = array(); + $navlinks[] = array('name' => get_string('accessiblefilepicker', 'repository'), 'link' => $url, 'type' => 'activityinstance'); + $navigation = build_navigation($navlinks); + print_header(get_string('accessiblefilepicker', 'repository'), get_string('accessiblefilepicker', 'repository'), $navigation); + echo '
'; + print_footer('empty'); +} + -- 2.39.5