From 9e2cd09cd7b7face7eb2d99cdbf4aeb0e8b3c78f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 21 Aug 2016 09:39:45 -0600 Subject: [PATCH] Changed page search to use SPL GlobIterator and more robust regex. Ever so slightly faster too! #995 --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Pages.php | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f760f84d5..5354965e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ 1. [](#bugfix) * Fix for lightbox media function throwing error [#981](https://github.com/getgrav/grav/issues/981) * Removed 307 redirect code option as it is not well supported [#743](https://github.com/getgrav/grav-plugin-admin/issues/743) + * Fixed issue with folders with name `*.md` are not confused with pages [#995](https://github.com/getgrav/grav/issues/995) # v1.1.2 ## 08/10/2016 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 26a338e6a..6468e4697 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -846,14 +846,22 @@ class Pages } $content_exists = false; - $pages_found = glob($directory . '/*' . CONTENT_EXT); + $pages_found = new \GlobIterator($directory . '/*' . CONTENT_EXT); + $page_found = null; + $page_extension = ''; - if ($pages_found) { + if ($pages_found and $pages_found->count() > 0) { + $page_extensions = $language->getFallbackPageExtensions(); + foreach ($page_extensions as $extension) { foreach ($pages_found as $found) { - if (preg_match('/^.*\/[0-9A-Za-z\-\_]+(' . $extension . ')$/', $found)) { + if ($found->isDir()) { + continue; + } + $regex = '/' . preg_quote($extension) . '$/'; + if (preg_match($regex, $found->getFilename())) { $page_found = $found; $page_extension = $extension; break 2; @@ -863,8 +871,7 @@ class Pages } if ($parent && !empty($page_found)) { - $file = new \SplFileInfo($page_found); - $page->init($file, $page_extension); + $page->init($page_found, $page_extension); $content_exists = true; @@ -1065,12 +1072,12 @@ class Pages } else { // else just sort the list according to specified key if (extension_loaded('intl')) { - $locale = setlocale(LC_COLLATE, 0); //`setlocale` with a 0 param returns the current locale set - $col = \Collator::create($locale); + $locale = setlocale(LC_COLLATE, 0); //`setlocale` with a 0 param returns the current locale set + $col = \Collator::create($locale); if ($col) { - $col->asort($list, $sort_flags); + $col->asort($list, $sort_flags); } else { - asort($list, $sort_flags); + asort($list, $sort_flags); } } else { asort($list, $sort_flags);