echo "Running test...\n"; // Run though all the locations // var_dump($LOCATIONS); $url = LTIX::curPageUrlScript(); $i = 500; foreach ($LOCATIONS as $key => $location) { // echo(htmlentities($location)."\n"); $api_url = str_replace('geo_test.php', 'data/geojson', $url); $sample_url = $api_url . '?sensor=false&address=' . urlencode($location); $sample_data = Net::doGet($sample_url); $sample_count = strlen($sample_data); $response = Net::getLastHttpResponse(); $sample_json = json_decode($sample_data); if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) { echo "*** Bad response={$response} url={$sample_url} json_error=" . json_last_error_msg() . "\n"; echo jsonIndent($sample_data); continue; } // echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n"); if (!isset($sample_json->results[0]->place_id)) { echo "*** Could not find place_id {$location}\n"; // echo(jsonIndent($sample_data)); continue; } $sample_place = $sample_json->results[0]->place_id; echo "location={$location} place={$sample_place}\n"; if ($i-- < 1) { break; } } echo "</pre>\n";
$_SESSION['error'] = $stmt->errorImplode; header('Location: ' . addSession('configure.php')); } return; } // Load up the assignment $row = loadAssignment($LTI); $json = ""; if ($row !== false) { $json = $row['json']; } // Clean up the JSON for presentation if (strlen($json) < 1) { $json = getDefaultJson(); } $json = jsonIndent($json); // View $OUTPUT->header(); $OUTPUT->bodyStart(); $OUTPUT->flashMessages(); if (!$USER->instructor) { die("Requires instructor role"); } ?> <p>Be careful in making any changes if this assignment has submissions.</p> <p> The assignment is configured by carefully editing the json below without introducing syntax errors. Someday this will have a slick configuration screen but for now we edit the json. I borrowed this user interface from the early days of Coursera configuration screens :). See the instructions below for detail on how to configure the assignment
/** * Send setings data using the JSON protocol from IMS LTI 2.x * * @param debug_log This can either be false or an empty array. If * this is an array, it is filled with data as the steps progress. * Each step is an array with a string message as the first element * and optional debug detail (i.e. like a post body) as the second * element. * * @return mixed If things go well this returns true. * If this goes badly, this returns a string with an error message. */ public static function sendJSONSettings($settings, $settings_url, $key_key, $secret, &$debug_log = false) { $content_type = "application/vnd.ims.lti.v2.toolsettings.simple+json"; if (is_array($debug_log)) { $debug_log[] = array('Sending ' . count($settings) . ' settings to settings_url=' . $settings_url); } // Make sure everything is a string $sendsettings = array(); foreach ($settings as $k => $v) { $sendsettings[$k] = "" . $v; } $postBody = jsonIndent(json_encode($sendsettings)); if (is_array($debug_log)) { $debug_log[] = array('Settings JSON Request', $postBody); } $response = self::sendOAuthBody("PUT", $settings_url, $key_key, $secret, $content_type, $postBody); if (is_array($debug_log)) { $debug_log[] = array('Settings JSON Response', $response); } global $LastOAuthBodyBaseString; $lbs = $LastOAuthBodyBaseString; if (is_array($debug_log)) { $debug_log[] = array('Our base string', $lbs); } // TODO: Be better at error checking... return true; }
<?php require_once "../../config.php"; require_once $CFG->dirroot . "/pdo.php"; require_once $CFG->dirroot . "/lib/lms_lib.php"; use Tsugi\Core\LTIX; use Tsugi\Util\LTI; use Tsugi\Util\Mersenne_Twister; require_once "sql_util.php"; $LTI = LTIX::requireData(); // Compute the stuff for the output $code = $USER->id + $LINK->id + $CONTEXT->id; header('Content-Disposition: attachment; filename="roster_data.json"'); header('Content-Type: application/json; charset=utf-8'); $roster = makeRoster($code); echo jsonIndent(json_encode($roster));
$ack = false; if ($re_register) { $ack = bin2hex(openssl_random_pseudo_bytes(10)); } // Lets register! $OUTPUT->togglePre("Registration Request", htmlent_utf8($body)); $more_headers = array(); if ($ack !== false) { $more_headers[] = 'VND-IMS-CONFIRM-URL: ' . $CFG->wwwroot . '/lti/tp_commit.php?commit=' . urlencode($ack); } $response = LTI::sendOAuthBody("POST", $register_url, $reg_key, $reg_password, "application/vnd.ims.lti.v2.toolproxy+json", $body, $more_headers, $hmac256); $OUTPUT->togglePre("Registration Request Headers", htmlent_utf8(Net::getBodySentDebug())); global $LastOAuthBodyBaseString; $OUTPUT->togglePre("Registration Request Base String", $LastOAuthBodyBaseString); $OUTPUT->togglePre("Registration Response Headers", htmlent_utf8(Net::getBodyReceivedDebug())); $OUTPUT->togglePre("Registration Response", htmlent_utf8(jsonIndent($response))); // Parse the response object and update the shared_secret if needed $responseObject = json_decode($response); if ($responseObject != null) { $tc_tool_proxy_guid = $responseObject->tool_proxy_guid; if ($tc_tool_proxy_guid) { $oauth_consumer_key = $tc_tool_proxy_guid; echo '<p>Tool consumer returned tool_proxy_guid=' . $tc_tool_proxy_guid . " (using as oauth_consumer_key)</p>\n"; if ($tool_proxy_guid && $tool_proxy_guid != $tc_tool_proxy_guid) { echo '<p style="color: yellow;">Note: Returned tool_proxy_guid did not match launch oauth_consumer_key/tool_proxy_guid=' . $tool_proxy_guid . "</p>\n"; } } else { echo '<p style="color: red;">Error: Tool Consumer did not include tool_proxy_guid in its response.</p>' . "\n"; } if ($oauth_splitsecret && $shared_secret) { if (!isset($responseObject->tc_half_shared_secret)) {
} // Must retrieve the information $getUrl = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($address); $data = Net::doGet($getUrl); $response = Net::getLastHttpResponse(); $json_data = json_decode($data); if ($json_data == null) { error_log("JSON error from Google for {$address}: " . json_last_error_msg()); error_log($data); } // If there is a problem and we have cache even if expired, use cached copy if ($json_data == null || $response != 200) { if ($json_content != null) { error_log("Error {$response} on {$getUrl} - cached copy used"); echo jsonIndent(json_encode($json_content)); return; } error_log("Error {$response} on {$getUrl}"); http_response_code($response); $retval = array('error' => 'Failure to connect to Google', "url" => $getUrl, "response" => $response, "data" => $data); echo jsonIndent(json_encode($retval)); return; } $PDOX->queryDie("INSERT INTO {$p}pydata_geo \n (geo_key, geo_sha256, json_content, created_at, updated_at) VALUES \n ( :KEY, :SHA, :JSON, NOW(), NOW() )\n ON DUPLICATE KEY\n UPDATE json_content = :JSON, updated_at = NOW()", array(':SHA' => $address_sha256, ':KEY' => $address, ':JSON' => jsonIndent(json_encode($json_data)))); if ($json_content != null) { error_log("Updated cache for {$address} updated_at={$updated_at}"); } else { error_log("Inserted {$address} into cache"); } echo jsonIndent(json_encode($json_data)) . "\n";
if (!isset($_SESSION['html_data'])) { return; } $data = $_SESSION['html_data']; unset($_SESSION['html_data']); echo "<pre>\n"; echo "Input HTML\n"; echo htmlentities($data); echo "\n"; // First validate using // https://github.com/validator/validator/wiki/Service:-Input:-POST-body $validator = 'https://validator.w3.org/nu/?out=json&parser=html5'; echo "Calling the validator {$validator} ... \n"; $return = Net::doBody($validator, "POST", $data, 'Content-type: text/html; charset=utf-8'); echo "Validator Output:\n"; echo htmlentities(jsonIndent($return)); if ($return . length > 0) { echo "Your code did not validate. Please return to the W3 validator at validator.w3.org to check your code."; } else { echo $data; $dom = new DOMDocument(); @$dom->loadHTML($data); print "First check that major components are there.\n" . '<br>'; try { $nodes = $dom->getElementsByTagName('html'); if ($nodes->length == 1) { print "Found html tag!\n" . '<br>'; print "...making sure English language is specified!" . '<br>'; foreach ($nodes as $p) { if ($p->getAttribute('lang') === "en") { print "...Found it!!\n" . '<br>';
} else { $arr['note'] = "This file contains the actual data for your assignment</note>"; } $new = getShuffledNames($code); $nums = getRandomNumbers($code, min(50, count($new)), 100); $data = array(); for ($i = 0; $i < count($nums); $i++) { $data[$new[$i]] = $nums[$i]; } arsort($data); $comments = array(); foreach ($data as $k => $v) { $comments[] = array('name' => $k, 'count' => $v); } $arr['comments'] = $comments; echo jsonIndent(json_encode($arr)); return; } else { if (strpos($local_path, "known_by_") === 0) { header('Content-Type: text/html'); $code = 12345; $name = $NAMES[0]; $pieces = preg_split('/[_.]/', $local_path); if (count($pieces) == 4) { $where = array_search($pieces[2], $NAMES); if ($where !== false) { $name = $NAMES[$where]; $code = $where; } else { $name = $pieces[2]; $code = 12345;
<?php require_once "../../../config.php"; require_once $CFG->dirroot . "/lib/lms_lib.php"; require_once "../locations.php"; $address = isset($_GET['address']) ? $_GET['address'] : false; header('Content-Type: application/json; charset=utf-8'); if ($address === false) { sort($LOCATIONS); echo jsonIndent(json_encode($LOCATIONS)); return; } $where = array_search($address, $LOCATIONS); if ($where === false) { http_response_code(400); $retval = array('error' => 'Address not found in the list of available locations', 'locations' => $LOCATIONS); echo jsonIndent(json_encode($retval)); return; } // Check to see if we already have this in the variable if ($GEODATA !== false) { echo $GEODATA[$address]; return; } lmsDie("DIE: Data failure - please contact the instructor");