]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-20470, use a gloabl varible repositoryuseexternallink to make filepicker return...
authordongsheng <dongsheng>
Wed, 7 Oct 2009 10:16:45 +0000 (10:16 +0000)
committerdongsheng <dongsheng>
Wed, 7 Oct 2009 10:16:45 +0000 (10:16 +0000)
admin/settings/plugins.php
lang/en_utf8/repository.php
repository/lib.php
repository/ws.php

index cf44967733ced81e3e18359fa6f868c12eeae71e..1161a4b74b420ffb9b140ea469be8b2290712e28 100644 (file)
@@ -205,6 +205,7 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
     $temp->add(new admin_setting_managerepository());
     $temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
     $temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
+    $temp->add(new admin_setting_configcheckbox('repositoryuseexternallink', get_string('useexternallink', 'repository'), get_string('configuseexternallink', 'repository'), 0));
     $ADMIN->add('repositorysettings', $temp);
     $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
         get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
index 4a258fba1bd62f7ce0d9ba1f8d719c6c9ca9bddd..586236c07db90dc607bb1b7dd76f9865a3e887e8 100644 (file)
@@ -119,6 +119,8 @@ $string['updown'] = 'Display order';
 $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';
index 89b823a568e66695b03ff66d2bf0c32c66aa6dfc..2e469d448e1175e9b03b02cd41dd38923b4fed4b 100644 (file)
@@ -640,13 +640,16 @@ abstract class repository {
                 if ($returnvalue !== '*' and $repository->supported_return_value() !== '*') {
                     $tmp = $repository->supported_return_value();
                     if ($tmp != $returnvalue) {
-                        $is_supported = false;
+                        if ($returnvalue == 'link' && $repository->supported_external_link()) {
+                        } else {
+                            $is_supported = false;
+                        }
                     }
                 }
                 if (!$onlyvisible || ($repository->is_visible() && !$repository->disabled)) {
                     // super_called will make sure the parent construct function is called
                     // by repository construct function
-                    $capability = has_capability('repository/'.$repo->repositorytype.':view', $context, $USER->id);
+                    $capability = has_capability('repository/'.$repo->repositorytype.':view', get_system_context());
                     if ($is_supported && $capability) {
                         $ret[] = $repository;
                     }
@@ -1009,7 +1012,7 @@ abstract class repository {
         $updown = get_string('updown', 'repository');
         //retrieve list of instances. In administration context we want to display all
         //instances of a type, even if this type is not visible. In course/user context we
-        //want to display only visible instances, but for every type types. The repository_get_instances()
+        //want to display only visible instances, but for every type types. The repository::get_instances()
         //third parameter displays only visible type.
         $instances = repository::get_instances(array($context),null,!$admin,$typename);
         $instancesnumber = count($instances);
@@ -1145,12 +1148,15 @@ abstract class repository {
      */
     public function get_file($url, $filename = '') {
         global $CFG;
-
-        $path = $this->prepare_file($filename);
-        $fp = fopen($path, 'w');
-        $c = new curl;
-        $c->download(array(array('url'=>$url, 'file'=>$fp)));
-        return $path;
+        if (!empty($CFG->repositoryuseexternallink) && $this->supported_external_link()) {
+            return $url;
+        } else {
+            $path = $this->prepare_file($filename);
+            $fp = fopen($path, 'w');
+            $c = new curl;
+            $c->download(array(array('url'=>$url, 'file'=>$fp)));
+            return $path;
+        }
     }
 
     /**
@@ -1213,6 +1219,13 @@ abstract class repository {
         // return 'ref_id';
         return 'ref_id';
     }
+    /**
+     * does it return a file url or a item_id
+     * @return string
+     */
+    public function supported_external_link() {
+        return false;
+    }
 
     /**
      * Provide repository instance information for Ajax
index 7b22028f55b9267c5d4f29ee1d8c2c5ba6a78479..18989e2984a70a0aaeb0d21fbc1ec1d55ca8e2ae 100644 (file)
@@ -203,6 +203,9 @@ EOD;
                 // $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');
@@ -213,6 +216,7 @@ EOD;
                 }
                 if (is_array($filepath)) {
                     // file api don't have real file path, so we need more file api specific info for "local" plugin
+                    // only used by local plugin
                     $fileinfo = $filepath;
                     $info = array();
                     $info['client_id'] = $client_id;
@@ -225,6 +229,7 @@ EOD;
                     $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;