From 795dff011f8a671375742df1bbd009be6043d0b8 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Wed, 21 Sep 2011 09:52:37 -0400 Subject: [PATCH] Updates to get the plugin to work side-by-side with the basicLTI plugin --- mod/lti/OAuth.php | 6 ++- mod/lti/OAuthBody.php | 2 + mod/lti/TrivialStore.php | 2 + mod/lti/locallib.php | 89 ++++++++++++++++++++++++++++++++++++++-- mod/lti/servicelib.php | 4 +- mod/lti/settings.php | 81 ------------------------------------ 6 files changed, 97 insertions(+), 87 deletions(-) diff --git a/mod/lti/OAuth.php b/mod/lti/OAuth.php index 9c9d9637818..47bb8cddf8f 100644 --- a/mod/lti/OAuth.php +++ b/mod/lti/OAuth.php @@ -54,13 +54,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace moodle\mod\lti;//Using a namespace as the basicLTI module imports classes with the same names + defined('MOODLE_INTERNAL') || die; $oauth_last_computed_signature = false; /* Generic exception class */ -class OAuthException extends Exception { +class OAuthException extends \Exception { // pass } @@ -704,7 +706,7 @@ class OAuthUtil { public static function urlencode_rfc3986($input) { if (is_array($input)) { return array_map(array( - 'OAuthUtil', + 'moodle\mod\lti\OAuthUtil', 'urlencode_rfc3986' ), $input); } else { diff --git a/mod/lti/OAuthBody.php b/mod/lti/OAuthBody.php index 757bbf0ad17..514a99957dc 100644 --- a/mod/lti/OAuthBody.php +++ b/mod/lti/OAuthBody.php @@ -54,6 +54,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace moodle\mod\lti;//Using a namespace as the basicLTI module imports classes with the same names + require_once($CFG->dirroot . '/mod/lti/OAuth.php'); require_once($CFG->dirroot . '/mod/lti/TrivialStore.php'); diff --git a/mod/lti/TrivialStore.php b/mod/lti/TrivialStore.php index 88940932b0f..afe686c3b8f 100644 --- a/mod/lti/TrivialStore.php +++ b/mod/lti/TrivialStore.php @@ -58,6 +58,8 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 */ +namespace moodle\mod\lti;//Using a namespace as the basicLTI module imports classes with the same names + defined('MOODLE_INTERNAL') || die; /** diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index ac025422c95..60162b3b580 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -47,6 +47,8 @@ defined('MOODLE_INTERNAL') || die; +use moodle\mod\lti as lti; + require_once($CFG->dirroot.'/mod/lti/OAuth.php'); define('LTI_URL_DOMAIN_REGEX', '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'); @@ -240,6 +242,87 @@ function lti_build_request($instance, $typeconfig, $course) { return $requestparams; } +function lti_get_tool_table($tools, $id){ + global $CFG, $USER; + $html = ''; + + $typename = get_string('typename', 'lti'); + $baseurl = get_string('baseurl', 'lti'); + $action = get_string('action', 'lti'); + $createdon = get_string('createdon', 'lti'); + + if($id == 'lti_configured'){ + $html .= '
'.get_string('addtype', 'lti').'
'; + } + + if (!empty($tools)) { + $html .= << + + + + + + + + + +HTML; + + foreach ($tools as $type) { + $date = userdate($type->timecreated); + $accept = get_string('accept', 'lti'); + $update = get_string('update', 'lti'); + $delete = get_string('delete', 'lti'); + + $accepthtml = << + {$accept} + +HTML; + + $deleteaction = 'delete'; + + if($type->state == LTI_TOOL_STATE_CONFIGURED){ + $accepthtml = ''; + } + + if($type->state != LTI_TOOL_STATE_REJECTED) { + $deleteaction = 'reject'; + $delete = get_string('reject', 'lti'); + } + + $html .= << + + + + + +HTML; + } + $html .= '
$typename$baseurl$createdon$action
+ {$type->name} + + {$type->baseurl} + + {$date} + + {$accepthtml} + + {$update} + + + {$delete} + +
'; + } else { + $html .= get_string('no_' . $id, 'lti'); + } + + return $html; +} + /** * Splits the custom parameters field to the various parameters * @@ -823,10 +906,10 @@ function lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $ $testtoken = ''; - $hmacmethod = new OAuthSignatureMethod_HMAC_SHA1(); - $testconsumer = new OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); + $hmacmethod = new lti\OAuthSignatureMethod_HMAC_SHA1(); + $testconsumer = new lti\OAuthConsumer($oauthconsumerkey, $oauthconsumersecret, null); - $accreq = OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms); + $accreq = lti\OAuthRequest::from_consumer_and_token($testconsumer, $testtoken, $method, $endpoint, $parms); $accreq->sign_request($hmacmethod, $testconsumer, $testtoken); // Pass this back up "out of band" for debugging diff --git a/mod/lti/servicelib.php b/mod/lti/servicelib.php index e913aee762e..b3a61682d44 100644 --- a/mod/lti/servicelib.php +++ b/mod/lti/servicelib.php @@ -2,6 +2,8 @@ require_once($CFG->dirroot.'/mod/lti/OAuthBody.php'); +use moodle\mod\lti as lti; + define('LTI_ITEM_TYPE', 'mod'); define('LTI_ITEM_MODULE', 'lti'); define('LTI_SOURCE', 'mod/lti'); @@ -150,7 +152,7 @@ function lti_verify_message($ltiinstance, $body, $headers = null){ $secret = $ltiinstance->password; } - handleOAuthBodyPOST($key, $secret, $body, $headers); + lti\handleOAuthBodyPOST($key, $secret, $body, $headers); } function lti_verify_sourcedid($ltiinstance, $parsed){ diff --git a/mod/lti/settings.php b/mod/lti/settings.php index 04331e5bcf5..81940c369d6 100644 --- a/mod/lti/settings.php +++ b/mod/lti/settings.php @@ -51,87 +51,6 @@ global $PAGE, $CFG, $SITE; require_once($CFG->dirroot.'/mod/lti/locallib.php'); -function lti_get_tool_table($tools, $id){ - global $CFG, $USER; - $html = ''; - - $typename = get_string('typename', 'lti'); - $baseurl = get_string('baseurl', 'lti'); - $action = get_string('action', 'lti'); - $createdon = get_string('createdon', 'lti'); - - if($id == 'lti_configured'){ - $html .= '
'.get_string('addtype', 'lti').'
'; - } - - if (!empty($tools)) { - $html .= << - - - - - - - - - -HTML; - - foreach ($tools as $type) { - $date = userdate($type->timecreated); - $accept = get_string('accept', 'lti'); - $update = get_string('update', 'lti'); - $delete = get_string('delete', 'lti'); - - $accepthtml = << - {$accept} - -HTML; - - $deleteaction = 'delete'; - - if($type->state == LTI_TOOL_STATE_CONFIGURED){ - $accepthtml = ''; - } - - if($type->state != LTI_TOOL_STATE_REJECTED) { - $deleteaction = 'reject'; - $delete = get_string('reject', 'lti'); - } - - $html .= << - - - - - -HTML; - } - $html .= '
$typename$baseurl$createdon$action
- {$type->name} - - {$type->baseurl} - - {$date} - - {$accepthtml} - - {$update} - - - {$delete} - -
'; - } else { - $html .= get_string('no_' . $id, 'lti'); - } - - return $html; -} - if ($ADMIN->fulltree) { $configuredtoolshtml = ''; $pendingtoolshtml = '';