diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index a1cd27f..88a4776 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -275,6 +275,8 @@ class H5PDefaultStorage implements \H5PFileStorage { throw new \Exception('unabletocopy'); } + $ignoredFiles = self::getIgnoredFiles("{$source}/.h5pignore"); + $dir = opendir($source); if ($dir === FALSE) { trigger_error('Unable to open directory ' . $source, E_USER_WARNING); @@ -282,7 +284,7 @@ class H5PDefaultStorage implements \H5PFileStorage { } while (false !== ($file = readdir($dir))) { - if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') { + if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore' && !in_array($file, $ignoredFiles)) { if (is_dir("{$source}/{$file}")) { self::copyFileTree("{$source}/{$file}", "{$destination}/{$file}"); } @@ -294,6 +296,25 @@ class H5PDefaultStorage implements \H5PFileStorage { closedir($dir); } + /** + * Retrieve array of file names from file. + * + * @param string $file + * @return array Array with files that should be ignored + */ + private static function getIgnoredFiles($file) { + if (file_exists($file) === FALSE) { + return array(); + } + + $contents = file_get_contents($file); + if ($contents === FALSE) { + return array(); + } + + return preg_split('/\s+/', $contents); + } + /** * Recursive function that makes sure the specified directory exists and * is writable.