From f956d7113ff989168de87709bf5537b830e23c09 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 8 Apr 2015 22:55:27 +0200 Subject: [PATCH] use FilesystemIterator to solve windows path issue more elegantly --- system/src/Grav/Common/Page/Media.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index 83a4762ca..93c8ddb04 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -40,14 +40,14 @@ class Media extends Getters $this->path = $path; - $iterator = new \DirectoryIterator($path); + $iterator = new \FilesystemIterator($path, \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::SKIP_DOTS); $media = []; /** @var \DirectoryIterator $info */ - foreach ($iterator as $info) { + foreach ($iterator as $path => $info) { // Ignore folders and Markdown files. - if ($info->isDot() || !$info->isFile() || $info->getExtension() == 'md') { + if (!$info->isFile() || $info->getExtension() == 'md') { continue; } @@ -58,9 +58,9 @@ class Media extends Getters if ($type === 'alternative') { $media["{$basename}.{$ext}"][$type] = isset($media["{$basename}.{$ext}"][$type]) ? $media["{$basename}.{$ext}"][$type] : []; - $media["{$basename}.{$ext}"][$type][$extra] = str_replace(DIRECTORY_SEPARATOR, DS, $info->getPathname()); + $media["{$basename}.{$ext}"][$type][$extra] = $path; } else { - $media["{$basename}.{$ext}"][$type] = str_replace(DIRECTORY_SEPARATOR, DS, $info->getPathname()); + $media["{$basename}.{$ext}"][$type] = $path; } }