function lti_parse_request($wp)
{
    if (is_basic_lti_request()) {
        global $wpdb;
        /*$secret = lti_get_secret_from_consumer_key();
        		$consumer_key = $_POST[ 'oauth_consumer_key' ] ;*/
        //$db_connector = LTI_Data_Connector::getDataConnector('', 'none');
        get_lti_hash();
        // initialise the remote login hash
        // oritgigo: These two lines made it possible to connect to the database
        mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        mysql_select_db(DB_NAME);
        $db_connector = LTI_Data_Connector::getDataConnector($wpdb->base_prefix);
        $consumer = new LTI_Tool_Consumer($consumer_key, $db_connector);
        $tool = new LTI_Tool_Provider('lti_do_actions', $db_connector);
        $tool->execute();
    }
}
Exemple #2
0
function lti_parse_request($wp)
{
    // Note: we should use the base_prefix always as when in site
    // blogs the prefix changes to prefixblog_id_, i.e. wp_60_
    global $wpdb;
    if (empty($_POST['lti_message_type'])) {
        return FALSE;
    }
    // Clear any existing session variables for this plugin
    lti_reset_session();
    // Deal with magic quotes before they cause OAuth to fail
    lti_strip_magic_quotes();
    // Do the necessary
    $tool = new LTI_Tool_Provider('lti_do_connect', array($wpdb->base_prefix));
    $tool->setParameterConstraint('resource_link_id', TRUE, 40);
    $tool->setParameterConstraint('user_id', TRUE);
    // Get settings and check whether sharing is enabled.
    $tool->allowSharing = TRUE;
    $tool->execute();
    exit;
}
 /**
  * Perform a Memberships service request.
  *
  * The user table is updated with the new list of user objects.
  *
  * @param boolean $withGroups True is group information is to be requested as well
  *
  * @return mixed Array of LTI_User objects or False if the request was not successful
  */
 public function doMembershipsService($withGroups = FALSE)
 {
     $users = array();
     $old_users = $this->getUserResultSourcedIDs(TRUE, LTI_Tool_Provider::ID_SCOPE_RESOURCE);
     $this->ext_response = NULL;
     $url = $this->getSetting('ext_ims_lis_memberships_url');
     $params = array();
     $params['id'] = $this->getSetting('ext_ims_lis_memberships_id');
     $ok = FALSE;
     if ($withGroups) {
         $ok = $this->doService('basic-lis-readmembershipsforcontextwithgroups', $url, $params);
     }
     if ($ok) {
         $this->group_sets = array();
         $this->groups = array();
     } else {
         $ok = $this->doService('basic-lis-readmembershipsforcontext', $url, $params);
     }
     if ($ok) {
         if (!isset($this->ext_nodes['memberships']['member'])) {
             $members = array();
         } else {
             if (!isset($this->ext_nodes['memberships']['member'][0])) {
                 $members = array();
                 $members[0] = $this->ext_nodes['memberships']['member'];
             } else {
                 $members = $this->ext_nodes['memberships']['member'];
             }
         }
         for ($i = 0; $i < count($members); $i++) {
             $user = new LTI_User($this, $members[$i]['user_id']);
             #
             ### Set the user name
             #
             $firstname = isset($members[$i]['person_name_given']) ? $members[$i]['person_name_given'] : '';
             $lastname = isset($members[$i]['person_name_family']) ? $members[$i]['person_name_family'] : '';
             $fullname = isset($members[$i]['person_name_full']) ? $members[$i]['person_name_full'] : '';
             $user->setNames($firstname, $lastname, $fullname);
             #
             ### Set the user email
             #
             $email = isset($members[$i]['person_contact_email_primary']) ? $members[$i]['person_contact_email_primary'] : '';
             $user->setEmail($email, $this->consumer->defaultEmail);
             #
             ### Set the user roles
             #
             if (isset($members[$i]['roles'])) {
                 $user->roles = LTI_Tool_Provider::parseRoles($members[$i]['roles']);
             }
             #
             ### Set the user groups
             #
             if (!isset($members[$i]['groups']['group'])) {
                 $groups = array();
             } else {
                 if (!isset($members[$i]['groups']['group'][0])) {
                     $groups = array();
                     $groups[0] = $members[$i]['groups']['group'];
                 } else {
                     $groups = $members[$i]['groups']['group'];
                 }
             }
             for ($j = 0; $j < count($groups); $j++) {
                 $group = $groups[$j];
                 if (isset($group['set'])) {
                     $set_id = $group['set']['id'];
                     if (!isset($this->group_sets[$set_id])) {
                         $this->group_sets[$set_id] = array('title' => $group['set']['title'], 'groups' => array(), 'num_members' => 0, 'num_staff' => 0, 'num_learners' => 0);
                     }
                     $this->group_sets[$set_id]['num_members']++;
                     if ($user->isStaff()) {
                         $this->group_sets[$set_id]['num_staff']++;
                     }
                     if ($user->isLearner()) {
                         $this->group_sets[$set_id]['num_learners']++;
                     }
                     if (!in_array($group['id'], $this->group_sets[$set_id]['groups'])) {
                         $this->group_sets[$set_id]['groups'][] = $group['id'];
                     }
                     $this->groups[$group['id']] = array('title' => $group['title'], 'set' => $set_id);
                 } else {
                     $this->groups[$group['id']] = array('title' => $group['title']);
                 }
                 $user->groups[] = $group['id'];
             }
             #
             ### If a result sourcedid is provided save the user
             #
             if (isset($members[$i]['lis_result_sourcedid'])) {
                 $user->lti_result_sourcedid = $members[$i]['lis_result_sourcedid'];
                 $user->save();
             }
             $users[] = $user;
             #
             ### Remove old user (if it exists)
             #
             unset($old_users[$user->getId(LTI_Tool_Provider::ID_SCOPE_RESOURCE)]);
         }
         #
         ### Delete any old users which were not in the latest list from the tool consumer
         #
         foreach ($old_users as $id => $user) {
             $user->delete();
         }
     } else {
         $users = FALSE;
     }
     return $users;
 }
 function __construct($data_connector = '', $callbackHandler = NULL)
 {
     parent::__construct($data_connector, $callbackHandler);
 }
