/** * Prints a Basic LTI activity * * $param int $basicltiid Basic LTI activity id */ function lti_view($instance) { global $PAGE, $CFG; if (empty($instance->typeid)) { $tool = lti_get_tool_by_url_match($instance->toolurl, $instance->course); if ($tool) { $typeid = $tool->id; } else { $typeid = null; } } else { $typeid = $instance->typeid; } if ($typeid) { $typeconfig = lti_get_type_config($typeid); } else { //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. $typeconfig = (array)$instance; $typeconfig['sendname'] = $instance->instructorchoicesendname; $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; $typeconfig['customparameters'] = $instance->instructorcustomparameters; $typeconfig['acceptgrades'] = $instance->instructorchoiceacceptgrades; $typeconfig['allowroster'] = $instance->instructorchoiceallowroster; $typeconfig['forcessl'] = '0'; } //Default the organizationid if not specified if (empty($typeconfig['organizationid'])) { $urlparts = parse_url($CFG->wwwroot); $typeconfig['organizationid'] = $urlparts['host']; } if (!empty($instance->resourcekey)) { $key = $instance->resourcekey; } else if (!empty($typeconfig['resourcekey'])) { $key = $typeconfig['resourcekey']; } else { $key = ''; } if (!empty($instance->password)) { $secret = $instance->password; } else if (!empty($typeconfig['password'])) { $secret = $typeconfig['password']; } else { $secret = ''; } $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; $endpoint = trim($endpoint); //If the current request is using SSL and a secure tool URL is specified, use it if (lti_request_is_using_ssl() && !empty($instance->securetoolurl)) { $endpoint = trim($instance->securetoolurl); } //If SSL is forced, use the secure tool url if specified. Otherwise, make sure https is on the normal launch URL. if ($typeconfig['forcessl'] == '1') { if (!empty($instance->securetoolurl)) { $endpoint = trim($instance->securetoolurl); } $endpoint = lti_ensure_url_is_https($endpoint); } else { if (!strstr($endpoint, '://')) { $endpoint = 'http://' . $endpoint; } } $orgid = $typeconfig['organizationid']; $course = $PAGE->course; $requestparams = lti_build_request($instance, $typeconfig, $course); $launchcontainer = lti_get_launch_container($instance, $typeconfig); $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id); if ( $orgid ) { $requestparams["tool_consumer_instance_guid"] = $orgid; } if (empty($key) || empty($secret)) { $returnurlparams['unsigned'] = '1'; //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns $url = new moodle_url('/mod/lti/return.php', $returnurlparams); $returnurl = $url->out(false); if ($typeconfig['forcessl'] == '1') { $returnurl = lti_ensure_url_is_https($returnurl); } $requestparams['launch_presentation_return_url'] = $returnurl; } if (!empty($key) && !empty($secret)) { $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret); } else { //If no key and secret, do the launch unsigned. $parms = $requestparams; } $debuglaunch = ( $instance->debuglaunch == 1 ); $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); echo $content; }
/** * Prepares an LTI registration request message * * $param object $instance Tool Proxy instance object */ function lti_register($toolproxy) { $endpoint = $toolproxy->regurl; // Change the status to pending. $toolproxy->state = LTI_TOOL_PROXY_STATE_PENDING; lti_update_tool_proxy($toolproxy); $requestparams = lti_build_registration_request($toolproxy); $content = lti_post_launch_html($requestparams, $endpoint, false); echo $content; }
/** * Prints a Basic LTI activity * * $param int $basicltiid Basic LTI activity id */ function lti_view($instance) { global $PAGE, $CFG; if (empty($instance->typeid)) { $tool = lti_get_tool_by_url_match($instance->toolurl, $instance->course); if ($tool) { $typeid = $tool->id; } else { $typeid = null; } } else { $typeid = $instance->typeid; } if ($typeid) { $typeconfig = lti_get_type_config($typeid); } else { //There is no admin configuration for this tool. Use configuration in the lti instance record plus some defaults. $typeconfig = (array) $instance; $typeconfig['sendname'] = $instance->instructorchoicesendname; $typeconfig['sendemailaddr'] = $instance->instructorchoicesendemailaddr; $typeconfig['customparameters'] = $instance->instructorcustomparameters; $typeconfig['acceptgrades'] = $instance->instructorchoiceacceptgrades; $typeconfig['allowroster'] = $instance->instructorchoiceallowroster; $typeconfig['forcessl'] = '0'; } //Default the organizationid if not specified if (empty($typeconfig['organizationid'])) { $urlparts = parse_url($CFG->wwwroot); $typeconfig['organizationid'] = $urlparts['host']; } if (!empty($instance->resourcekey)) { $key = $instance->resourcekey; } else { if (!empty($typeconfig['resourcekey'])) { $key = $typeconfig['resourcekey']; } else { $key = ''; } } if (!empty($instance->password)) { $secret = $instance->password; } else { if (!empty($typeconfig['password'])) { $secret = $typeconfig['password']; } else { $secret = ''; } } $endpoint = !empty($instance->toolurl) ? $instance->toolurl : $typeconfig['toolurl']; $endpoint = trim($endpoint); //If the current request is using SSL and a secure tool URL is specified, use it if (lti_request_is_using_ssl() && !empty($instance->securetoolurl)) { $endpoint = trim($instance->securetoolurl); } //If SSL is forced, use the secure tool url if specified. Otherwise, make sure https is on the normal launch URL. if ($typeconfig['forcessl'] == '1') { if (!empty($instance->securetoolurl)) { $endpoint = trim($instance->securetoolurl); } $endpoint = lti_ensure_url_is_https($endpoint); } else { if (!strstr($endpoint, '://')) { $endpoint = 'http://' . $endpoint; } } $orgid = $typeconfig['organizationid']; $course = $PAGE->course; $requestparams = lti_build_request($instance, $typeconfig, $course, $typeid); $launchcontainer = lti_get_launch_container($instance, $typeconfig); $returnurlparams = array('course' => $course->id, 'launch_container' => $launchcontainer, 'instanceid' => $instance->id); if ($orgid) { $requestparams["tool_consumer_instance_guid"] = $orgid; } if (!empty($CFG->mod_lti_institution_name)) { $requestparams['tool_consumer_instance_name'] = $CFG->mod_lti_institution_name; } else { $requestparams['tool_consumer_instance_name'] = get_site()->fullname; } if (empty($key) || empty($secret)) { $returnurlparams['unsigned'] = '1'; } // Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns. $url = new moodle_url('/mod/lti/return.php', $returnurlparams); $returnurl = $url->out(false); if ($typeconfig['forcessl'] == '1') { $returnurl = lti_ensure_url_is_https($returnurl); } $target = null; switch ($launchcontainer) { case LTI_LAUNCH_CONTAINER_EMBED: case LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS: $target = 'iframe'; break; case LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW: $target = 'frame'; break; case LTI_LAUNCH_CONTAINER_WINDOW: $target = 'window'; break; } if (!is_null($target)) { $requestparams['launch_presentation_document_target'] = $target; } $requestparams['launch_presentation_return_url'] = $returnurl; // Allow request params to be updated by sub-plugins. $plugins = core_component::get_plugin_list('ltisource'); foreach (array_keys($plugins) as $plugin) { $pluginparams = component_callback('ltisource_' . $plugin, 'before_launch', array($instance, $endpoint, $requestparams), array()); if (!empty($pluginparams) && is_array($pluginparams)) { $requestparams = array_merge($requestparams, $pluginparams); } } if (!empty($key) && !empty($secret)) { $parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret); $endpointurl = new moodle_url($endpoint); $endpointparams = $endpointurl->params(); // Strip querystring params in endpoint url from $parms to avoid duplication. if (!empty($endpointparams) && !empty($parms)) { foreach (array_keys($endpointparams) as $paramname) { if (isset($parms[$paramname])) { unset($parms[$paramname]); } } } } else { //If no key and secret, do the launch unsigned. $parms = $requestparams; } $debuglaunch = $instance->debuglaunch == 1; $content = lti_post_launch_html($parms, $endpoint, $debuglaunch); echo $content; }
/** * Prepares an LTI registration request message * * $param object $instance Tool Proxy instance object */ function lti_register($toolproxy) { global $PAGE, $CFG; $key = $toolproxy->guid; $secret = $toolproxy->secret; $endpoint = $toolproxy->regurl; $requestparams = array(); $requestparams['lti_message_type'] = 'ToolProxyRegistrationRequest'; $requestparams['lti_version'] = 'LTI-2p0'; $requestparams['reg_key'] = $key; $requestparams['reg_password'] = $secret; // Change the status to pending. $toolproxy->state = LTI_TOOL_PROXY_STATE_PENDING; lti_update_tool_proxy($toolproxy); // Add the profile URL. $profileservice = lti_get_service_by_name('profile'); $profileservice->set_tool_proxy($toolproxy); $requestparams['tc_profile_url'] = $profileservice->parse_value('$ToolConsumerProfile.url'); // Add the return URL. $returnurlparams = array('id' => $toolproxy->id, 'sesskey' => sesskey()); $url = new \moodle_url('/mod/lti/registrationreturn.php', $returnurlparams); $returnurl = $url->out(false); $requestparams['launch_presentation_return_url'] = $returnurl; $content = lti_post_launch_html($requestparams, $endpoint, false); echo $content; }
// You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Handle sending a user to a tool provider to initiate a content-item selection. * * @package mod_lti * @copyright 2015 Vital Source Technologies http://vitalsource.com * @author Stephen Vickers * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once '../../config.php'; require_once $CFG->dirroot . '/mod/lti/lib.php'; require_once $CFG->dirroot . '/mod/lti/locallib.php'; $id = required_param('id', PARAM_INT); $courseid = required_param('course', PARAM_INT); $title = optional_param('title', '', PARAM_TEXT); $text = optional_param('text', '', PARAM_RAW); // Check access and capabilities. $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); require_login($course); $context = context_course::instance($courseid); require_capability('moodle/course:manageactivities', $context); require_capability('mod/lti:addcoursetool', $context); // Set the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns. $returnurlparams = ['course' => $course->id, 'id' => $id, 'sesskey' => sesskey()]; $returnurl = new \moodle_url('/mod/lti/contentitem_return.php', $returnurlparams); // Prepare the request. $request = lti_build_content_item_selection_request($id, $course, $returnurl, $title, $text, [], []); // Get the launch HTML. $content = lti_post_launch_html($request->params, $request->url, false); echo $content;