Export improvements

namespaces
Svein-Tore Griff With 2013-11-15 01:13:00 +01:00
parent 9dd710a8fb
commit cab8e258be
2 changed files with 17 additions and 19 deletions

View File

@ -1039,33 +1039,35 @@ Class H5PExport {
public $h5pC; public $h5pC;
/** /**
* Constructor for the H5PStorage * Constructor for the H5PExport
* *
* @param object $H5PFramework * @param object $H5PFramework
* The frameworks implementation of the H5PFrameworkInterface * The frameworks implementation of the H5PFrameworkInterface
* @param H5PCore
* Reference to an insance of H5PCore
*/ */
public function __construct($H5PFramework, $H5PCore) { public function __construct($H5PFramework, $H5PCore) {
$this->h5pF = $H5PFramework; $this->h5pF = $H5PFramework;
$this->h5pC = $H5PCore; $this->h5pC = $H5PCore;
} }
/** /**
* Create the h5p package * Create the H5P package
* *
* @param object $exports * @param object $exportData
* The data to be exported. * The data to be exported.
* @return h5p package. * @return H5P package.
*/ */
public function exportToZip($exports) { public function exportToZip($exportData) {
$h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR; $h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR;
$tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $exports['contentId']; $tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $exportData['contentId'];
$zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $exports['contentId'] . '.h5p'; $zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $exportData['contentId'] . '.h5p';
// Check if h5p-package already exists. // Check if h5p-package already exists.
if (!file_exists($zipPath) == true) { if (!file_exists($zipPath) == true) {
// Temp dir to put the h5p files in // Temp dir to put the h5p files in
@mkdir($tempPath); @mkdir($tempPath);
$this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $exports['contentId'], $tempPath . DIRECTORY_SEPARATOR . 'content'); $this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $exportData['contentId'], $tempPath . DIRECTORY_SEPARATOR . 'content');
// Copies libraries to temp dir and create mention in h5p.json // Copies libraries to temp dir and create mention in h5p.json
foreach($exports['libraries'] as $library) { foreach($exportData['libraries'] as $library) {
$source = $h5pDir . 'libraries' . DIRECTORY_SEPARATOR . $library['machineName'] . '-' . $library['majorVersion'] . '.' . $library['minorVersion']; $source = $h5pDir . 'libraries' . DIRECTORY_SEPARATOR . $library['machineName'] . '-' . $library['majorVersion'] . '.' . $library['minorVersion'];
$destination = $tempPath . DIRECTORY_SEPARATOR . $library['machineName']; $destination = $tempPath . DIRECTORY_SEPARATOR . $library['machineName'];
$this->h5pC->copyTree($source, $destination); $this->h5pC->copyTree($source, $destination);
@ -1086,13 +1088,13 @@ Class H5PExport {
} }
} }
// Make embedTypes into an array // Make embedTypes into an array
$embedTypes = explode(', ', $exports['embedType']); $embedTypes = explode(', ', $exportData['embedType']);
// Build h5p.json // Build h5p.json
$h5pJson = array ( $h5pJson = array (
'title' => $exports['title'], 'title' => $exportData['title'],
'language' => $exports['language'], 'language' => $exportData['language'],
'mainLibrary' => $exports['mainLibrary'], 'mainLibrary' => $exportData['mainLibrary'],
'embedTypes' => $embedTypes, 'embedTypes' => $embedTypes,
); );
// Add preloaded and dynamic dependencies if they exist // Add preloaded and dynamic dependencies if they exist
@ -1128,7 +1130,7 @@ Class H5PExport {
// Set headers for automagic download!! // Set headers for automagic download!!
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
header('Content-Type: application/zip'); header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=' . $exports['title'] . '.h5p'); header('Content-Disposition: attachment; filename="' . $exportData['title'] . '.h5p"');
readfile ($zipPath); readfile ($zipPath);
} }
} }

View File

@ -63,10 +63,6 @@ H5P.init = function () {
return false; return false;
}); });
}; };
if (H5PIntegration.isExportEnabled()) {
H5P.jQuery('<div class="h5p-export"><a href="' + window.location + '/h5p-export">Last ned H5P</a></div>').insertAfter($el).children();
}
}); });
// H5Ps living in iframes. Note: Fullscreen button will be added // H5Ps living in iframes. Note: Fullscreen button will be added