function _avatar_selection_scan_images in Avatar Selection 6
Same name and namespace in other branches
- 5.2 avatar_selection.module \_avatar_selection_scan_images()
- 7 avatar_selection.admin.inc \_avatar_selection_scan_images()
Scan the directory for new files.
Parameters
$name: The name of the avatar(s).
$access: The permission - the value determines which user roles have rights to see the avatar.
$og: Organic group (optional).
$weight: Avatar weight to assign.
Return value
Number of images found.
1 call to _avatar_selection_scan_images()
- avatar_selection_upload_form_submit in ./
avatar_selection.admin.inc - Submit the image upload form in the Avatar Selection administration page.
File
- ./
avatar_selection.admin.inc, line 24 - Administrative page callbacks for the avatar_selection module.
Code
function _avatar_selection_scan_images($name, $access, $og = array(), $weight = 0) {
$avatars = array();
$add_count = 0;
$delete_count = 0;
$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, TRUE);
$result = db_query("SELECT avatar FROM {avatar_selection} avs");
while ($avatar = db_fetch_object($result)) {
$avatars[$avatar->avatar] = $avatar->avatar;
}
// Search for new files. Remove matching records from avatars array.
foreach ($listings as $listing) {
$filename = str_replace("{$dir}/", '', $listing->filename);
if (in_array($filename, $avatars)) {
unset($avatars[$filename]);
}
else {
_avatar_selection_save_avatar_info(0, $filename, empty($name) ? $filename : $name, $access, $og, $weight);
$add_count++;
}
}
// Remove records from database where we have an avatar entry but no
// corresponding file.
foreach ($avatars as $avatar) {
avatar_selection_image_delete($avatar);
$delete_count++;
}
$count['add'] = $add_count;
$count['delete'] = $delete_count;
return $count;
}