Index: avatar_selection.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/avatar_selection/Attic/avatar_selection.install,v retrieving revision 1.1.2.8.2.1 diff -u -r1.1.2.8.2.1 avatar_selection.install --- avatar_selection.install 7 Dec 2007 09:31:17 -0000 1.1.2.8.2.1 +++ avatar_selection.install 19 Dec 2007 12:30:08 -0000 @@ -39,6 +39,7 @@ variable_del('avatar_selection_force_user_avatar'); variable_del('avatar_selection_avatar_per_page'); variable_del('avatar_selection_set_random_default'); + variable_del('avatar_selection_distinctive_avatars'); // delete the images $dir = file_create_path('avatar_selection') .'/'; Index: avatar_selection.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/avatar_selection/avatar_selection.module,v retrieving revision 1.1.2.20.2.2 retrieving revision 1.1.2.20.2.4 diff -u -r1.1.2.20.2.2 -r1.1.2.20.2.4 --- avatar_selection.module 17 Dec 2007 14:06:55 -0000 1.1.2.20.2.2 +++ avatar_selection.module 19 Dec 2007 13:11:27 -0000 1.1.2.20.2.4 @@ -139,7 +139,7 @@ // Don't allow user to delete a selected avatar $path = '/avatar_selection/'; - if ($form['picture']['current_picture']['#value'] + if (!empty($form['picture']['current_picture']['#value']) && preg_match($path, $form['picture']['current_picture']['#value'])) { unset($form['picture']['picture_delete']); } @@ -210,8 +210,11 @@ function avatar_selection_get_random_image($user) { $avatars = _avatar_selection_image_list($user); - $avatar = array_rand($avatars['avatars'], 1); - return $avatar; + if ($avatars['total'] > 0) { + $avatar = array_rand($avatars['avatars'], 1); + return $avatar; + } + return ' '; } function _avatar_selection_image_list($user = "") { @@ -262,6 +265,15 @@ } } } + + // remove ones already in use if necessary + if (!empty($user) && variable_get('avatar_selection_distinctive_avatars', FALSE)) { + $result = db_query("SELECT DISTINCT avs.avatar FROM {avatar_selection} avs LEFT JOIN {users} u ON u.picture = avs.avatar WHERE u.picture IS NOT NULL AND u.uid <> %d", $user->uid); + while ($avatar = db_fetch_object($result)) { + while ($avatar = db_fetch_object($result)) { + $avs_image = $avatar->avatar; + unset($listings[$avs_image]); + } + } $total_avatars = count($listings); @@ -342,6 +354,11 @@ '#description' => t('Automatically set a random avatar image to be used when the user doesn\'t set one for their account.'), '#default_value' => variable_get('avatar_selection_set_random_default', FALSE), ); + $form['update']['distinctive_avatars'] = array('#type' => 'checkbox', + '#title' => t('Enable distinctive avatars.'), + '#description' => t('Only allow users to pick an avatar that isn\'t already in use by another user. If there are no available avatars left, the default avatar image will be used.'), + '#default_value' => variable_get('avatar_selection_distinctive_avatars', FALSE), + ); $form['update']['submit'] = array( @@ -588,6 +605,7 @@ variable_set('avatar_selection_force_user_avatar', $form_values['force_set_image']); variable_set('avatar_selection_avatar_per_page', $form_values['avatar_per_page']); variable_set('avatar_selection_set_random_default', $form_values['set_random_default']); + variable_set('avatar_selection_distinctive_avatars', $form_values['distinctive_avatars']); drupal_set_message(t('Configuration has been updated.')); } }