function _avatar_selection_image_list in Avatar Selection 5
Same name and namespace in other branches
- 5.2 avatar_selection.module \_avatar_selection_image_list()
- 6 avatar_selection.module \_avatar_selection_image_list()
- 7 avatar_selection.module \_avatar_selection_image_list()
3 calls to _avatar_selection_image_list()
File
- ./
avatar_selection.module, line 216
Code
function _avatar_selection_image_list($user = "") {
$avatars = array();
$dir = file_create_path('avatar_selection');
$mask = '.*\\.(gif|GIF|Gif|jpg|JPG|Jpg|jpeg|JPEG|Jpeg|png|PNG|Png)';
$listings = file_scan_directory($dir, $mask, array(
'.',
'..',
'CVS',
), 0, FALSE);
$result = db_query("SELECT avatar, access, og_access FROM {avatar_selection} avs");
while ($avatar = db_fetch_object($result)) {
$avs_image = $avatar->avatar;
$avs_access = preg_split('/\\s*,\\s*/', $avatar->access);
$og_access = preg_split('/\\s*,\\s*/', $avatar->og_access);
$del_avatar = 1;
// check the organic groups
if (module_exists("og")) {
if (!empty($avatar->og_access)) {
if (!empty($user->og_groups) && is_array($user->og_groups)) {
foreach ($user->og_groups as $gid => $grp) {
if (in_array($gid, $og_access)) {
$del_avatar = 2;
break;
}
}
}
// delete it if it's not in one of the valid groups
if ($del_avatar == 1 && !empty($user) && $user->uid != 1) {
unset($listings[$avs_image]);
}
}
}
// check the user roles
if (!empty($avatar->access)) {
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $rid => $role) {
if (in_array($rid, $avs_access)) {
$del_avatar = 0;
break;
}
}
}
// delete it if it's not in a valid role
if ($del_avatar != 0 && !empty($user) && $user->uid != 1) {
unset($listings[$avs_image]);
}
}
}
$total_avatars = count($listings);
foreach ($listings as $listing) {
$avatars[$dir . '/' . $listing->basename] = theme('image', file_create_url($dir . '/' . $listing->basename), $listing->basename, $listing->basename, NULL, FALSE);
}
$selects['avatars'] = $avatars;
$selects['total'] = $total_avatars;
return $selects;
}