Skip to content

Commit

Permalink
"MDL-20470, use a gloabl varible repositoryuseexternallink to make fi…
Browse files Browse the repository at this point in the history
…lepicker return the link instead of downloading to moodle file pool"
  • Loading branch information
dongsheng committed Oct 7, 2009
1 parent 551f442 commit 92eaeca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
$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),
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
$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';
31 changes: 22 additions & 9 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,16 @@ public static function get_instances($contexts=array(), $userid = null, $onlyvis
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;
}
Expand Down Expand Up @@ -1009,7 +1012,7 @@ public static function display_instances_list($context, $typename = null) {
$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);
Expand Down Expand Up @@ -1145,12 +1148,15 @@ public function prepare_file($filename) {
*/
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;
}
}

/**
Expand Down Expand Up @@ -1213,6 +1219,13 @@ public function supported_return_value() {
// 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
Expand Down
5 changes: 5 additions & 0 deletions repository/ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
// $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');
Expand All @@ -213,6 +216,7 @@
}
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;
Expand All @@ -225,6 +229,7 @@
$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;
Expand Down

0 comments on commit 92eaeca

Please sign in to comment.