/**
  * Handle file uploads through AJAX.
  *
  * @since 1.1.0
  */
 public function ajax_files()
 {
     $plugin = H5P_Plugin::get_instance();
     $files_directory = $plugin->get_h5p_path();
     if (!wp_verify_nonce(filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING), 'h5p_editor_ajax')) {
         H5PCore::ajaxError(__('Invalid security token. Please reload the editor.', $this->plugin_slug));
         exit;
     }
     $contentId = filter_input(INPUT_POST, 'contentId', FILTER_SANITIZE_NUMBER_INT);
     if ($contentId) {
         $files_directory .= '/content/' . $contentId;
     } else {
         $files_directory .= '/editor';
     }
     $editor = $this->get_h5peditor_instance();
     $interface = $plugin->get_h5p_instance('interface');
     $file = new H5peditorFile($interface, $files_directory);
     if (!$file->isLoaded()) {
         H5PCore::ajaxError(__('File not found on server. Check file upload settings.', $this->plugin_slug));
         exit;
     }
     if ($file->validate() && $file->copy()) {
         // Keep track of temporary files so they can be cleaned up later.
         $editor->addTmpFile($file);
     }
     header('Cache-Control: no-cache');
     // Must support IE, so cannot use application/json
     header('Content-type: text/plain; charset=utf-8');
     print $file->getResult();
     exit;
 }
Esempio n. 2
0
     // TODO: Check permissions
     if (!\H5PCore::validToken('editorajax', required_param('token', PARAM_RAW))) {
         \H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
         exit;
     }
     // Get Content ID and Context ID for upload
     $contentid = required_param('contentId', PARAM_INT);
     $contextid = required_param('contextId', PARAM_INT);
     // Create file
     $file = new H5peditorFile(\mod_hvp\framework::instance('interface'));
     if (!$file->isLoaded()) {
         H5PCore::ajaxError(get_string('filenotfound', 'hvp'));
         break;
     }
     // Make sure file is valid
     if ($file->validate()) {
         $core = \mod_hvp\framework::instance('core');
         // Save the valid file
         $file_id = $core->fs->saveFile($file, $contentid, $contextid);
         // Track temporary files for later cleanup
         $DB->insert_record_raw('hvp_tmpfiles', array('id' => $file_id), false, false, true);
     }
     $file->printResult();
     break;
     /*
      * Throw error if AJAX isnt handeled
      */
 /*
  * Throw error if AJAX isnt handeled
  */
 default:
Esempio n. 3
0
 public function files()
 {
     // $files_directory = file_directory_path();
     $files_directory = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media';
     if (isset($_POST['contentId']) && $_POST['contentId']) {
         $files_directory .= DIRECTORY_SEPARATOR . 'h5p/content/' . $_POST['contentId'];
     } else {
         $files_directory .= DIRECTORY_SEPARATOR . 'h5peditor';
     }
     $file = new H5peditorFile($files_directory);
     if (!$file->isLoaded()) {
         return;
     }
     if ($file->validate() && $file->copy()) {
         $storage = H5PJoomla::getInstance('editorstorage');
         $storage->addTempFile($file);
     }
     print $file->getResult();
 }
 /**
  * Handle file uploads through AJAX.
  *
  * @since 1.1.0
  */
 public function ajax_files()
 {
     global $wpdb;
     $plugin = H5P_Plugin::get_instance();
     $files_directory = $plugin->get_h5p_path();
     $contentId = filter_input(INPUT_POST, 'contentId', FILTER_SANITIZE_NUMBER_INT);
     if ($contentId) {
         $files_directory .= '/content/' . $contentId;
     } else {
         $files_directory .= '/editor';
     }
     $editor = $this->get_h5peditor_instance();
     $interface = $plugin->get_h5p_instance('interface');
     $file = new H5peditorFile($interface, $files_directory);
     if (!$file->isLoaded()) {
         exit;
     }
     if ($file->validate() && $file->copy()) {
         // Keep track of temporary files so they can be cleaned up later.
         $editor->addTmpFile($file);
     }
     header('Cache-Control: no-cache');
     header('Content-type: application/json; charset=utf-8');
     print $file->getResult();
     exit;
 }