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() { $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; }
/** * 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; }