"MDL-19181, 1. fixed repository listing when using non-admin role 2. added boilerplate"

This commit is contained in:
Dongsheng Cai 2009-11-06 09:07:46 +00:00
parent 3b59ba8c73
commit 6f2cd52aa5
7 changed files with 253 additions and 148 deletions

View File

@ -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 = " <br/> ". $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 = "<br/>" . $instancenumber .
" " . get_string('instancesforothers', 'repository');
} else {

View File

@ -1,4 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@ -15,6 +16,16 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//
/**
* This file is used to browse repositories in non-javascript mode
*
* @since 2.0
* @package moodlecore
* @subpackage repository
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
* @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 '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
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 '<form action="'.$url->out(false).'" method="post" enctype="multipart/form-data" style="display:inline">';
@ -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 '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
echo '<div>';
@ -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);

View File

@ -18,11 +18,9 @@ class repository_flickr extends repository {
/**
*
* @global <type> $SESSION
* @global <type> $CFG
* @param <type> $repositoryid
* @param <type> $context
* @param <type> $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 <type>
* @return bool
*/
public function check_login() {
return !empty($this->token);
@ -60,7 +58,7 @@ class repository_flickr extends repository {
/**
*
* @return <type>
* @return mixed
*/
public function logout() {
set_user_preference($this->setting, '');
@ -72,8 +70,8 @@ class repository_flickr extends repository {
/**
*
* @param <type> $options
* @return <type>
* @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 <type> $config
* @return <type>
* @param string $config
* @return mixed
*/
public function get_option($config = '') {
if ($config==='api_key') {
@ -108,7 +106,7 @@ class repository_flickr extends repository {
/**
*
* @return <type>
* @return bool
*/
public function global_search() {
if (empty($this->token)) {
@ -120,8 +118,7 @@ class repository_flickr extends repository {
/**
*
* @param <type> $ajax
* @return <type>
* @return null
*/
public function print_login() {
if ($this->options['ajax']) {
@ -138,9 +135,9 @@ class repository_flickr extends repository {
/**
*
* @param <type> $photos
* @param <type> $page
* @return <type>
* @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 <type> $search_text
* @return <type>
* @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 <type>
* @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 <type> $CFG
* @param <type> $photo_id
* @param <type> $file
* @return <type>
* @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 <type> $CFG
* @param <type> $
* @param object $mform
*/
public function type_config_form(&$mform) {
global $CFG;
@ -262,12 +257,16 @@ 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");
$callbackurl = get_string('callbackwarning', 'repository_flickr');
$mform->addElement('static', null, '', $callbackurl);
}
else {
} else {
$callbackurl = $CFG->wwwroot.'/repository/ws.php?callback=yes&amp;repo_id='.$instances[0]->id;
$mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_flickr', $callbackurl));
}
@ -278,7 +277,7 @@ class repository_flickr extends repository {
/**
* Names of the plugin settings
* @return <type>
* @return array
*/
public static function get_type_option_names() {
return array('api_key', 'secret');

View File

@ -1,42 +1,32 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 2008 onwards Moodle Pty Ltd http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <dongsheng@moodle.com>
* @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 <dongsheng@moodle.com>
* @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;
}
@ -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 <dongsheng@moodle.com>
* @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 <dongsheng@moodle.com>
* @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 <dongsheng@moodle.com>
* @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 .= <<<EOD

View File

@ -1,8 +1,6 @@
///////////////////////////////////////////////////////////////////////////
// //
// Don't modify this file unless you know how it works //
// //
///////////////////////////////////////////////////////////////////////////
// File picker core Javascript code for Moodle
// Author: Dongsheng Cai <dongsheng@moodle.com>
/**
* 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 += '<p><img src="'+icon+'" /></p>';
html += '<p><label for="newname-'+client_id+'">'+fp_lang.saveas+'</label>';
html += '<input type="text" id="newname-'+client_id+'" value="" /></p>';
html += '<p><input type="checkbox" id="external-'+client_id+'" value="" /> Link external</p>';
html += '<p><input type="hidden" id="fileurl-'+client_id+'" value="'+url+'" />';
html += '<input type="button" onclick="repository_client.download(\''+client_id+'\', \''+repo_id+'\')" value="'+fp_lang.downbtn+'" />';
html += '<input type="button" onclick="repository_client.viewfiles(\''+client_id+'\')" value="'+fp_lang.cancel+'" /></p>';
html += '</div>';
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;

View File

@ -1,6 +1,30 @@
<?php
/// The Web service script that is called from the filepicker front end
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The Web service script that is called from the filepicker front end
*
* @since 2.0
* @package moodlecore
* @subpackage repository
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../config.php');
require_once('../lib/filelib.php');
@ -14,13 +38,14 @@
$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);
$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);
$link_external = optional_param('link_external', '', PARAM_ALPHA);
/// Headers to make it not cacheable
header("Cache-Control: no-cache, must-revalidate");
@ -62,7 +87,10 @@
}
break;
case 'gsearch': // Global Search
$repos = repository::get_instances(array(get_context_instance_by_id($contextid), get_system_context()));
$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)));

View File

@ -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');
}