Skip to content

Commit

Permalink
Merge branch 'MDL-49185-master' of git://github.com/lameze/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 7, 2015
2 parents 6bf2e10 + 01f38dd commit cc623a3
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions mod/lti/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* @author Jordi Piguillem
* @author Nikolas Galanis
* @author Chris Scribner
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand Down Expand Up @@ -278,7 +280,7 @@ function lti_register($toolproxy) {
$requestparams['tc_profile_url'] = $profileservice->parse_value('$ToolConsumerProfile.url');

// Add the return URL.
$returnurlparams = array('id' => $toolproxy->id, 'sesskey'=>sesskey());
$returnurlparams = array('id' => $toolproxy->id, 'sesskey' => sesskey());
$url = new \moodle_url('/mod/lti/registrationreturn.php', $returnurlparams);
$returnurl = $url->out(false);

Expand Down Expand Up @@ -509,11 +511,13 @@ function lti_build_custom_parameters($toolproxy, $tool, $instance, $params, $cus
}
if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] != LTI_SETTING_NEVER) {
if ($instructorcustomstr) {
$custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params, $instructorcustomstr, $islti2), $custom);
$custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params,
$instructorcustomstr, $islti2), $custom);
}
}
if ($islti2) {
$custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params, $tool->parameter, true), $custom);
$custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params,
$tool->parameter, true), $custom);
$settings = lti_get_tool_settings($tool->toolproxyid);
$custom = array_merge($custom, lti_get_custom_parameters($toolproxy, $tool, $params, $settings));
$settings = lti_get_tool_settings($tool->toolproxyid, $instance->course);
Expand Down Expand Up @@ -725,6 +729,39 @@ function lti_get_tool_proxy_table($toolproxies, $id) {
return $html;
}

/**
* Extracts the enabled capabilities into an array, including those implicitly declared in a parameter
*
* @param object $tool Tool instance object
*
* @return Array of enabled capabilities
*/
function lti_get_enabled_capabilities($tool) {
if (!empty($tool->enabledcapability)) {
$enabledcapabilities = explode("\n", $tool->enabledcapability);
} else {
$enabledcapabilities = array();
}
$paramstr = str_replace("\r\n", "\n", $tool->parameter);
$paramstr = str_replace("\n\r", "\n", $paramstr);
$paramstr = str_replace("\r", "\n", $paramstr);
$params = explode("\n", $paramstr);
foreach ($params as $param) {
$pos = strpos($param, '=');
if (($pos === false) || ($pos < 1)) {
continue;
}
$value = trim(core_text::substr($param, $pos + 1, strlen($param)));
if (substr($value, 0, 1) == '$') {
$value = substr($value, 1);
if (!in_array($value, $enabledcapabilities)) {
$enabledcapabilities[] = $value;
}
}
}
return $enabledcapabilities;
}

/**
* Splits the custom parameters field to the various parameters
*
Expand All @@ -743,7 +780,7 @@ function lti_split_custom_parameters($toolproxy, $tool, $params, $customstr, $is
$lines = explode("\n", $customstr); // Or should this split on "/[\n;]/"?
$retval = array();
foreach ($lines as $line) {
$pos = strpos($line, "=");
$pos = strpos($line, '=');
if ( $pos === false || $pos < 1 ) {
continue;
}
Expand Down Expand Up @@ -801,7 +838,7 @@ function lti_parse_custom_parameter($toolproxy, $tool, $params, $value, $islti2)
$value = substr($value, 1);
} else if (substr($value, 0, 1) == '$') {
$value1 = substr($value, 1);
$enabledcapabilities = explode("\n", $tool->enabledcapability);
$enabledcapabilities = lti_get_enabled_capabilities($tool);
if (!$islti2 || in_array($value1, $enabledcapabilities)) {
$capabilities = lti_get_capabilities();
if (array_key_exists($value1, $capabilities)) {
Expand Down

0 comments on commit cc623a3

Please sign in to comment.