//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 {
<?php
+
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// 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');
$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
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">';
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>';
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);
/**
*
- * @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;
/**
*
- * @return <type>
+ * @return bool
*/
public function check_login() {
return !empty($this->token);
/**
*
- * @return <type>
+ * @return mixed
*/
public function logout() {
set_user_preference($this->setting, '');
/**
*
- * @param <type> $options
- * @return <type>
+ * @param array $options
+ * @return mixed
*/
public function set_option($options = array()) {
if (!empty($options['api_key'])) {
/**
*
- * @param <type> $config
- * @return <type>
+ * @param string $config
+ * @return mixed
*/
public function get_option($config = '') {
if ($config==='api_key') {
/**
*
- * @return <type>
+ * @return bool
*/
public function global_search() {
if (empty($this->token)) {
/**
*
- * @param <type> $ajax
- * @return <type>
+ * @return null
*/
public function print_login() {
if ($this->options['ajax']) {
/**
*
- * @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);
/**
*
- * @param <type> $search_text
- * @return <type>
+ * @param string $search_text
+ * @return array
*/
public function search($search_text) {
$photos = $this->flickr->photos_search(array(
*
* @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);
/**
*
- * @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;
/**
* Add Plugin settings input to Moodle form
- * @global <type> $CFG
- * @param <type> $
+ * @param object $mform
*/
public function type_config_form(&$mform) {
global $CFG;
$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');
/**
* Names of the plugin settings
- * @return <type>
+ * @return array
*/
public static function get_type_option_names() {
return array('api_key', 'secret');
<?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');
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.
* 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 {
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();
}
*
* 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:
* // 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
* @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) {
}
$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) {
}
}
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;
}
/**
//}
- //Uncomment this following line if you wanna display all directory ()even empty
if (!$search || $_filecount || (stristr($tmp['title'], $search) !== false)) {
$filecount += $_filecount;
$list[] = $tmp;
//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();
$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;
}
public function type_config_form(&$mform) {
}
- /**
+ /**
* Edit/Create Instance Settings Moodle form
* @param object $ Moodle form (passed by reference)
*/
}
/**
- * 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 {
}
/**
- * 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
$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;
}
}
-
/**
- * 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;
}
/**
- * Loads
+ * Loads file picker Javascript files
+ *
* @return void
*/
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;
$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');
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
-///////////////////////////////////////////////////////////////////////////
-// //
-// 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.
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){
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;
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;
<?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');
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");
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()) {
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)));
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');
}