From 7a44f66448fcdc53ed3c371c25317e553217eec8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 26 Apr 2014 16:59:18 +0200 Subject: [ticket/12273] Use RecursiveDirectoryIterator in md_exporter PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 540ec9a0d7..cb14ff5778 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -377,14 +377,21 @@ class md_exporter * Works recursive with any depth * * @param string $dir Directory to go through - * @param string $path Path from root to $dir * @return array List of files (including directories) */ - public function get_recursive_file_list($dir, $path = '') + public function get_recursive_file_list($dir) { try { - $iterator = new \DirectoryIterator($dir); + $iterator = new \RecursiveIteratorIterator( + new \phpbb\recursive_dot_prefix_filter_iterator( + new \RecursiveDirectoryIterator( + $dir, + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::SELF_FIRST + ); } catch (\Exception $e) { @@ -394,24 +401,17 @@ class md_exporter $files = array(); foreach ($iterator as $file_info) { - /** @var \DirectoryIterator $file_info */ - if ($file_info->isDot()) + /** @var \RecursiveDirectoryIterator $file_info */ + if ($file_info->isDir()) { continue; } - // Do not scan some directories - if ($file_info->isDir()) - { - $sub_dir = $this->get_recursive_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); - foreach ($sub_dir as $file) - { - $files[] = $file_info->getFilename() . '/' . $file; - } - } - else if (substr($file_info->getFilename(), -5) == '.html') + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + + if (substr($relative_path, -5) == '.html') { - $files[] = $file_info->getFilename(); + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); } } -- cgit v1.2.1