mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-18 01:08:52 +00:00
[ticket/12273] Use RecursiveDirectoryIterator with filter in php_exporter
PHPBB3-12273
This commit is contained in:
parent
7a44f66448
commit
927c219b1f
2 changed files with 59 additions and 42 deletions
|
@ -100,17 +100,22 @@ class php_exporter
|
|||
/**
|
||||
* Returns a list of files in $dir
|
||||
*
|
||||
* 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)
|
||||
* @return array List of files (including the path)
|
||||
*/
|
||||
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\event\recursive_event_filter_iterator(
|
||||
new \RecursiveDirectoryIterator(
|
||||
$dir,
|
||||
\FilesystemIterator::SKIP_DOTS
|
||||
)
|
||||
),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||
);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
@ -120,42 +125,9 @@ class php_exporter
|
|||
$files = array();
|
||||
foreach ($iterator as $file_info)
|
||||
{
|
||||
/** @var \DirectoryIterator $file_info */
|
||||
if ($file_info->isDot())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not scan some directories
|
||||
if ($file_info->isDir() && (
|
||||
($path == '' && in_array($file_info->getFilename(), array(
|
||||
'cache',
|
||||
'develop',
|
||||
'ext',
|
||||
'files',
|
||||
'language',
|
||||
'store',
|
||||
'vendor',
|
||||
)))
|
||||
|| ($path == '/includes' && in_array($file_info->getFilename(), array('utf')))
|
||||
|| ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data')))
|
||||
|| ($path == '/phpbb' && in_array($file_info->getFilename(), array('event')))
|
||||
))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else 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(), -4) == '.php')
|
||||
{
|
||||
$files[] = $file_info->getFilename();
|
||||
}
|
||||
/** @var \RecursiveDirectoryIterator $file_info */
|
||||
$relative_path = $iterator->getInnerIterator()->getSubPathname();
|
||||
$files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
|
||||
}
|
||||
|
||||
return $files;
|
||||
|
|
45
phpBB/phpbb/event/recursive_event_filter_iterator.php
Normal file
45
phpBB/phpbb/event/recursive_event_filter_iterator.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package event
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\event;
|
||||
|
||||
/**
|
||||
* Class recursive_event_filter_iterator
|
||||
*
|
||||
* This filter ignores directories and files starting with a dot.
|
||||
* It also skips some directories that do not contain events anyway,
|
||||
* such as e.g. files/, store/ and vendor/
|
||||
*
|
||||
* @package phpbb\event
|
||||
*/
|
||||
class recursive_event_filter_iterator extends \RecursiveFilterIterator
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function accept()
|
||||
{
|
||||
$relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $this->current());
|
||||
$filename = $this->current()->getFilename();
|
||||
|
||||
return (substr($relative_path, -4) === '.php' || $this->current()->isDir())
|
||||
&& $filename[0] !== '.'
|
||||
&& strpos($relative_path, 'phpBB/cache/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/develop/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/ext/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/files/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/includes/utf/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/language/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/phpbb/db/migration/data/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/phpbb/event/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/store/') !== 0
|
||||
&& strpos($relative_path, 'phpBB/vendor/') !== 0
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue