aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/avatar
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2012-11-21 21:42:42 +0100
committerMarc Alexander <admin@m-a-styles.de>2012-11-21 21:42:42 +0100
commit8a01bc171837be40818f285035ccefa5ac819213 (patch)
tree57052a9a2665e4f14382882ef4d621398a20d23a /phpBB/includes/avatar
parent24ac0393360aed07a17b7acaca0add6083cf8ddd (diff)
downloadforums-8a01bc171837be40818f285035ccefa5ac819213.tar
forums-8a01bc171837be40818f285035ccefa5ac819213.tar.gz
forums-8a01bc171837be40818f285035ccefa5ac819213.tar.bz2
forums-8a01bc171837be40818f285035ccefa5ac819213.tar.xz
forums-8a01bc171837be40818f285035ccefa5ac819213.zip
[feature/avatars] Use RecursiveDirectoryIterator for gallery avatar
RecursiveDirectoryIterator is now used for populating the avatar list array of the gallery avatar. PHPBB3-10018
Diffstat (limited to 'phpBB/includes/avatar')
-rw-r--r--phpBB/includes/avatar/driver/local.php54
1 files changed, 21 insertions, 33 deletions
diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php
index a206f5b1b0..8ac511f909 100644
--- a/phpBB/includes/avatar/driver/local.php
+++ b/phpBB/includes/avatar/driver/local.php
@@ -159,45 +159,33 @@ 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);
-
- if ($dh)
+ $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST);
+ foreach ($iterator as $file_info)
{
- while (($cat = readdir($dh)) !== false)
+ $file_path = $file_info->getPath();
+ $image = $file_info->getFilename();
+
+ // Match all images in the gallery folder
+ if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image) && is_file($file_path . '/' . $image))
{
- if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
+ if (function_exists('getimagesize'))
{
- 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 (function_exists('getimagesize'))
- {
- $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image);
- }
- else
- {
- $dims = array(0, 0);
- }
- $avatar_list[$cat][$image] = array(
- 'file' => rawurlencode($cat) . '/' . rawurlencode($image),
- 'filename' => rawurlencode($image),
- 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
- 'width' => $dims[0],
- 'height' => $dims[1],
- );
- }
- }
- @closedir($ch);
- }
+ $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),
+ 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
+ 'width' => $dims[0],
+ 'height' => $dims[1],
+ );
}
- @closedir($dh);
}
-
@ksort($avatar_list);
if ($this->cache != null)