mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'equella' of git://github.com/danpoltawski/moodle
This commit is contained in:
commit
37b8257de5
79
repository/equella/callback.php
Normal file
79
repository/equella/callback.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* EQUELLA callback
|
||||
*
|
||||
* @since 2.0
|
||||
* @package repository
|
||||
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
|
||||
$json = required_param('tlelinks', PARAM_RAW);
|
||||
|
||||
require_login();
|
||||
|
||||
$decodedinfo = json_decode($json);
|
||||
$info = array_pop($decodedinfo);
|
||||
|
||||
$url = '';
|
||||
if (isset($info->url)) {
|
||||
$url = s(clean_param($info->url, PARAM_URL));
|
||||
}
|
||||
|
||||
$filename = '';
|
||||
if (isset($info->name)) {
|
||||
$filename = s(clean_param($info->name, PARAM_FILE));
|
||||
}
|
||||
|
||||
$thumbnail = '';
|
||||
if (isset($info->thumbnail)) {
|
||||
$thumbnail = s(clean_param($info->thumbnail, PARAM_URL));
|
||||
}
|
||||
|
||||
$author = '';
|
||||
if (isset($info->owner)) {
|
||||
$author = s(clean_param($info->owner, PARAM_NOTAGS));
|
||||
}
|
||||
|
||||
$license = '';
|
||||
if (isset($info->license)) {
|
||||
$license = s(clean_param($info->license, PARAM_ALPHAEXT));
|
||||
}
|
||||
|
||||
$js =<<<EOD
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
window.onload = function() {
|
||||
var resource = {};
|
||||
resource.title = "$filename";
|
||||
resource.source = "$url";
|
||||
resource.thumbnail = '$thumbnail';
|
||||
resource.author = "$author";
|
||||
resource.license = "$license";
|
||||
parent.M.core_filepicker.select_file(resource);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body><noscript></noscript></body>
|
||||
</html>
|
||||
EOD;
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
die($js);
|
25
repository/equella/db/access.php
Normal file
25
repository/equella/db/access.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
$capabilities = array(
|
||||
'repository/equella:view' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'user' => CAP_ALLOW
|
||||
)
|
||||
)
|
||||
);
|
38
repository/equella/lang/en/repository_equella.php
Normal file
38
repository/equella/lang/en/repository_equella.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
$string['pluginname'] = 'EQUELLA repository';
|
||||
$string['configplugin'] = 'Configuration for EQUELLA repository';
|
||||
$string['search'] = 'Search EQUELLA';
|
||||
$string['breadcrumb'] = 'EQUELLA';
|
||||
|
||||
$string['equellaurl'] = 'EQUELLA URL';
|
||||
$string['equellaaction'] = 'EQUELLA action';
|
||||
$string['equellaoptions'] = 'EQUELLA options';
|
||||
$string['sharedid'] = 'Shared secret ID';
|
||||
$string['sharedsecrets'] = 'Shared secret';
|
||||
|
||||
$string['selectrestriction'] = 'Restrict selection';
|
||||
$string['selectrestriction.desc'] = 'Choose whether course editors should only be able to select an item summary, an attached resources or either';
|
||||
$string['restrictionnone'] = 'No restriction';
|
||||
$string['restrictionitemsonly'] = 'Item summary only';
|
||||
$string['restrictionattachmentsonly'] = 'Attached resource only';
|
||||
|
||||
$string['sharedsecretsheading'] = 'Shared Secret Settings';
|
||||
$string['sharedsecretshelp'] = '<p>Below you can set a default EQUELLA shared secret for single signing-on users. You can configure different shared secrets for general (read) usage, and a specialised role based shared secret for each <em>write</em> role in your Moodle site. If a shared secret ID is not configured for a role then the default shared secret ID and shared secret are used.</p><p>All shared secret IDs and shared secrets must also be configured within EQUELLA and the shared secret module enabled. This configuration is found in the EQUELLA Administration Console under User Management > Shared Secrets.</p>';
|
||||
$string['group'] = '{$a} role settings';
|
||||
$string['groupdefault'] = 'Default';
|
||||
$string['sharedidtitle'] = 'Shared secret ID';
|
||||
$string['sharedsecrettitle'] = 'Shared secret';
|
314
repository/equella/lib.php
Normal file
314
repository/equella/lib.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
|
||||
class repository_equella extends repository {
|
||||
/** @var array mimetype filter */
|
||||
private $mimetypes = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $repositoryid repository instance id
|
||||
* @param int|stdClass a context id or context object
|
||||
* @param array $options repository options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
|
||||
if (isset($this->options['mimetypes'])) {
|
||||
$mt = $this->options['mimetypes'];
|
||||
if (!empty($mt) && is_array($mt) && !in_array('*', $mt)) {
|
||||
$this->mimetypes = array_unique(array_map(array($this, 'to_mime_type'), $mt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display embedded equella interface
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $page
|
||||
* @param array
|
||||
*/
|
||||
public function get_listing($path = null, $page = null) {
|
||||
global $COURSE;
|
||||
$callbackurl = new moodle_url('/repository/equella/callback.php', array('repo_id'=>$this->id));
|
||||
|
||||
$mimetypesstr = '';
|
||||
$restrict = '';
|
||||
if (!empty($this->mimetypes)) {
|
||||
$mimetypesstr = '&mimeTypes=' . implode(',', $this->mimetypes);
|
||||
// We're restricting to a mime type, so we always restrict to selecting resources only.
|
||||
$restrict = '&attachmentonly=true';
|
||||
} else if ($this->get_option('equella_select_restriction') != 'none') {
|
||||
// The option value matches the EQUELLA paramter name.
|
||||
$restrict = '&' . $this->get_option('equella_select_restriction') . '=true';
|
||||
}
|
||||
|
||||
$url = $this->get_option('equella_url')
|
||||
. '?method=lms'
|
||||
. '&returnurl='.urlencode($callbackurl)
|
||||
. '&returnprefix=tle'
|
||||
. '&template=standard'
|
||||
. '&token='.urlencode($this->getssotoken('write'))
|
||||
. '&courseId='.urlencode($COURSE->id)
|
||||
. '&courseCode='.urlencode($COURSE->shortname)
|
||||
. '&action=searchThin'
|
||||
. '&forcePost=true'
|
||||
. '&cancelDisabled=true'
|
||||
. '&attachmentUuidUrls=true'
|
||||
. '&options='.urlencode($this->get_option('equella_options') . $mimetypesstr)
|
||||
. $restrict;
|
||||
$list = array();
|
||||
$list['object'] = array();
|
||||
$list['object']['type'] = 'text/html';
|
||||
$list['object']['src'] = $url;
|
||||
$list['nologin'] = true;
|
||||
$list['nosearch'] = true;
|
||||
$list['norefresh'] = true;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported equella file types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function supported_returntypes() {
|
||||
return FILE_REFERENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare file reference information
|
||||
*
|
||||
* @param string $source
|
||||
* @return string file referece
|
||||
*/
|
||||
public function get_file_reference($source) {
|
||||
return base64_encode($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file, this function can be overridden by subclass. {@link curl}
|
||||
*
|
||||
* @param string $url the url of file
|
||||
* @param string $filename save location
|
||||
* @return string the location of the file
|
||||
*/
|
||||
public function get_file($url, $filename = '') {
|
||||
global $USER;
|
||||
$cookiename = uniqid('', true) . '.cookie';
|
||||
$dir = make_temp_directory('repository/equella/' . $USER->id);
|
||||
$cookiepathname = $dir . '/' . $cookiename;
|
||||
$path = $this->prepare_file($filename);
|
||||
$fp = fopen($path, 'w');
|
||||
$c = new curl(array('cookie'=>$cookiepathname));
|
||||
$c->download(array(array('url'=>$url, 'file'=>$fp)), array('CURLOPT_FOLLOWLOCATION'=>true));
|
||||
// Close file handler.
|
||||
fclose($fp);
|
||||
// Delete cookie jar.
|
||||
unlink($cookiepathname);
|
||||
return array('path'=>$path, 'url'=>$url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file from external repository by reference
|
||||
* {@link repository::get_file_reference()}
|
||||
* {@link repository::get_file()}
|
||||
*
|
||||
* @param stdClass $reference file reference db record
|
||||
* @return stdClass|null|false
|
||||
*/
|
||||
public function get_file_by_reference($reference) {
|
||||
$ref = base64_decode($reference->reference);
|
||||
$url = $this->appendtoken($ref);
|
||||
|
||||
if (!$url) {
|
||||
// Occurs when the user isn't known..
|
||||
return false;
|
||||
}
|
||||
|
||||
// We use this cache to get the correct file size.
|
||||
$cachedfilepath = cache_file::get($url, array('ttl' => 0));
|
||||
if ($cachedfilepath === false) {
|
||||
// Cache the file.
|
||||
$path = $this->get_file($url);
|
||||
$cachedfilepath = cache_file::create_from_file($url, $path['path']);
|
||||
}
|
||||
|
||||
$fileinfo = new stdClass;
|
||||
$fileinfo->filepath = $cachedfilepath;
|
||||
|
||||
return $fileinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send equella file to browser
|
||||
*
|
||||
* @param stored_file $stored_file
|
||||
*/
|
||||
public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) {
|
||||
$reference = base64_decode($stored_file->get_reference());
|
||||
$url = $this->appendtoken($reference);
|
||||
if ($url) {
|
||||
header('Location: ' . $url);
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Instance settings input to Moodle form
|
||||
*
|
||||
* @param moodleform $mform
|
||||
*/
|
||||
public function instance_config_form($mform) {
|
||||
$mform->addElement('text', 'equella_url', get_string('equellaurl', 'repository_equella'));
|
||||
$mform->setType('equella_url', PARAM_URL);
|
||||
|
||||
$strrequired = get_string('required');
|
||||
$mform->addRule('equella_url', $strrequired, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'equella_options', get_string('equellaoptions', 'repository_equella'));
|
||||
$mform->setType('equella_options', PARAM_NOTAGS);
|
||||
|
||||
$choices = array(
|
||||
'none' => get_string('restrictionnone', 'repository_equella'),
|
||||
'itemonly' => get_string('restrictionitemsonly', 'repository_equella'),
|
||||
'attachmentonly' => get_string('restrictionattachmentsonly', 'repository_equella'),
|
||||
);
|
||||
$mform->addElement('select', 'equella_select_restriction', get_string('selectrestriction', 'repository_equella'), $choices);
|
||||
|
||||
$mform->addElement('header', '',
|
||||
get_string('group', 'repository_equella', get_string('groupdefault', 'repository_equella')));
|
||||
$mform->addElement('text', 'equella_shareid', get_string('sharedid', 'repository_equella'));
|
||||
$mform->setType('equella_shareid', PARAM_RAW);
|
||||
$mform->addRule('equella_shareid', $strrequired, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'equella_sharedsecret', get_string('sharedsecrets', 'repository_equella'));
|
||||
$mform->setType('equella_sharedsecret', PARAM_RAW);
|
||||
$mform->addRule('equella_sharedsecret', $strrequired, 'required', null, 'client');
|
||||
|
||||
foreach (self::get_all_editing_roles() as $role) {
|
||||
$mform->addElement('header', '', get_string('group', 'repository_equella', format_string($role->name)));
|
||||
$mform->addElement('text', "equella_{$role->shortname}_shareid", get_string('sharedid', 'repository_equella'));
|
||||
$mform->setType("equella_{$role->shortname}_shareid", PARAM_RAW);
|
||||
$mform->addElement('text', "equella_{$role->shortname}_sharedsecret",
|
||||
get_string('sharedsecrets', 'repository_equella'));
|
||||
$mform->setType("equella_{$role->shortname}_sharedsecret", PARAM_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the instance settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_instance_option_names() {
|
||||
$rv = array('equella_url','equella_select_restriction', 'equella_options',
|
||||
'equella_shareid', 'equella_sharedsecret'
|
||||
);
|
||||
|
||||
foreach (self::get_all_editing_roles() as $role) {
|
||||
array_push($rv, "equella_{$role->shortname}_shareid");
|
||||
array_push($rv, "equella_{$role->shortname}_sharedsecret");
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate equella token
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $shareid
|
||||
* @param string $sharedsecret
|
||||
* @return string
|
||||
*/
|
||||
private static function getssotoken_raw($username, $shareid, $sharedsecret) {
|
||||
$time = time() . '000';
|
||||
return urlencode($username)
|
||||
. ':'
|
||||
. $shareid
|
||||
. ':'
|
||||
. $time
|
||||
. ':'
|
||||
. base64_encode(pack('H*', md5($username . $shareid . $time . $sharedsecret)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Append token
|
||||
*
|
||||
* @param string $url
|
||||
* @param $readwrite
|
||||
* @return string
|
||||
*/
|
||||
private function appendtoken($url, $readwrite = null) {
|
||||
$ssotoken = $this->getssotoken($readwrite);
|
||||
if (!$ssotoken) {
|
||||
return false;
|
||||
}
|
||||
return $url . (strpos($url, '?') != false ? '&' : '?') . 'token=' . urlencode($ssotoken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate equella sso token
|
||||
*
|
||||
* @param string $readwrite
|
||||
* @return string
|
||||
*/
|
||||
private function getssotoken($readwrite = 'read') {
|
||||
global $USER;
|
||||
|
||||
if (empty($USER->username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($readwrite == 'write') {
|
||||
|
||||
foreach (self::get_all_editing_roles() as $role) {
|
||||
if (user_has_role_assignment($USER->id, $role->id, $this->context->id)) {
|
||||
// See if the user has a role that is linked to an equella role.
|
||||
$shareid = $this->get_option("equella_{$role->shortname}_shareid");
|
||||
if (!empty($shareid)) {
|
||||
return $this->getssotoken_raw($USER->username, $shareid,
|
||||
$this->get_option("equella_{$role->shortname}_sharedsecret"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If we are only reading, use the unadorned shareid and secret.
|
||||
$shareid = $this->get_option('equella_shareid');
|
||||
if (!empty($shareid)) {
|
||||
return $this->getssotoken_raw($USER->username, $shareid, $this->get_option('equella_sharedsecret'));
|
||||
}
|
||||
}
|
||||
|
||||
private static function get_all_editing_roles() {
|
||||
return get_roles_with_capability('moodle/course:manageactivities', CAP_ALLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert moodle mimetypes list to equella format
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
private static function to_mime_type($value) {
|
||||
return mimeinfo('type', $value);
|
||||
}
|
||||
}
|
BIN
repository/equella/pix/icon.png
Normal file
BIN
repository/equella/pix/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 590 B |
21
repository/equella/version.php
Normal file
21
repository/equella/version.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012060100; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2012052500; // Requires this Moodle version.
|
||||
$plugin->component = 'repository_equella'; // Full name of the plugin (used for diagnostics).
|
Loading…
x
Reference in New Issue
Block a user