"120988f929-274612", "resource_link_title" => "Weekly Blog", "resource_link_description" => "Each student needs to reflect on the weekly reading. These should be one paragraph long.", "user_id" => "292832126", "roles" => "Instructor", // or Learner "lis_person_name_full" => 'Jane Q. Public', "lis_person_contact_email_primary" => "user@school.edu", "lis_person_sourcedid" => "school.edu:user", "context_id" => "456434513", "context_title" => "Design of Personal Environments", "context_label" => "SI182", ]; return $parms; } function validateDescriptor($descriptor) { $xml = new SimpleXMLElement($xmldata); if (! $xml) { echo("Error parsing Descriptor XML\n"); return; } $launch_url = $xml->secure_launch_url[0]; if (! $launch_url) { $launch_url = $xml->launch_url[0]; } if ($launch_url) { $launch_url = (string) $launch_url; } return $launch_url; } // Parse a descriptor function launchInfo($xmldata) { $xml = new SimpleXMLElement($xmldata); if (! $xml) { echo("Error parsing Descriptor XML\n"); return; } $launch_url = $xml->secure_launch_url[0]; if (! $launch_url) { $launch_url = $xml->launch_url[0]; } if ($launch_url) { $launch_url = (string) $launch_url; } $custom = []; if ($xml->custom[0]->parameter) { foreach ($xml->custom[0]->parameter as $resource) { $key = (string) $resource['key']; $key = strtolower($key); $nk = ""; for ($i = 0; $i < strlen($key); $i++) { $ch = substr($key, $i, 1); if ($ch >= "a" && $ch <= "z") { $nk .= $ch; } elseif ($ch >= "0" && $ch <= "9") { $nk .= $ch; } else { $nk .= "_"; } } $value = (string) $resource; $custom["custom_" . $nk] = $value; } } return ["launch_url" => $launch_url, "custom" => $custom ] ; } function split_custom_parameters($customstr) { $lines = preg_split("/[\n;]/", $customstr); $retval = []; foreach ($lines as $line) { $pos = strpos($line, "="); if ($pos === false || $pos < 1) { continue; } $key = trim(substr($line, 0, $pos)); $val = trim(substr($line, $pos + 1)); $key = map_keyname($key); $retval['custom_' . $key] = $val; } return $retval; } function map_keyname($key) { $newkey = ""; $key = strtolower(trim($key)); foreach (str_split($key) as $ch) { if (($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9')) { $newkey .= $ch; } else { $newkey .= '_'; } } return $newkey; } function signParameters( $oldparms, $endpoint, $method, $oauth_consumer_key, $oauth_consumer_secret, $submit_text = false, $org_id = false, $org_desc = false ) { global $last_base_string; $parms = $oldparms; if (! isset($parms["lti_version"])) { $parms["lti_version"] = "LTI-1p0"; } if (! isset($parms["lti_message_type"])) { $parms["lti_message_type"] = "basic-lti-launch-request"; } if (! isset($parms["oauth_callback"])) { $parms["oauth_callback"] = "about:blank"; } if ($org_id) { $parms["tool_consumer_instance_guid"] = $org_id; } if ($org_desc) { $parms["tool_consumer_instance_description"] = $org_desc; } if ($submit_text) { $parms["ext_submit"] = $submit_text; } $test_token = ''; $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, null); $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms); $acc_req->sign_request($hmac_method, $test_consumer, $test_token); // Pass this back up "out of band" for debugging $last_base_string = $acc_req->get_signature_base_string(); $newparms = $acc_req->get_parameters(); return $newparms; } function signOnly($oldparms, $endpoint, $method, $oauth_consumer_key, $oauth_consumer_secret) { global $last_base_string; $parms = $oldparms; $test_token = ''; $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, null); $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms); $acc_req->sign_request($hmac_method, $test_consumer, $test_token); // Pass this back up "out of band" for debugging $last_base_string = $acc_req->get_signature_base_string(); $newparms = $acc_req->get_parameters(); return $newparms; } function postLaunchHTML($newparms, $endpoint, $debug = false, $iframeattr = false) { global $last_base_string; $r = "
\n"; if ($iframeattr) { $r = "
\n" ; } else { $r = "\n" ; } $submit_text = $newparms['ext_submit']; foreach ($newparms as $key => $value) { $key = htmlspecialchars($key); $value = htmlspecialchars($value); if ($key == "ext_submit") { $r .= "\n"; } if ($debug) { $r .= "\n"; $r .= ""; $r .= get_string("toggle_debug_data", "basiclti") . "\n"; $r .= "
\n"; $r .= "" . get_string("basiclti_endpoint", "basiclti") . "
\n"; $r .= $endpoint . "
\n 
\n"; $r .= "" . get_string("basiclti_parameters", "basiclti") . "
\n"; foreach ($newparms as $key => $value) { $key = htmlspecialchars($key); $value = htmlspecialchars($value); $r .= "$key = $value
\n"; } $r .= " 
\n"; $r .= "

" . get_string("basiclti_base_string", "basiclti") . "
\n" . $last_base_string . "

\n"; $r .= "
\n"; } $r .= "
\n"; if ($iframeattr) { $r .= "\n"; } if (! $debug) { $ext_submit = "ext_submit"; $ext_submit_text = $submit_text; $r .= " \n"; } $r .= "
\n"; return $r; } /* This is a bit of homage to Moodle's pattern of internationalisation */ function get_string($key, $bundle) { return $key; } function do_post_request($url, $data, $optional_headers = null) { $params = ['http' => [ 'method' => 'POST', 'content' => $data ]]; if ($optional_headers !== null) { $header = $optional_headers . "\r\n"; } // $header = $header . "Content-type: application/x-www-form-urlencoded\r\n"; $params['http']['header'] = $header; $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; }