From a6b01f510f74c46d288515ef158ecfce787fa170 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 22 Feb 2017 11:25:05 +0100 Subject: [PATCH 1/3] Use realpath() instead of document root = safer Document root might be rewritten or incorrect for some sites(observed on multiple WP) HFP-784 --- h5p.classes.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index b0ad889..e04a0e9 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1589,15 +1589,11 @@ Class H5PExport { $zip = new ZipArchive(); $zip->open($tmpFile, ZipArchive::CREATE | ZipArchive::OVERWRITE); - // Some system needs the root prefix for ZipArchive's addFile() - $rootPrefix = (empty($_SERVER['DOCUMENT_ROOT']) ? '' : $_SERVER['DOCUMENT_ROOT'] . '/'); - // Add all the files from the tmp dir. foreach ($files as $file) { // Please note that the zip format has no concept of folders, we must // use forward slashes to separate our directories. - $zip->addFile($file->absolutePath, $file->relativePath); - $zip->addFile($rootPrefix . $file->absolutePath, $file->relativePath); + $zip->addFile(realpath($file->absolutePath), $file->relativePath); } // Close zip and remove tmp dir From bfda796ab7605889ea87b64f082233a97a52968c Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 30 Mar 2017 13:55:44 +0200 Subject: [PATCH 2/3] Allow processing after export is generated --- h5p.classes.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index e04a0e9..2b95829 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -557,7 +557,7 @@ interface H5PFrameworkInterface { /** * Will trigger after the export file is created. */ - public function afterExportCreated(); + public function afterExportCreated($content, $filename); /** * Check if user has permissions to an action @@ -1600,9 +1600,10 @@ Class H5PExport { $zip->close(); H5PCore::deleteFileTree($tmpPath); + $filename = $content['slug'] . '-' . $content['id'] . '.h5p'; try { // Save export - $this->h5pC->fs->saveExport($tmpFile, $content['slug'] . '-' . $content['id'] . '.h5p'); + $this->h5pC->fs->saveExport($tmpFile, $filename); } catch (Exception $e) { $this->h5pF->setErrorMessage($this->h5pF->t($e->getMessage())); @@ -1610,7 +1611,7 @@ Class H5PExport { } unlink($tmpFile); - $this->h5pF->afterExportCreated(); + $this->h5pF->afterExportCreated($content, $filename); return true; } From bd851f292984cff338a1d2e411de8271c0fed74d Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 18 Apr 2017 14:54:58 +0200 Subject: [PATCH 3/3] Remove http_response_code() Not supported prior to PHP 5.4 HFP-959 --- h5p.classes.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 1fe5140..44f0f1b 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2777,10 +2777,6 @@ class H5PCore { * @param null|int $status_code Http response code */ private static function printJson($data, $status_code = NULL) { - if ($status_code !== NULL) { - http_response_code($status_code); - } - header('Cache-Control: no-cache'); header('Content-type: application/json; charset=utf-8'); print json_encode($data);