Add support for temporary file suffix

HFP-1100
pull/40/head
Frode Petterson 2017-07-07 10:51:57 +02:00
parent f07ce1b3c3
commit b1531bcbc0
3 changed files with 19 additions and 1 deletions

View File

@ -426,6 +426,18 @@ class H5PDefaultStorage implements \H5PFileStorage {
$path = "{$this->path}/content/{$contentId}/{$file}"; $path = "{$this->path}/content/{$contentId}/{$file}";
if (file_exists($path)) { if (file_exists($path)) {
unlink($path); unlink($path);
// Clean up any empty parent directories to avoid cluttering the file system
$parts = explode('/', $path);
while (array_pop($parts) !== NULL) {
$dir = implode('/', $parts);
if (is_dir($dir) && count(scandir($dir)) === 2) { // empty contains '.' and '..'
rmdir($dir); // Remove empty parent
}
else {
return; // Not empty
}
}
} }
} }

View File

@ -3400,6 +3400,11 @@ class H5PContentValidator {
$file->path = $matches[5]; $file->path = $matches[5];
} }
// Remove temporary files suffix
if (substr($file->path, -4, 4) === '#tmp') {
$file->path = substr($file->path, 0, strlen($file->path) - 4);
}
// Make sure path and mime does not have any special chars // Make sure path and mime does not have any special chars
$file->path = htmlspecialchars($file->path, ENT_QUOTES, 'UTF-8', FALSE); $file->path = htmlspecialchars($file->path, ENT_QUOTES, 'UTF-8', FALSE);
if (isset($file->mime)) { if (isset($file->mime)) {

View File

@ -678,7 +678,8 @@ H5P.getPath = function (path, contentId) {
} }
var prefix; var prefix;
if (contentId !== undefined) { var isTmpFile = (path.substr(-4,4) === '#tmp');
if (contentId !== undefined && !isTmpFile) {
// Check for custom override URL // Check for custom override URL
if (H5PIntegration.contents !== undefined && if (H5PIntegration.contents !== undefined &&
H5PIntegration.contents['cid-' + contentId]) { H5PIntegration.contents['cid-' + contentId]) {