public/wordpress/wp-content/plugins/h5p/admin/class-h5p-content-admin.php
/**
   * Handle form submit when uploading, deleteing or editing H5Ps.
   * TODO: Rename to process_content_form ?
   *
   * @since 1.1.0
   */
Handle form submit when uploading, deleteing or editing H5Ps.


Handle form submit when uploading deleteing or editing H5Ps .
public function process_new_content() {
    $plugin = H5P_Plugin::get_instance();
    $consent = filter_input(INPUT_POST, 'consent', FILTER_VALIDATE_BOOLEAN);
    if ($consent !== NULL && !get_option('h5p_has_request_user_consent', FALSE) && current_user_can('manage_options')) {
      check_admin_referer('h5p_consent', 'can_has'); 
      update_option('h5p_hub_is_enabled', $consent);
      update_option('h5p_send_usage_statistics', $consent);
      update_option('h5p_has_request_user_consent', TRUE);
    }
    $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
    if ($id) {
      $this->load_content($id);
      if (is_string($this->content)) {
        H5P_Plugin_Admin::set_error($this->content);
        $this->content = NULL;
      }
    }
    if ($this->content !== NULL) {
      if (!$this->current_user_can_edit($this->content)) {
        H5P_Plugin_Admin::set_error(__('You are not allowed to edit this content.', $this->plugin_slug));
        return;
      }
      $delete = filter_input(INPUT_GET, 'delete');
      if ($delete) {
        if (wp_verify_nonce($delete, 'deleting_h5p_content')) {
          $this->set_content_tags($this->content['id']);
          $storage = $plugin->get_h5p_instance('storage');
          $storage->deletePackage($this->content);
          new H5P_Event('content', 'delete',
              $this->content['id'],
              $this->content['title'],
              $this->content['library']['name'],
              $this->content['library']['majorVersion'] . '.' . $this->content['library']['minorVersion']);
          wp_safe_redirect(admin_url('admin.php?page=h5p'));
          return;
        }
        H5P_Plugin_Admin::set_error(__('Invalid confirmation code, not deleting.', $this->plugin_slug));
      }
    }
    $action = filter_input(INPUT_POST, 'action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^(upload|create)$/')));
    if ($action) {
      check_admin_referer('h5p_content', 'yes_sir_will_do'); 
      $core = $plugin->get_h5p_instance('core'); 
      $result = FALSE;
      if ($action === 'create') {
        $result = $this->handle_content_creation($this->content);
      }
      elseif (isset($_FILES['h5p_file']) && $_FILES['h5p_file']['error'] === 0) {
        $content = ($this->content === NULL ? array('disable' => H5PCore::DISABLE_NONE) : $this->content);
        $content['uploaded'] = true;
        $this->get_disabled_content_features($core, $content);
        $plugin_admin = H5P_Plugin_Admin::get_instance();
        $result = $plugin_admin->handle_upload($content);
      }
      if ($result) {
        $content['id'] = $result;
        $this->set_content_tags($content['id'], filter_input(INPUT_POST, 'tags'));
        wp_safe_redirect(admin_url('admin.php?page=h5p&task=show&id=' . $result));
        exit;
      }
    }
  }
public function process_new_content ( ) { $ plugin = H5P_Plugin :: get_instance ( ) ; $ consent = filter_input ( INPUT_POST , 'consent' , FILTER_VALIDATE_BOOLEAN ) ; if ( $ consent !== NULL && ! get_option ( 'h5p_has_request_user_consent' , FALSE ) && current_user_can ( 'manage_options' ) ) { check_admin_referer ( 'h5p_consent' , 'can_has' ) ; update_option ( 'h5p_hub_is_enabled' , $ consent ) ; update_option ( 'h5p_send_usage_statistics' , $ consent ) ; update_option ( 'h5p_has_request_user_consent' , TRUE ) ; } $ id = filter_input ( INPUT_GET , 'id' , FILTER_SANITIZE_NUMBER_INT ) ; if ( $ id ) { $ this -> load_content ( $ id ) ; if ( is_string ( $ this -> content ) ) { H5P_Plugin_Admin :: set_error ( $ this -> content ) ; $ this -> content = NULL ; } } if ( $ this -> content !== NULL ) { if ( ! $ this -> current_user_can_edit ( $ this -> content ) ) { H5P_Plugin_Admin :: set_error ( __ ( 'You are not allowed to edit this content.' , $ this -> plugin_slug ) ) ; return ; } $ delete = filter_input ( INPUT_GET , 'delete' ) ; if ( $ delete ) { if ( wp_verify_nonce ( $ delete , 'deleting_h5p_content' ) ) { $ this -> set_content_tags ( $ this -> content [ 'id' ] ) ; $ storage = $ plugin -> get_h5p_instance ( 'storage' ) ; $ storage -> deletePackage ( $ this -> content ) ; new H5P_Event ( 'content' , 'delete' , $ this -> content [ 'id' ] , $ this -> content [ 'title' ] , $ this -> content [ 'library' ] [ 'name' ] , $ this -> content [ 'library' ] [ 'majorVersion' ] . '.' . $ this -> content [ 'library' ] [ 'minorVersion' ] ) ; wp_safe_redirect ( admin_url ( 'admin.php?page=h5p' ) ) ; return ; } H5P_Plugin_Admin :: set_error ( __ ( 'Invalid confirmation code, not deleting.' , $ this -> plugin_slug ) ) ; } } $ action = filter_input ( INPUT_POST , 'action' , FILTER_VALIDATE_REGEXP , array ( 'options' => array ( 'regexp' => '/^(upload|create)$/' ) ) ) ; if ( $ action ) { check_admin_referer ( 'h5p_content' , 'yes_sir_will_do' ) ; $ core = $ plugin -> get_h5p_instance ( 'core' ) ; $ result = FALSE ; if ( $ action === 'create' ) { $ result = $ this -> handle_content_creation ( $ this -> content ) ; } elseif ( isset ( $ _FILES [ 'h5p_file' ] ) && $ _FILES [ 'h5p_file' ] [ 'error' ] === 0 ) { $ content = ( $ this -> content === NULL ? array ( 'disable' => H5PCore :: DISABLE_NONE ) : $ this -> content ) ; $ content [ 'uploaded' ] = true ; $ this -> get_disabled_content_features ( $ core , $ content ) ; $ plugin_admin = H5P_Plugin_Admin :: get_instance ( ) ; $ result = $ plugin_admin -> handle_upload ( $ content ) ; } if ( $ result ) { $ content [ 'id' ] = $ result ; $ this -> set_content_tags ( $ content [ 'id' ] , filter_input ( INPUT_POST , 'tags' ) ) ; wp_safe_redirect ( admin_url ( 'admin.php?page=h5p&task=show&id=' . $ result ) ) ; exit ; } } }
Handle form submit when uploading, deleteing or editing H5Ps.
Handle form submit when uploading deleteing or editing H5Ps .
// Verify form // Check if we have any content or errors loading content // We have existing content // The user isn't allowed to edit this content // Check if we're deleting content // Log content delete // Check if we're uploading or creating content // Verify form // Make sure core is loaded // Handle creation of new content. // Create new content if none exists // Handle file upload