diff --git a/LTI-Launch-settings.jpg b/LTI-Launch-settings.jpg
new file mode 100644
index 0000000..6d4abb6
Binary files /dev/null and b/LTI-Launch-settings.jpg differ
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6b2ff0c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,53 @@
+An LTI-compatible launching plugin for Wordpress, updated to work with https://www.cengage.uk/
+
+General Wordpress plugin installation instructions can be found here: http://codex.wordpress.org/Managing_Plugins#Automatic_Plugin_Installation
+
+### Using shortcodes:
+
+After installing the plugin, add content launching with the [lti-launch]
+shortcode.
+
+
+Some examples:
+
+ [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=iframe configuration_url=http://launcher.saltbox.com/lms/configuration resource_link_id=testcourseplacement1]
+
+ [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=newwindow action=link configuration_url=http://launcher.saltbox.com/lms/configuration resource_link_id=testcourseplacement1]
+
+ [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=self action=button launch_url=http://launcher.saltbox.com/launch resource_link_id=testcourseplacement1]
+
+
+Options:
+
+- display
+
+ - newwindow: launches into a new window
+
+ - self: launches into the same window, replacing the current content
+
+ - iframe: launches into an iframe embedded in the content
+
+- action
+
+ - button: shows a button to the user, which they click on to launch
+
+ - link: shows a link to the user, which they click on to launch
+
+- configuration_url: the URL to the launch XML configuration
+
+- launch_url: The launch URL of the LTI-compatible tool
+
+
+Caution! Since shortcodes are visible to content viewers if their plugin is
+disabled, OAuth secret keys will become visible if this plugin is disabled.
+
+### Using TLI Content - Launch Settings:
+
+After installing this plugin, you will notice a new "LTI content" menu item in the WP Admin dashboard. Here you will be able to create a custom post, witch in the end generates a shortcode that can be used on any page.
+
+TLI Launch setting example::
+
+
+Copyright (c) 2021 Saltbox Services.
+Licensed under the GPLv3. See the LICENSE.md file for details.
+
diff --git a/README.rst b/README.rst
deleted file mode 100644
index 5fc9a72..0000000
--- a/README.rst
+++ /dev/null
@@ -1,51 +0,0 @@
-An LTI-compatible launching plugin for Wordpress.
-
-
-General Wordpress plugin installation instructions can be found here: http://codex.wordpress.org/Managing_Plugins#Automatic_Plugin_Installation
-
-
-After installing the plugin, add content launching with the [lti-launch]
-shortcode.
-
-
-Some examples::
-
- [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=iframe configuration_url=http://launcher.saltbox.com/lms/configuration resource_link_id=testcourseplacement1]
-
-
- [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=newwindow action=link configuration_url=http://launcher.saltbox.com/lms/configuration resource_link_id=testcourseplacement1]
-
-
- [lti-launch consumer_key=yourconsumerkey secret_key=yoursecretkey display=self action=button launch_url=http://launcher.saltbox.com/launch resource_link_id=testcourseplacement1]
-
-
-Options:
-
-- display
-
- - newwindow: launches into a new window
-
- - self: launches into the same window, replacing the current content
-
- - iframe: launches into an iframe embedded in the content
-
-- action
-
- - button: shows a button to the user, which they click on to launch
-
- - link: shows a link to the user, which they click on to launch
-
-- configuration_url: the URL to the launch XML configuration
-
-- launch_url: The launch URL of the LTI-compatible tool
-
-
-
-Caution! Since shortcodes are visible to content viewers if their plugin is
-disabled, OAuth secret keys will become visible if this plugin is disabled.
-
-
-
-Copyright (c) 2014 Saltbox Services.
-Licensed under the GPLv3. See the LICENSE.md file for details.
-
diff --git a/lti-consumer-form.php b/lti-consumer-form.php
new file mode 100644
index 0000000..520b0c3
--- /dev/null
+++ b/lti-consumer-form.php
@@ -0,0 +1,31 @@
+
+
LTI Content Options
+
+
diff --git a/lti-consumer.php b/lti-consumer.php
index 56d21d7..a0fed57 100644
--- a/lti-consumer.php
+++ b/lti-consumer.php
@@ -3,8 +3,8 @@
* Plugin Name: LTI-compatible consumer
* Plugin URI:
* Description: An LTI-compatible launching plugin for Wordpress.
- * Version: 0.4.1
- * Author: John Weaver
+ * Version: 0.4.6
+ * Author: John Weaver , Darrel Kleynhans
* License: GPLv3
*/
@@ -12,42 +12,255 @@
require('OAuth.php');
+define('LTI_CONSUMER_PLUGIN_PATH', dirname(__FILE__) . '/');
+define('LTI_CONSUMER_PLUGIN_SITE_HOME_URL', get_site_url());
+define('LTI_CONSUMER_PLUGIN_URL', plugins_url('', __FILE__));
+
/*
* Create the lti_launch custom post type.
*/
add_action('init', 'Saltbox\sb_create_lti_post_type_func');
+
function sb_create_lti_post_type_func() {
register_post_type(
- 'lti_launch',
- array(
- 'labels' => array(
- 'name' => __('LTI content'),
- 'singular_name' => __('LTI content'),
- 'add_new_item' => __('Add new LTI content'),
- 'edit_item' => __('Edit LTI content'),
- 'new_item' => __('New LTI content'),
- 'view_item' => __('View LTI content'),
- 'search_items' => __('Search LTI content'),
- 'not_found' => __('No LTI content found'),
- 'not_found_in_trash' => __('No LTI content found in Trash'),
- ),
- 'description' => __('An LTI-compatible tool for content launch'),
- 'publicly_queryable' => true,
- 'public' => true,
- 'has_archive' => true,
- 'supports' => array(
- 'title',
- 'editor',
- ),
- )
+ 'lti_launch',
+ array(
+ 'labels' => array(
+ 'name' => __('LTI content'),
+ 'singular_name' => __('LTI content'),
+ 'add_new_item' => __('Add new LTI content'),
+ 'edit_item' => __('Edit LTI content'),
+ 'new_item' => __('New LTI content'),
+ 'view_item' => __('View LTI content'),
+ 'search_items' => __('Search LTI content'),
+ 'not_found' => __('No LTI content found'),
+ 'not_found_in_trash' => __('No LTI content found in Trash'),
+ ),
+ 'description' => __('An LTI-compatible tool for content launch'),
+ 'publicly_queryable' => true,
+ 'public' => true,
+ 'has_archive' => true,
+ 'supports' => array(
+ 'title',
+ 'editor',
+ ),
+ )
+ );
+}
+
+// Add menu item for options
+// Hook
+add_action('admin_menu', 'Saltbox\add_sb_options_submenu');
+
+//admin_menu callback function
+function add_sb_options_submenu() {
+ add_submenu_page(
+ 'edit.php?post_type=lti_launch', //$parent_slug
+ __('LTI content options'), //$page_title
+ __('LTI options'), //$menu_title
+ 'manage_options', //$capability
+ 'lti_launch_options', //$menu_slug
+ 'Saltbox\sb_lti_options_submenu_render_page'//$function
+ );
+
+ add_submenu_page(
+ 'edit.php?post_type=lti_launch', //$parent_slug
+ __('Content selector'), //$page_title
+ __('Content selector'), //$menu_title
+ 'manage_options', //$capability
+ 'lti_content_selector', //$menu_slug
+ 'Saltbox\sb_lti_content_selector_submenu_render_page'//$function
+ );
+}
+
+//add_submenu_page callback function
+function sb_lti_options_submenu_render_page() {
+ if (!current_user_can('manage_options')) {
+ wp_die('Unauthorized user');
+ }
+
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ if (!isset($_POST['_wpnonce_sb_lti_options_page_action']) || !wp_verify_nonce($_POST['_wpnonce_sb_lti_options_page_action'], 'sb_lti_options_page_action')) {
+ //Nonce check failed.
+ wp_die("Error! Nonce verification failed from admin.");
+ }
+
+ if (isset($_POST['lti_instructor_user_role'])) {
+ update_option('lti_instructor_user_role', $_POST['lti_instructor_user_role']);
+ }
+ }
+
+ $instructor_role = get_option('lti_instructor_user_role', 'administrator');
+
+ $editable_roles = get_editable_roles();
+ include 'lti-consumer-form.php';
+}
+
+//add_submenu_page callback function
+function sb_lti_content_selector_submenu_render_page() {
+ if (!current_user_can('manage_options')) {
+ wp_die('Unauthorized user');
+ }
+
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ sb_get_lti_content_selector();
+ // include 'lti-launch-settings.php';
+ return;
+ }
+
+ //wp_nonce_field('lti_content_inner_custom_box', 'lti_content_inner_custom_nonce');
+ $instructor_role = get_option('lti_instructor_user_role', array('administrator'));
+ //Get all the admin WP users.
+ $args = array(
+ 'role__in' => $instructor_role,
+ 'orderby' => 'user_nicename',
+ 'order' => 'ASC'
);
+ $users = get_users($args);
+
+ $consumer_key = get_option('lti_meta_consumer_key');
+ $secret_key = get_option('lti_meta_secret_key');
+ $display = get_option('lti_meta_display', 'iframe');
+ $action = get_option('lti_meta_action');
+ $launch_url = get_option('lti_meta_launch_url');
+ $configuration_url = get_option('lti_meta_configuration_url');
+ $return_url = get_option('lti_meta_return_url');
+ $version = get_option('lti_meta_version', 'LTI-1p1');
+ $instructor_user = get_option('lti_meta_instructor_user');
+ $institution_role = get_option('lti_meta_roles');
+ $other_parameters = get_option('lti_meta_other_parameters');
+ //admin_url('edit.php?post_type=lti_launch&page=lti_content_selector')
+ //echo LTI_CONSUMER_PLUGIN_URL . '/lti-content-selector.php'
+ ?>
+
+
+ $value) {
+ $parameters[$key] = $value;
+ }
+ }
+
+ $parameters = sb_package_launch(
+ $version,
+ $consumer_key, $consumer_secret,
+ $launch_url,
+ $parameters);
+
+ // Strip out GET parameters from the parameters we pass
+ // into the POST body.
+ parse_str(parse_url($launch_url, PHP_URL_QUERY), $qs_params);
+ foreach ($qs_params as $k => $v) {
+ unset($parameters[$k]);
+ }
+
+
+
+ $html = sb_lti_launch(array(
+ 'parameters' => array_filter($parameters),
+ 'id' => $id,
+ 'display' => $display,
+ 'action' => $action,
+ 'url' => $launch_url,
+ 'text' => 'Lti content selector',
+ ));
+ echo $html;
}
add_filter('post_row_actions', 'Saltbox\sb_add_shortcode_generator_link', 10, 2);
-add_filter('page_row_actions', 'Saltbox\sb_add_shortcode_generator_link', 10, 2);
+
function sb_add_shortcode_generator_link($actions, $post) {
- if ( $post->post_type == 'lti_launch' ) {
+ if ($post->post_type == 'lti_launch') {
unset($actions['view']);
$actions['shortcode_generator'] = 'Shortcode: [lti-launch id=' . $post->post_name . ']';
}
@@ -55,32 +268,38 @@ function sb_add_shortcode_generator_link($actions, $post) {
return $actions;
}
-
-
add_action('add_meta_boxes', 'Saltbox\sb_lti_content_meta_box');
+
function sb_lti_content_meta_box() {
add_meta_box(
- 'lti_content_custom_section_id',
- __('LTI launch settings', 'lti-consumer'),
- 'Saltbox\sb_lti_content_inner_custom_box',
- 'lti_launch'
+ 'lti_content_custom_section_id',
+ __('LTI launch settings', 'lti-consumer'),
+ 'Saltbox\sb_lti_content_inner_custom_box',
+ 'lti_launch'
);
}
-
add_filter('get_sample_permalink_html', 'Saltbox\sb_permalink_removal', 1000, 4);
+
function sb_permalink_removal($return, $id, $new_title, $new_slug) {
global $post;
- if ( $post && $post->post_type == 'lti_launch' ) {
+ if ($post && $post->post_type == 'lti_launch') {
return '';
} else {
return $return;
}
}
-
function sb_lti_content_inner_custom_box($lti_content) {
wp_nonce_field('lti_content_inner_custom_box', 'lti_content_inner_custom_nonce');
+ $instructor_role = get_option('lti_instructor_user_role', array('administrator'));
+ //Get all the admin WP users.
+ $args = array(
+ 'role__in' => $instructor_role,
+ 'orderby' => 'user_nicename',
+ 'order' => 'ASC'
+ );
+ $users = get_users($args);
$consumer_key = get_post_meta($lti_content->ID, '_lti_meta_consumer_key', true);
$secret_key = get_post_meta($lti_content->ID, '_lti_meta_secret_key', true);
@@ -90,112 +309,55 @@ function sb_lti_content_inner_custom_box($lti_content) {
$configuration_url = get_post_meta($lti_content->ID, '_lti_meta_configuration_url', true);
$return_url = get_post_meta($lti_content->ID, '_lti_meta_return_url', true);
$version = get_post_meta($lti_content->ID, '_lti_meta_version', true);
+ $instructor_user = get_post_meta($lti_content->ID, '_lti_meta_instructor_user', true);
+ $institution_role = get_post_meta($lti_content->ID, '_lti_meta_roles', true);
+ $other_parameters = get_post_meta($lti_content->ID, '_lti_meta_other_parameters', true);
- if ( $display === '' ) {
+ if ($display === '') {
$display = 'iframe';
}
- if ( $version !== 'LTI-1p1' && $version !== 'LTI-1p0' ) {
+ if ($version !== 'LTI-1p1' && $version !== 'LTI-1p0') {
$version = 'LTI-1p1';
}
-
-?>
- All of the following fields are optional, and can be overridden by specifying the corresponding parameters to the lti-launch shortcode.
-
-
-
-
-All of the following fields are optional, and can be overridden by specifying the corresponding parameters to the lti-launch shortcode.';
+ include 'lti-launch-settings.php';
}
-
add_filter('the_content', 'Saltbox\sb_lti_content_include_launcher');
+
function sb_lti_content_include_launcher($content) {
global $post;
- if ( $post->post_type == 'lti_launch' ) {
+ if ($post->post_type == 'lti_launch') {
$content .= '[lti-launch id=' . $post->post_name . ' resource_link_id=' . $post->ID . ']
';
}
return $content;
}
-
add_action('save_post', 'Saltbox\sb_lti_content_save_post');
+
function sb_lti_content_save_post($post_id) {
// From http://codex.wordpress.org/Function_Reference/add_meta_box
// Check if our nonce is set.
- if ( ! isset( $_POST['lti_content_inner_custom_nonce'] ) ) {
+ if (!isset($_POST['lti_content_inner_custom_nonce'])) {
return $post_id;
}
$nonce = $_POST['lti_content_inner_custom_nonce'];
// Verify that the nonce is valid.
- if ( !wp_verify_nonce( $nonce, 'lti_content_inner_custom_box' ) ) {
- return $post_id;
+ if (!wp_verify_nonce($nonce, 'lti_content_inner_custom_box')) {
+ return $post_id;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
- if ( !current_user_can( 'edit_post', $post_id ) ) {
+ if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
@@ -210,6 +372,9 @@ function sb_lti_content_save_post($post_id) {
$configuration_url = esc_url_raw($_POST['lti_content_field_configuration_url']);
$return_url = esc_url_raw($_POST['lti_content_field_return_url']);
$version = sanitize_text_field($_POST['lti_content_field_version']);
+ $instructor_user = sanitize_text_field($_POST['lti_content_field_instructor_user']);
+ $institution_role = sanitize_text_field($_POST['lti_content_field_role']);
+ $other_parameters = sanitize_textarea_field($_POST['lti_content_field_other_parameters']);
// Update the meta field in the database.
update_post_meta($post_id, '_lti_meta_consumer_key', $consumer_key);
@@ -220,53 +385,59 @@ function sb_lti_content_save_post($post_id) {
update_post_meta($post_id, '_lti_meta_configuration_url', $configuration_url);
update_post_meta($post_id, '_lti_meta_return_url', $return_url);
update_post_meta($post_id, '_lti_meta_version', $version);
+ update_post_meta($post_id, '_lti_meta_instructor_user', $instructor_user);
+ update_post_meta($post_id, '_lti_meta_roles', $institution_role);
+ update_post_meta($post_id, '_lti_meta_other_parameters', $other_parameters);
}
-
-
/*
* Add the lti-launch shortcode.
*/
add_shortcode('lti-launch', 'Saltbox\sb_lti_launch_func');
+
function sb_lti_launch_func($attrs) {
$data = sb_lti_launch_process($attrs);
+ return sb_lti_launch($data);
+}
- if ( array_key_exists('error', $data) ) {
+function sb_lti_launch($data) {
+ if (array_key_exists('error', $data)) {
$html = '';
} else {
$html = '';
$id = uniqid();
$iframeId = uniqid();
- if ( $data['display'] == 'newwindow' ) {
+ if ($data['display'] == 'newwindow') {
$target = '_blank';
- } else if ( $data['display'] == 'iframe' ) {
+ } else if ($data['display'] == 'iframe') {
$target = 'frame-' . $iframeId;
} else {
$target = '_self';
}
- if ( $data['action'] == 'auto' || $data['display'] == 'iframe' ) {
+ if ($data['action'] == 'auto' || $data['display'] == 'iframe') {
$autolaunch = 'yes';
} else {
$autolaunch = 'no';
}
$html .= "';
@@ -275,37 +446,37 @@ function sb_lti_launch_func($attrs) {
return $html;
}
-
add_action('wp_head', 'Saltbox\sb_lti_launch_ajaxurl');
+
function sb_lti_launch_ajaxurl() {
-?>
-
-
+ post_type == 'lti_launch' ) {
+ if ($lti_launch && $lti_launch->post_type == 'lti_launch') {
do_action('lti_launch', $_POST['post']);
}
}
-
/*
* Find lti-launch shortcodes in posts and add a resource_link_id to any found
* if they don't already have one set.
*/
add_action('save_post', 'Saltbox\sb_ensure_resource_link_id_func', 5, 1);
+
function sb_ensure_resource_link_id_func($post_id) {
// get post content
$content = get_post($post_id)->post_content;
@@ -314,19 +485,18 @@ function sb_ensure_resource_link_id_func($post_id) {
$pattern = get_shortcode_regex();
preg_match_all("/$pattern/s", $content, $matches);
- foreach ( $matches[0] as $match ) {
- if ( strpos($match, '[lti-launch') === 0 ) {
+ foreach ($matches[0] as $match) {
+ if (strpos($match, '[lti-launch') === 0) {
// Replace the original shortcode with the rewritten one
$content = substr_replace(
- $content,
- sb_add_resource_link_id_if_not_present($match),
- strpos($content, $match),
- strlen($match));
+ $content,
+ sb_add_resource_link_id_if_not_present($match),
+ strpos($content, $match),
+ strlen($match));
}
}
// transform content
-
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'Saltbox\sb_ensure_resource_link_id_func', 5, 1);
@@ -339,45 +509,67 @@ function sb_ensure_resource_link_id_func($post_id) {
return $post_id;
}
-
/*
* Insert our LTI launch script into the page.
*/
add_action('wp_enqueue_scripts', 'Saltbox\sb_add_launch_script_func');
add_action('admin_enqueue_scripts', 'Saltbox\sb_add_launch_script_func');
+
function sb_add_launch_script_func() {
wp_enqueue_script('lti_launch', plugins_url('scripts/launch.js', __FILE__), array('jquery'));
}
-
function sb_add_resource_link_id_if_not_present($shortcode) {
// split args out of shortcode, excluding the [] as well
$pieces = explode(' ', substr($shortcode, 1, -1));
// check if resource_link_id is present
$found = false;
- foreach ( $pieces as $piece ) {
- if ( strpos(trim($piece), 'resource_link_id=') === 0 ) {
+ foreach ($pieces as $piece) {
+ if (strpos(trim($piece), 'resource_link_id=') === 0) {
$found = true;
break;
}
}
// add resource_link_id if not present
- if ( !$found ) {
+ if (!$found) {
array_push($pieces, 'resource_link_id=' . uniqid());
}
- // recombine args
- return '[' . implode(' ', $pieces) . ']';
+ $onsave = false;
+ foreach ($pieces as $piece) {
+ if (strpos(trim($piece), 'onsave=') === 0) {
+ $onsave = true;
+ break;
+ }
+ }
+
+ if ($onsave) {
+ return do_shortcode( '[' . implode(' ', $pieces) . ']');
+
+ // Replace the original shortcode with the rewritten one
+ $content = substr_replace(
+ $content,
+ $processed,
+ strpos($content, $match),
+ strlen($match));
+ }else{
+ // recombine args
+ return '[' . implode(' ', $pieces) . ']';
+ }
+
}
/*
* Utilities
*/
-function sb_extract_user_id() {
- // Find some relevant information about the current user
- $current_user = wp_get_current_user();
+
+function sb_extract_user_id($userId) {
+ $current_user = get_lti_wp_user($userId);
+ if ($current_user == null) {
+ return array('error' => 'You must be logged in to launch this content.');
+ }
return array(
'user_id' => $current_user->ID,
@@ -387,24 +579,48 @@ function sb_extract_user_id() {
);
}
+// Find some relevant information about the current user, or the selected instructor user.
+function get_lti_wp_user($userId) {
+ if (isset($userId) && intval($userId) > 0) {
+ return get_user_by('id', $userId);
+ } else if (is_user_logged_in()) {
+ return wp_get_current_user();
+ } else {
+ $postBody = file_get_contents("php://input");
+ $body = json_decode($postBody, true);
+ if (!empty($body['token'])) {
+ $token = $body['token'];
+ $user = apply_filters('vibebp_api_get_user_from_token', '', $token);
+ $user_id = $user->id;
+ if (!empty($user_id)) {
+ return get_user_by('id', $user_id);
+ }
+ }
+ }
+ return null;
+}
+
function sb_extract_site_id() {
// Find some relevant information about the site
+ $context_id = basename(get_permalink());
+ if (empty($context_id)) {
+ $context_id = 'app';
+ }
return array(
- 'context_id' => basename(get_permalink()),
+ 'context_id' => $context_id,
'tool_consumer_instance_url' => get_site_url(),
);
}
-
function sb_determine_launch_url($configuration_url) {
$launch_url = wp_cache_get($configuration_url, 'lti-consumer', false, $found);
- if ( $found ) {
+ if ($found) {
return $launch_url;
}
$parts = parse_url($configuration_url);
- if ( $parts == false || !array_key_exists('scheme', $parts) || ($parts['scheme'] != 'http' && $parts['scheme'] != 'https') ) {
+ if ($parts == false || !array_key_exists('scheme', $parts) || ($parts['scheme'] != 'http' && $parts['scheme'] != 'https')) {
// Don't trust weird URLs (could be file path or something).
$launch_url = false;
} else {
@@ -420,7 +636,7 @@ function sb_determine_launch_url($configuration_url) {
$config = simplexml_load_string($config_string);
$launch_url = (string) $config->children('blti', true)->launch_url;
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$launch_url = false;
}
}
@@ -430,30 +646,27 @@ function sb_determine_launch_url($configuration_url) {
return $launch_url;
}
-
function sb_lti_launch_process($attrs) {
- // Reject launch for non-logged in users
- if ( !is_user_logged_in() ) {
+ // Reject launch for non-logged in users
+ if (get_lti_wp_user(null) == null) {
return array('error' => 'You must be logged in to launch this content.');
} else {
+ $instructor_user = -1;
$parameters = array();
- // grab user information
- $parameters = array_merge($parameters, sb_extract_user_id());
// grab site information
$parameters = array_merge($parameters, sb_extract_site_id());
$post_id = '';
$text = '';
- if ( array_key_exists('id', $attrs) ) {
+ if (array_key_exists('id', $attrs)) {
$posts = get_posts(array(
'name' => $attrs['id'],
'post_type' => 'lti_launch',
'post_status' => 'publish',
'posts_per_page' => 1,
));
-
- if ( $posts ) {
+ if ($posts) {
$lti_content = $posts[0];
$post_id = $lti_content->ID;
$consumer_key = get_post_meta($lti_content->ID, '_lti_meta_consumer_key', true);
@@ -462,78 +675,97 @@ function sb_lti_launch_process($attrs) {
$action = get_post_meta($lti_content->ID, '_lti_meta_action', true);
$launch_url = get_post_meta($lti_content->ID, '_lti_meta_launch_url', true);
$configuration_url = get_post_meta($lti_content->ID, '_lti_meta_configuration_url', true);
- if ( $configuration_url === "" ) {
- unset($configuration_url);
+ if ($configuration_url === "") {
+ unset($configuration_url);
}
$return_url = get_post_meta($lti_content->ID, '_lti_meta_return_url', true);
$text = $lti_content->post_title;
$version = get_post_meta($lti_content->ID, '_lti_meta_version', true) or 'LTI-1p1';
+ $instructor_user = intval(get_post_meta($lti_content->ID, '_lti_meta_instructor_user', true));
+ $institution_role = get_post_meta($lti_content->ID, '_lti_meta_roles', true);
+ $other_parameters = get_post_meta($lti_content->ID, '_lti_meta_other_parameters', true);
}
}
+ // grab user information
+ $parameters = array_merge($parameters, sb_extract_user_id($instructor_user));
// incorporate information from $attrs
- if ( array_key_exists('resource_link_id', $attrs) ) {
+ if (array_key_exists('resource_link_id', $attrs)) {
$parameters['resource_link_id'] = $attrs['resource_link_id'];
} else {
return array('error' => 'You must specify the resource_link_id.');
}
- if ( array_key_exists('return_url', $attrs) ) {
+ if (array_key_exists('return_url', $attrs)) {
$parameters['launch_presentation_return_url'] = $attrs['return_url'];
- } else if ( isset($return_url) && $return_url ) {
+ } else if (isset($return_url) && $return_url) {
$parameters['launch_presentation_return_url'] = $return_url;
}
- if ( array_key_exists('version', $attrs) ) {
+ if (array_key_exists('roles', $attrs)) {
+ $parameters['roles'] = $attrs['roles'];
+ } else if (isset($institution_role) && $institution_role) {
+ $parameters['roles'] = $institution_role;
+ }
+
+ if (array_key_exists('version', $attrs)) {
$version = $attrs['version'];
- } else if ( !isset($version) ) {
+ } else if (!isset($version)) {
$version = 'LTI-1p1';
}
- if ( array_key_exists('configuration_url', $attrs) ) {
+ if (array_key_exists('configuration_url', $attrs)) {
$launch_url = sb_determine_launch_url($attrs['configuration_url']);
- if ( $launch_url == false ) {
+ if ($launch_url == false) {
return array('error' => 'Could not determine launch URL.');
}
- } else if ( array_key_exists('launch_url', $attrs) ) {
+ } else if (array_key_exists('launch_url', $attrs)) {
$launch_url = $attrs['launch_url'];
- } else if ( isset($configuration_url) && $configuration_url ) {
+ } else if (isset($configuration_url) && $configuration_url) {
$launch_url = sb_determine_launch_url($configuration_url);
- if ( $launch_url == false ) {
+ if ($launch_url == false) {
return array('error' => 'Could not determine launch URL.');
}
- } else if ( !isset($launch_url) || $launch_url === "" ) {
+ } else if (!isset($launch_url) || $launch_url === "") {
return array('error' => 'Missing launch URL and URL to configuration XML. One of these is required.');
}
- if ( array_key_exists('consumer_key', $attrs) ) {
+ if (array_key_exists('consumer_key', $attrs)) {
$consumer_key = $attrs['consumer_key'];
- } else if ( !isset($consumer_key) ) {
+ } else if (!isset($consumer_key)) {
return array('error' => 'Missing OAuth consumer key.');
}
- if ( array_key_exists('secret_key', $attrs) ) {
+ if (array_key_exists('secret_key', $attrs)) {
$consumer_secret = $attrs['secret_key'];
- } else if ( !isset($consumer_secret) ) {
+ } else if (!isset($consumer_secret)) {
return array('error' => 'Missing OAuth consumer secret.');
}
- if ( !isset($display) ) {
+ if (!isset($display)) {
$display = 'newwindow';
}
- if ( array_key_exists('display', $attrs) ) {
+ if (array_key_exists('display', $attrs)) {
$display = $attrs['display'];
}
- if ( array_key_exists('action', $attrs) ) {
+ if (array_key_exists('action', $attrs)) {
$action = $attrs['action'];
- } else if ( !isset($action) ) {
+ } else if (!isset($action)) {
$action = 'button';
}
+ if (isset($other_parameters) && !empty($other_parameters)) {
+ $obj = json_decode($other_parameters);
+ if ($obj != null)
+ foreach ($obj as $key => $value) {
+ $parameters[$key] = $value;
+ }
+ }
+
$parameters = sb_package_launch(
$version,
$consumer_key, $consumer_secret,
@@ -543,8 +775,8 @@ function sb_lti_launch_process($attrs) {
// Strip out GET parameters from the parameters we pass
// into the POST body.
parse_str(parse_url($launch_url, PHP_URL_QUERY), $qs_params);
- foreach ( $qs_params as $k => $v ) {
- unset($parameters[$k]);
+ foreach ($qs_params as $k => $v) {
+ unset($parameters[$k]);
}
return array(
@@ -558,16 +790,15 @@ function sb_lti_launch_process($attrs) {
}
}
-
function sb_package_launch($version, $key, $secret, $launch_url, $parameters) {
$parameters['lti_version'] = $version;
$parameters['lti_message_type'] = 'basic-lti-launch-request';
$consumer = new OAuthConsumer($key, $secret);
$oauth_request = OAuthRequest::from_consumer_and_token(
- $consumer, null, 'POST',
- $launch_url, $parameters);
+ $consumer, null, 'POST',
+ $launch_url, $parameters);
$oauth_request->sign_request(
- new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
+ new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
return $oauth_request->get_parameters();
-};
+}
\ No newline at end of file
diff --git a/lti-launch-settings.php b/lti-launch-settings.php
new file mode 100644
index 0000000..115d8d2
--- /dev/null
+++ b/lti-launch-settings.php
@@ -0,0 +1,105 @@
+
+
\ No newline at end of file