first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+267
View File
@@ -0,0 +1,267 @@
<?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/>.
/**
* This file is the main controller to do with the portfolio export wizard.
*
* @package core_portfolio
* @copyright 2008 Penny Leach <penny@catalyst.net.nz>,
* Martin Dougiamas <http://dougiamas.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*/
require_once(__DIR__ . '/../config.php');
if (empty($CFG->enableportfolios)) {
throw new \moodle_exception('disabled', 'portfolio');
}
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->libdir . '/portfolio/caller.php');
require_once($CFG->libdir . '/portfolio/plugin.php');
$dataid = optional_param('id', 0, PARAM_INT); // The ID of partially completed export, corresponds to a record in portfolio_tempdata.
$type = optional_param('type', null, PARAM_SAFEDIR); // If we're returning from an external system (postcontrol) for a single-export only plugin.
$cancel = optional_param('cancel', 0, PARAM_RAW); // User has cancelled the request.
$cancelsure = optional_param('cancelsure', 0, PARAM_BOOL); // Make sure they confirm first.
$logreturn = optional_param('logreturn', 0, PARAM_BOOL); // When cancelling, we can also come from the log page, rather than the caller.
$instanceid = optional_param('instance', 0, PARAM_INT); // The instance of configured portfolio plugin.
$courseid = optional_param('course', 0, PARAM_INT); // The courseid the data being exported belongs to (caller object should provide this later).
$stage = optional_param('stage', PORTFOLIO_STAGE_CONFIG, PARAM_INT); // Stage of the export we're at (stored in the exporter).
$postcontrol = optional_param('postcontrol', 0, PARAM_INT); // When returning from some bounce to an external system, this gets passed.
$callbackcomponent = optional_param('callbackcomponent', null, PARAM_PATH); // Callback component eg mod_forum - the component of the exporting content.
$callbackclass = optional_param('callbackclass', null, PARAM_ALPHAEXT); // Callback class eg forum_portfolio_caller - the class to handle the exporting content.
$callerformats = optional_param('callerformats', null, PARAM_TAGLIST); // Comma separated list of formats the specific place exporting content supports.
require_login(); // this is selectively called again with $course later when we know for sure which one we're in.
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/portfolio/add.php', array('id' => $dataid, 'sesskey' => sesskey()));
$PAGE->set_pagelayout('admin');
$exporter = null;
if ($postcontrol && $type && !$dataid) {
// we're returning from an external system that can't construct dynamic return urls
// this is a special "one export of this type only per session" case
if (portfolio_static_function($type, 'allows_multiple_exports')) {
throw new portfolio_exception('multiplesingleresume', 'portfolio');
}
if (!$dataid = portfolio_export_type_to_id($type, $USER->id)) {
throw new portfolio_exception('invalidtempid', 'portfolio');
}
} else {
// we can't do this in the above case, because we're redirecting straight back from an external system
// this is not really ideal, but since we're in a "staged" wizard, the session key is checked in other stages.
require_sesskey(); // pretty much everything in this page is a write that could be hijacked, so just do this at the top here
}
// if we have a dataid, it means we're in the middle of an export,
// so rewaken it and continue.
if (!empty($dataid)) {
try {
$exporter = portfolio_exporter::rewaken_object($dataid);
} catch (portfolio_exception $e) {
// this can happen in some cases, a cancel request is sent when something is already broken
// so process it elegantly and move on.
if ($cancel) {
if ($logreturn) {
redirect($CFG->wwwroot . '/user/portfoliologs.php');
}
redirect($CFG->wwwroot);
} else {
throw $e;
}
}
// we have to wake it up first before we can cancel it
// so temporary directories etc get cleaned up.
if ($cancel) {
if ($cancelsure) {
$exporter->cancel_request($logreturn);
} else {
portfolio_export_pagesetup($PAGE, $exporter->get('caller'));
$exporter->print_header(get_string('confirmcancel', 'portfolio'));
echo $OUTPUT->box_start();
$yesbutton = new single_button(new moodle_url('/portfolio/add.php', array('id' => $dataid, 'cancel' => 1, 'cancelsure' => 1, 'logreturn' => $logreturn)), get_string('yes'));
if ($logreturn) {
$nobutton = new single_button(new moodle_url('/user/portfoliologs.php'), get_string('no'));
} else {
$nobutton = new single_button(new moodle_url('/portfolio/add.php', array('id' => $dataid)), get_string('no'));
}
echo $OUTPUT->confirm(get_string('confirmcancel', 'portfolio'), $yesbutton, $nobutton);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
}
// verify we still belong to the correct user and permissions are still ok
$exporter->verify_rewaken();
// if we don't have an instanceid in the exporter
// it means we've just posted from the 'choose portfolio instance' page
// so process that and start up the portfolio plugin
if (!$exporter->get('instance')) {
if ($instanceid) {
try {
$instance = portfolio_instance($instanceid);
} catch (portfolio_exception $e) {
portfolio_export_rethrow_exception($exporter, $e);
}
// this technically shouldn't happen but make sure anyway
if ($broken = portfolio_instance_sanity_check($instance)) {
throw new portfolio_export_exception($exporter, $broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin'));
}
// now we're all set up, ready to go
$instance->set('user', $USER);
$exporter->set('instance', $instance);
$exporter->save();
}
}
portfolio_export_pagesetup($PAGE, $exporter->get('caller')); // this calls require_login($course) if it can..
// completely new request, look to see what information we've been passed and set up the exporter object.
} else {
// you cannot get here with no information for us, we must at least have the caller.
if (empty($_GET) && empty($_POST)) {
portfolio_exporter::print_expired_export();
}
// we'e just posted here for the first time and have might the instance already
if ($instanceid) {
// this can throw exceptions but there's no point catching and rethrowing here
// as the exporter isn't created yet.
$instance = portfolio_instance($instanceid);
if ($broken = portfolio_instance_sanity_check($instance)) {
throw new portfolio_exception($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin'));
}
$instance->set('user', $USER);
} else {
$instance = null;
}
// we must be passed this from the caller, we cannot start a new export
// without knowing information about what part of moodle we come from.
if (empty($callbackcomponent) || empty($callbackclass)) {
debugging('no callback file or class');
portfolio_exporter::print_expired_export();
}
// so each place in moodle can pass callback args here
// process the entire request looking for ca_*
// be as lenient as possible while still being secure
// so only accept certain parameter types.
$callbackargs = array();
foreach (array_keys(array_merge($_GET, $_POST)) as $key) {
if (strpos($key, 'ca_') === 0) {
if (!$value = optional_param($key, false, PARAM_ALPHAEXT)) {
if (!$value = optional_param($key, false, PARAM_FLOAT)) {
$value = optional_param($key, false, PARAM_PATH);
}
}
// strip off ca_ for niceness
$callbackargs[substr($key, 3)] = $value;
}
}
// Ensure that we found a file we can use, if not throw an exception.
portfolio_include_callback_file($callbackcomponent, $callbackclass);
$caller = new $callbackclass($callbackargs);
$caller->set('user', $USER);
if ($formats = explode(',', $callerformats)) {
$caller->set_formats_from_button($formats);
}
$caller->load_data();
// this must check capabilities and either throw an exception or return false.
if (!$caller->check_permissions()) {
throw new portfolio_caller_exception('nopermissions', 'portfolio', $caller->get_return_url());
}
portfolio_export_pagesetup($PAGE, $caller); // this calls require_login($course) if it can..
// finally! set up the exporter object with the portfolio instance, and caller information elements
$exporter = new portfolio_exporter($instance, $caller, $callbackcomponent);
// set the export-specific variables, and save.
$exporter->set('user', $USER);
$exporter->save();
}
if (!$exporter->get('instance')) {
// we've just arrived but have no instance
// in this case the exporter object and the caller object have been set up above
// so just make a little form to select the portfolio plugin instance,
// which is the last thing to do before starting the export.
//
// first check to make sure there is actually a point
$options = portfolio_instance_select(
portfolio_instances(),
$exporter->get('caller')->supported_formats(),
get_class($exporter->get('caller')),
$exporter->get('caller')->get_mimetype(),
'instance',
true,
true
);
if (empty($options)) {
throw new portfolio_export_exception($exporter, 'noavailableplugins', 'portfolio');
} else if (count($options) == 1) {
// no point displaying a form, just redirect.
$optionskeys = array_keys($options);
$instance = array_shift($optionskeys);
redirect($CFG->wwwroot . '/portfolio/add.php?id= ' . $exporter->get('id') . '&instance=' . $instance . '&sesskey=' . sesskey());
}
// be very selective about not including this unless we really need to
require_once($CFG->libdir . '/portfolio/forms.php');
$mform = new portfolio_instance_select('', array('id' => $exporter->get('id'), 'caller' => $exporter->get('caller'), 'options' => $options));
if ($mform->is_cancelled()) {
$exporter->cancel_request();
} else if ($fromform = $mform->get_data()){
redirect($CFG->wwwroot . '/portfolio/add.php?instance=' . $fromform->instance . '&amp;id=' . $exporter->get('id'));
exit;
}
else {
$exporter->print_header(get_string('selectplugin', 'portfolio'));
echo $OUTPUT->box_start();
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
}
// if we haven't been passed &stage= grab it from the exporter.
if (!$stage) {
$stage = $exporter->get('stage');
}
// for places returning control to pass (rather than PORTFOLIO_STAGE_PACKAGE
// which is unstable if they can't get to the constant (eg external system)
$alreadystolen = false;
if ($postcontrol) { // the magic request variable plugins must pass on returning here
try {
// allow it to read whatever gets sent back in the request
// this is useful for plugins that redirect away and back again
// adding a token to the end of the url, for example box.net
$exporter->instance()->post_control($stage, array_merge($_GET, $_POST));
} catch (portfolio_plugin_exception $e) {
portfolio_export_rethrow_exception($exporter, $e);
}
$alreadystolen = true; // remember this so we don't get caught in a steal control loop!
}
// actually do the work now..
$exporter->process_stage($stage, $alreadystolen);
@@ -0,0 +1,65 @@
<?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/>.
/**
* This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up.
*
* @package core_portfolio
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_portfolio\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* The trait used to provide a backwards compatibility for third-party plugins.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait legacy_polyfill {
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
static::_export_portfolio_user_data($userid, $context, $subcontext, $linkarray);
}
/**
* Delete all user information for the provided context.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context) {
static::_delete_portfolio_for_context($context);
}
/**
* Delete all user information for the provided user and context.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context) {
static::_delete_portfolio_for_user($userid, $context);
}
}
@@ -0,0 +1,66 @@
<?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/>.
/**
* Privacy class for requesting user data.
*
* @package core_portfolio
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_portfolio\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Provider for the portfolio API.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface portfolio_provider extends
// The portfolio_provider should be implemented by plugins which only provide information to a subsystem.
\core_privacy\local\request\plugin\subsystem_provider,
// The implementation for prtfolios is handled in the subsystem itself.
\core_privacy\local\request\shared_userlist_provider {
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray);
/**
* Delete all user information for the provided context.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context);
/**
* Delete all user information for the provided user and context.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context);
}
+311
View File
@@ -0,0 +1,311 @@
<?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/>.
/**
* Privacy class for requesting user data.
*
* @package core_portfolio
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_portfolio\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
use core_privacy\local\request\context;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use core_privacy\local\request\approved_userlist;
/**
* Provider for the portfolio API.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// The core portfolio system stores preferences related to the other portfolio subsystems.
\core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\core_userlist_provider,
// The portfolio subsystem will be called by other components.
\core_privacy\local\request\subsystem\plugin_provider,
\core_privacy\local\request\shared_userlist_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_database_table('portfolio_instance_user', [
'instance' => 'privacy:metadata:instance',
'userid' => 'privacy:metadata:userid',
'name' => 'privacy:metadata:name',
'value' => 'privacy:metadata:value'
], 'privacy:metadata:instancesummary');
$collection->add_database_table('portfolio_log', [
'userid' => 'privacy:metadata:portfolio_log:userid',
'time' => 'privacy:metadata:portfolio_log:time',
'caller_class' => 'privacy:metadata:portfolio_log:caller_class',
'caller_component' => 'privacy:metadata:portfolio_log:caller_component',
], 'privacy:metadata:portfolio_log');
// Temporary data is not exported/deleted in privacy API. It is cleaned by cron.
$collection->add_database_table('portfolio_tempdata', [
'data' => 'privacy:metadata:portfolio_tempdata:data',
'expirytime' => 'privacy:metadata:portfolio_tempdata:expirytime',
'userid' => 'privacy:metadata:portfolio_tempdata:userid',
'instance' => 'privacy:metadata:portfolio_tempdata:instance',
], 'privacy:metadata:portfolio_tempdata');
$collection->add_plugintype_link('portfolio', [], 'privacy:metadata');
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
$sql = "SELECT ctx.id
FROM {context} ctx
WHERE ctx.instanceid = :userid AND ctx.contextlevel = :usercontext
AND (EXISTS (SELECT 1 FROM {portfolio_instance_user} WHERE userid = :userid1) OR
EXISTS (SELECT 1 FROM {portfolio_log} WHERE userid = :userid2))
";
$params = ['userid' => $userid, 'usercontext' => CONTEXT_USER, 'userid1' => $userid, 'userid2' => $userid];
$contextlist = new contextlist();
$contextlist->add_from_sql($sql, $params);
return $contextlist;
}
/**
* Get the list of users within a specific context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if (!$context instanceof \context_user) {
return;
}
$params = [$context->instanceid];
$sql = "SELECT userid
FROM {portfolio_instance_user}
WHERE userid = ?";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "SELECT userid
FROM {portfolio_log}
WHERE userid = ?";
$userlist->add_from_sql('userid', $sql, $params);
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;
if ($contextlist->get_component() != 'core_portfolio') {
return;
}
$correctusercontext = array_filter($contextlist->get_contexts(), function($context) use ($contextlist) {
if ($context->contextlevel == CONTEXT_USER && $context->instanceid == $contextlist->get_user()->id) {
return $context;
}
});
if (empty($correctusercontext)) {
return;
}
$usercontext = array_shift($correctusercontext);
$sql = "SELECT pi.id AS instanceid, pi.name,
piu.id AS preferenceid, piu.name AS preference, piu.value,
pl.id AS logid, pl.time AS logtime, pl.caller_class, pl.caller_file,
pl.caller_component, pl.returnurl, pl.continueurl
FROM {portfolio_instance} pi
LEFT JOIN {portfolio_instance_user} piu ON piu.instance = pi.id AND piu.userid = :userid1
LEFT JOIN {portfolio_log} pl ON pl.portfolio = pi.id AND pl.userid = :userid2
WHERE piu.id IS NOT NULL OR pl.id IS NOT NULL";
$params = ['userid1' => $usercontext->instanceid, 'userid2' => $usercontext->instanceid];
$instances = [];
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $record) {
$instances += [$record->name =>
(object)[
'name' => $record->name,
'preferences' => [],
'logs' => [],
]
];
if ($record->preferenceid) {
$instances[$record->name]->preferences[$record->preferenceid] = (object)[
'name' => $record->preference,
'value' => $record->value,
];
}
if ($record->logid) {
$instances[$record->name]->logs[$record->logid] = (object)[
'time' => transform::datetime($record->logtime),
'caller_class' => $record->caller_class,
'caller_file' => $record->caller_file,
'caller_component' => $record->caller_component,
'returnurl' => $record->returnurl,
'continueurl' => $record->continueurl
];
}
}
$rs->close();
if (!empty($instances)) {
foreach ($instances as &$instance) {
if (!empty($instance->preferences)) {
$instance->preferences = array_values($instance->preferences);
} else {
unset($instance->preferences);
}
if (!empty($instance->logs)) {
$instance->logs = array_values($instance->logs);
} else {
unset($instance->logs);
}
}
\core_privacy\local\request\writer::with_context($contextlist->current())->export_data(
[get_string('privacy:path', 'portfolio')], (object) $instances);
}
}
/**
* Delete all data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
global $DB;
// Context could be anything, BEWARE!
if ($context->contextlevel == CONTEXT_USER) {
$DB->delete_records('portfolio_instance_user', ['userid' => $context->instanceid]);
$DB->delete_records('portfolio_tempdata', ['userid' => $context->instanceid]);
$DB->delete_records('portfolio_log', ['userid' => $context->instanceid]);
}
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();
if ($context instanceof \context_user) {
$DB->delete_records('portfolio_instance_user', ['userid' => $context->instanceid]);
$DB->delete_records('portfolio_tempdata', ['userid' => $context->instanceid]);
$DB->delete_records('portfolio_log', ['userid' => $context->instanceid]);
}
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;
if ($contextlist->get_component() != 'core_portfolio') {
return;
}
$correctusercontext = array_filter($contextlist->get_contexts(), function($context) use ($contextlist) {
if ($context->contextlevel == CONTEXT_USER && $context->instanceid == $contextlist->get_user()->id) {
return $context;
}
});
if (empty($correctusercontext)) {
return;
}
$usercontext = array_shift($correctusercontext);
$DB->delete_records('portfolio_instance_user', ['userid' => $usercontext->instanceid]);
$DB->delete_records('portfolio_tempdata', ['userid' => $usercontext->instanceid]);
$DB->delete_records('portfolio_log', ['userid' => $usercontext->instanceid]);
}
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
static::call_plugin_method('export_portfolio_user_data', [$userid, $context, $subcontext, $linkarray]);
}
/**
* Deletes all user content for a context in all portfolio plugins.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context) {
static::call_plugin_method('delete_portfolio_for_context', [$context]);
}
/**
* Deletes all user content for a user in a context in all portfolio plugins.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context) {
static::call_plugin_method('delete_portfolio_for_user', [$userid, $context]);
}
/**
* Internal method for looping through all of the portfolio plugins and calling a method.
*
* @param string $methodname Name of the method to call on the plugins.
* @param array $params The parameters that go with the method being called.
*/
protected static function call_plugin_method($methodname, $params) {
// Note: Even if portfolio is _now_ disabled, there may be legacy data to export.
\core_privacy\manager::plugintype_class_callback('portfolio', portfolio_provider::class, $methodname, $params);
}
}
@@ -0,0 +1,48 @@
<?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/>.
/**
* Privacy class for requesting user data.
*
* @package portfolio_download
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_download\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Provider for the portfolio_download plugin.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This portfolio plugin does not store any data itself.
// It has no database tables, and it purely acts as a conduit, sending data externally.
\core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
// this script is a slightly more user friendly way to 'send' the file to them
// (using portfolio/file.php) but still give them the 'return to where you were' link
// to go back to their assignment, or whatever
require(__DIR__.'/../../config.php');
if (empty($CFG->enableportfolios)) {
throw new \moodle_exception('disabled', 'portfolio');
}
require_once($CFG->libdir.'/portfoliolib.php');
require_once($CFG->libdir.'/portfolio/exporter.php');
$id = required_param('id', PARAM_INT);
$PAGE->set_url('/portfolio/download/file.php', array('id' => $id));
$exporter = portfolio_exporter::rewaken_object($id);
portfolio_export_pagesetup($PAGE, $exporter->get('caller'));
$exporter->verify_rewaken();
$exporter->print_header(get_string('downloading', 'portfolio_download'), false);
$returnurl = $exporter->get('caller')->get_return_url();
echo $OUTPUT->notification('<a href="' . $returnurl . '">' . get_string('returntowhereyouwere', 'portfolio') . '</a><br />');
// if they don't have javascript, they can submit the form here to get the file.
// if they do, it does it nicely for them.
echo '<div id="redirect">
<form action="' . $exporter->get('instance')->get_base_file_url() . '" method="post" id="redirectform" target="download-iframe">
<input type="submit" value="' . get_string('downloadfile', 'portfolio_download') . '" />
</form>
<iframe class="d-none" name="download-iframe" src=""></iframe>
</div>
';
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#redirectform').submit(function() {
$('#redirect').addClass('hide');
}).submit();
});");
echo $OUTPUT->footer();
@@ -0,0 +1,29 @@
<?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/>.
/**
* Strings for component 'portfolio_download', language 'en', branch 'MOODLE_20_STABLE'
*
* @package portfolio_download
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['downloadfile'] = 'Download your portfolio export file';
$string['downloading'] = 'Downloading ...';
$string['pluginname'] = 'File download';
$string['privacy:metadata'] = 'This plugin does not store personal data, nor does it export personal data to an external location.';
+56
View File
@@ -0,0 +1,56 @@
<?php
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/plugin.php');
class portfolio_plugin_download extends portfolio_plugin_pull_base {
protected $exportconfig;
public static function get_name() {
return get_string('pluginname', 'portfolio_download');
}
public static function allows_multiple_instances() {
return false;
}
public function expected_time($callertime) {
return PORTFOLIO_TIME_LOW;
}
public function prepare_package() {
$files = $this->exporter->get_tempfiles();
if (count($files) == 1) {
$this->set('file', array_shift($files));
} else {
$this->set('file', $this->exporter->zip_tempfiles()); // this will throw a file_exception which the exporter catches separately.
}
}
public function steal_control($stage) {
if ($stage == PORTFOLIO_STAGE_FINISHED) {
global $CFG;
return $CFG->wwwroot . '/portfolio/download/file.php?id=' . $this->get('exporter')->get('id');
}
}
public function send_package() {}
public function verify_file_request_params($params) {
// for download plugin the only thing we need to verify is that
// the logged in user is the same as the exporting user
global $USER;
if ($USER->id != $this->user->id) {
return false;
}
return true;
}
public function get_interactive_continue_url() {
return false;
}
}
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Version details
*
* @package portfolio
* @subpackage download
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'portfolio_download'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
+60
View File
@@ -0,0 +1,60 @@
<?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/>.
/**
* For portfolio plugins that are 'pull' - ie, send the request and then wait
* for the remote system to request the file for moodle,
* this is the script that serves up the export file to them.
*
* @package core_portfolio
* @copyright 2008 Penny Leach <penny@catalyst.net.nz>,
* Martin Dougiamas <http://dougiamas.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../config.php');
if (empty($CFG->enableportfolios)) {
throw new \moodle_exception('disabled', 'portfolio');
}
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->libdir . '/filelib.php');
// exporter id
$id = required_param('id', PARAM_INT);
require_login();
$PAGE->set_url('/portfolio/add.php', array('id' => $id));
$exporter = portfolio_exporter::rewaken_object($id);
$exporter->verify_rewaken();
// push plugins don't need to access this script.
if ($exporter->get('instance')->is_push()) {
throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
}
// it's up to the plugin to verify the request parameters, like a token or whatever
if (!$exporter->get('instance')->verify_file_request_params(array_merge($_GET, $_POST))) {
throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
}
// ok, we're good, send the file and finish the export.
$exporter->get('instance')->send_file();
$exporter->process_stage_cleanup(true);
exit;
@@ -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/>.
/**
* Privacy class for requesting user data.
*
* @package portfolio_flickr
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_flickr\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
/**
* Provider for the portfolio_flickr plugin.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This portfolio plugin does not store any data itself.
// It has no database tables, and it purely acts as a conduit, sending data externally.
\core_privacy\local\metadata\provider,
\core_portfolio\privacy\portfolio_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
return $collection->add_external_location_link('flickr.com', ['data' => 'privacy:metadata:data'], 'privacy:metadata');
}
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
}
/**
* Delete all user information for the provided context.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context) {
}
/**
* Delete all user information for the provided user and context.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context) {
}
}
@@ -0,0 +1,50 @@
<?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/>.
/**
* Strings for component 'portfolio_flickr', language 'en', branch 'MOODLE_20_STABLE'
*
* @package portfolio_flickr
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['apikey'] = 'API key';
$string['contenttype'] = 'Content types';
$string['err_noapikey'] = 'No API key';
$string['err_noapikey_help'] = 'There is no API key configured for this plugin. You can get one of these from Flickr services page.';
$string['hidefrompublicsearches'] = 'Hide these images from public searches?';
$string['isfamily'] = 'Visible to family';
$string['isfriend'] = 'Visible to friends';
$string['ispublic'] = 'Public (anyone can see them)';
$string['moderate'] = 'Moderate';
$string['noauthtoken'] = 'Could not retrieve an authentication token for use in this session';
$string['other'] = 'Art, illustration, CGI, or other non-photographic images';
$string['photo'] = 'Photos';
$string['pluginname'] = 'Flickr.com';
$string['privacy:metadata'] = 'This plugin sends data externally to a linked Flickr account. It does not store data locally.';
$string['privacy:metadata:data'] = 'Personal data passed through from the portfolio subsystem.';
$string['restricted'] = 'Restricted';
$string['safe'] = 'Safe';
$string['safetylevel'] = 'Safety level';
$string['screenshot'] = 'Screenshots';
$string['set'] = 'Set';
$string['setupinfo'] = 'Setup instructions';
$string['setupinfodetails'] = 'To obtain API key and the secret string, log in to Flickr and <a href="{$a->applyurl}">apply for a new key</a>. Once new key and secret are generated for you, follow the \'Edit auth flow for this app\' link at the page. Select \'App Type\' to \'Web Application\'. Into the \'Callback URL\' field, put the value: <br /><code>{$a->callbackurl}</code><br />Optionally, you can also provide your Moodle site description and logo. These values can be set later at <a href="{$a->keysurl}">the page</a> listing your Flickr applications.';
$string['sharedsecret'] = 'Secret string';
$string['title'] = 'Title';
$string['uploadfailed'] = 'Failed to upload image(s) to flickr.com: {$a}';
+313
View File
@@ -0,0 +1,313 @@
<?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/>.
/**
* @package portfolio
* @subpackage flickr
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/portfolio/plugin.php');
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/flickrclient.php');
class portfolio_plugin_flickr extends portfolio_plugin_push_base {
/** @var flickr_client */
private $flickr;
private $raw_sets;
public function supported_formats() {
return array(PORTFOLIO_FORMAT_IMAGE);
}
public static function get_name() {
return get_string('pluginname', 'portfolio_flickr');
}
public function prepare_package() {
}
public function send_package() {
foreach ($this->exporter->get_tempfiles() as $file) {
// @TODO get max size from flickr people_getUploadStatus
$filesize = $file->get_filesize();
if ($this->is_valid_image($file)) {
$photoid = $this->flickr->upload($file, [
'title' => $this->get_export_config('title'),
'description' => $this->get_export_config('description'),
'tags' => $this->get_export_config('tags'),
'is_public' => $this->get_export_config('is_public'),
'is_friend' => $this->get_export_config('is_friend'),
'is_family' => $this->get_export_config('is_family'),
'safety_level' => $this->get_export_config('safety_level'),
'content_type' => $this->get_export_config('content_type'),
'hidden' => $this->get_export_config('hidden'),
]);
if ($photoid === false) {
$this->set_user_config([
'accesstoken' => null,
'accesstokensecret' => null,
]);
throw new portfolio_plugin_exception('uploadfailed', 'portfolio_flickr', '', 'Authentication failed');
}
// Attach photo to a set if requested.
if ($this->get_export_config('set')) {
$result = $this->flickr->call('photosets.addPhoto', [
'photoset_id' => $this->get_export_config('set'),
'photo_id' => $photoid,
], 'POST');
}
}
}
}
public static function allows_multiple_instances() {
return false;
}
public function get_interactive_continue_url() {
return 'https://www.flickr.com/photos/organize';
}
public function expected_time($callertime) {
return $callertime;
}
public static function get_allowed_config() {
return array('apikey', 'sharedsecret');
}
public static function has_admin_config() {
return true;
}
public static function admin_config_form(&$mform) {
global $CFG;
$strrequired = get_string('required');
$mform->addElement('text', 'apikey', get_string('apikey', 'portfolio_flickr'), array('size' => 30));
$mform->addRule('apikey', $strrequired, 'required', null, 'client');
$mform->setType('apikey', PARAM_RAW_TRIMMED);
$mform->addElement('text', 'sharedsecret', get_string('sharedsecret', 'portfolio_flickr'));
$mform->addRule('sharedsecret', $strrequired, 'required', null, 'client');
$mform->setType('sharedsecret', PARAM_RAW_TRIMMED);
$a = new stdClass();
$a->applyurl = 'http://www.flickr.com/services/api/keys/apply/';
$a->keysurl = 'http://www.flickr.com/services/api/keys/';
$a->callbackurl = $CFG->wwwroot . '/portfolio/add.php?postcontrol=1&type=flickr';
$mform->addElement('static', 'setupinfo', get_string('setupinfo', 'portfolio_flickr'),
get_string('setupinfodetails', 'portfolio_flickr', $a));
}
public function has_export_config() {
return true;
}
public function get_allowed_user_config() {
return array('accesstoken', 'accesstokensecret');
}
public function steal_control($stage) {
if ($stage != PORTFOLIO_STAGE_CONFIG) {
return false;
}
$accesstoken = $this->get_user_config('accesstoken');
$accesstokensecret = $this->get_user_config('accesstokensecret');
$callbackurl = new moodle_url('/portfolio/add.php', ['postcontrol' => 1, 'type' => 'flickr']);
$this->flickr = new flickr_client($this->get_config('apikey'), $this->get_config('sharedsecret'), $callbackurl);
if (!empty($accesstoken) && !empty($accesstokensecret)) {
// The user has authenticated us already.
$this->flickr->set_access_token($accesstoken, $accesstokensecret);
return false;
}
$reqtoken = $this->flickr->request_token();
$this->flickr->set_request_token_secret(['caller' => 'portfolio_flickr'], $reqtoken['oauth_token_secret']);
$authurl = new moodle_url($reqtoken['authorize_url'], ['perms' => 'write']);
return $authurl->out(false);
}
public function post_control($stage, $params) {
if ($stage != PORTFOLIO_STAGE_CONFIG) {
return;
}
if (empty($params['oauth_token']) || empty($params['oauth_verifier'])) {
throw new portfolio_plugin_exception('noauthtoken', 'portfolio_flickr');
}
$callbackurl = new moodle_url('/portfolio/add.php', ['postcontrol' => 1, 'type' => 'flickr']);
$this->flickr = new flickr_client($this->get_config('apikey'), $this->get_config('sharedsecret'), $callbackurl);
$secret = $this->flickr->get_request_token_secret(['caller' => 'portfolio_flickr']);
// Exchange the request token for the access token.
$accesstoken = $this->flickr->get_access_token($params['oauth_token'], $secret, $params['oauth_verifier']);
// Store the access token and the access token secret as the user
// config so that we can use it on behalf of the user in next exports.
$this->set_user_config([
'accesstoken' => $accesstoken['oauth_token'],
'accesstokensecret' => $accesstoken['oauth_token_secret'],
]);
}
public function export_config_form(&$mform) {
$mform->addElement('text', 'plugin_title', get_string('title', 'portfolio_flickr'));
$mform->setType('plugin_title', PARAM_TEXT);
$mform->addElement('textarea', 'plugin_description', get_string('description'));
$mform->setType('plugin_description', PARAM_CLEANHTML);
$mform->addElement('text', 'plugin_tags', get_string('tags'));
$mform->setType('plugin_tags', PARAM_TAGLIST);
$mform->addElement('checkbox', 'plugin_is_public', get_string('ispublic', 'portfolio_flickr'));
$mform->addElement('checkbox', 'plugin_is_family', get_string('isfamily', 'portfolio_flickr'));
$mform->addElement('checkbox', 'plugin_is_friend', get_string('isfriend', 'portfolio_flickr'));
$mform->disabledIf('plugin_is_friend', 'plugin_is_public', 'checked');
$mform->disabledIf('plugin_is_family', 'plugin_is_public', 'checked');
$safety_levels = array(1 => $this->get_export_value_name('safety_level', 1),
2 => $this->get_export_value_name('safety_level', 2),
3 => $this->get_export_value_name('safety_level', 3));
$content_types = array(1 => $this->get_export_value_name('content_type', 1),
2 => $this->get_export_value_name('content_type', 2),
3 => $this->get_export_value_name('content_type', 3));
$hidden_values = array(1,2);
$mform->addElement('select', 'plugin_safety_level', get_string('safetylevel', 'portfolio_flickr'), $safety_levels);
$mform->addElement('select', 'plugin_content_type', get_string('contenttype', 'portfolio_flickr'), $content_types);
$mform->addElement('advcheckbox', 'plugin_hidden', get_string('hidefrompublicsearches', 'portfolio_flickr'), get_string('yes'), null, $hidden_values);
$mform->setDefaults(array('plugin_is_public' => true));
$rawsets = $this->get_sets();
if (!empty($rawsets)) {
$sets = array('0' => '----');
foreach ($rawsets as $key => $value) {
$sets[$key] = $value;
}
$mform->addElement('select', 'plugin_set', get_string('set', 'portfolio_flickr'), $sets);
}
}
/**
* Fetches a list of current user's photosets (albums) on flickr.
*
* @return array (int)id => (string)title
*/
private function get_sets() {
if (empty($this->raw_sets)) {
$this->raw_sets = $this->flickr->call('photosets.getList');
}
if ($this->raw_sets === false) {
// Authentication failed, drop the locally stored token to force re-authentication.
$this->set_user_config([
'accesstoken' => null,
'accesstokensecret' => null,
]);
return array();
}
$sets = array();
foreach ($this->raw_sets->photosets->photoset as $set) {
$sets[$set->id] = $set->title->_content;
}
return $sets;
}
public function get_allowed_export_config() {
return array('set', 'title', 'description', 'tags', 'is_public', 'is_family', 'is_friend', 'safety_level', 'content_type', 'hidden');
}
public function get_export_summary() {
return array(get_string('set', 'portfolio_flickr') => $this->get_export_value_name('set', $this->get_export_config('set')),
get_string('title', 'portfolio_flickr') => $this->get_export_config('title'),
get_string('description') => $this->get_export_config('description'),
get_string('tags') => $this->get_export_config('tags'),
get_string('ispublic', 'portfolio_flickr') => $this->get_export_value_name('is_public', $this->get_export_config('is_public')),
get_string('isfamily', 'portfolio_flickr') => $this->get_export_value_name('is_family', $this->get_export_config('is_family')),
get_string('isfriend', 'portfolio_flickr') => $this->get_export_value_name('is_friend', $this->get_export_config('is_friend')),
get_string('safetylevel', 'portfolio_flickr') => $this->get_export_value_name('safety_level', $this->get_export_config('safety_level')),
get_string('contenttype', 'portfolio_flickr') => $this->get_export_value_name('content_type', $this->get_export_config('content_type')),
get_string('hidefrompublicsearches', 'portfolio_flickr') => $this->get_export_value_name('hidden', $this->get_export_config('hidden')));
}
private function get_export_value_name($param, $value) {
$params = array('set' => $this->get_sets(),
'is_public' => array(0 => get_string('no'), 1 => get_string('yes')),
'is_family' => array(0 => get_string('no'), 1 => get_string('yes')),
'is_friend' => array(0 => get_string('no'), 1 => get_string('yes')),
'safety_level' => array(1 => get_string('safe', 'portfolio_flickr'),
2 => get_string('moderate', 'portfolio_flickr'),
3 => get_string('restricted', 'portfolio_flickr')),
'content_type' => array(1 => get_string('photo', 'portfolio_flickr'),
2 => get_string('screenshot', 'portfolio_flickr'),
3 => get_string('other', 'portfolio_flickr')),
'hidden' => array(1 => get_string('no'), 2 => get_string('yes')));
if (isset($params[$param][$value])) {
return $params[$param][$value];
} else {
return '-';
}
}
/**
* For now, flickr doesn't support this because we can't dynamically construct callbackurl
*/
public static function allows_multiple_exports() {
return false;
}
/**
* Verifies the file is a valid optimised image - gif, png and jpeg only.
* Currently, Flickr only supports these file types.
*
* @param stored_file $file
* @return bool true if the file is ok
*/
private function is_valid_image(stored_file $file): bool {
$mimetype = $file->get_mimetype();
if (!file_mimetype_in_typegroup($mimetype, 'optimised_image')) {
return false;
}
if (!$info = $file->get_imageinfo()) {
return false;
}
if ($info['mimetype'] !== $mimetype) {
return false;
}
return true;
}
}
@@ -0,0 +1,47 @@
<?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/>.
/**
* Privacy provider tests.
*
* @package portfolio_flickr
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_flickr\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider tests class.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Verify that a collection of metadata is returned for this component and that it just links to an external location.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('portfolio_flickr');
$collection = \portfolio_flickr\privacy\provider::get_metadata($collection);
$this->assertNotEmpty($collection);
$items = $collection->get_collection();
$this->assertEquals(1, count($items));
$this->assertInstanceOf(\core_privacy\local\metadata\types\external_location::class, $items[0]);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Version details
*
* @package portfolio
* @subpackage flickr
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'portfolio_flickr'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
@@ -0,0 +1,80 @@
<?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/>.
/**
* Privacy class for requesting user data.
*
* @package portfolio_googledocs
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_googledocs\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
/**
* Provider for the portfolio_googledocs plugin.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This portfolio plugin does not store any data itself.
// It has no database tables, and it purely acts as a conduit, sending data externally.
\core_privacy\local\metadata\provider,
\core_portfolio\privacy\portfolio_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
return $collection->add_external_location_link('docs.google.com', ['data' => 'privacy:metadata:data'],
'privacy:metadata');
}
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
}
/**
* Delete all user information for the provided context.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context) {
}
/**
* Delete all user information for the provided user and context.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context) {
}
}
+35
View File
@@ -0,0 +1,35 @@
<?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/>.
/**
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_portfolio_googledocs_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
@@ -0,0 +1,35 @@
<?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/>.
/**
* Strings for component 'portfolio_googledocs', language 'en', branch 'MOODLE_20_STABLE'
*
* @package portfolio_googledocs
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['clientid'] = 'Client ID';
$string['noauthtoken'] = 'An authentication token has not been received from Google. Please ensure you are allowing Moodle to access your Google account';
$string['nooauthcredentials'] = 'OAuth credentials required.';
$string['nooauthcredentials_help'] = 'To use the Google Drive portfolio plugin you must configure OAuth credentials in the portfolio settings.';
$string['nosessiontoken'] = 'A session token does not exist preventing export to google.';
$string['oauthinfo'] = '<p>To use this plugin, you must register your site with Google, as described in the documentation <a href="{$a->docsurl}">Google OAuth 2.0 setup</a>.</p><p>As part of the registration process, you will need to enter the following URL as \'Authorized Redirect URIs\':</p><p>{$a->callbackurl}</p><p>Once registered, you will be provided with a client ID and secret which can be used to configure all Google Drive plugins.</p>';
$string['pluginname'] = 'Google Drive';
$string['privacy:metadata'] = 'This plugin sends data externally to a linked Google account. It does not store data locally.';
$string['privacy:metadata:data'] = 'Personal data passed through from the portfolio subsystem.';
$string['sendfailed'] = 'The file {$a} failed to transfer to google';
$string['secret'] = 'Secret';
+265
View File
@@ -0,0 +1,265 @@
<?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/>.
/**
* Google Documents Portfolio Plugin
*
* @author Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once($CFG->libdir.'/portfolio/plugin.php');
require_once($CFG->libdir . '/google/lib.php');
class portfolio_plugin_googledocs extends portfolio_plugin_push_base {
/**
* Google Client.
* @var Google_Client
*/
private $client = null;
/**
* Google Drive Service.
* @var Google_Service_Drive
*/
private $service = null;
/**
* URL to redirect Google to.
* @var string
*/
const REDIRECTURL = '/admin/oauth2callback.php';
/**
* Key in session which stores token (_drive_file is access level).
* @var string
*/
const SESSIONKEY = 'googledrive_accesstoken_drive_file';
public function supported_formats() {
return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML);
}
public static function get_name() {
return get_string('pluginname', 'portfolio_googledocs');
}
public function prepare_package() {
// We send the files as they are, no prep required.
return true;
}
public function get_interactive_continue_url() {
return 'http://drive.google.com/';
}
public function expected_time($callertime) {
// We're forcing this to be run 'interactively' because the plugin
// does not support running in cron.
return PORTFOLIO_TIME_LOW;
}
public function send_package() {
if (!$this->client) {
throw new portfolio_plugin_exception('noauthtoken', 'portfolio_googledocs');
}
// Create a parent directory for the export to Google Drive so that all files from the
// same export can be contained in one place for easy downloading.
$now = time();
$exportdirectoryname = $this->exporter->get('caller')->display_name();
$exportdirectoryname = strtolower(join('-', explode(' ', $exportdirectoryname)));
$exportdirectoryname = "/portfolio-export-{$exportdirectoryname}-{$now}";
$directoryids = [];
foreach ($this->exporter->get_tempfiles() as $file) {
$filepath = $exportdirectoryname . $file->get_filepath();
$directories = array_filter(explode('/', $filepath), function($part) {
return !empty($part);
});
// Track how deep into the directory structure we are. This is the key
// we'll use to keep track of previously created directory ids.
$path = '/';
// Track the parent directory so that we can look up it's id for creating
// subdirectories in Google Drive.
$parentpath = null;
// Create each of the directories in Google Drive that we need.
foreach ($directories as $directory) {
// Update the current path for this file.
$path .= "{$directory}/";
if (!isset($directoryids[$path])) {
// This directory hasn't been created yet so let's go ahead and create it.
$parents = !is_null($parentpath) ? [$directoryids[$parentpath]] : [];
try {
$filemetadata = new Google_Service_Drive_DriveFile([
'title' => $directory,
'mimeType' => 'application/vnd.google-apps.folder',
'parents' => $parents
]);
$drivefile = $this->service->files->insert($filemetadata, ['fields' => 'id']);
$directoryids[$path] = ['id' => $drivefile->id];
} catch (Exception $e) {
throw new portfolio_plugin_exception('sendfailed', 'portfolio_gdocs', $directory);
}
}
$parentpath = $path;
}
try {
// Create drivefile object and fill it with data.
$drivefile = new Google_Service_Drive_DriveFile();
$drivefile->setTitle($file->get_filename());
$drivefile->setMimeType($file->get_mimetype());
// Add the parent directory id to make sure the file gets created in the correct
// directory in Google Drive.
$drivefile->setParents([$directoryids[$filepath]]);
$filecontent = $file->get_content();
$this->service->files->insert($drivefile,
array('data' => $filecontent,
'mimeType' => $file->get_mimetype(),
'uploadType' => 'multipart'));
} catch ( Exception $e ) {
throw new portfolio_plugin_exception('sendfailed', 'portfolio_gdocs', $file->get_filename());
}
}
return true;
}
/**
* Gets the access token from session and sets it to client.
*
* @return null|string null or token.
*/
private function get_access_token() {
global $SESSION;
if (isset($SESSION->{self::SESSIONKEY}) && $SESSION->{self::SESSIONKEY}) {
$this->client->setAccessToken($SESSION->{self::SESSIONKEY});
return $SESSION->{self::SESSIONKEY};
}
return null;
}
/**
* Sets the access token to session
*
* @param string $token access token in json format
* @return
*/
private function set_access_token($token) {
global $SESSION;
$SESSION->{self::SESSIONKEY} = $token;
}
public function steal_control($stage) {
global $CFG;
if ($stage != PORTFOLIO_STAGE_CONFIG) {
return false;
}
$this->initialize_oauth();
if ($this->get_access_token()) {
// Ensure that token is not expired.
if (!$this->client->isAccessTokenExpired()) {
return false;
}
}
return $this->client->createAuthUrl();
}
public function post_control($stage, $params) {
if ($stage != PORTFOLIO_STAGE_CONFIG) {
return;
}
// Get the authentication code send by Google.
$code = isset($params['oauth2code']) ? $params['oauth2code'] : null;
// Try to authenticate (throws exception which is catched higher).
$this->client->authenticate($code);
// Make sure we accually have access token at this time
// ...and store it for further use.
if ($accesstoken = $this->client->getAccessToken()) {
$this->set_access_token($accesstoken);
} else {
throw new portfolio_plugin_exception('nosessiontoken', 'portfolio_gdocs');
}
}
public static function allows_multiple_instances() {
return false;
}
public static function has_admin_config() {
return true;
}
public static function get_allowed_config() {
return array('clientid', 'secret');
}
public static function admin_config_form(&$mform) {
$a = new stdClass;
$a->docsurl = get_docs_url('Google_OAuth_2.0_setup');
$a->callbackurl = (new moodle_url(self::REDIRECTURL))->out(false);
$mform->addElement('static', null, '', get_string('oauthinfo', 'portfolio_googledocs', $a));
$mform->addElement('text', 'clientid', get_string('clientid', 'portfolio_googledocs'));
$mform->setType('clientid', PARAM_RAW_TRIMMED);
$mform->addElement('text', 'secret', get_string('secret', 'portfolio_googledocs'));
$mform->setType('secret', PARAM_RAW_TRIMMED);
$strrequired = get_string('required');
$mform->addRule('clientid', $strrequired, 'required', null, 'client');
$mform->addRule('secret', $strrequired, 'required', null, 'client');
}
private function initialize_oauth() {
$redirecturi = new moodle_url(self::REDIRECTURL);
$returnurl = new moodle_url('/portfolio/add.php');
$returnurl->param('postcontrol', 1);
$returnurl->param('id', $this->exporter->get('id'));
$returnurl->param('sesskey', sesskey());
$clientid = $this->get_config('clientid');
$secret = $this->get_config('secret');
// Setup Google client.
$this->client = get_google_client();
$this->client->setClientId($clientid);
$this->client->setClientSecret($secret);
$this->client->setScopes(array(Google_Service_Drive::DRIVE_FILE));
$this->client->setRedirectUri($redirecturi->out(false));
// URL to be called when redirecting from authentication.
$this->client->setState($returnurl->out_as_local_url(false));
// Setup drive upload service.
$this->service = new Google_Service_Drive($this->client);
}
public function instance_sanity_check() {
$clientid = $this->get_config('clientid');
$secret = $this->get_config('secret');
// If there is no oauth config (e.g. plugins upgraded from < 2.3 then
// there will be no config and this plugin should be disabled.
if (empty($clientid) or empty($secret)) {
return 'nooauthcredentials';
}
return 0;
}
}
+109
View File
@@ -0,0 +1,109 @@
<?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/>.
namespace portfolio_googledocs;
use portfolio_admin_form;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/forms.php');
/**
* Googledocs portfolio functional test.
*
* @package portfolio_googledocs
* @category tests
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plugin_test extends \advanced_testcase {
/** @var string name of the portfolio plugin */
protected $pluginname = 'googledocs';
/**
* Creates a new instance of the portfolio plugin
*
* @param string $name name of the instance
* @param \stdClass $data config data for the instance
* @return portfolio_plugin_base
*/
protected function enable_plugin($name = 'Instance name', $data = null) {
$data = $data ?: new \stdClass();
$instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data);
\core_plugin_manager::reset_caches();
return $instance;
}
/**
* Test for method enable_plugin()
*/
public function test_enable(): void {
global $DB;
$this->resetAfterTest();
$instance = $this->enable_plugin();
$record = $DB->get_record('portfolio_instance', ['plugin' => $this->pluginname]);
$this->assertEquals($record->id, $instance->get('id'));
$this->assertEquals('portfolio_plugin_' . $this->pluginname, get_class($instance));
$this->assertEquals(1, $instance->get('visible'));
}
/**
* Test submitting a form for creating an instance
*/
public function test_create_form(): void {
$formdata = ['name' => 'Instance name', 'clientid' => 'CLIENT', 'secret' => 'SECRET'];
portfolio_admin_form::mock_submit($formdata);
$form = new portfolio_admin_form('', array('plugin' => $this->pluginname,
'instance' => null, 'portfolio' => null,
'action' => 'new', 'visible' => 1));
$data = $form->get_data();
$this->assertEquals('new', $data->action);
$this->assertEquals(1, $data->visible);
$this->assertEquals($this->pluginname, $data->plugin);
foreach ($formdata as $key => $value) {
$this->assertEquals($value, $data->$key);
}
}
/**
* Test submitting a form for editing an instance
*/
public function test_edit_form(): void {
$this->resetAfterTest();
$instance = $this->enable_plugin();
$formdata = ['name' => 'New name', 'clientid' => 'CLIENT', 'secret' => 'SECRET'];
portfolio_admin_form::mock_submit($formdata);
$form = new portfolio_admin_form('', array('plugin' => $this->pluginname,
'instance' => $instance, 'portfolio' => $instance->get('id'),
'action' => 'edit', 'visible' => $instance->get('visible')));
$this->assertTrue($form->is_validated());
$this->assertTrue($form->is_submitted());
$data = $form->get_data();
$this->assertEquals('edit', $data->action);
$this->assertEquals($instance->get('visible'), $data->visible);
$this->assertEquals($this->pluginname, $data->plugin);
foreach ($formdata as $key => $value) {
$this->assertEquals($value, $data->$key);
}
}
}
@@ -0,0 +1,47 @@
<?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/>.
/**
* Privacy provider tests.
*
* @package portfolio_googledocs
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_googledocs\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider tests class.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Verify that a collection of metadata is returned for this component and that it just links to an external location.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('portfolio_googledocs');
$collection = \portfolio_googledocs\privacy\provider::get_metadata($collection);
$this->assertNotEmpty($collection);
$items = $collection->get_collection();
$this->assertEquals(1, count($items));
$this->assertInstanceOf(\core_privacy\local\metadata\types\external_location::class, $items[0]);
}
}
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /portfolio/googledocs system,
information provided here is intended especially for developers.
=== 3.9 ===
* The Google Drive portfolio exports are now bundled in a single parent folder. The paths for the exported files will
now be created in Drive so that exported files are in the correct directory structure.
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Version details
*
* @package portfolio
* @subpackage googledocs
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'portfolio_googledocs'; // Full name of the plugin (used for diagnostics).
$plugin->cron = 0;
@@ -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/>.
/**
* Privacy class for requesting user data.
*
* @package portfolio_mahara
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_mahara\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
/**
* Provider for the portfolio_mahara plugin.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This portfolio plugin does not store any data itself.
// It has no database tables, and it purely acts as a conduit, sending data externally.
\core_privacy\local\metadata\provider,
\core_portfolio\privacy\portfolio_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
return $collection->add_external_location_link('mahara', ['data' => 'privacy:metadata:data'], 'privacy:metadata');
}
/**
* Export all portfolio data from each portfolio plugin for the specified userid and context.
*
* @param int $userid The user to export.
* @param \context $context The context to export.
* @param array $subcontext The subcontext within the context to export this information to.
* @param array $linkarray The weird and wonderful link array used to display information for a specific item
*/
public static function export_portfolio_user_data(int $userid, \context $context, array $subcontext, array $linkarray) {
}
/**
* Delete all user information for the provided context.
*
* @param \context $context The context to delete user data for.
*/
public static function delete_portfolio_for_context(\context $context) {
}
/**
* Delete all user information for the provided user and context.
*
* @param int $userid The user to delete
* @param \context $context The context to refine the deletion.
*/
public static function delete_portfolio_for_user(int $userid, \context $context) {
}
}
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="portfolio/mahara/db" VERSION="20120122" COMMENT="XMLDB file for Moodle portfolio/mahara"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="portfolio_mahara_queue" COMMENT="maps mahara tokens to transfer ids">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="transferid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="fk to portfolio_tempdata.id"/>
<FIELD NAME="token" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="the token mahara sent us to use for this transfer."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="transferfk" TYPE="foreign" FIELDS="transferid" REFTABLE="portfolio_tempdata" REFFIELDS="id" COMMENT="fk to portfolio_tempdata"/>
</KEYS>
<INDEXES>
<INDEX NAME="tokenidx" UNIQUE="false" FIELDS="token" COMMENT="index for token field (used for lookups)"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
+43
View File
@@ -0,0 +1,43 @@
<?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/>.
/**
* This file contains the mnet services for the mahara portfolio plugin
*
* @since Moodle 2.0
* @package moodlecore
* @subpackage portfolio
* @copyright 2010 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$publishes = array(
'pf' => array(
'apiversion' => 1,
'classname' => 'portfolio_plugin_mahara',
'filename' => 'lib.php',
'methods' => array(
'fetch_file'
),
),
);
$subscribes = array(
'pf' => array(
'send_content_intent' => 'portfolio/mahara/lib.php/send_content_intent',
'send_content_ready' => 'portfolio/mahara/lib.php/send_content_ready',
),
);
@@ -0,0 +1,49 @@
<?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/>.
/**
* Strings for component 'portfolio_mahara', language 'en', branch 'MOODLE_20_STABLE'
*
* @package portfolio_mahara
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['enableleap2a'] = 'Enable Leap2A portfolio support (requires Mahara 1.3 or higher)';
$string['err_invalidhost'] = 'Invalid MNet host';
$string['err_invalidhost_help'] = 'This plugin is misconfigured to point to an invalid (or deleted) MNet host. This plugin relies on Moodle Networking peers with SSO IDP published, SSO_SP subscribed, and portfolio subscribed <b>and</b> published.';
$string['err_networkingoff'] = 'MNet is off';
$string['err_networkingoff_help'] = 'MNet authentication is currently disabled. Please enable it before trying to configure this plugin. Any instances of this plugin have been hidden until MNet is enabled. They will then need to be manually set to visible again.';
$string['err_nomnetauth'] = 'The MNet authentication plugin is disabled';
$string['err_nomnetauth_help'] = 'The MNet authentication plugin is disabled, but is required for this service';
$string['err_nomnethosts'] = 'Relies on MNet';
$string['err_nomnethosts_help'] = 'This plugin relies on MNet peers with SSO IDP published, SSO SP subscribed, portfolio services published <b>and</b> subscribed as well as the MNet authentication plugin. Any instances of this plugin have been hidden until these conditions are met. They will then manually need setting to visible again.';
$string['failedtojump'] = 'Failed to start communication with remote server';
$string['failedtoping'] = 'Failed to start communication with remote server: {$a}';
$string['mnethost'] = 'MNet host';
$string['mnet_nofile'] = 'Could not find file in transfer object - weird error';
$string['mnet_nofilecontents'] = 'Found file in transfer object, but could not get contents - weird error: {$a}';
$string['mnet_noid'] = 'Could not find the matching transfer record for this token';
$string['mnet_notoken'] = 'Could not find token matching this transfer';
$string['mnet_wronghost'] = 'Remote host did not match the transfer record for this token';
$string['pf_description'] = 'Allow users to push Moodle content to this host<br />Subscribe to <b>and</b> publish this service to allow authenticated users in your site to push content to {$a}<br /><ul><li><em>Dependency</em>: You must also <strong>publish</strong> the SSO (Identify Provider) service to {$a}.</li><li><em>Dependency</em>: You must also <strong>subscribe</strong> to the SSO (Service Provider) service on {$a}</li><li><em>Dependency</em>: You must also enable the MNet authentication plugin.</li></ul><br />';
$string['pf_name'] = 'Portfolio services';
$string['pluginname'] = 'Mahara ePortfolio';
$string['privacy:metadata'] = 'This plugin sends data externally to a linked Mahara application. It does not store data locally.';
$string['privacy:metadata:data'] = 'Personal data passed through from the portfolio subsystem.';
$string['senddisallowed'] = 'You cannot transfer files to Mahara at this time';
$string['url'] = 'URL';
+392
View File
@@ -0,0 +1,392 @@
<?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/>.
/**
* This file contains the class definition for the mahara portfolio plugin
*
* @since Moodle 2.0
* @package moodlecore
* @subpackage portfolio
* @copyright 2009 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('PORTFOLIO_MAHARA_ERR_NETWORKING_OFF', 'err_networkingoff');
define('PORTFOLIO_MAHARA_ERR_NOHOSTS', 'err_nomnethosts');
define('PORTFOLIO_MAHARA_ERR_INVALIDHOST', 'err_invalidhost');
define('PORTFOLIO_MAHARA_ERR_NOMNETAUTH', 'err_nomnetauth');
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/plugin.php');
require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->dirroot . '/mnet/lib.php');
define('PORTFOLIO_MAHARA_QUEUE', PORTFOLIO_TIME_HIGH);
define('PORTFOLIO_MAHARA_IMMEDIATE', PORTFOLIO_TIME_MODERATE);
class portfolio_plugin_mahara extends portfolio_plugin_pull_base {
private $hosts; // used in the admin config form
private $mnethost; // privately set during export from the admin config value (mnethostid)
private $hostrecord; // the host record that corresponds to the peer
private $token; // during-transfer token
private $sendtype; // whatever mahara has said it can handle (immediate or queued)
private $filesmanifest; // manifest of files to send to mahara (set during prepare_package and sent later)
private $totalsize; // total size of all included files added together
private $continueurl; // if we've been sent back a specific url to continue to (eg folder id)
/** @var mnet_environment the equivalent of old $MNET global. */
public $mnet;
protected function init() {
$this->mnet = get_mnet_environment();
}
public function __wakeup() {
$this->mnet = get_mnet_environment();
}
public static function get_name() {
return get_string('pluginname', 'portfolio_mahara');
}
public static function get_allowed_config() {
return array('mnethostid', 'enableleap2a');
}
public function supported_formats() {
if ($this->get_config('enableleap2a')) {
return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
}
return array(PORTFOLIO_FORMAT_FILE);
}
public function expected_time($callertime) {
if ($this->sendtype == PORTFOLIO_MAHARA_QUEUE) {
return PORTFOLIO_TIME_FORCEQUEUE;
}
return $callertime;
}
public static function has_admin_config() {
return true;
}
public static function admin_config_form(&$mform) {
$strrequired = get_string('required');
$hosts = self::get_mnet_hosts(); // this is called by sanity check but it's ok because it's cached
foreach ($hosts as $host) {
$hosts[$host->id] = $host->name;
}
$mform->addElement('select', 'mnethostid', get_string('mnethost', 'portfolio_mahara'), $hosts);
$mform->addRule('mnethostid', $strrequired, 'required', null, 'client');
$mform->setType('mnethostid', PARAM_INT);
$mform->addElement('selectyesno', 'enableleap2a', get_string('enableleap2a', 'portfolio_mahara'));
$mform->setType('enableleap2a', PARAM_BOOL);
}
public function instance_sanity_check() {
// make sure the host record exists since we don't have referential integrity
if (!is_enabled_auth('mnet')) {
return PORTFOLIO_MAHARA_ERR_NOMNETAUTH;
}
try {
$this->ensure_mnethost();
}
catch (portfolio_exception $e) {
return PORTFOLIO_MAHARA_ERR_INVALIDHOST;
}
// make sure we have the right services
$hosts = $this->get_mnet_hosts();
if (!array_key_exists($this->get_config('mnethostid'), $hosts)) {
return PORTFOLIO_MAHARA_ERR_INVALIDHOST;
}
return 0;
}
public static function plugin_sanity_check() {
global $CFG, $DB;
$errorcode = 0;
if (!isset($CFG->mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode != 'strict') {
$errorcode = PORTFOLIO_MAHARA_ERR_NETWORKING_OFF;
}
if (!is_enabled_auth('mnet')) {
$errorcode = PORTFOLIO_MAHARA_ERR_NOMNETAUTH;
}
if (!self::get_mnet_hosts()) {
$errorcode = PORTFOLIO_MAHARA_ERR_NOHOSTS;
}
return $errorcode;
}
private static function get_mnet_hosts() {
global $DB, $CFG;
static $hosts;
if (isset($hosts)) {
return $hosts;
}
$hosts = $DB->get_records_sql(' SELECT
h.id,
h.wwwroot,
h.ip_address,
h.name,
h.public_key,
h.public_key_expires,
h.transport,
h.portno,
h.last_connect_time,
h.last_log_id,
h.applicationid,
a.name as app_name,
a.display_name as app_display_name,
a.xmlrpc_server_url
FROM {mnet_host} h
JOIN {mnet_application} a ON h.applicationid=a.id
JOIN {mnet_host2service} hs1 ON hs1.hostid = h.id
JOIN {mnet_service} s1 ON hs1.serviceid = s1.id
JOIN {mnet_host2service} hs2 ON hs2.hostid = h.id
JOIN {mnet_service} s2 ON hs2.serviceid = s2.id
JOIN {mnet_host2service} hs3 ON hs3.hostid = h.id
JOIN {mnet_service} s3 ON hs3.serviceid = s3.id
WHERE
h.id <> ? AND
h.deleted = 0 AND
a.name = ? AND
s1.name = ? AND hs1.publish = ? AND
s2.name = ? AND hs2.subscribe = ? AND
s3.name = ? AND hs3.subscribe = ? AND
s3.name = ? AND hs3.publish = ?',
array($CFG->mnet_localhost_id, 'mahara', 'sso_idp', 1, 'sso_sp', 1, 'pf', 1, 'pf', 1));
return $hosts;
}
public function prepare_package() {
$files = $this->exporter->get_tempfiles();
$this->totalsize = 0;
foreach ($files as $f) {
$this->filesmanifest[$f->get_contenthash()] = array(
'filename' => $f->get_filename(),
'sha1' => $f->get_contenthash(),
'size' => $f->get_filesize(),
);
$this->totalsize += $f->get_filesize();
}
$this->set('file', $this->exporter->zip_tempfiles()); // this will throw a file_exception which the exporter catches separately.
}
public function send_package() {
global $CFG;
// send the 'content_ready' request to mahara
require_once($CFG->dirroot . '/mnet/xmlrpc/client.php');
$client = new mnet_xmlrpc_client();
$client->set_method('portfolio/mahara/lib.php/send_content_ready');
$client->add_param($this->token);
$client->add_param($this->get('user')->username);
$client->add_param($this->resolve_format());
$client->add_param(array(
'filesmanifest' => $this->filesmanifest,
'zipfilesha1' => $this->get('file')->get_contenthash(),
'zipfilesize' => $this->get('file')->get_filesize(),
'totalsize' => $this->totalsize,
));
$client->add_param($this->get_export_config('wait'));
$this->ensure_mnethost();
if (!$client->send($this->mnethost)) {
foreach ($client->error as $errormessage) {
list($code, $message) = array_map('trim',explode(':', $errormessage, 2));
$message .= "ERROR $code:<br/>$errormessage<br/>";
}
throw new portfolio_export_exception($this->get('exporter'), 'failedtoping', 'portfolio_mahara', '', $message);
}
// we should get back... an ok and a status
// either we've been waiting a while and mahara has fetched the file or has queued it.
$response = (object)$client->response;
if (!$response->status) {
throw new portfolio_export_exception($this->get('exporter'), 'failedtoping', 'portfolio_mahara');
}
if ($response->type =='queued') {
$this->exporter->set_forcequeue();
}
if (isset($response->querystring)) {
$this->continueurl = $response->querystring;
}
// if we're not queuing the logging might have already happened
$this->exporter->update_log_url($this->get_static_continue_url());
}
public function get_static_continue_url() {
$remoteurl = '';
if ($this->resolve_format() == 'file') {
$remoteurl = '/artefact/file/'; // we hopefully get the files that were imported highlighted
}
if (isset($this->continueurl)) {
$remoteurl .= $this->continueurl;
}
return $remoteurl;
}
public function resolve_static_continue_url($remoteurl) {
global $CFG;
$this->ensure_mnethost();
$u = new moodle_url('/auth/mnet/jump.php', array('hostid' => $this->get_config('mnethostid'), 'wantsurl' => $remoteurl));
return $u->out();
}
public function get_interactive_continue_url() {
return $this->resolve_static_continue_url($this->get_static_continue_url());
}
public function steal_control($stage) {
if ($stage != PORTFOLIO_STAGE_CONFIG) {
return false;
}
global $CFG;
return $CFG->wwwroot . '/portfolio/mahara/preconfig.php?id=' . $this->exporter->get('id');
}
public function verify_file_request_params($params) {
return false;
// the data comes from an xmlrpc request,
// not a request to file.php
}
/**
* sends the 'content_intent' ping to mahara
* if all goes well, this will set the 'token' and 'sendtype' member variables.
*/
public function send_intent() {
global $CFG, $DB;
require_once($CFG->dirroot . '/mnet/xmlrpc/client.php');
$client = new mnet_xmlrpc_client();
$client->set_method('portfolio/mahara/lib.php/send_content_intent');
$client->add_param($this->get('user')->username);
$this->ensure_mnethost();
if (!$client->send($this->mnethost)) {
foreach ($client->error as $errormessage) {
list($code, $message) = array_map('trim',explode(':', $errormessage, 2));
$message .= "ERROR $code:<br/>$errormessage<br/>";
}
throw new portfolio_export_exception($this->get('exporter'), 'failedtoping', 'portfolio_mahara', '', $message);
}
// we should get back... the send type and a shared token
$response = (object)$client->response;
if (empty($response->sendtype) || empty($response->token)) {
throw new portfolio_export_exception($this->get('exporter'), 'senddisallowed', 'portfolio_mahara');
}
switch ($response->sendtype) {
case 'immediate':
$this->sendtype = PORTFOLIO_MAHARA_IMMEDIATE;
break;
case 'queue':
$this->sendtype = PORTFOLIO_MAHARA_QUEUE;
break;
case 'none':
default:
throw new portfolio_export_exception($this->get('exporter'), 'senddisallowed', 'portfolio_mahara');
}
$this->token = $response->token;
$this->get('exporter')->save();
// put the entry in the mahara queue table now too
$q = new stdClass;
$q->token = $this->token;
$q->transferid = $this->get('exporter')->get('id');
$DB->insert_record('portfolio_mahara_queue', $q);
}
private function ensure_mnethost() {
if (!empty($this->hostrecord) && !empty($this->mnethost)) {
return;
}
global $DB;
if (!$this->hostrecord = $DB->get_record('mnet_host', array('id' => $this->get_config('mnethostid')))) {
throw new portfolio_plugin_exception(PORTFOLIO_MAHARA_ERR_INVALIDHOST, 'portfolio_mahara');
}
$this->mnethost = new mnet_peer();
$this->mnethost->set_wwwroot($this->hostrecord->wwwroot);
}
/**
* xmlrpc (mnet) function to get the file.
* reads in the file and returns it base_64 encoded
* so that it can be enrypted by mnet.
*
* @param string $token the token recieved previously during send_content_intent
*/
public static function fetch_file($token) {
global $DB;
$remoteclient = get_mnet_remote_client();
try {
if (!$transferid = $DB->get_field('portfolio_mahara_queue', 'transferid', array('token' => $token))) {
throw new mnet_server_exception(8009, 'mnet_notoken', 'portfolio_mahara');
}
$exporter = portfolio_exporter::rewaken_object($transferid);
} catch (portfolio_exception $e) {
throw new mnet_server_exception(8010, 'mnet_noid', 'portfolio_mahara');
}
if ($exporter->get('instance')->get_config('mnethostid') != $remoteclient->id) {
throw new mnet_server_exception(8011, 'mnet_wronghost', 'portfolio_mahara');
}
global $CFG;
try {
$i = $exporter->get('instance');
$f = $i->get('file');
if (empty($f) || !($f instanceof stored_file)) {
throw new mnet_server_exception(8012, 'mnet_nofile', 'portfolio_mahara');
}
try {
$c = $f->get_content();
} catch (file_exception $e) {
throw new mnet_server_exception(8013, 'mnet_nofilecontents', 'portfolio_mahara', $e->getMessage());
}
$contents = base64_encode($c);
} catch (Exception $e) {
throw new mnet_server_exception(8013, 'mnet_nofile', 'portfolio_mahara');
}
$exporter->log_transfer();
$exporter->process_stage_cleanup(true);
return $contents;
}
public function cleanup() {
global $DB;
$DB->delete_records('portfolio_mahara_queue', array('transferid' => $this->get('exporter')->get('id'), 'token' => $this->token));
}
/**
* internal helper function, that converts between the format constant,
* which might be too specific (eg 'image') and the class in our *supported* list
* which might be higher up the format hierarchy tree (eg 'file')
*/
private function resolve_format() {
global $CFG;
$thisformat = $this->get_export_config('format');
$allformats = portfolio_supported_formats();
require_once($CFG->libdir . '/portfolio/formats.php');
$thisobj = new $allformats[$thisformat];
foreach ($this->supported_formats() as $f) {
$class = $allformats[$f];
if ($thisobj instanceof $class) {
return $f;
}
}
}
}
+60
View File
@@ -0,0 +1,60 @@
<?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/>.
/**
* This file is the landing point for returning to moodle after authenticating at mahara
*
* @since Moodle 2.0
* @package moodlecore
* @subpackage portfolio
* @copyright 2009 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
if (empty($CFG->enableportfolios)) {
throw new \moodle_exception('disabled', 'portfolio');
}
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/plugin.php');
require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->dirroot . '/mnet/lib.php');
require_login();
$id = required_param('id', PARAM_INT); // id of current export
$landed = optional_param('landed', false, PARAM_BOOL); // this is the parameter we get back after we've jumped to mahara
if (!$landed) {
$exporter = portfolio_exporter::rewaken_object($id);
$exporter->verify_rewaken();
$mnetauth = get_auth_plugin('mnet');
if (!$url = $mnetauth->start_jump_session($exporter->get('instance')->get_config('mnethostid'), '/portfolio/mahara/preconfig.php?landed=1&id=' . $id, true)) {
throw new porfolio_exception('failedtojump', 'portfolio_mahara');
}
redirect($url);
} else {
// now we have the sso session set up, start sending intent stuff and then redirect back to portfolio/add.php when we're done
$exporter = portfolio_exporter::rewaken_object($id);
$exporter->verify_rewaken();
$exporter->get('instance')->send_intent();
redirect($CFG->wwwroot . '/portfolio/add.php?postcontrol=1&sesskey=' . sesskey() . '&id=' . $id);
}
@@ -0,0 +1,47 @@
<?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/>.
/**
* Privacy provider tests.
*
* @package portfolio_mahara
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_mahara\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider tests class.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Verify that a collection of metadata is returned for this component and that it just links to an external location.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('portfolio_mahara');
$collection = \portfolio_mahara\privacy\provider::get_metadata($collection);
$this->assertNotEmpty($collection);
$items = $collection->get_collection();
$this->assertEquals(1, count($items));
$this->assertInstanceOf(\core_privacy\local\metadata\types\external_location::class, $items[0]);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?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/>.
/**
* This file contains the version information for the mahara portfolio plugin
*
* @since Moodle 2.0
* @package portfolio
* @subpackage mahara
* @copyright 2009 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'portfolio_mahara'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
@@ -0,0 +1,158 @@
<?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/>.
namespace core_portfolio\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Unit tests for the Portfolio API's privacy legacy_polyfill.
*
* @package core_portfolio
* @category test
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class legacy_polyfill_test extends \advanced_testcase {
/**
* Test that the core_portfolio\privacy\legacy_polyfill works and that the static _export_portfolio_user_data can be called.
*/
public function test_export_portfolio_user_data(): void {
$userid = 476;
$context = \context_system::instance();
$mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_export_portfolio_user_data', [$userid, $context, [], []]);
test_legacy_polyfill_portfolio_provider::$mock = $mock;
test_legacy_polyfill_portfolio_provider::export_portfolio_user_data($userid, $context, [], []);
}
/**
* Test for _get_metadata shim.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('core_portfolio');
$this->assertSame($collection, test_legacy_polyfill_portfolio_provider::get_metadata($collection));
}
/**
* Test the _delete_portfolio_for_context shim.
*/
public function test_delete_portfolio_for_context(): void {
$context = \context_system::instance();
$mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_delete_portfolio_for_context', [$context]);
test_legacy_polyfill_portfolio_provider::$mock = $mock;
test_legacy_polyfill_portfolio_provider::delete_portfolio_for_context($context);
}
/**
* Test the _delete_portfolio_for_context shim.
*/
public function test_delete_portfolio_for_user(): void {
$userid = 696;
$context = \context_system::instance();
$mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
->method('get_return_value')
->with('_delete_portfolio_for_user', [$userid, $context]);
test_legacy_polyfill_portfolio_provider::$mock = $mock;
test_legacy_polyfill_portfolio_provider::delete_portfolio_for_user($userid, $context);
}
}
/**
* Legacy polyfill test class for the portfolio_provider.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class test_legacy_polyfill_portfolio_provider implements
\core_privacy\local\metadata\provider,
\core_portfolio\privacy\portfolio_provider {
use \core_portfolio\privacy\legacy_polyfill;
use \core_privacy\local\legacy_polyfill;
/**
* @var test_legacy_polyfill_portfolio_provider $mock.
*/
public static $mock = null;
/**
* Export all user data for the portfolio plugin.
*
* @param int $userid
* @param context $context
* @param array $subcontext
* @param array $linkarray
*/
protected static function _export_portfolio_user_data($userid, \context $context, array $subcontext, array $linkarray) {
static::$mock->get_return_value(__FUNCTION__, func_get_args());
}
/**
* Deletes all user data for the given context.
*
* @param context $context
*/
protected static function _delete_portfolio_for_context(\context $context) {
static::$mock->get_return_value(__FUNCTION__, func_get_args());
}
/**
* Delete personal data for the given user and context.
*
* @param int $userid
* @param context $context
*/
protected static function _delete_portfolio_for_user($userid, \context $context) {
static::$mock->get_return_value(__FUNCTION__, func_get_args());
}
/**
* Returns metadata about this plugin.
*
* @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to.
* @return \core_privacy\local\metadata\collection A listing of user data stored through this system.
*/
protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) {
return $collection;
}
}
/**
* Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class test_portfolio_legacy_polyfill_mock_wrapper {
/**
* Get the return value for the specified item.
*/
public function get_return_value() {
}
}
+260
View File
@@ -0,0 +1,260 @@
<?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/>.
/**
* Privacy provider tests.
*
* @package core_portfolio
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_portfolio\privacy;
defined('MOODLE_INTERNAL') || die();
use core_portfolio\privacy\provider;
use core_privacy\local\request\approved_userlist;
/**
* Privacy provider tests class.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
protected function create_portfolio_data($plugin, $name, $user, $preference, $value) {
global $DB;
$portfolioinstance = (object) [
'plugin' => $plugin,
'name' => $name,
'visible' => 1
];
$portfolioinstance->id = $DB->insert_record('portfolio_instance', $portfolioinstance);
$userinstance = (object) [
'instance' => $portfolioinstance->id,
'userid' => $user->id,
'name' => $preference,
'value' => $value
];
$DB->insert_record('portfolio_instance_user', $userinstance);
$DB->insert_record('portfolio_log', [
'portfolio' => $portfolioinstance->id,
'userid' => $user->id,
'caller_class' => 'forum_portfolio_caller',
'caller_component' => 'mod_forum',
'time' => time(),
]);
$DB->insert_record('portfolio_log', [
'portfolio' => $portfolioinstance->id,
'userid' => $user->id,
'caller_class' => 'workshop_portfolio_caller',
'caller_component' => 'mod_workshop',
'time' => time(),
]);
}
/**
* Verify that a collection of metadata is returned for this component and that it just returns the righ types for 'portfolio'.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('core_portfolio');
$collection = provider::get_metadata($collection);
$this->assertNotEmpty($collection);
$items = $collection->get_collection();
$this->assertEquals(4, count($items));
$this->assertInstanceOf(\core_privacy\local\metadata\types\database_table::class, $items[0]);
$this->assertInstanceOf(\core_privacy\local\metadata\types\database_table::class, $items[1]);
$this->assertInstanceOf(\core_privacy\local\metadata\types\database_table::class, $items[2]);
$this->assertInstanceOf(\core_privacy\local\metadata\types\plugintype_link::class, $items[3]);
}
/**
* Test that the export for a user id returns a user context.
*/
public function test_get_contexts_for_userid(): void {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$context = \context_user::instance($user->id);
$this->create_portfolio_data('googledocs', 'Google Docs', $user, 'visible', 1);
$contextlist = provider::get_contexts_for_userid($user->id);
$this->assertEquals($context->id, $contextlist->current()->id);
}
/**
* Test that exporting user data works as expected.
*/
public function test_export_user_data(): void {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$context = \context_user::instance($user->id);
$this->create_portfolio_data('googledocs', 'Google Docs', $user, 'visible', 1);
$contextlist = new \core_privacy\local\request\approved_contextlist($user, 'core_portfolio', [$context->id]);
provider::export_user_data($contextlist);
$writer = \core_privacy\local\request\writer::with_context($context);
$portfoliodata = $writer->get_data([get_string('privacy:path', 'portfolio')]);
$this->assertEquals('Google Docs', $portfoliodata->{'Google Docs'}->name);
}
/**
* Test that deleting only results in the one context being removed.
*/
public function test_delete_data_for_all_users_in_context(): void {
global $DB;
$this->resetAfterTest();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->create_portfolio_data('googledocs', 'Google Docs', $user1, 'visible', 1);
$this->create_portfolio_data('onedrive', 'Microsoft onedrive', $user2, 'visible', 1);
// Check a system context sent through.
$systemcontext = \context_system::instance();
provider::delete_data_for_all_users_in_context($systemcontext);
$records = $DB->get_records('portfolio_instance_user');
$this->assertCount(2, $records);
$this->assertCount(4, $DB->get_records('portfolio_log'));
$context = \context_user::instance($user1->id);
provider::delete_data_for_all_users_in_context($context);
$records = $DB->get_records('portfolio_instance_user');
// Only one entry should remain for user 2.
$this->assertCount(1, $records);
$data = array_shift($records);
$this->assertEquals($user2->id, $data->userid);
$this->assertCount(2, $DB->get_records('portfolio_log'));
}
/**
* Test that deleting only results in one user's data being removed.
*/
public function test_delete_data_for_user(): void {
global $DB;
$this->resetAfterTest();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->create_portfolio_data('googledocs', 'Google Docs', $user1, 'visible', 1);
$this->create_portfolio_data('onedrive', 'Microsoft onedrive', $user2, 'visible', 1);
$records = $DB->get_records('portfolio_instance_user');
$this->assertCount(2, $records);
$this->assertCount(4, $DB->get_records('portfolio_log'));
$context = \context_user::instance($user1->id);
$contextlist = new \core_privacy\local\request\approved_contextlist($user1, 'core_portfolio', [$context->id]);
provider::delete_data_for_user($contextlist);
$records = $DB->get_records('portfolio_instance_user');
// Only one entry should remain for user 2.
$this->assertCount(1, $records);
$data = array_shift($records);
$this->assertEquals($user2->id, $data->userid);
$this->assertCount(2, $DB->get_records('portfolio_log'));
}
/**
* Test that only users with a user context are fetched.
*/
public function test_get_users_in_context(): void {
$this->resetAfterTest();
$component = 'core_portfolio';
// Create a user.
$user = $this->getDataGenerator()->create_user();
$usercontext = \context_user::instance($user->id);
// The list of users should not return anything yet (related data still haven't been created).
$userlist = new \core_privacy\local\request\userlist($usercontext, $component);
provider::get_users_in_context($userlist);
$this->assertCount(0, $userlist);
// Create portfolio data for user.
$this->create_portfolio_data('googledocs', 'Google Docs', $user,
'visible', 1);
// The list of users for user context should return the user.
provider::get_users_in_context($userlist);
$this->assertCount(1, $userlist);
$expected = [$user->id];
$actual = $userlist->get_userids();
$this->assertEquals($expected, $actual);
// The list of users for system context should not return any users.
$systemcontext = \context_system::instance();
$userlist = new \core_privacy\local\request\userlist($systemcontext, $component);
provider::get_users_in_context($userlist);
$this->assertCount(0, $userlist);
}
/**
* Test that data for users in approved userlist is deleted.
*/
public function test_delete_data_for_users(): void {
$this->resetAfterTest();
$component = 'core_portfolio';
// Create user1.
$user1 = $this->getDataGenerator()->create_user();
$usercontext1 = \context_user::instance($user1->id);
// Create user1.
$user2 = $this->getDataGenerator()->create_user();
$usercontext2 = \context_user::instance($user2->id);
// Create portfolio data for user1 and user2.
$this->create_portfolio_data('googledocs', 'Google Docs', $user1,
'visible', 1);
$this->create_portfolio_data('onedrive', 'Microsoft onedrive', $user2,
'visible', 1);
// The list of users for usercontext1 should return user1.
$userlist1 = new \core_privacy\local\request\userlist($usercontext1, $component);
provider::get_users_in_context($userlist1);
$this->assertCount(1, $userlist1);
$expected = [$user1->id];
$actual = $userlist1->get_userids();
$this->assertEquals($expected, $actual);
// The list of users for usercontext2 should return user2.
$userlist2 = new \core_privacy\local\request\userlist($usercontext2, $component);
provider::get_users_in_context($userlist2);
$this->assertCount(1, $userlist2);
$expected = [$user2->id];
$actual = $userlist2->get_userids();
$this->assertEquals($expected, $actual);
// Add userlist1 to the approved user list.
$approvedlist = new approved_userlist($usercontext1, $component, $userlist1->get_userids());
// Delete user data using delete_data_for_user for usercontext1.
provider::delete_data_for_users($approvedlist);
// Re-fetch users in usercontext1 - The user list should now be empty.
$userlist1 = new \core_privacy\local\request\userlist($usercontext1, $component);
provider::get_users_in_context($userlist1);
$this->assertCount(0, $userlist1);
// Re-fetch users in usercontext2 - The user list should not be empty (user2).
$userlist2 = new \core_privacy\local\request\userlist($usercontext2, $component);
provider::get_users_in_context($userlist2);
$this->assertCount(1, $userlist2);
// User data should be only removed in the user context.
$systemcontext = \context_system::instance();
// Add userlist2 to the approved user list in the system context.
$approvedlist = new approved_userlist($systemcontext, $component, $userlist2->get_userids());
// Delete user1 data using delete_data_for_user.
provider::delete_data_for_users($approvedlist);
// Re-fetch users in usercontext2 - The user list should not be empty (user2).
$userlist1 = new \core_privacy\local\request\userlist($usercontext2, $component);
provider::get_users_in_context($userlist1);
$this->assertCount(1, $userlist1);
}
}
+43
View File
@@ -0,0 +1,43 @@
This files describes API changes in /portfolio/ portfolio system,
information provided here is intended especially for developers.
=== 4.0 ===
* The portfolio_boxnet has been completely removed.
* The portfolio_picasa has been completely removed (Picasa is discontinued since 2016).
=== 3.7 ===
* The portfolio_cron() function has been removed. Please use portfolio_cron_task scheduled task instead.
=== 3.1 ===
* The following functions, previously used (exclusively) by upgrade steps are not available
anymore because of the upgrade cleanup performed for this version. See MDL-51580 for more info:
- portfolio_picasa_admin_upgrade_notification()
- portfolio_googledocs_admin_upgrade_notification()
- portfolio_boxnet_admin_upgrade_notification()
=== 2.4 ===
The set_callback_options function's third parameter has been changed from a file path
to the component name - see MDL-33791. However, if any existing code passes a file path
Moodle will attempt to obtain the component name from the file path provided. Also, the
callback class should be located in the module's locallib.php file.
Example of change:
This:
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
Now becomes:
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), 'mod_assignment');
=== 2.3 ===
required changes:
* The following methods must now be declared static for php5 compatibility:
- admin_config_form
- admin_config_validation