public/wordpress/wp-content/plugins/h5p/admin/class-h5p-plugin-admin.php
/**
   * Handle user results reported by the H5P content.
   *
   * @since 1.5.0
   */
Handle user results reported by the H5P content.
Handle user results reported by the H5P content .
public function ajax_contents_user_data() {
    global $wpdb;
    $content_id = filter_input(INPUT_GET, 'content_id');
    $data_id = filter_input(INPUT_GET, 'data_type');
    $sub_content_id = filter_input(INPUT_GET, 'sub_content_id');
    $current_user = wp_get_current_user();
    if ($content_id === NULL ||
        $data_id === NULL ||
        $sub_content_id === NULL ||
        !$current_user->ID) {
      return; 
    }
    $response = (object) array(
      'success' => TRUE
    );
    $data = filter_input(INPUT_POST, 'data');
    $preload = filter_input(INPUT_POST, 'preload');
    $invalidate = filter_input(INPUT_POST, 'invalidate');
    if ($data !== NULL && $preload !== NULL && $invalidate !== NULL) {
      if (!wp_verify_nonce(filter_input(INPUT_GET, 'token'), 'h5p_contentuserdata')) {
        H5PCore::ajaxError(__('Invalid security token', $this->plugin_slug));
        exit;
      }
      if ($data === '0') {
        $wpdb->delete($wpdb->prefix . 'h5p_contents_user_data',
          array(
            'content_id' => $content_id,
            'data_id' => $data_id,
            'user_id' => $current_user->ID,
            'sub_content_id' => $sub_content_id
          ),
          array('%d', '%s', '%d', '%d'));
      }
      else {
        $preload = ($preload === '0' ? 0 : 1);
        $invalidate = ($invalidate === '0' ? 0 : 1);
        $update = $wpdb->get_var($wpdb->prepare(
          "SELECT content_id
           FROM {$wpdb->prefix}h5p_contents_user_data
           WHERE content_id = %d
             AND user_id = %d
             AND data_id = %s
             AND sub_content_id = %d",
            $content_id, $current_user->ID, $data_id, $sub_content_id
        ));
        if ($update === NULL) {
          $wpdb->insert($wpdb->prefix . 'h5p_contents_user_data',
            array(
              'user_id' => $current_user->ID,
              'content_id' => $content_id,
              'sub_content_id' => $sub_content_id,
              'data_id' => $data_id,
              'data' => $data,
              'preload' => $preload,
              'invalidate' => $invalidate,
              'updated_at' => current_time('mysql', 1)
            ),
            array('%d', '%d', '%d', '%s', '%s', '%d', '%d', '%s')
          );
        }
        else {
          $wpdb->update($wpdb->prefix . 'h5p_contents_user_data',
            array(
              'data' => $data,
              'preload' => $preload,
              'invalidate' => $invalidate,
              'updated_at' => current_time('mysql', 1)
            ),
            array(
              'user_id' => $current_user->ID,
              'content_id' => $content_id,
              'data_id' => $data_id,
              'sub_content_id' => $sub_content_id
            ),
            array('%s', '%d', '%d', '%s'),
            array('%d', '%d', '%s', '%d')
          );
        }
      }
      H5PCore::ajaxSuccess();
      exit;
    }
    else {
      $response->data = $wpdb->get_var($wpdb->prepare(
        "SELECT hcud.data
         FROM {$wpdb->prefix}h5p_contents_user_data hcud
         WHERE user_id = %d
           AND content_id = %d
           AND data_id = %s
           AND sub_content_id = %d",
        $current_user->ID, $content_id, $data_id, $sub_content_id
      ));
      if ($response->data === NULL) {
        unset($response->data);
      }
    }
    header('Cache-Control: no-cache');
    header('Content-type: application/json; charset=utf-8');
    print json_encode($response);
    exit;
  }
