/** * Delete the resource link share key from the database * * @param LTI_Resource_Link_Share_Key $share_key * @return bool */ public function Resource_Link_Share_Key_delete($share_key) { $id = $share_key->getId(); $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE share_key_id = :id'; $query = $this->db->prepare($sql); $query->bindValue('id', $id, PDO::PARAM_STR); $ok = $query->execute(); if ($ok) { $share_key->initialise(); } return $ok; }
function lti_create_share_key() { global $wpdb, $current_user; // Get the context $consumer = new LTI_Tool_Consumer($_SESSION[LTI_SESSION_PREFIX . 'key'], array($wpdb->base_prefix)); $resource = new LTI_Resource_Link($consumer, $_SESSION[LTI_SESSION_PREFIX . 'resourceid']); if (!empty($_POST['email'])) { $share_key = new LTI_Resource_Link_Share_Key($resource); if (isset($_POST['life'])) { $share_key->life = $_POST['life']; } if (isset($_POST['enabled'])) { $_POST['enabled'] ? $share_key->auto_approve = TRUE : ($share_key->auto_approve = FALSE); } $share_key->save(); wp_get_current_user(); $senttext = __('Instructor: ', 'lti-text') . '<b>' . $current_user->display_name . '</b>' . __(' has shared', 'lti-text') . '<br /><br />' . __('Blog Name: ', 'lti-text') . '<b>' . get_bloginfo('name') . '</b>' . __(' with your module. To link up with this Blog:', 'lti-text') . '<br /><br />' . sprintf(__('Place this key (%s) in the custom parameters of the link to WordPress in your course as:', 'lti-text'), $share_key->getId()) . '<br /><br />' . sprintf(__('share_key=%s', 'lti-text'), $share_key->getId()); // Write friendly times if ($_POST['life'] <= 12) { $time = sprintf(_n('%s hour', '%s hours', $_POST['life'], 'lti-text'), $_POST['life']); } if ($_POST['life'] >= 24 && $_POST['life'] <= 144) { $days = intval($_POST['life'] / 24); $time = sprintf(_n('%s day', '%s days', $days, 'lti-text'), $days); } if ($_POST['life'] == 168) { $time = '1 week'; } if ($share_key->auto_approve) { $senttext .= '<br /><br />' . sprintf(__('The share key must be activated within %s.', 'lti-text'), $time); } else { $senttext .= '<br /><br />' . sprintf(__('The share key must be activated within %s and will only work after then being approved by an administrator of the site being shared.', 'lti-text'), $time); } // Send text/html $headers = 'Content-Type: text/html; charset=UTF-8'; if (wp_mail($_POST['email'], 'WordPress Share Key', $senttext, $headers)) { echo '<div class="wrap"><h2>' . __('Share this Site', 'lti-text') . '</h2>'; echo '<p>' . sprintf(__('The text below has been emailed to %s', 'lti-text'), $_POST['email']) . '</p>'; echo '<p1>' . $senttext . '</p1></div>'; } else { echo '<div class="wrap"><h2>' . __('Share this Site', 'lti-text') . '</h2>'; echo '<p>' . $senttext . '</p></div>'; } } else { ?> <h2><?php _e('Add Share Key', 'lti-text'); ?> </h2> <p><?php _e('You may share this site with users using other LTI links into WordPress. These might be:', 'lti-text'); ?> </p> <ul style="list-style-type: disc; margin-left: 15px; padding-left: 15px;"> <li><?php _e('other links from within the same course/module', 'lti-text'); ?> </li> <li><?php _e('links from other course/modules in the same VLE/LMS', 'lti-text'); ?> </li> <li><?php _e('links from a different VLE/LMS within your institution or outside', 'lti-text'); ?> </li> </ul> <p><?php _e('To invite another link to share this site:', 'lti-text'); ?> </p> <ul style="list-style-type: disc; margin-left: 15px; padding-left: 15px;"> <li><?php _e('use the button below to generate a new share key (you may choose to pre-approve the share or leave it to be approved once the key has been activated)', 'lti-text'); ?> </li> <li><?php _e('send the share key to an instructor for the other link', 'lti-text'); ?> </li> </ul> <?php if (lti_get_scope($_SESSION[LTI_SESSION_PREFIX . 'key']) == 0) { echo '<p><strong>' . __('The username format of this tool consumer is set to global and it is NOT recommended to share your site when user accounts are being created using this option.', 'lti-text') . '</strong></p>'; } ?> <form method="post" action="<?php get_admin_url(); ?> admin.php?page=lti_create_share_key"> <table class="form-table"> <tbody> <tr class="form-required"> <th scope="row"> <?php _e('Life', 'lti-text'); ?> <span class="description"><?php _e('(required)', 'lti-text'); ?> </span> </th> <td> <select name="life"> <option value="1">1 <?php _e('hour', 'lti-text'); ?> </option> <option value="2">2 <?php _e('hours', 'lti-text'); ?> </option> <option value="12">12 <?php _e('hours', 'lti-text'); ?> </option> <option value="24">1 <?php _e('day', 'lti-text'); ?> </option> <option value="48">2 <?php _e('days', 'lti-text'); ?> </option> <option value="72">3 <?php _e('days', 'lti-text'); ?> </option> <option value="96">4 <?php _e('days', 'lti-text'); ?> </option> <option value="120">5 <?php _e('days', 'lti-text'); ?> </option> <option value="144">6 <?php _e('days', 'lti-text'); ?> </option> <option value="168">1 <?php _e('week', 'lti-text'); ?> </option> </select> </td> </tr> <tr> <th scope="row"> <?php _e('Enabled', 'lti-text'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <span><?php _e('Enabled', 'lti-text'); ?> </span> </legend> <label for="enabled"> <input name="enabled" type="checkbox" id="enabled" value="true" /> <?php _e('Automatically allow requests from this share without further approval', 'lti-text'); ?> </label> </fieldset> </td> </tr> <tr class="form-field form-required"> <th scope="row"> <label for="email"> <?php _e('Enter the email address for the sharing recipient:', 'lti-text'); ?> <span class="description"><?php _e('(required)', 'lti-text'); ?> </span> </label> </th> <td> <input id="email" type="text" aria-required="true" value="" name="email"> </td> </tr> </tbody> </table> <input type="hidden" name="action" value="continue" /> <p class="submit"> <input id="share" class="button-primary" type="submit" value="<?php _e('Add Share Key', 'lti-text'); ?> " name="sharekey"> </p> </form> <?php } }