public/wordpress/wp-content/plugins/h5p/admin/class-h5p-plugin-admin.php
/**
   * Handle user results reported by the H5P content.
   *
   * @since 1.2.0
   */
Handle user results reported by the H5P content.
Handle user results reported by the H5P content .
public function ajax_results() {
    global $wpdb;
    $content_id = filter_input(INPUT_POST, 'contentId', FILTER_VALIDATE_INT);
    if (!$content_id) {
      H5PCore::ajaxError(__('Invalid content', $this->plugin_slug));
      exit;
    }
    if (!wp_verify_nonce(filter_input(INPUT_GET, 'token'), 'h5p_result')) {
      H5PCore::ajaxError(__('Invalid security token', $this->plugin_slug));
      exit;
    }
    $user_id = get_current_user_id();
    $result_id = $wpdb->get_var($wpdb->prepare(
        "SELECT id
        FROM {$wpdb->prefix}h5p_results
        WHERE user_id = %d
        AND content_id = %d",
        $user_id,
        $content_id
    ));
    $table = $wpdb->prefix . 'h5p_results';
    $data = array(
      'score' => filter_input(INPUT_POST, 'score', FILTER_VALIDATE_INT),
      'max_score' => filter_input(INPUT_POST, 'maxScore', FILTER_VALIDATE_INT),
      'opened' => filter_input(INPUT_POST, 'opened', FILTER_VALIDATE_INT),
      'finished' => filter_input(INPUT_POST, 'finished', FILTER_VALIDATE_INT),
      'time' => filter_input(INPUT_POST, 'time', FILTER_VALIDATE_INT)
    );
    if ($data['time'] === NULL) {
      $data['time'] = 0;
    }
    $format = array(
      '%d',
      '%d',
      '%d',
      '%d',
      '%d'
    );
    do_action_ref_array('h5p_alter_user_result', array(&$data, $result_id, $content_id, $user_id));
    if (!$result_id) {
      $data['user_id'] = $user_id;
      $format[] = '%d';
      $data['content_id'] = $content_id;
      $format[] = '%d';
      $wpdb->insert($table, $data, $format);
    }
    else {
      $wpdb->update($table, $data, array('id' => $result_id), $format, array('%d'));
    }
    $content = $wpdb->get_row($wpdb->prepare("
        SELECT c.title, l.name, l.major_version, l.minor_version
          FROM {$wpdb->prefix}h5p_contents c
          JOIN {$wpdb->prefix}h5p_libraries l ON l.id = c.library_id
         WHERE c.id = %d
        ", $content_id));
    new H5P_Event('results', 'set',
        $content_id, $content->title,
        $content->name, $content->major_version . '.' . $content->minor_version);
    H5PCore::ajaxSuccess();
    exit;
  }
public function ajax_results ( ) { global $ wpdb ; $ content_id = filter_input ( INPUT_POST , 'contentId' , FILTER_VALIDATE_INT ) ; if ( ! $ content_id ) { H5PCore :: ajaxError ( __ ( 'Invalid content' , $ this -> plugin_slug ) ) ; exit ; } if ( ! wp_verify_nonce ( filter_input ( INPUT_GET , 'token' ) , 'h5p_result' ) ) { H5PCore :: ajaxError ( __ ( 'Invalid security token' , $ this -> plugin_slug ) ) ; exit ; } $ user_id = get_current_user_id ( ) ; $ result_id = $ wpdb -> get_var ( $ wpdb -> prepare ( " SELECT id
        FROM  { $ wpdb -> prefix } h5p_results
        WHERE user_id = %d
        AND content_id = %d " , $ user_id , $ content_id ) ) ; $ table = $ wpdb -> prefix . 'h5p_results' ; $ data = array ( 'score' => filter_input ( INPUT_POST , 'score' , FILTER_VALIDATE_INT ) , 'max_score' => filter_input ( INPUT_POST , 'maxScore' , FILTER_VALIDATE_INT ) , 'opened' => filter_input ( INPUT_POST , 'opened' , FILTER_VALIDATE_INT ) , 'finished' => filter_input ( INPUT_POST , 'finished' , FILTER_VALIDATE_INT ) , 'time' => filter_input ( INPUT_POST , 'time' , FILTER_VALIDATE_INT ) ) ; if ( $ data [ 'time' ] === NULL ) { $ data [ 'time' ] = 0 ; } $ format = array ( '%d' , '%d' , '%d' , '%d' , '%d' ) ; do_action_ref_array ( 'h5p_alter_user_result' , array ( & $ data , $ result_id , $ content_id , $ user_id ) ) ; if ( ! $ result_id ) { $ data [ 'user_id' ] = $ user_id ; $ format [ ] = '%d' ; $ data [ 'content_id' ] = $ content_id ; $ format [ ] = '%d' ; $ wpdb -> insert ( $ table , $ data , $ format ) ; } else { $ wpdb -> update ( $ table , $ data , array ( 'id' => $ result_id ) , $ format , array ( '%d' ) ) ; } $ content = $ wpdb -> get_row ( $ wpdb -> prepare ( " 
        SELECT c.title, l.name, l.major_version, l.minor_version
          FROM  { $ wpdb -> prefix } h5p_contents c
          JOIN  { $ wpdb -> prefix } h5p_libraries l ON l.id = c.library_id
         WHERE c.id = %d
         " , $ content_id ) ) ; new H5P_Event ( 'results' , 'set' , $ content_id , $ content -> title , $ content -> name , $ content -> major_version . '.' . $ content -> minor_version ) ; H5PCore :: ajaxSuccess ( ) ; exit ; }
Handle user results reported by the H5P content.
Handle user results reported by the H5P content .
/**
     * Allows you to alter a user's submitted result for a given H5P content
     * This action is fired before the result is saved.
     *
     * @since 1.8.0
     *
     * @param object &$data Has the following properties score,max_score,opened,finished,time
     * @param int $result_id Only set if updating result
     * @param int $content_id Identifier of the H5P Content
     * @param int $user_id Identfieri of the User
     */ // Insert new results // Update existing results // Get content info for log // Log view // Success