]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-20602, add support for FILE_INTERNAL and FILE_EXTERNAL"
authorDongsheng Cai <unoter@gmail.com>
Mon, 2 Nov 2009 06:45:12 +0000 (06:45 +0000)
committerDongsheng Cai <unoter@gmail.com>
Mon, 2 Nov 2009 06:45:12 +0000 (06:45 +0000)
21 files changed:
repository/alfresco/repository.class.php
repository/boxnet/repository.class.php
repository/draft/repository.class.php
repository/filesystem/repository.class.php
repository/flickr/repository.class.php
repository/flickr_public/image.php
repository/flickr_public/repository.class.php
repository/googledocs/repository.class.php
repository/lib.php
repository/local/repository.class.php
repository/mahara/repository.class.php
repository/picasa/repository.class.php
repository/remotemoodle/repository.class.php
repository/repository.src.js
repository/repository_ajax.php [moved from repository/ws.php with 85% similarity, mode: 0755]
repository/s3/repository.class.php
repository/upload/repository.class.php
repository/url/repository.class.php
repository/webdav/repository.class.php
repository/wikimedia/repository.class.php
repository/youtube/repository.class.php

index eb557c48d77b458d3a9fa074ef026b81585b9230..bdc09eac56cdda96cba1945e755d3b1028856a47 100755 (executable)
@@ -201,5 +201,8 @@ class repository_alfresco extends repository {
             return true;
         }
     }
+    public function supported_returntypes() {
+        return FILE_INTERNAL | FILE_EXTERNAL;
+    }
 }
 
index 19071d88335a077b26f5817d6cfe13278e06c740..cb0975db4fcf2b87ed5c0fab1d76c1a5d5b27f1f 100755 (executable)
@@ -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;
+    }
 }
 
index 806f56985290404ac2862461674f870bbde3ea03..619f608baf234e82400cf6319be86a848b9f1f12 100755 (executable)
@@ -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);
+    }
 }
 
index d728a34af44e32471ee17291061b41ce4cc5763d..f4c553c7d4ac222ab8c074285fede1877c0c7a28 100644 (file)
@@ -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;
+    }
 }
index b9a05521826f4ba3db050bcb2cea56044184838d..5ab542a705814687635c5a2f83406a63635e51b8 100755 (executable)
@@ -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);
+    }
 }
index 373b4129ce77d1e29e416cfbc0a54ef5630929cf..70511ce269d1a6a0868cf86fc89a26b26a2c0ce4 100755 (executable)
@@ -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);
index 6fbfc0f3862fd6e62374a5f6c3dd5e0f1dc94253..53093a669a8499fa457c2147786de327770ebed5 100644 (file)
@@ -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);
+    }
 }
index f854e2645d5fd81f9f80b4238933fcb1ccec1c55..8a8694b1feb2464ef970622d354b438d2188ef4d 100644 (file)
@@ -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
index 2e469d448e1175e9b03b02cd41dd38923b4fed4b..84db2a17782af6be7cedffc85ccb84d075c067ce 100644 (file)
 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";
index b29ddf13688b873b267259995df1d5297f0d8277..866d4b83c89e6f3a319c1499b1848d98e8a19b37 100755 (executable)
@@ -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;
+    }
 }
 
index 7f6f32e090cfb2d3f1de2efa7867fe0d1a64cfa5..a99db28c5628d450b6855efb29b493e0d7c36fb6 100644 (file)
@@ -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;
+    }
 }
 
index f03a91d50daac038c847e3b7c0a8f2d54bf15659..242f9f88b9f76d32b46fe59ef256585c9073519b 100644 (file)
@@ -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
index 9898144d17a1a6902e38bb303e26516cfb6bd1e1..b215e048a9feca6239cc8dbca418f2a8aa79b10d 100644 (file)
@@ -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;
+    }
 }
 
index b56f1539e05749320b330f6e0f123a80210bb0dc..d830e21de06621214cdb56d56b2f32ca57f70ebf 100644 (file)
  * 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 = '*';
         }
old mode 100644 (file)
new mode 100755 (executable)
similarity index 85%
rename from repository/ws.php
rename to repository/repository_ajax.php
index 4d203ad..c0c57f5
@@ -1,4 +1,4 @@
-<?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));
@@ -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;
-                }
-                $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));
index beb61977bbee6b6d019d6b592331c7008b0bef37..a9a5182d93a91b5141c7f95f0e7a43b6b9b31dca 100644 (file)
@@ -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;
+    }
 }
index 5813cd4016539978eb9165153739d64f8e0f565c..72d5e6152eec378debf5e43f81b831a79e9e5903 100755 (executable)
@@ -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;
+    }
 }
 
index e295dc2695bd9c24fdea0d6caf1bd3ac1ef10caf..c36e7fad55d29bde6714a35771509580a443d03c 100755 (executable)
@@ -137,5 +137,8 @@ EOD;
     public function get_name(){
         return get_string('repositoryname', 'repository_url');;
     }
+    public function supported_returntypes() {
+        return (FILE_INTERNAL | FILE_EXTERNAL);
+    }
 }
 
index f49aa2b59e4c8df2f90a2084cfec6db1fd5a84b9..80ae36d81bffb0c03781eeb6f3bde948ca20bcb4 100644 (file)
@@ -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);
+    }
 }
index c65044693cd0dd71817d854f7de01c405b60189d..69c1d220becf512dca83777285a4bfdec812874e 100644 (file)
@@ -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);
+    }
 }
index 5a79a4305b57e37bba4dda2fbc097d00ddfa80d8..1af405148e3fcf1bf26eb88154045158221c4dc4 100644 (file)
@@ -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;
+    }
 }