return true;
}
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL | FILE_EXTERNAL;
+ }
}
$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;
+ }
}
* @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();
public function get_name(){
return get_string('repositoryname', 'repository_draft');;
}
+ public function supported_returntypes() {
+ return (FILE_INTERNAL | FILE_EXTERNAL);
+ }
}
}
$mform->addElement('static', null, '', get_string('information','repository_filesystem'));
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
public function supported_filetypes() {
return array('web_image');
}
+ public function supported_returntypes() {
+ return (FILE_INTERNAL | FILE_EXTERNAL);
+ }
}
default:
break;
}
- if (empty($this->image)) {
- throw new moodle_exception('invalidimage');
- }
$this->width = imagesx($this->image);
$this->height = imagesy($this->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);
$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;
}
public function supported_filetypes() {
return array('web_image');
}
+ public function supported_returntypes() {
+ return (FILE_INTERNAL | FILE_EXTERNAL);
+ }
}
$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
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
/**
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();
}
public $context;
public $options;
public $readonly;
+ public $returntypes;
/**
* Return a type for a given type name.
* @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();
}
}
}
- 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)) {
//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();
$this->options[$n] = $v;
}
$this->name = $this->get_name();
+ $this->returntypes = $this->supported_returntypes();
$this->super_called = true;
}
*/
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;
}
/**
* 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);
}
/**
* @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();
<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;
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";
* @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();
public function get_name(){
return get_string('repositoryname', 'repository_local');;
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
///the administrator just need to set a peer
return array('peer');
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
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
///the administrator just need to set a peer
return array('peer');
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
* 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';
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,
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);
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!='*'){
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){
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 = {
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) {
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 : "")
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);
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) {
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)
);
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);
}
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) {
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) {
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));
}
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
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));
}
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);
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);
}
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 = '*';
}
-<?php
+<?php // $Id$
/// The Web service script that is called from the filepicker front end
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));
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;
- }
- $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 ($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));
+ }
}
- 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));
$mform->addRule('secret_key', $strrequired, 'required', null, 'client');
return true;
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
public function get_name(){
return get_string('repositoryname', 'repository_upload');
}
+ public function supported_returntypes() {
+ return FILE_INTERNAL;
+ }
}
public function get_name(){
return get_string('repositoryname', 'repository_url');;
}
+ public function supported_returntypes() {
+ return (FILE_INTERNAL | FILE_EXTERNAL);
+ }
}
$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);
+ }
}
public static function get_type_option_names() {
return null;
}
+ public function supported_returntypes() {
+ return (FILE_INTERNAL | FILE_EXTERNAL);
+ }
}
return $list;
}
- public function get_file($url, $title) {
- return $url;
- }
public function global_search() {
return false;
}
$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;
+ }
}