public function ajax_contents_user_data ( ) { global $ wpdb ; $ content_id = filter_input ( INPUT_GET , 'content_id' ) ; $ data_id = filter_input ( INPUT_GET , 'data_type' ) ; $ sub_content_id = filter_input ( INPUT_GET , 'sub_content_id' ) ; $ current_user = wp_get_current_user ( ) ; if ( $ content_id === NULL || $ data_id === NULL || $ sub_content_id === NULL || ! $ current_user -> ID ) { return ; } $ response = ( object ) array ( 'success' => TRUE ) ; $ data = filter_input ( INPUT_POST , 'data' ) ; $ preload = filter_input ( INPUT_POST , 'preload' ) ; $ invalidate = filter_input ( INPUT_POST , 'invalidate' ) ; if ( $ data !== NULL && $ preload !== NULL && $ invalidate !== NULL ) { if ( ! wp_verify_nonce ( filter_input ( INPUT_GET , 'token' ) , 'h5p_contentuserdata' ) ) { H5PCore :: ajaxError ( __ ( 'Invalid security token' , $ this -> plugin_slug ) ) ; exit ; } if ( $ data === '0' ) { $ wpdb -> delete ( $ wpdb -> prefix . 'h5p_contents_user_data' , array ( 'content_id' => $ content_id , 'data_id' => $ data_id , 'user_id' => $ current_user -> ID , 'sub_content_id' => $ sub_content_id ) , array ( '%d' , '%s' , '%d' , '%d' ) ) ; } else { $ preload = ( $ preload === '0' ? 0 : 1 ) ; $ invalidate = ( $ invalidate === '0' ? 0 : 1 ) ; $ update = $ wpdb -> get_var ( $ wpdb -> prepare ( " SELECT content_id
           FROM  { $ wpdb -> prefix } h5p_contents_user_data
           WHERE content_id = %d
             AND user_id = %d
             AND data_id = %s
             AND sub_content_id = %d " , $ content_id , $ current_user -> ID , $ data_id , $ sub_content_id ) ) ; if ( $ update === NULL ) { $ wpdb -> insert ( $ wpdb -> prefix . 'h5p_contents_user_data' , array ( 'user_id' => $ current_user -> ID , 'content_id' => $ content_id , 'sub_content_id' => $ sub_content_id , 'data_id' => $ data_id , 'data' => $ data , 'preload' => $ preload , 'invalidate' => $ invalidate , 'updated_at' => current_time ( 'mysql' , 1 ) ) , array ( '%d' , '%d' , '%d' , '%s' , '%s' , '%d' , '%d' , '%s' ) ) ; } else { $ wpdb -> update ( $ wpdb -> prefix . 'h5p_contents_user_data' , array ( 'data' => $ data , 'preload' => $ preload , 'invalidate' => $ invalidate , 'updated_at' => current_time ( 'mysql' , 1 ) ) , array ( 'user_id' => $ current_user -> ID , 'content_id' => $ content_id , 'data_id' => $ data_id , 'sub_content_id' => $ sub_content_id ) , array ( '%s' , '%d' , '%d' , '%s' ) , array ( '%d' , '%d' , '%s' , '%d' ) ) ; } } H5PCore :: ajaxSuccess ( ) ; exit ; } else { $ response -> data = $ wpdb -> get_var ( $ wpdb -> prepare ( " SELECT hcud.data
         FROM  { $ wpdb -> prefix } h5p_contents_user_data hcud
         WHERE user_id = %d
           AND content_id = %d
           AND data_id = %s
           AND sub_content_id = %d " , $ current_user -> ID , $ content_id , $ data_id , $ sub_content_id ) ) ; if ( $ response -> data === NULL ) { unset ( $ response -> data ) ; } } header ( 'Cache-Control: no-cache' ) ; header ( 'Content-type: application/json; charset=utf-8' ) ; print json_encode ( $ response ) ; exit ; }
Handle user results reported by the H5P content.
Handle user results reported by the H5P content .
// Missing parameters // Remove data // Wash values to ensure 0 or 1. // Determine if we should update or insert // Insert new data // Update old data // Inserted, updated or deleted // Fetch data