$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));
+ $temp->add(new admin_setting_configcheckbox('repositoryallowexternallinks', get_string('allowexternallinks', 'repository'), get_string('configallowexternallinks', 'repository'), 1));
$ADMIN->add('repositorysettings', $temp);
$ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
$string['addfile'] = 'Add...';
$string['addplugin'] = 'Add a repository plugin';
$string['activaterep'] = 'Active repositories';
+$string['allowexternallinks'] = 'Allow external links';
+$string['configallowexternallinks'] = 'Disable using external links in repository';
$string['areabackup'] = 'Backups';
$string['areacategoryintro'] = 'Category introduction';
$string['areacourseintro'] = 'Course introduction';
$string['invalidplugin'] = 'Invalid repository $a plug-in';
$string['invalidjson'] = 'Invalid JSON string';
$string['listview'] = 'View as list';
+$string['linkexternal'] = 'Link external';
$string['login'] = 'Login';
$string['logout'] = 'Logout';
$string['loading'] = 'Loading...';
$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';
return $this->build_list($photos, $page);
}
+ public function get_link($photo_id) {
+ global $CFG;
+ $result = $this->flickr->photos_getSizes($photo_id);
+ $url = '';
+ if(!empty($result[4])) {
+ $url = $result[4]['source'];
+ } elseif(!empty($result[3])) {
+ $url = $result[3]['source'];
+ } elseif(!empty($result[2])) {
+ $url = $result[2]['source'];
+ }
+ return $url;
+ }
+
/**
*
* @param string $photo_id
}
/**
+ * Print a search form
*
- * @return <type>
+ * @return string
*/
public function print_search() {
$str = '';
return $str;
}
+ public function get_link($photo_id) {
+ global $CFG;
+ $result = $this->flickr->photos_getSizes($photo_id);
+ $url = '';
+ if(!empty($result[4])) {
+ $url = $result[4]['source'];
+ } elseif(!empty($result[3])) {
+ $url = $result[3]['source'];
+ } elseif(!empty($result[2])) {
+ $url = $result[2]['source'];
+ }
+ return $url;
+ }
+
/**
*
* @global object $CFG
return $dir.$filename;
}
+ /**
+ * Return file URL, for most plugins, the parameter is the original
+ * url, but some plugins use a file id, so we need this function to
+ * convert file id to original url.
+ *
+ * @param string $url the url of file
+ */
+ public function get_link($url) {
+ return $url;
+ }
+
/**
* Download a file, this function can be overridden by
* subclass.
$lang['refresh'] = get_string('refresh', 'repository');
$lang['invalidjson'] = get_string('invalidjson', 'repository');
$lang['listview'] = get_string('listview', 'repository');
+ $lang['linkexternal'] = get_string('linkexternal', 'repository');
$lang['login'] = get_string('login', 'repository');
$lang['logout'] = get_string('logout', 'repository');
$lang['loading'] = get_string('loading', 'repository');
$options = array();
$sys_context = get_system_context();
$options['contextid'] = $sys_context->id;
+ $externallink = (int)get_config(null, 'repositoryallowexternallinks');
+ if (empty($externallink)) {
+ $options['externallink'] = false;
+ } else {
+ $options['externallink'] = true;
+ }
$options['icons']['loading'] = $OUTPUT->old_icon_url('i/loading');
+ $options['icons']['logout'] = $OUTPUT->old_icon_url('a/logout');
+ $options['icons']['help'] = $OUTPUT->old_icon_url('a/help');
$options['icons']['progressbar'] = $OUTPUT->old_icon_url('i/progressbar');
- $options['icons']['search'] = $OUTPUT->old_icon_url('a/search');
- $options['icons']['refresh'] = $OUTPUT->old_icon_url('a/refresh');
+ $options['icons']['search'] = $OUTPUT->old_icon_url('a/search');
$options['icons']['setting'] = $OUTPUT->old_icon_url('a/setting');
- $options['icons']['logout'] = $OUTPUT->old_icon_url('a/logout');
- $options['icons']['help'] = $OUTPUT->old_icon_url('a/help');
+ $options['icons']['refresh'] = $OUTPUT->old_icon_url('a/refresh');
$options = json_encode($options);
// fp_config includes filepicker options
}
}
repository_client.select_file = function(oldname, url, icon, client_id, repo_id) {
+ var fp = repository_client.fp[client_id];
if (repository_client.files[client_id] == undefined) {
repository_client.files[client_id] = 0;
}
html += '<p><img src="'+icon+'" /></p>';
html += '<p><label for="newname-'+client_id+'">'+fp_lang.saveas+'</label>';
html += '<input type="text" id="newname-'+client_id+'" value="" /></p>';
- html += '<p><input type="checkbox" id="external-'+client_id+'" value="" /> Link external</p>';
+
+ if (fp_config.externallink && fp.env == 'editor') {
+ html += '<p><input type="checkbox" id="external_link-'+client_id+'" value="" />'+fp_lang.linkexternal+'</p>';
+ }
html += '<p><input type="hidden" id="fileurl-'+client_id+'" value="'+url+'" />';
html += '<input type="button" onclick="repository_client.download(\''+client_id+'\', \''+repo_id+'\')" value="'+fp_lang.downbtn+'" />';
html += '<input type="button" onclick="repository_client.viewfiles(\''+client_id+'\')" value="'+fp_lang.cancel+'" /></p>';
repository_client.req_cb, repository_client.postdata(params));
}
repository_client.download = function(client_id, repo_id) {
+ var params = [];
var fp = repository_client.fp[client_id];
var title = document.getElementById('newname-'+client_id).value;
new_filename = title;
var file = document.getElementById('fileurl-'+client_id).value;
- var link_external = document.getElementById('external-'+client_id).checked;
+ if (fp.env == 'editor') {
+ var link_external = document.getElementById('external_link-'+client_id).checked;
+ if (link_external) {
+ params['link_external'] = 'yes';
+ }
+ } if (fp.env == 'url') {
+ params['link_external'] = 'yes';
+ }
repository_client.loading(client_id, 'download', title);
- var params = [];
if(fp.itemid){
params['itemid']=fp.itemid;
}
- if (link_external) {
- params['link_external'] = 'yes';
- }
params['env']=fp.env;
params['file']=file;
params['savepath']=fp.savepath;
break;
case 'download':
try {
- if ($env == 'url' or $link_external === 'yes') {
- if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $file)) {
- die(json_encode(array('type'=>'link', 'client_id'=>$client_id,
- 'url'=>$file, 'id'=>$file, 'file'=>$file)));
- } else {
- $err->e = get_string('invalidurl');
- die(json_encode($err));
- }
- }
// we have two special repoisitory type need to deal with
if ($repo->options['type'] == 'local' or $repo->options['type'] == 'draft') {
$fileinfo = $repo->move_to_draft($file, $title, $itemid, $save_path);
die(json_encode($info));
}
+ $allowexternallink = (int)get_config(null, 'repositoryallowexternallinks');
+ if (!empty($allowexternallink)) {
+ $allowexternallink = true;
+ } else {
+ $allowexternallink = false;
+ }
+ // allow external links in url element all the time
+ $allowexternallink = ($allowexternallink || ($env == 'url'));
+
+ if ($allowexternallink and $link_external === 'yes' and ($repo->supported_returntypes() || FILE_EXTERNAL)) {
+ try {
+ $link = $repo->get_link($file);
+ } catch (repository_exception $e){
+ }
+ $info = array();
+ $info['client_id'] = $client_id;
+ $info['file'] = $title;
+ $info['type'] = 'link';
+ $info['url'] = $link;
+ die(json_encode($info));
+ }
+
$filepath = $repo->get_file($file, $title, $itemid, $save_path);
if ($filepath === false) {
$err->e = get_string('cannotdownload', 'repository');