ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç PKʢ\5&googledocs/db/upgrade.phpnu[. /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_portfolio_googledocs_upgrade($oldversion) { // 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. // Automatically generated Moodle v4.5.0 release upgrade line. // Put any upgrade step following this. // Automatically generated Moodle v5.0.0 release upgrade line. // Put any upgrade step following this. return true; } PKʢ\W+googledocs/lang/en/portfolio_googledocs.phpnu[. /** * 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'] = '

To use this plugin, you must register your site with Google, as described in the documentation Google OAuth 2.0 setup.

As part of the registration process, you will need to enter the following URL as \'Authorized Redirect URIs\':

{$a->callbackurl}

Once registered, you will be provided with a client ID and secret which can be used to configure all Google Drive plugins.

'; $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'; PKʢ\PG'G'googledocs/lib.phpnu[. /** * Google Documents Portfolio Plugin * * @author Dan Poltawski * @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; } } PKʢ\googledocs/version.phpnu[. /** * 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 = 2025041400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'portfolio_googledocs'; // Full name of the plugin (used for diagnostics). $plugin->cron = 0; PKʢ\Q-G> > 'googledocs/classes/privacy/provider.phpnu[. /** * Privacy class for requesting user data. * * @package portfolio_googledocs * @copyright 2018 Jake Dallimore * @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 * @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) { } } PKʢ\ Tgoogledocs/upgrade.txtnu[=== 4.5 Onwards === This file has been replaced by UPGRADING.md. See MDL-81125 for further information. === 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. PKʢ\Í66*googledocs/tests/privacy/provider_test.phpnu[. /** * Privacy provider tests. * * @package portfolio_googledocs * @copyright 2018 Jake Dallimore * @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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final 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]); } } PKʢ\Iv] googledocs/tests/plugin_test.phpnu[. 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 */ final 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); } } } PKʢ\44 4 #classes/privacy/legacy_polyfill.phpnu[. /** * This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up. * * @package core_portfolio * @copyright 2018 Jake Dallimore * @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 * @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); } } PKʢ\)m33classes/privacy/provider.phpnu[. /** * Privacy class for requesting user data. * * @package core_portfolio * @copyright 2018 Jake Dallimore * @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 * @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); } } PKʢ\C{S S &classes/privacy/portfolio_provider.phpnu[. /** * Privacy class for requesting user data. * * @package core_portfolio * @copyright 2018 Jake Dallimore * @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 * @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); } PKʢ\ eTfile.phpnu[. /** * 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 , * Martin Dougiamas * @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; PKʢ\e upgrade.txtnu[=== 4.5 Onwards === This file has been replaced by UPGRADING.md. See MDL-81125 for further information. === 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 PKʢ\='download/lang/en/portfolio_download.phpnu[. /** * 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.'; PKʢ\S  download/lib.phpnu[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; } } PKʢ\r불download/version.phpnu[. /** * 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 = 2025041400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'portfolio_download'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0; PKʢ\ۈ%download/classes/privacy/provider.phpnu[. /** * Privacy class for requesting user data. * * @package portfolio_download * @copyright 2018 Jake Dallimore * @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 * @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'; } } PKʢ\OBrrdownload/file.phpnu[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('' . get_string('returntowhereyouwere', 'portfolio') . '
'); // 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 '
'; $PAGE->requires->js_amd_inline(" require(['jquery'], function($) { $('#redirectform').submit(function() { $('#redirect').addClass('hide'); }).submit(); });"); echo $OUTPUT->footer(); PKʢ\  UPGRADING.mdnu[# core_portfolio (subsystem / plugintype) Upgrade notes ## 5.0 ### Removed - Removed portfolio_mahara plugin from core For more information see [MDL-84308](https://tracker.moodle.org/browse/MDL-84308) PKʢ\B N11add.phpnu[. /** * This file is the main controller to do with the portfolio export wizard. * * @package core_portfolio * @copyright 2008 Penny Leach , * Martin Dougiamas * @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 . '&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); PKʢ\?w-w-tests/privacy/provider_test.phpnu[. /** * Privacy provider tests. * * @package core_portfolio * @copyright 2018 Jake Dallimore * @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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final 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); } } PKʢ\?R&tests/privacy/legacy_polyfill_test.phpnu[. 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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final 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 * @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 * @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() { } } PKʢ\ݐR" " #flickr/lang/en/portfolio_flickr.phpnu[. /** * 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 apply for a new key. 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:
{$a->callbackurl}
Optionally, you can also provide your Moodle site description and logo. These values can be set later at the page listing your Flickr applications.'; $string['sharedsecret'] = 'Secret string'; $string['title'] = 'Title'; $string['uploadfailed'] = 'Failed to upload image(s) to flickr.com: {$a}'; PKʢ\y155flickr/lib.phpnu[. /** * @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; } } PKʢ\"P/flickr/version.phpnu[. /** * 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 = 2025041400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'portfolio_flickr'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0; PKʢ\ #flickr/classes/privacy/provider.phpnu[. /** * Privacy class for requesting user data. * * @package portfolio_flickr * @copyright 2018 Jake Dallimore * @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 * @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) { } } PKʢ\6&&&flickr/tests/privacy/provider_test.phpnu[. /** * Privacy provider tests. * * @package portfolio_flickr * @copyright 2018 Jake Dallimore * @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 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final 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]); } } PKʢ\5&googledocs/db/upgrade.phpnu[PKʢ\W+googledocs/lang/en/portfolio_googledocs.phpnu[PKʢ\PG'G'googledocs/lib.phpnu[PKʢ\6googledocs/version.phpnu[PKʢ\Q-G> > 'k;googledocs/classes/privacy/provider.phpnu[PKʢ\ THgoogledocs/upgrade.txtnu[PKʢ\Í66*Jgoogledocs/tests/privacy/provider_test.phpnu[PKʢ\Iv] Qgoogledocs/tests/plugin_test.phpnu[PKʢ\44 4 #aclasses/privacy/legacy_polyfill.phpnu[PKʢ\)m33wlclasses/privacy/provider.phpnu[PKʢ\C{S S &Lclasses/privacy/portfolio_provider.phpnu[PKʢ\ eTfile.phpnu[PKʢ\e upgrade.txtnu[PKʢ\='download/lang/en/portfolio_download.phpnu[PKʢ\S  download/lib.phpnu[PKʢ\r불0download/version.phpnu[PKʢ\ۈ%download/classes/privacy/provider.phpnu[PKʢ\OBrrdownload/file.phpnu[PKʢ\  UPGRADING.mdnu[PKʢ\B N11add.phpnu[PKʢ\?w-w-h tests/privacy/provider_test.phpnu[PKʢ\?R&.9tests/privacy/legacy_polyfill_test.phpnu[PKʢ\ݐR" " #Oflickr/lang/en/portfolio_flickr.phpnu[PKʢ\y155[flickr/lib.phpnu[PKʢ\"P/flickr/version.phpnu[PKʢ\ #ƕflickr/classes/privacy/provider.phpnu[PKʢ\6&&&flickr/tests/privacy/provider_test.phpnu[PK