[feature/avatars] Use RecursiveDirectoryIterator for gallery avatar

RecursiveDirectoryIterator is now used for populating the avatar list
array of the gallery avatar.

PHPBB3-10018
This commit is contained in:
Marc Alexander 2012-11-21 21:42:42 +01:00
parent 24ac039336
commit 8a01bc1718

View file

@ -159,29 +159,24 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
$avatar_list = array();
$path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
$dh = @opendir($path);
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file_info)
{
$file_path = $file_info->getPath();
$image = $file_info->getFilename();
if ($dh)
{
while (($cat = readdir($dh)) !== false)
{
if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
{
if ($ch = @opendir("$path/$cat"))
{
while (($image = readdir($ch)) !== false)
{
// Match all images in the gallery folder
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image))
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image) && is_file($file_path . '/' . $image))
{
if (function_exists('getimagesize'))
{
$dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image);
$dims = getimagesize($file_path . '/' . $image);
}
else
{
$dims = array(0, 0);
}
$cat = str_replace("$path/", '', $file_path);
$avatar_list[$cat][$image] = array(
'file' => rawurlencode($cat) . '/' . rawurlencode($image),
'filename' => rawurlencode($image),
@ -191,13 +186,6 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
);
}
}
@closedir($ch);
}
}
}
@closedir($dh);
}
@ksort($avatar_list);
if ($this->cache != null)