Merge branch 'no-url-fopen' into content-user-data

semantics-font
Frode Petterson 2015-03-23 10:54:00 +01:00
commit e153acbf3e
2 changed files with 49 additions and 19 deletions

View File

@ -1482,8 +1482,6 @@ Class H5PExport {
// Build h5p.json // Build h5p.json
$h5pJson = array ( $h5pJson = array (
'title' => $content['title'], 'title' => $content['title'],
// TODO - stop using 'und', this is not the preferred way.
// Either remove language from the json if not existing, or use "language": null
'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und', 'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und',
'mainLibrary' => $content['library']['name'], 'mainLibrary' => $content['library']['name'],
'embedTypes' => $embedTypes, 'embedTypes' => $embedTypes,
@ -1514,28 +1512,52 @@ Class H5PExport {
$results = print_r(json_encode($h5pJson), true); $results = print_r(json_encode($h5pJson), true);
file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'h5p.json', $results); file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'h5p.json', $results);
// Get a complete file list from our tmp dir
$files = array();
self::populateFileList($tempPath, $files);
// Create new zip instance. // Create new zip instance.
$zip = new ZipArchive(); $zip = new ZipArchive();
$zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
// Get all files and folders in $tempPath // Add all the files from the tmp dir.
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); foreach ($files as $file) {
// Add files to zip // Please note that the zip format has no concept of folders, we must
foreach ($iterator as $key => $value) { // use forward slashes to separate our directories.
$test = '.'; $zip->addFile($file->absolutePath, $file->relativePath);
// Do not add the folders '.' and '..' to the zip. This will make zip invalid.
if (substr_compare($key, $test, -strlen($test), strlen($test)) !== 0) {
// Get files path in $tempPath
$filePath = explode($tempPath . DIRECTORY_SEPARATOR, $key);
// Add files to the zip with the intended file-structure
$zip->addFile($key, $filePath[1]);
}
} }
// Close zip and remove temp dir // Close zip and remove temp dir
$zip->close(); $zip->close();
H5PCore::deleteFileTree($tempPath); H5PCore::deleteFileTree($tempPath);
} }
/**
* Recursive function the will add the files of the given directory to the
* given files list. All files are objects with an absolute path and
* a relative path. The relative path is forward slashes only! Great for
* use in zip files and URLs.
*
* @param string $dir path
* @param array $files list
* @param string $relative prefix. Optional
*/
private static function populateFileList($dir, &$files, $relative = '') {
$strip = strlen($dir) + 1;
foreach (glob($dir . DIRECTORY_SEPARATOR . '*') as $file) {
$rel = $relative . substr($file, $strip);
if (is_dir($file)) {
self::populateFileList($file, $files, $rel . '/');
}
else {
$files[] = (object) array(
'absolutePath' => $file,
'relativePath' => $rel
);
}
}
}
/** /**
* Delete .h5p file * Delete .h5p file
* *
@ -1713,8 +1735,6 @@ class H5PCore {
// Recreate export file // Recreate export file
$exporter = new H5PExport($this->h5pF, $this); $exporter = new H5PExport($this->h5pF, $this);
$exporter->createExportFile($content); $exporter->createExportFile($content);
// TODO: Should we rather create the file once first accessed, like imagecache?
} }
// Cache. // Cache.
@ -2233,8 +2253,6 @@ class H5PCore {
/** /**
* Helper function for creating markup for the unsupported libraries list * Helper function for creating markup for the unsupported libraries list
* *
* TODO: Make help text translatable
*
* @return string Html * @return string Html
* */ * */
public function createMarkupForUnsupportedLibraryList($libraries) { public function createMarkupForUnsupportedLibraryList($libraries) {
@ -2335,7 +2353,6 @@ class H5PContentValidator {
// Keep track of the libraries we load to avoid loading it multiple times. // Keep track of the libraries we load to avoid loading it multiple times.
$this->libraries = array(); $this->libraries = array();
// TODO: Should this possible be done in core's loadLibrary? This might be done multiple places.
// Keep track of all dependencies for the given content. // Keep track of all dependencies for the given content.
$this->dependencies = array(); $this->dependencies = array();

View File

@ -538,6 +538,19 @@ H5P.getPath = function (path, contentId) {
return prefix + '/' + path; return prefix + '/' + path;
}; };
/**
* THIS FUNCTION IS DEPRECATED, USE getPath INSTEAD
* Will be remove march 2016.
*
* Find the path to the content files folder based on the id of the content
*
* @param contentId
* Id of the content requesting a path
*/
H5P.getContentPath = function (contentId) {
return H5PIntegration.url + '/content/' + contentId;
};
/** /**
* Get library class constructor from H5P by classname. * Get library class constructor from H5P by classname.
* Note that this class will only work for resolve "H5P.NameWithoutDot". * Note that this class will only work for resolve "H5P.NameWithoutDot".