From 6f2cd52aa5bc1fa5788a0c03340088338ebad402 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Fri, 6 Nov 2009 09:07:46 +0000 Subject: [PATCH] "MDL-19181, 1. fixed repository listing when using non-admin role 2. added boilerplate" --- lib/adminlib.php | 10 +- repository/filepicker.php | 27 ++- repository/flickr/repository.class.php | 67 ++++---- repository/lib.php | 225 +++++++++++++++---------- repository/repository.src.js | 16 +- repository/repository_ajax.php | 50 ++++-- user/repository.php | 6 +- 7 files changed, 253 insertions(+), 148 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index ddd7b7ee5f..df3848cdd1 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -5988,10 +5988,16 @@ class admin_setting_managerepository extends admin_setting { //calculate number of instances in order to display them for the Moodle administrator if (!empty($instanceoptionnames)) { - $admininstancenumber = count(repository::static_function($i->get_typename(), 'get_instances', array(get_context_instance(CONTEXT_SYSTEM)),null,false,$i->get_typename())); + $params = array(); + $params['context'] = array(get_system_context()); + $params['onlyvisible'] = false; + $params['type'] = $i->get_typename(); + $admininstancenumber = count(repository::static_function($i->get_typename(), + 'get_instances', array($params))); $admininstancenumbertext = "
". $admininstancenumber . " " . get_string('instancesforadmin', 'repository'); - $instancenumber = count(repository::static_function($i->get_typename(), 'get_instances', array(),null,false,$i->get_typename())) - $admininstancenumber; + $params['context'] = array(); + $instancenumber = count(repository::static_function($i->get_typename(), 'get_instances', array($params))) - $admininstancenumber; $instancenumbertext = "
" . $instancenumber . " " . get_string('instancesforothers', 'repository'); } else { diff --git a/repository/filepicker.php b/repository/filepicker.php index 6564221fb4..111881365c 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -1,4 +1,5 @@ . // +/** + * This file is used to browse repositories in non-javascript mode + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once('../config.php'); require_once($CFG->libdir.'/filelib.php'); require_once('lib.php'); @@ -41,7 +52,7 @@ $thumbnail = optional_param('thumbnail', '', PARAM_RAW); $targetpath = optional_param('targetpath', '', PARAM_PATH); $repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // the path in repository -$page = optional_param('page', '', PARAM_RAW); // What page in repository? +$curr_page = optional_param('page', '', PARAM_RAW); // What page in repository? $search_text = optional_param('s', '', PARAM_CLEANHTML); // draft area @@ -155,7 +166,7 @@ case 'sign': echo $OUTPUT->header(); echo '
'.get_string('back', 'repository')."
"; if ($repo->check_login()) { - $list = $repo->get_listing($req_path, $page); + $list = $repo->get_listing($req_path, $curr_page); $dynload = !empty($list['dynload'])?true:false; if (!empty($list['upload'])) { echo '
'; @@ -284,7 +295,11 @@ case 'confirm': case 'plugins': $user_context = get_context_instance(CONTEXT_USER, $USER->id); - $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); + $params = array(); + $params['context'] = array($user_context, get_system_context()); + $params['currentcontext'] = $PAGE->context; + $params['returntypes'] = 2; + $repos = repository::get_instances($params); echo $OUTPUT->header(); echo '
'.get_string('back', 'repository')."
"; echo '
'; @@ -430,7 +445,11 @@ case 'renameform': case 'browse': default: $user_context = get_context_instance(CONTEXT_USER, $USER->id); - $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); + $params = array(); + $params['context'] = array($user_context, get_system_context()); + $params['currentcontext'] = $PAGE->context; + $params['returntypes'] = 2; + $repos = repository::get_instances($params); $fs = get_file_storage(); $files = $fs->get_directory_files($user_context->id, 'user_draft', $itemid, $draftpath, false); diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index 5ab542a705..2c89f5f0b7 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -18,11 +18,9 @@ class repository_flickr extends repository { /** * - * @global $SESSION - * @global $CFG - * @param $repositoryid - * @param $context - * @param $options + * @param int $repositoryid + * @param object $context + * @param array $options */ public function __construct($repositoryid, $context = SITEID, $options = array()) { global $SESSION, $CFG; @@ -52,7 +50,7 @@ class repository_flickr extends repository { /** * - * @return + * @return bool */ public function check_login() { return !empty($this->token); @@ -60,7 +58,7 @@ class repository_flickr extends repository { /** * - * @return + * @return mixed */ public function logout() { set_user_preference($this->setting, ''); @@ -72,8 +70,8 @@ class repository_flickr extends repository { /** * - * @param $options - * @return + * @param array $options + * @return mixed */ public function set_option($options = array()) { if (!empty($options['api_key'])) { @@ -90,8 +88,8 @@ class repository_flickr extends repository { /** * - * @param $config - * @return + * @param string $config + * @return mixed */ public function get_option($config = '') { if ($config==='api_key') { @@ -108,7 +106,7 @@ class repository_flickr extends repository { /** * - * @return + * @return bool */ public function global_search() { if (empty($this->token)) { @@ -120,8 +118,7 @@ class repository_flickr extends repository { /** * - * @param $ajax - * @return + * @return null */ public function print_login() { if ($this->options['ajax']) { @@ -138,9 +135,9 @@ class repository_flickr extends repository { /** * - * @param $photos - * @param $page - * @return + * @param mixed $photos + * @param int $page + * @return array */ private function build_list($photos, $page = 1) { $photos_url = $this->flickr->urls_getUserPhotos($this->nsid); @@ -180,8 +177,8 @@ class repository_flickr extends repository { /** * - * @param $search_text - * @return + * @param string $search_text + * @return array */ public function search($search_text) { $photos = $this->flickr->photos_search(array( @@ -199,7 +196,7 @@ class repository_flickr extends repository { * * @param string $path * @param int $page - * @return + * @return array */ public function get_listing($path = '', $page = '1') { $photos_url = $this->flickr->urls_getUserPhotos($this->nsid); @@ -215,10 +212,9 @@ class repository_flickr extends repository { /** * - * @global $CFG - * @param $photo_id - * @param $file - * @return + * @param string $photo_id + * @param string $file + * @return string */ public function get_file($photo_id, $file = '') { global $CFG; @@ -242,8 +238,7 @@ class repository_flickr extends repository { /** * Add Plugin settings input to Moodle form - * @global $CFG - * @param $ + * @param object $mform */ public function type_config_form(&$mform) { global $CFG; @@ -262,14 +257,18 @@ class repository_flickr extends repository { $mform->addElement('text', 'secret', get_string('secret', 'repository_flickr'), array('value'=>$secret,'size' => '40')); //retrieve the flickr instances - $instances = repository::get_instances(array(),null,false,"flickr"); + $params = array(); + $params['context'] = array(); + //$params['currentcontext'] = $this->context; + $params['onlyvisible'] = false; + $params['type'] = 'flickr'; + $instances = repository::get_instances($params); if (empty($instances)) { - $callbackurl = get_string("callbackwarning","repository_flickr"); - $mform->addElement('static', null, '', $callbackurl); - } - else { - $callbackurl = $CFG->wwwroot.'/repository/ws.php?callback=yes&repo_id='.$instances[0]->id; - $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_flickr', $callbackurl)); + $callbackurl = get_string('callbackwarning', 'repository_flickr'); + $mform->addElement('static', null, '', $callbackurl); + } else { + $callbackurl = $CFG->wwwroot.'/repository/ws.php?callback=yes&repo_id='.$instances[0]->id; + $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_flickr', $callbackurl)); } $mform->addRule('api_key', $strrequired, 'required', null, 'client'); @@ -278,7 +277,7 @@ class repository_flickr extends repository { /** * Names of the plugin settings - * @return + * @return array */ public static function get_type_option_names() { return array('api_key', 'secret'); diff --git a/repository/lib.php b/repository/lib.php index 84db2a1778..091a9084c5 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1,42 +1,32 @@ . + /** - * About repository/lib.php: - * two main classes: - * 1. repository_type => a repository plugin, You can activate a plugin into - * Moodle. You also can set some general settings/options for this type of repository. - * All instances would share the same options (for example: a API key for the connection - * to the repository) - * 2. repository => an instance of a plugin. You can also call it an access or - * an account. An instance has specific settings (for example: a public url) and a specific - * name. That's this name which is displayed in the file picker. + * This file contains classes used to manage the repository plugins in Moodle + * and was introduced as part of the changes occuring in Moodle 2.0 + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - - require_once(dirname(dirname(__FILE__)) . '/config.php'); require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/formslib.php'); @@ -44,15 +34,13 @@ require_once($CFG->libdir . '/formslib.php'); define('FILE_EXTERNAL', 1); define('FILE_INTERNAL', 2); - -// File picker javascript code - /** + * This class is used to manage repository plugins + * * A repository_type is a repository plug-in. It can be Box.net, Flick-r, ... * A repository type can be edited, sorted and hidden. It is mandatory for an * administrator to create a repository type in order to be able to create * some instances of this type. - * * Coding note: * - a repository_type object is mapped to the "repository" database table * - "typename" attibut maps the "type" database field. It is unique. @@ -61,6 +49,11 @@ define('FILE_INTERNAL', 2); * options are also deleted from database * - When you create a type for a plugin that can't have multiple instances, a * instance is automatically created. + * + * @package moodlecore + * @subpackage repository + * @copyright 2009 Jerome Mouneyrac + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class repository_type { @@ -403,7 +396,11 @@ class repository_type { global $DB; //delete all instances of this type - $instances = repository::get_instances(array(), null, false, $this->_typename); + $params = array(); + $params['context'] = array(); + $params['onlyvisible'] = false; + $params['type'] = $this->_typename; + $instances = repository::get_instances($params); foreach ($instances as $instance) { $instance->delete(); } @@ -422,9 +419,7 @@ class repository_type { * * To use repository plugin, see: * http://docs.moodle.org/en/Development:Repository_How_to_Create_Plugin - * * class repository is an abstract class, some functions must be implemented in subclass. - * * See an example: repository/boxnet/repository.class.php * * A few notes: @@ -438,8 +433,10 @@ class repository_type { * // print a search box * $repo->print_search(); * - * @package repository - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class repository { // $disabled can be set to true to disable a plugin by force @@ -575,16 +572,34 @@ 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 = '*', $returntypes = 3) { + //public static function get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null, $accepted_types = '*', $returntypes = 3) { + public static function get_instances($args = array()) { global $DB, $CFG, $USER; + if (isset($args['currentcontext'])) { + $current_context = $args['currentcontext']; + } else { + $current_context = null; + } + + if (!empty($args['context'])) { + $contexts = $args['context']; + } else { + $contexts = array(); + } + + $onlyvisible = isset($args['onlyvisible']) ? $args['onlyvisible'] : true; + $type = isset($args['type']) ? $args['type'] : null; + $acceptedtypes = isset($args['accepted_types']) ? $args['accepted_types'] : '*'; + $returntypes = isset($args['returntypes']) ? $args['returntypes'] : 3; + $params = array(); $sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE '; $sql .= 'i.typeid = r.id '; - if (!empty($userid) && is_numeric($userid)) { + if (!empty($args['userid']) && is_numeric($args['userid'])) { $sql .= ' AND (i.userid = 0 or i.userid = ?)'; - $params[] = $userid; + $params[] = $args['userid']; } foreach ($contexts as $context) { @@ -611,38 +626,44 @@ abstract class repository { } $sql .= ' order by r.sortorder, i.name'; - if (!$repos = $DB->get_records_sql($sql, $params)) { - $repos = array(); + if (!$records = $DB->get_records_sql($sql, $params)) { + $records = array(); } - $ret = array(); + $repositories = array(); $ft = new file_type_to_ext(); - foreach ($repos as $repo) { - require_once($CFG->dirroot . '/repository/'. $repo->repositorytype.'/repository.class.php'); - $options['visible'] = $repo->visible; - $options['name'] = $repo->name; - $options['type'] = $repo->repositorytype; - $options['typeid'] = $repo->typeid; + foreach ($records as $record) { + require_once($CFG->dirroot . '/repository/'. $record->repositorytype.'/repository.class.php'); + $options['visible'] = $record->visible; + $options['name'] = $record->name; + $options['type'] = $record->repositorytype; + $options['typeid'] = $record->typeid; // tell instance what file types will be accepted by file picker - $options['accepted_types'] = $ft->get_file_ext($accepted_types); - $classname = 'repository_' . $repo->repositorytype;// + $options['accepted_types'] = $ft->get_file_ext($acceptedtypes); + $classname = 'repository_' . $record->repositorytype; + + $repository = new $classname($record->id, $record->contextid, $options, $record->readonly); + $is_supported = true; - $repository = new $classname($repo->id, $repo->contextid, $options, $repo->readonly); - $context = get_context_instance_by_id($repo->contextid); if (empty($repository->super_called)) { - debugging('parent::__construct must be called by '.$repo->repositorytype.' plugin.'); + // to make sure the super construct is called + debugging('parent::__construct must be called by '.$record->repositorytype.' plugin.'); } else { - if ($accepted_types !== '*' and $repository->supported_filetypes() !== '*') { - $accepted_types = $ft->get_file_ext($accepted_types); + // check mimetypes + if ($acceptedtypes !== '*' and $repository->supported_filetypes() !== '*') { + $acceptedtypes = $ft->get_file_ext($acceptedtypes); $supported_filetypes = $ft->get_file_ext($repository->supported_filetypes()); + $is_supported = false; foreach ($supported_filetypes as $type) { - if (in_array($type, $accepted_types)) { + if (in_array($type, $acceptedtypes)) { $is_supported = true; } } + } + // check return values if ($returntypes !== 3 and $repository->supported_returntypes() !== 3) { $type = $repository->supported_returntypes(); if ($type & $returntypes) { @@ -652,16 +673,21 @@ abstract class repository { } } 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', get_system_context()); + + // check capability in current context + if (!empty($current_context)) { + $capability = has_capability('repository/'.$record->repositorytype.':view', $current_context); + } else { + // TODO: what should we do if current context isn't set? + $capability = has_capability('repository/'.$record->repositorytype.':view', get_system_context()); + } if ($is_supported && $capability) { - $ret[] = $repository; + $repositories[] = $repository; } } } } - return $ret; + return $repositories; } /** @@ -960,7 +986,6 @@ abstract class repository { //} - //Uncomment this following line if you wanna display all directory ()even empty if (!$search || $_filecount || (stristr($tmp['title'], $search) !== false)) { $filecount += $_filecount; $list[] = $tmp; @@ -1019,7 +1044,12 @@ 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); + $params = array(); + $params['context'] = array($context, get_system_context()); + $params['currentcontext'] = $context; + $params['onlyvisible'] = !$admin; + $params['type'] = $typename; + $instances = repository::get_instances($params); $instancesnumber = count($instances); $alreadyplugins = array(); @@ -1235,6 +1265,7 @@ abstract class repository { $meta->icon = $CFG->httpswwwroot.'/repository/'.$meta->type.'/icon.png'; $meta->supported_types = $ft->get_file_ext($this->supported_filetypes()); $meta->accepted_types = $this->options['accepted_types']; + $meta->return_types = $this->supported_returntypes(); return $meta; } @@ -1530,7 +1561,7 @@ abstract class repository { public function type_config_form(&$mform) { } - /** + /** * Edit/Create Instance Settings Moodle form * @param object $ Moodle form (passed by reference) */ @@ -1566,7 +1597,13 @@ abstract class repository { } /** - * exception class for repository api + * Exception class for repository api + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class repository_exception extends moodle_exception { } @@ -1574,16 +1611,18 @@ class repository_exception extends moodle_exception { /** - * TODO: write comment + * This is a class used to define a repository instance form + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class repository_instance_form extends moodleform { protected $instance; protected $plugin; - /** - * TODO: write comment - * @global object $CFG - */ public function definition() { global $CFG; // type of plugin, string @@ -1636,12 +1675,6 @@ final class repository_instance_form extends moodleform { $this->add_action_buttons(true, get_string('save','repository')); } - /** - * TODO: write comment - * @global object $DB - * @param mixed $data - * @return mixed - */ public function validation($data) { global $DB; @@ -1655,9 +1688,14 @@ final class repository_instance_form extends moodleform { } } - /** - * Display a form with the general option fields of a type + * This is a class used to define a repository type setting form + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class repository_type_form extends moodleform { protected $instance; @@ -1739,7 +1777,8 @@ function repository_setup_default_plugins() { } /** - * Loads + * Loads file picker Javascript files + * * @return void */ function repository_head_setup() { @@ -1769,13 +1808,16 @@ function repository_head_setup() { /** * Return javascript to create file picker to browse repositories + * * @global object $CFG * @global object $USER + * @global object $PAGE + * @global object $OUTPUT * @param object $context the context * @param string $id unique id for every file picker * @param string $accepted_filetypes * @param string $returntypes the return value of file picker - * @return array + * @return string */ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $returntypes = 3) { global $CFG, $USER, $PAGE, $OUTPUT; @@ -1832,8 +1874,8 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $ $lang = json_encode($lang); $options = array(); - $context = get_system_context(); - $options['contextid'] = $context->id; + $sys_context = get_system_context(); + $options['contextid'] = $sys_context->id; $options['icons']['loading'] = $OUTPUT->old_icon_url('i/loading'); $options['icons']['progressbar'] = $OUTPUT->old_icon_url('i/progressbar'); $options['icons']['search'] = $OUTPUT->old_icon_url('a/search'); @@ -1865,7 +1907,12 @@ 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, $returntypes); + $params = array(); + $params['context'] = array($user_context, get_system_context()); + $params['currentcontext'] = $context; + $params['accepted_types'] = $accepted_filetypes; + $params['returntypes'] = $returntypes; + $repos = repository::get_instances($params); // print repository instances listing $js .= << + /** * repository_client is a javascript class, it contains several static * methods you can call it directly without creating an instance. @@ -630,12 +628,12 @@ repository_client.select_file = function(oldname, url, icon, client_id, repo_id) html += '

'; html += '

'; html += '

'; + html += '

Link external

'; html += '

'; html += ''; html += '

'; html += '
'; panel.get('element').innerHTML += html; - /* to deal with double quote, single quote, we need to use javascript change value */ document.getElementById('newname-'+client_id).value = oldname; var tree = document.getElementById('treediv-'+client_id); if(tree){ @@ -1012,11 +1010,15 @@ repository_client.download = function(client_id, repo_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; 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; @@ -1060,7 +1062,7 @@ repository_client.end = function(client_id, obj) { fp.target.value = obj['url']; } fp.target.onchange(); - }else if(fp.env=='texturl') { + }else if(fp.env=='url') { fp.target.value = obj['url']; } obj.filepath = fp.savepath; diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 8887b3ecf1..ef388efd1f 100755 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -1,6 +1,30 @@ . + + +/** + * The Web service script that is called from the filepicker front end + * + * @since 2.0 + * @package moodlecore + * @subpackage repository + * @copyright 2009 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ require_once('../config.php'); require_once('../lib/filelib.php'); @@ -8,19 +32,20 @@ require_login(); /// Parameters - $action = optional_param('action', '', PARAM_ALPHA); + $action = optional_param('action', '', PARAM_ALPHA); $callback = optional_param('callback', '', PARAM_CLEANHTML); $client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID $contextid = optional_param('ctx_id', SITEID, PARAM_INT); // context ID - $env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform - $file = optional_param('file', '', PARAM_RAW); // file to download - $title = optional_param('title', '', PARAM_FILE); // new file name - $itemid = optional_param('itemid', '', PARAM_INT); - $page = optional_param('page', '', PARAM_RAW); // page + $env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform + $file = optional_param('file', '', PARAM_RAW); // file to download + $itemid = optional_param('itemid', '', PARAM_INT); + $title = optional_param('title', '', PARAM_FILE); // new file name + $page = optional_param('page', '', PARAM_RAW); // page $repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // path $save_path = optional_param('savepath', '/', PARAM_PATH); - $search_text = optional_param('s', '', PARAM_CLEANHTML); + $search_text = optional_param('s', '', PARAM_CLEANHTML); + $link_external = optional_param('link_external', '', PARAM_ALPHA); /// Headers to make it not cacheable header("Cache-Control: no-cache, must-revalidate"); @@ -61,8 +86,11 @@ die(json_encode($err)); } break; - case 'gsearch': // Global Search - $repos = repository::get_instances(array(get_context_instance_by_id($contextid), get_system_context())); + case 'gsearch': // Global Search + $params = array(); + $params['context'] = array(get_context_instance_by_id($contextid), get_system_context()); + $params['currentcontext'] = get_context_instance_by_id($contextid); + $repos = repository::get_instances($params); $list = array(); foreach($repos as $repo){ if ($repo->global_search()) { @@ -200,7 +228,7 @@ EOD; break; case 'download': try { - if ($env == 'url' /* TODO: or request_external_url by user */) { + 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))); diff --git a/user/repository.php b/user/repository.php index 0129f1e9d1..c635cec988 100644 --- a/user/repository.php +++ b/user/repository.php @@ -63,7 +63,11 @@ include('tabs.php'); echo $OUTPUT->heading($configstr); echo $OUTPUT->box_start(); -if (!$instances = repository::get_instances($COURSE->context, $USER->id)) { +$params = array(); +$params['context'] = array($COURSE->context); +$params['currentcontext'] = $PAGE->context; +$params['userid'] = $USER->id; +if (!$instances = repository::get_instances($params)) { print_error('noinstances', 'repository', $CFG->wwwroot . '/user/view.php'); } -- 2.39.5