Exemple #5
0
 /**
  * Get the plugin instance...
  *
  * @param string|array $callbackHandler
  * @return \LTI_Tool_Provider
  */
 public function getLtiToolProvider($callbackHandler = null)
 {
     if (!$this->exists('res.lti.toolProvider')) {
         $tool = new \LTI_Tool_Provider($callbackHandler, $this->getLtiDataConnector());
         $tool->setParameterConstraint('oauth_consumer_key', TRUE, 50);
         $tool->setParameterConstraint('resource_link_id', TRUE, 50);
         $tool->setParameterConstraint('user_id', TRUE, 50);
         $tool->setParameterConstraint('roles', TRUE);
         $this->set('res.lti.toolProvider', $tool);
     }
     return $this->get('res.lti.toolProvider');
 }
 function prepare_items($per_page)
 {
     global $wpdb;
     /**
      * REQUIRED. Now we need to define our column headers. This includes a complete
      * array of columns to be displayed (slugs & titles), a list of columns
      * to keep hidden, and a list of columns that are sortable. Each of these
      * can be defined in another method (as we've done here) before being
      * used to build the value for our _column_headers property.
      */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     /**
      * REQUIRED. Finally, we build an array to be used by the class for column
      * headers. The $this->_column_headers property takes an array which contains
      * 3 other arrays. One for all columns, one for hidden columns, and one
      * for sortable columns.
      */
     $this->_column_headers = array($columns, $hidden, $sortable);
     /**
      * Optional. You can handle your bulk actions however you see fit. In this
      * case, we'll handle them within our package just to keep things clean.
      */
     $this->process_bulk_action();
     /**
      * Get all the consumers and convert in array for this class to process
      */
     $tool = new LTI_Tool_Provider('', array($wpdb->base_prefix));
     $lti_data = $tool->getConsumers();
     for ($i = 0; $i < count($lti_data); $i++) {
         $data[$i]['ID'] = $i;
         $data[$i]['name'] = $lti_data[$i]->name;
         $data[$i]['email_domain'] = $lti_data[$i]->email_domain;
         $data[$i]['key'] = $lti_data[$i]->getKey();
         $data[$i]['cname'] = "<span title='" . $lti_data[$i]->consumer_version . "'>" . $lti_data[$i]->consumer_name . "</span>";
         $available = $lti_data[$i]->getIsAvailable() ? 'Yes' : 'No';
         $now = time();
         $mouseover_dates = '';
         if (isset($lti_data[$i]->enable_from) && $lti_data[$i]->enable_from > $now) {
             $mouseover_dates = 'From ' . date('j-M-Y H:i', $lti_data[$i]->enable_from);
         } else {
             if (isset($lti_data[$i]->enable_until)) {
                 if ($lti_data[$i]->enable_until > $now) {
                     $mouseover_dates = 'Until ' . date('j-M-Y H:i', $lti_data[$i]->enable_until);
                 } else {
                     $mouseover_dates = 'Expired ' . date('j-M-Y H:i', $lti_data[$i]->enable_until);
                 }
             }
         }
         if (!empty($mouseover_dates)) {
             $pos = strrpos($mouseover_dates, ' 00:00');
             if ($pos !== FALSE && $pos == strlen($mouseover_dates) - 6) {
                 $mouseover_dates = substr($mouseover_dates, 0, $pos);
             }
             $available = "<span title=\"{$mouseover_dates}\">{$available}</span>";
         }
         $data[$i]['avail'] = $available;
         if (is_null($lti_data[$i]->last_access)) {
             $data[$i]['last'] = 'None';
         } else {
             $data[$i]['last'] = date('d-M-Y ', $lti_data[$i]->last_access);
         }
     }
     /**
      * This checks for sorting input and sorts the data in our array accordingly.
      *
      * In a real-world situation involving a database, you would probably want
      * to handle sorting by passing the 'orderby' and 'order' values directly
      * to a custom query. The returned data will be pre-sorted, and this array
      * sorting technique would be unnecessary.
      */
     function usort_reorder($a, $b)
     {
         $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name';
         //If no sort, default to title
         $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'asc';
         //If no order, default to asc
         $result = strcmp($a[$orderby], $b[$orderby]);
         //Determine sort order
         return $order === 'asc' ? $result : -$result;
         //Send final sort direction to usort
     }
     usort($data, 'usort_reorder');
     /**
      * REQUIRED for pagination. Let's figure out what page the user is currently
      * looking at. We'll need this later, so you should always include it in
      * your own package classes.
      */
     $current_page = $this->get_pagenum();
     /**
      * REQUIRED for pagination. Let's check how many items are in our data array.
      * In real-world use, this would be the total number of items in your database,
      * without filtering. We'll need this later, so you should always include it
      * in your own package classes.
      */
     $total_items = count($data);
     /**
      * The WP_List_Table class does not handle pagination for us, so we need
      * to ensure that the data is trimmed to only the current page. We can use
      * array_slice() to
      */
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     /**
      * REQUIRED. Now we can add our *sorted* data to the items property, where
      * it can be used by the rest of the class.
      */
     $this->items = $data;
     /**
      * REQUIRED. We also have to register our pagination options & calculations.
      */
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }