/**
  * Provide data for content results view.
  *
  * @since 1.2.0
  */
 public function ajax_content_results()
 {
     $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
     if (!$id) {
         return;
         // Missing id
     }
     $plugin = H5P_Plugin::get_instance();
     $content = $plugin->get_content($id);
     if (is_string($content) || !$this->current_user_can_edit($content)) {
         return;
         // Error loading content or no access
     }
     $plugin_admin = H5P_Plugin_Admin::get_instance();
     $plugin_admin->print_results($id);
 }
예제 #2
0
 /**
  * Handles upload of H5P libraries.
  *
  * @since 1.1.0
  */
 public function process_libraries()
 {
     $post = $_SERVER['REQUEST_METHOD'] === 'POST';
     if ($post && isset($_FILES['h5p_file']) && $_FILES['h5p_file']['error'] === 0) {
         check_admin_referer('h5p_library', 'lets_upgrade_that');
         // Verify form
         $plugin_admin = H5P_Plugin_Admin::get_instance();
         $plugin_admin->handle_upload(NULL, filter_input(INPUT_POST, 'h5p_upgrade_only') ? TRUE : FALSE);
         return;
     }
     if ($post && isset($_FILES['h5p_file']) && $_FILES['h5p_file']['error']) {
         $phpFileUploadErrors = array(1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 3 => 'The uploaded file was only partially uploaded', 4 => 'No file was uploaded', 6 => 'Missing a temporary folder', 7 => 'Failed to write file to disk.', 8 => 'A PHP extension stopped the file upload.');
         $errorMessage = $phpFileUploadErrors[$_FILES['h5p_file']['error']];
         H5P_Plugin_Admin::set_error(__($errorMessage, $this->plugin_slug));
         return;
     }
     $task = filter_input(INPUT_GET, 'task');
     if ($task === 'delete') {
         $library = $this->get_library();
         if (!$library) {
             return;
         }
         $plugin = H5P_Plugin::get_instance();
         $interface = $plugin->get_h5p_instance('interface');
         // Check if this library can be deleted
         $usage = $interface->getLibraryUsage($library->id, $interface->getNumNotFiltered() ? TRUE : FALSE);
         if ($usage['content'] !== 0 || $usage['libraries'] !== 0) {
             H5P_Plugin_Admin::set_error(__('This Library is used by content or other libraries and can therefore not be deleted.', $this->plugin_slug));
             return;
             // Nope
         }
         if ($post) {
             check_admin_referer('h5p_library', 'lets_delete_this');
             // Verify delete form
             $interface->deleteLibrary($this->library);
             wp_safe_redirect(admin_url('admin.php?page=h5p_libraries'));
         }
     }
 }
 /**
  * Handles upload of H5P libraries.
  *
  * @since 1.1.0
  */
 public function process_libraries()
 {
     $post = $_SERVER['REQUEST_METHOD'] === 'POST';
     $task = filter_input(INPUT_GET, 'task');
     if ($post) {
         // A form as has been submitted
         if (isset($_FILES['h5p_file'])) {
             // If file upload, we're uploading libraries
             if ($_FILES['h5p_file']['error'] === 0) {
                 // No upload errors, try to install package
                 check_admin_referer('h5p_library', 'lets_upgrade_that');
                 // Verify form
                 $plugin_admin = H5P_Plugin_Admin::get_instance();
                 $plugin_admin->handle_upload(NULL, filter_input(INPUT_POST, 'h5p_upgrade_only') ? TRUE : FALSE);
             } else {
                 $phpFileUploadErrors = array(1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 3 => 'The uploaded file was only partially uploaded', 4 => 'No file was uploaded', 6 => 'Missing a temporary folder', 7 => 'Failed to write file to disk.', 8 => 'A PHP extension stopped the file upload.');
                 $errorMessage = $phpFileUploadErrors[$_FILES['h5p_file']['error']];
                 H5P_Plugin_Admin::set_error(__($errorMessage, $this->plugin_slug));
             }
             return;
         } elseif ($task === NULL) {
             // No files, we must be trying to auto download & update
             check_admin_referer('h5p_update', 'download_update');
             // Verify form
             if (!H5P_Plugin_Admin::download_h5p_libraries(TRUE)) {
                 // Ignore update if it failed, user must manually update.
                 update_option('h5p_current_update', get_option('h5p_update_available', 0));
                 H5P_Plugin_Admin::set_error(vsprintf(wp_kses(__('Unfortunately, we were unable to update your installed content types. You must manually download the update from <a href="%s" target="_blank">H5P.org</a>, and then upload it through the <em>Upload Libraries</em> section. If you need futher assistance, please file a <a href="%s" target="_blank">support request</a> or check out our <a href="%s" target="_blank">forum</a>.', $this->plugin_slug), array('a' => array('href' => array(), 'target' => array()), 'em' => array())), array(esc_url('https://h5p.org/update-all-content-types'), esc_url('https://wordpress.org/support/plugin/h5p'), esc_url('https://h5p.org/forum'))));
             }
         }
     }
     if ($task === 'delete') {
         $library = $this->get_library();
         if (!$library) {
             return;
         }
         $plugin = H5P_Plugin::get_instance();
         $interface = $plugin->get_h5p_instance('interface');
         // Check if this library can be deleted
         $usage = $interface->getLibraryUsage($library->id, $interface->getNumNotFiltered() ? TRUE : FALSE);
         if ($usage['content'] !== 0 || $usage['libraries'] !== 0) {
             H5P_Plugin_Admin::set_error(__('This Library is used by content or other libraries and can therefore not be deleted.', $this->plugin_slug));
             return;
             // Nope
         }
         if ($post) {
             check_admin_referer('h5p_library', 'lets_delete_this');
             // Verify delete form
             $interface->deleteLibrary($this->library);
             wp_safe_redirect(admin_url('admin.php?page=h5p_libraries'));
         }
     }
 }