$temp->add(new admin_setting_managerepository());
$temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
$temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
+ $temp->add(new admin_setting_configcheckbox('repositoryuseexternallink', get_string('useexternallink', 'repository'), get_string('configuseexternallink', 'repository'), 0));
$ADMIN->add('repositorysettings', $temp);
$ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
+$string['useexternallink'] = 'Use external link instead downloading files';
+$string['configuseexternallink'] = 'Will return the external link to file picker instead downloading external files';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
if ($returnvalue !== '*' and $repository->supported_return_value() !== '*') {
$tmp = $repository->supported_return_value();
if ($tmp != $returnvalue) {
- $is_supported = false;
+ if ($returnvalue == 'link' && $repository->supported_external_link()) {
+ } else {
+ $is_supported = false;
+ }
}
}
if (!$onlyvisible || ($repository->is_visible() && !$repository->disabled)) {
// super_called will make sure the parent construct function is called
// by repository construct function
- $capability = has_capability('repository/'.$repo->repositorytype.':view', $context, $USER->id);
+ $capability = has_capability('repository/'.$repo->repositorytype.':view', get_system_context());
if ($is_supported && $capability) {
$ret[] = $repository;
}
$updown = get_string('updown', 'repository');
//retrieve list of instances. In administration context we want to display all
//instances of a type, even if this type is not visible. In course/user context we
- //want to display only visible instances, but for every type types. The repository_get_instances()
+ //want to display only visible instances, but for every type types. The repository::get_instances()
//third parameter displays only visible type.
$instances = repository::get_instances(array($context),null,!$admin,$typename);
$instancesnumber = count($instances);
*/
public function get_file($url, $filename = '') {
global $CFG;
-
- $path = $this->prepare_file($filename);
- $fp = fopen($path, 'w');
- $c = new curl;
- $c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $path;
+ if (!empty($CFG->repositoryuseexternallink) && $this->supported_external_link()) {
+ return $url;
+ } else {
+ $path = $this->prepare_file($filename);
+ $fp = fopen($path, 'w');
+ $c = new curl;
+ $c->download(array(array('url'=>$url, 'file'=>$fp)));
+ return $path;
+ }
}
/**
// return 'ref_id';
return 'ref_id';
}
+ /**
+ * does it return a file url or a item_id
+ * @return string
+ */
+ public function supported_external_link() {
+ return false;
+ }
/**
* Provide repository instance information for Ajax
// $file is the specific information of file, such as url, or meta information
// $title is the file name in file pool
// $itemid and $save_path will be used by local plugin only
+ if ($env == 'texturl') {
+ $CFG->repositoryuseexternallink = true;
+ }
$filepath = $repo->get_file($file, $title, $itemid, $save_path);
if ($filepath === false) {
$err->e = get_string('cannotdownload', 'repository');
}
if (is_array($filepath)) {
// file api don't have real file path, so we need more file api specific info for "local" plugin
+ // only used by local plugin
$fileinfo = $filepath;
$info = array();
$info['client_id'] = $client_id;
$url = $filepath;
echo json_encode(array('type'=>'link', 'client_id'=>$client_id, 'url'=>$url, 'id'=>$url, 'file'=>$url));
} else {
+ // used by most repository plugins
// move downloaded file to file pool
$info = repository::move_to_filepool($filepath, $title, $itemid, $save_path);
$info['client_id'] = $client_id;