mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
"MDL-20602, add support for FILE_INTERNAL and FILE_EXTERNAL"
This commit is contained in:
parent
95b320e59f
commit
41076c587f
@ -201,5 +201,8 @@ class repository_alfresco extends repository {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL | FILE_EXTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,5 +242,8 @@ class repository_boxnet extends repository {
|
||||
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
|
||||
$mform->addElement('static', null, '', get_string('information','repository_boxnet'));
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL | FILE_EXTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ class repository_draft extends repository {
|
||||
* @param string $itemid
|
||||
* @return string the location of the file
|
||||
*/
|
||||
public function get_file($fid, $title = '', $itemid = '') {
|
||||
public function move_to_draft($fid, $title = '', $itemid = '') {
|
||||
global $USER;
|
||||
$ret = array();
|
||||
$browser = get_file_browser();
|
||||
@ -100,5 +100,8 @@ class repository_draft extends repository {
|
||||
public function get_name(){
|
||||
return get_string('repositoryname', 'repository_draft');;
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,4 +142,7 @@ class repository_filesystem extends repository {
|
||||
}
|
||||
$mform->addElement('static', null, '', get_string('information','repository_filesystem'));
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
@ -286,4 +286,7 @@ class repository_flickr extends repository {
|
||||
public function supported_filetypes() {
|
||||
return array('web_image');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,6 @@ class moodle_image {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (empty($this->image)) {
|
||||
throw new moodle_exception('invalidimage');
|
||||
}
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
}
|
||||
@ -103,10 +100,7 @@ class moodle_image {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function saveas($imagepath='') {
|
||||
if (empty($imagepath)) {
|
||||
$imagepath = $this->imagepath;
|
||||
}
|
||||
function saveas($imagepath) {
|
||||
switch($this->info['mime']) {
|
||||
case 'image/jpeg':
|
||||
return imagejpeg($this->image, $imagepath);
|
||||
|
@ -383,9 +383,13 @@ class repository_flickr_public extends repository {
|
||||
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||
|
||||
$watermark = get_config('flickr_public', 'watermark');
|
||||
if (!empty($watermark)) {
|
||||
if ($watermark === 'on') {
|
||||
$img = new moodle_image($path);
|
||||
$img->watermark($url, array(10,10), array('ttf'=>true, 'fontsize'=>9))->saveas($path);
|
||||
$pathinfo = pathinfo($path);
|
||||
$newpath = $pathinfo['dirname'] . '/wm_' . $pathinfo['basename'];
|
||||
$img->watermark($url, array(10,10), array('ttf'=>true, 'fontsize'=>9))->saveas($newpath);
|
||||
unlink($path);
|
||||
$path = $newpath;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
@ -451,4 +455,7 @@ class repository_flickr_public extends repository {
|
||||
public function supported_filetypes() {
|
||||
return array('web_image');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
@ -102,10 +102,13 @@ class repository_googledocs extends repository {
|
||||
$gdocs->download_file($url, $fp);
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
public function supported_filetypes() {
|
||||
return array('document');
|
||||
}
|
||||
public function supported_filetypes() {
|
||||
return array('document');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
//Icon from: http://www.iconspedia.com/icon/google-2706.html
|
||||
|
@ -40,6 +40,11 @@
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
define('FILE_EXTERNAL', 1);
|
||||
define('FILE_INTERNAL', 2);
|
||||
|
||||
|
||||
// File picker javascript code
|
||||
|
||||
/**
|
||||
@ -398,7 +403,7 @@ class repository_type {
|
||||
global $DB;
|
||||
|
||||
//delete all instances of this type
|
||||
$instances = repository::get_instances(array(),null,false,$this->_typename);
|
||||
$instances = repository::get_instances(array(), null, false, $this->_typename);
|
||||
foreach ($instances as $instance) {
|
||||
$instance->delete();
|
||||
}
|
||||
@ -444,6 +449,7 @@ abstract class repository {
|
||||
public $context;
|
||||
public $options;
|
||||
public $readonly;
|
||||
public $returntypes;
|
||||
|
||||
/**
|
||||
* Return a type for a given type name.
|
||||
@ -569,7 +575,7 @@ abstract class repository {
|
||||
* @param string $type a type name to retrieve
|
||||
* @return array repository instances
|
||||
*/
|
||||
public static function get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $accepted_types = '*', $returnvalue = '*') {
|
||||
public static function get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $accepted_types = '*', $returntypes = 3) {
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
$params = array();
|
||||
@ -637,13 +643,12 @@ abstract class repository {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($returnvalue !== '*' and $repository->supported_return_value() !== '*') {
|
||||
$tmp = $repository->supported_return_value();
|
||||
if ($tmp != $returnvalue) {
|
||||
if ($returnvalue == 'link' && $repository->supported_external_link()) {
|
||||
} else {
|
||||
$is_supported = false;
|
||||
}
|
||||
if ($returntypes !== 3 and $repository->supported_returntypes() !== 3) {
|
||||
$type = $repository->supported_returntypes();
|
||||
if ($type & $returntypes) {
|
||||
//
|
||||
} else {
|
||||
$is_supported = false;
|
||||
}
|
||||
}
|
||||
if (!$onlyvisible || ($repository->is_visible() && !$repository->disabled)) {
|
||||
@ -1014,7 +1019,7 @@ abstract class repository {
|
||||
//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()
|
||||
//third parameter displays only visible type.
|
||||
$instances = repository::get_instances(array($context),null,!$admin,$typename);
|
||||
$instances = repository::get_instances(array($context), null, !$admin, $typename);
|
||||
$instancesnumber = count($instances);
|
||||
$alreadyplugins = array();
|
||||
|
||||
@ -1111,6 +1116,7 @@ abstract class repository {
|
||||
$this->options[$n] = $v;
|
||||
}
|
||||
$this->name = $this->get_name();
|
||||
$this->returntypes = $this->supported_returntypes();
|
||||
$this->super_called = true;
|
||||
}
|
||||
|
||||
@ -1148,15 +1154,11 @@ abstract class repository {
|
||||
*/
|
||||
public function get_file($url, $filename = '') {
|
||||
global $CFG;
|
||||
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;
|
||||
}
|
||||
$path = $this->prepare_file($filename);
|
||||
$fp = fopen($path, 'w');
|
||||
$c = new curl;
|
||||
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1214,17 +1216,8 @@ abstract class repository {
|
||||
* does it return a file url or a item_id
|
||||
* @return string
|
||||
*/
|
||||
public function supported_return_value() {
|
||||
// return 'link';
|
||||
// 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;
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1781,10 +1774,10 @@ function repository_head_setup() {
|
||||
* @param object $context the context
|
||||
* @param string $id unique id for every file picker
|
||||
* @param string $accepted_filetypes
|
||||
* @param string $returnvalue the return value of file picker
|
||||
* @param string $returntypes the return value of file picker
|
||||
* @return array
|
||||
*/
|
||||
function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returnvalue = '*') {
|
||||
function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returntypes = 3) {
|
||||
global $CFG, $USER, $PAGE, $OUTPUT;
|
||||
|
||||
$ft = new file_type_to_ext();
|
||||
@ -1856,8 +1849,8 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $
|
||||
<script type="text/javascript">
|
||||
var fp_lang = $lang;
|
||||
var fp_config = $options;
|
||||
file_extensions.image = $image_file_ext;
|
||||
file_extensions.media = $video_file_ext;
|
||||
MOODLE.repository.extensions.image = $image_file_ext;
|
||||
MOODLE.repository.extensions.media = $video_file_ext;
|
||||
</script>
|
||||
EOD;
|
||||
|
||||
@ -1872,17 +1865,17 @@ EOD;
|
||||
if (is_array($accepted_filetypes) && in_array('*', $accepted_filetypes)) {
|
||||
$accepted_filetypes = '*';
|
||||
}
|
||||
$repos = repository::get_instances(array($user_context, $context, get_system_context()), null, true, null, $accepted_filetypes, $returnvalue);
|
||||
$repos = repository::get_instances(array($user_context, $context, get_system_context()), null, true, null, $accepted_filetypes, $returntypes);
|
||||
|
||||
// print repository instances listing
|
||||
$js .= <<<EOD
|
||||
<script type="text/javascript">
|
||||
repository_listing['$id'] = [];
|
||||
MOODLE.repository.listing['$id'] = [];
|
||||
EOD;
|
||||
foreach ($repos as $repo) {
|
||||
$meta = $repo->get_meta();
|
||||
$js .= "\r\n";
|
||||
$js .= 'repository_listing[\''.$id.'\']['.$meta->id.']='.json_encode($meta).';';
|
||||
$js .= 'MOODLE.repository.listing[\''.$id.'\']['.$meta->id.']='.json_encode($meta).';';
|
||||
$js .= "\n";
|
||||
}
|
||||
$js .= "\r\n";
|
||||
|
@ -128,7 +128,7 @@ class repository_local extends repository {
|
||||
* @return array The metainfo of file
|
||||
* @see curl package
|
||||
*/
|
||||
public function get_file($encoded, $title = '', $itemid = '', $save_path = '/') {
|
||||
public function move_to_draft($encoded, $title = '', $itemid = '', $save_path = '/') {
|
||||
global $USER, $DB;
|
||||
$ret = array();
|
||||
|
||||
@ -158,5 +158,8 @@ class repository_local extends repository {
|
||||
public function get_name(){
|
||||
return get_string('repositoryname', 'repository_local');;
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,5 +342,8 @@ class repository_mahara extends repository {
|
||||
///the administrator just need to set a peer
|
||||
return array('peer');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,9 @@ class repository_picasa extends repository {
|
||||
public function supported_filetypes() {
|
||||
return array('web_image');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
// Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
|
||||
|
@ -320,5 +320,8 @@ class repository_remotemoodle extends repository {
|
||||
///the administrator just need to set a peer
|
||||
return array('peer');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,18 +10,32 @@
|
||||
* repo = new repository_client();
|
||||
*/
|
||||
|
||||
var id2clientid = {};
|
||||
var id2itemid = {};
|
||||
if (!MOODLE) {
|
||||
var MOODLE = {};
|
||||
}
|
||||
if (!MOODLE.repository) {
|
||||
MOODLE.repository = {};
|
||||
}
|
||||
|
||||
MOODLE.repository.listing = {};
|
||||
MOODLE.repository.extensions = {};
|
||||
MOODLE.repository.cache = {};
|
||||
MOODLE.repository.cache.client_id = {};
|
||||
|
||||
var repository_listing = {};
|
||||
var cached_client_id = {};
|
||||
var file_extensions = {};
|
||||
/* when selected a file, filename will be cached in this varible */
|
||||
var new_filename = '';
|
||||
// will be used by login form
|
||||
var cached_id;
|
||||
var cached_repo_id;
|
||||
// repository_client has static functions
|
||||
var id2clientid = {};
|
||||
var id2itemid = {};
|
||||
|
||||
/**
|
||||
* repository_client is a javascript class, it contains several static
|
||||
* methods you can call it directly without creating an instance.
|
||||
* If you are going to create a file picker, you need create an instance
|
||||
* repo = new repository_client();
|
||||
*/
|
||||
var repository_client = (function(){
|
||||
// private static field
|
||||
var version = '2.0';
|
||||
@ -51,6 +65,9 @@ var repository_client = (function(){
|
||||
el.className = 'file-picker';
|
||||
this.client_id = client_id;
|
||||
document.body.appendChild(el);
|
||||
|
||||
MOODLE.repository.api = moodle_cfg.wwwroot+'/repository/repository_ajax.php';
|
||||
|
||||
this.filepicker = new YAHOO.widget.Panel('file-picker-' + client_id, {
|
||||
draggable: true,
|
||||
close: true,
|
||||
@ -134,7 +151,7 @@ var repository_client = (function(){
|
||||
params['client_id']=this.client_id;
|
||||
repository_client.loading(this.client_id, 'load');
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=gsearch', this.search_cb, repository_client.postdata(params));
|
||||
MOODLE.repository.api+'?action=gsearch', this.search_cb, repository_client.postdata(params));
|
||||
}
|
||||
search_btn.on('contentReady', function() {
|
||||
search_btn.on('click', this.fnSearch, this.input_keyword);
|
||||
@ -173,9 +190,9 @@ var repository_client = (function(){
|
||||
var container = new YAHOO.util.Element('repo-list-'+this.client_id);
|
||||
container.set('innerHTML', '');
|
||||
container.on('contentReady', function() {
|
||||
this.init_search();
|
||||
for(var i in repository_listing[this.client_id]) {
|
||||
var repo = repository_listing[this.client_id][i];
|
||||
this.init_search();
|
||||
for(var i in MOODLE.repository.listing[this.client_id]) {
|
||||
var repo = MOODLE.repository.listing[this.client_id][i];
|
||||
var support = false;
|
||||
if(this.env=='editor' && this.accepted_types != '*'){
|
||||
if(repo.supported_types!='*'){
|
||||
@ -210,7 +227,7 @@ var repository_client = (function(){
|
||||
var client_id = result[1];
|
||||
var repo_id = result[2];
|
||||
// high light currect selected repository
|
||||
for(var cc in repository_listing[client_id]){
|
||||
for(var cc in MOODLE.repository.listing[client_id]){
|
||||
var tmp_id = 'repo-call-'+client_id+'-'+ cc;
|
||||
var el = document.getElementById(tmp_id);
|
||||
if(el){
|
||||
@ -260,7 +277,7 @@ repository_client.req = function(client_id, id, path, page) {
|
||||
params['page']=page;
|
||||
}
|
||||
params['accepted_types'] = r.accepted_types;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', moodle_cfg.wwwroot+'/repository/ws.php?action=list', this.req_cb, this.postdata(params));
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', MOODLE.repository.api+'?action=list', this.req_cb, this.postdata(params));
|
||||
}
|
||||
|
||||
repository_client.req_cb = {
|
||||
@ -319,7 +336,7 @@ repository_client.req_search_results = function(client_id, id, path, page) {
|
||||
params['page']=page;
|
||||
}
|
||||
params['accepted_types'] = r.accepted_types;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', moodle_cfg.wwwroot+'/repository/ws.php?action=search', this.req_cb, this.postdata(params));
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', MOODLE.repository.api+'?action=search', this.req_cb, this.postdata(params));
|
||||
}
|
||||
|
||||
repository_client.print_login = function(id, data) {
|
||||
@ -421,7 +438,7 @@ repository_client.login = function(id, repo_id) {
|
||||
params['accepted_types'] = this.fp[id].accepted_types;
|
||||
this.loading(id, 'load');
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=sign', this.req_cb, this.postdata(params));
|
||||
MOODLE.repository.api+'?action=sign', this.req_cb, this.postdata(params));
|
||||
}
|
||||
repository_client.login_keypress = function(evt,action) {
|
||||
evt = (evt) ? evt : ((window.event) ? window.event : "")
|
||||
@ -465,7 +482,7 @@ repository_client.search = function(id, repo_id) {
|
||||
params['accepted_types'] = this.fp[id].accepted_types;
|
||||
this.loading(id, 'load');
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=search', this.req_cb, this.postdata(params));
|
||||
MOODLE.repository.api+'?action=search', this.req_cb, this.postdata(params));
|
||||
}
|
||||
repository_client.loading = function(id, type, name) {
|
||||
var panel = new YAHOO.util.Element('panel-'+id);
|
||||
@ -529,7 +546,7 @@ repository_client.view_as_list = function(client_id, data) {
|
||||
params['client_id']=node.client_id;
|
||||
params['accepted_types']=fp.accepted_types;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=list',callback,repository_client.postdata(params));
|
||||
MOODLE.repository.api+'?action=list',callback,repository_client.postdata(params));
|
||||
}
|
||||
tree.dynload.client_id = client_id;
|
||||
if(fp.fs.dynload) {
|
||||
@ -811,7 +828,7 @@ repository_client.view_as_icons = function(client_id, data) {
|
||||
params['itemid'] = this.itemid;
|
||||
params['title'] = this.title;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=delete',
|
||||
MOODLE.repository.api+'?action=delete',
|
||||
this,
|
||||
repository_client.postdata(params)
|
||||
);
|
||||
@ -842,7 +859,7 @@ repository_client.view_as_icons = function(client_id, data) {
|
||||
params['client_id'] = client_id;
|
||||
repository_client.loading(client_id, 'load');
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=list', repository_client.req_cb, repository_client.postdata(params));
|
||||
MOODLE.repository.api+'?action=list', repository_client.req_cb, repository_client.postdata(params));
|
||||
}else{
|
||||
repository_client.view_as_icons(client_id, this.fs);
|
||||
}
|
||||
@ -931,7 +948,7 @@ repository_client.print_footer = function(client_id) {
|
||||
params['client_id']=client_id;
|
||||
repository_client.loading(client_id, 'load');
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=ccache', repository_client.req_cb, repository_client.postdata(params));
|
||||
MOODLE.repository.api+'?action=ccache', repository_client.req_cb, repository_client.postdata(params));
|
||||
}
|
||||
}
|
||||
if(fs.manage) {
|
||||
@ -977,17 +994,17 @@ repository_client.postdata = function(obj) {
|
||||
|
||||
repository_client.popup = function(client_id, url) {
|
||||
window.open(url,'repo_auth', 'location=0,status=0,scrollbars=0,width=500,height=300');
|
||||
cached_client_id = client_id;
|
||||
MOODLE.repository.cache.client_id = client_id;
|
||||
return true;
|
||||
}
|
||||
function repository_callback(id) {
|
||||
repository_client.req(cached_client_id, id, '');
|
||||
repository_client.req(MOODLE.repository.cache.client_id, id, '');
|
||||
}
|
||||
repository_client.logout = function(client_id, repo_id) {
|
||||
var params = [];
|
||||
params['repo_id'] = repo_id;
|
||||
params['client_id'] = client_id;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', moodle_cfg.wwwroot+'/repository/ws.php?action=logout',
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', MOODLE.repository.api+'?action=logout',
|
||||
repository_client.req_cb, repository_client.postdata(params));
|
||||
}
|
||||
repository_client.download = function(client_id, repo_id) {
|
||||
@ -1009,7 +1026,7 @@ repository_client.download = function(client_id, repo_id) {
|
||||
params['repo_id']=repo_id;
|
||||
params['client_id']=client_id;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=download',
|
||||
MOODLE.repository.api+'?action=download',
|
||||
repository_client.download_cb,
|
||||
repository_client.postdata(params));
|
||||
}
|
||||
@ -1096,7 +1113,7 @@ repository_client.upload = function(client_id) {
|
||||
YAHOO.util.Connect.setForm(aform, true, true);
|
||||
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=upload&itemid='+fp.itemid
|
||||
MOODLE.repository.api+'?action=upload&itemid='+fp.itemid
|
||||
+'&sesskey='+moodle_cfg.sesskey
|
||||
+'&ctx_id='+fp_config.contextid
|
||||
+'&savepath='+fp.savepath
|
||||
@ -1138,7 +1155,7 @@ repository_client.search_form = function(client_id, id) {
|
||||
params['ctx_id']=fp_config.contextid;
|
||||
params['repo_id']=id;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST',
|
||||
moodle_cfg.wwwroot+'/repository/ws.php?action=searchform',
|
||||
MOODLE.repository.api+'?action=searchform',
|
||||
repository_client.search_form_cb,
|
||||
repository_client.postdata(params));
|
||||
}
|
||||
@ -1155,13 +1172,13 @@ success: function(o) {
|
||||
el.id = 'fp-search-dlg';
|
||||
var dlg_title = document.createElement('DIV');
|
||||
dlg_title.className = 'hd';
|
||||
dlg_title.innerHTML = fp_lang.searching+"\"" + repository_listing[data.client_id][fp.fs.repo_id].name + '"';
|
||||
dlg_title.innerHTML = fp_lang.searching+"\"" + MOODLE.repository.listing[data.client_id][fp.fs.repo_id].name + '"';
|
||||
var dlg_body = document.createElement('DIV');
|
||||
dlg_body.className = 'bd';
|
||||
var sform = document.createElement('FORM');
|
||||
sform.method = 'POST';
|
||||
sform.id = "fp-search-form";
|
||||
sform.action = moodle_cfg.wwwroot+'/repository/ws.php?action=search';
|
||||
sform.action = MOODLE.repository.api+'?action=search';
|
||||
sform.innerHTML = data['form'];
|
||||
dlg_body.appendChild(sform);
|
||||
el.appendChild(dlg_title);
|
||||
@ -1173,7 +1190,7 @@ success: function(o) {
|
||||
repository_client.loading(client_id, 'load');
|
||||
YAHOO.util.Connect.setForm('fp-search-form', false, false);
|
||||
this.cancel();
|
||||
var url = moodle_cfg.wwwroot+'/repository/ws.php?action=search&env='+dlg_handler.env
|
||||
var url = MOODLE.repository.api+'?action=search&env='+dlg_handler.env
|
||||
+'&client_id='+client_id;
|
||||
var trans = YAHOO.util.Connect.asyncRequest('POST', url,
|
||||
repository_client.req_cb);
|
||||
@ -1245,9 +1262,9 @@ function open_filepicker(id, params) {
|
||||
}
|
||||
if(params.filetype) {
|
||||
if(params.filetype == 'image') {
|
||||
r.accepted_types = file_extensions.image;
|
||||
r.accepted_types = MOODLE.repository.extensions.image;
|
||||
} else if(params.filetype == 'video' || params.filetype== 'media') {
|
||||
r.accepted_types = file_extensions.media;
|
||||
r.accepted_types = MOODLE.repository.extensions.media;
|
||||
} else if(params.filetype == 'file') {
|
||||
r.accepted_types = '*';
|
||||
}
|
||||
|
53
repository/ws.php → repository/repository_ajax.php
Normal file → Executable file
53
repository/ws.php → repository/repository_ajax.php
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php // $Id$
|
||||
|
||||
/// The Web service script that is called from the filepicker front end
|
||||
|
||||
@ -104,7 +104,7 @@
|
||||
require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php');
|
||||
$classname = 'repository_' . $type;
|
||||
try {
|
||||
$repo = new $classname($repo_id, $contextid, array('ajax'=>true, 'name'=>$repository->name, 'client_id'=>$client_id));
|
||||
$repo = new $classname($repo_id, $contextid, array('ajax'=>true, 'name'=>$repository->name, 'type'=>$type, 'client_id'=>$client_id));
|
||||
} catch (repository_exception $e){
|
||||
$err->e = $e->getMessage();
|
||||
die(json_encode($err));
|
||||
@ -200,41 +200,34 @@ EOD;
|
||||
break;
|
||||
case 'download':
|
||||
try {
|
||||
// $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;
|
||||
if ($env == 'url' /* TODO: or request_external_url by user */) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
$filepath = $repo->get_file($file, $title, $itemid, $save_path);
|
||||
if ($filepath === false) {
|
||||
$err->e = get_string('cannotdownload', 'repository');
|
||||
die(json_encode($err));
|
||||
}
|
||||
if (empty($itemid)) {
|
||||
$itemid = (int)substr(hexdec(uniqid()), 0, 9)+rand(1,100);
|
||||
}
|
||||
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;
|
||||
// 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);
|
||||
$info = array();
|
||||
$info['client_id'] = $client_id;
|
||||
$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 if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) {
|
||||
// process external link
|
||||
$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;
|
||||
echo json_encode($info);
|
||||
die(json_encode($info));
|
||||
}
|
||||
|
||||
$filepath = $repo->get_file($file, $title, $itemid, $save_path);
|
||||
if ($filepath === false) {
|
||||
$err->e = get_string('cannotdownload', 'repository');
|
||||
die(json_encode($err));
|
||||
}
|
||||
$info = repository::move_to_filepool($filepath, $title, $itemid, $save_path);
|
||||
$info['client_id'] = $client_id;
|
||||
echo json_encode($info);
|
||||
} catch (repository_exception $e){
|
||||
$err->e = $e->getMessage();
|
||||
die(json_encode($err));
|
@ -81,4 +81,7 @@ class repository_s3 extends repository {
|
||||
$mform->addRule('secret_key', $strrequired, 'required', null, 'client');
|
||||
return true;
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
@ -70,5 +70,8 @@ class repository_upload extends repository {
|
||||
public function get_name(){
|
||||
return get_string('repositoryname', 'repository_upload');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,5 +137,8 @@ EOD;
|
||||
public function get_name(){
|
||||
return get_string('repositoryname', 'repository_url');;
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,4 +144,7 @@ class repository_webdav extends repository {
|
||||
$mform->addElement('text', 'webdav_user', get_string('webdav_user', 'repository_webdav'), array('size' => '40'));
|
||||
$mform->addElement('text', 'webdav_password', get_string('webdav_password', 'repository_webdav'), array('size' => '40'));
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,7 @@ class repository_wikimedia extends repository {
|
||||
public static function get_type_option_names() {
|
||||
return null;
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return (FILE_INTERNAL | FILE_EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
@ -55,9 +55,6 @@ class repository_youtube extends repository {
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function get_file($url, $title) {
|
||||
return $url;
|
||||
}
|
||||
public function global_search() {
|
||||
return false;
|
||||
}
|
||||
@ -80,10 +77,10 @@ class repository_youtube extends repository {
|
||||
$ret['login_btn_action'] = 'search';
|
||||
return $ret;
|
||||
}
|
||||
public function supported_return_value() {
|
||||
return 'link';
|
||||
}
|
||||
public function supported_filetypes() {
|
||||
return array('web_video');
|
||||
}
|
||||
public function supported_returntypes() {
|
||||
return FILE_EXTERNAL;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user