Index: contributions/modules/avatarapproval/avatarapproval.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/avatarapproval/avatarapproval.module,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 avatarapproval.module
--- contributions/modules/avatarapproval/avatarapproval.module	9 Aug 2007 21:26:29 -0000	1.2.2.1
+++ contributions/modules/avatarapproval/avatarapproval.module	11 Aug 2007 17:01:56 -0000
@@ -129,10 +129,7 @@ function avatarapproval_user($op, &$edit
         //If it isn't we are going to create one
         if(!$avatar_master) {
           $info = image_get_info($edit['picture']);
-          $new_file = variable_get('file_directory_path', 'files') .'/'.
-            variable_get('user_picture_path', 'pictures') . '/' . $md5 . '.' .
-            $info['extension'];
-          $new_file = str_replace('//', '/', $new_file);
+          $new_file = avatarapproval_get_directory() . $md5 . '.' . $info['extension'];
           avatarapproval_create_master($edit['picture'], $new_file, $md5, $info['extension']);
           avatarapproval_add_user($account->uid, $md5, $info['extension']);
           unset($edit['picture']);
@@ -157,6 +154,9 @@ function avatarapproval_user($op, &$edit
 
           if($avatar_master->approved != AVATAR_APPROVED) {
             unset($edit['picture']);
+            if($avatar_master->approved == AVATAR_DISAPPROVED) {
+              drupal_set_message(t('Avatar was previously disapproved'));
+            }
           }
         }
       }//if(file_exists($edit['picture']))
@@ -184,14 +184,14 @@ function avatarapproval_profile_alter(&$
   //We need the $user->uid to make sure other people can't see the unapproved
   //avatars
   global $user;
-  $picture_directory = variable_get('file_directory_path', 'files') .'/'.
-    variable_get('user_picture_path', 'pictures') . '/';
-  $picture_directory = str_replace('//', '/', $picture_directory);
+  $picture_directory = avatarapproval_get_directory();
+
   //If the picture field is empty, the user doesn't have avatar approval priviliges,
   //or if someone is trying to view another users profile, we don't want to load this
   if($account->uid == $user->uid || user_access('approve avatars')) {
     $query = db_query('SELECT extension, approved FROM {avatar_approval} '.
-                       'WHERE uid = %d and approved = %d' , $account->uid, AVATAR_NOT_YET_MODERATED);
+                       'WHERE uid = %d AND approved = %d AND active = %d',
+                       $account->uid, AVATAR_NOT_YET_MODERATED, AVATAR_ACTIVE);
     //Lets only show this information if the user having an avatar in the approval queue
     if(db_num_rows($query)) {
       $avatars = array();
@@ -265,6 +265,9 @@ function avatarapproval_add_user($uid, $
     '( uid, md5, extension, timestamp, approved, active ) VALUES '.
     '(%d, "%s", "%s", %d, %d, %d ) ',
     $uid, $md5, $extension, time(), $approved, AVATAR_ACTIVE);
+  if($avatar_master->approved != AVATAR_APPROVED){
+    db_query('UPDATE users SET picture = "" WHERE uid = %d', $uid);
+  }
   return $approved;
 }
 
@@ -291,16 +294,16 @@ function avatarapproval_do_approval($md5
   global $user;
   db_query('UPDATE {avatar_approval} SET approved = %d, moderator = "%s", '.
     'timestamp = %d WHERE md5 = "%s"', $approved, $user->name, time(), $md5);
-  
+  //we need to add the avatar location back to the users table.
   $affected_users = db_query('SELECT uid , extension FROM {avatar_approval} '.
     'WHERE md5 = "%s" AND active = %d AND uid != 0', $md5, AVATAR_ACTIVE);
-  $picture_directory = variable_get('file_directory_path', 'files') .'/'.
-    variable_get('user_picture_path', 'pictures') . '/';
-  $picture_directory = str_replace('//', '/', $picture_directory);
+  $picture_directory = variable_get('file_directory_path', 'files')
+  .'/'.variable_get('user_picture_path', 'pictures') . '/';
+
   while($users = db_fetch_object($affected_users)) {
     $picture = '';
     if($approved == AVATAR_APPROVED) {
-      $picture = $picture_directory . 'picture-'. $users->uid . '.' . $users->extension;
+      $picture = $picture_directory . 'picture-'. $users->uid . '.' . $users->extension;     
     }
     db_query('UPDATE {users} SET picture = "%s" WHERE uid = %d', $picture, $users->uid);
   }
@@ -319,14 +322,12 @@ function avatarapproval_do_disapprove($m
  */
 
 function avatarapproval_do_delete($md5) {
+  avatarapproval_do_disapprove($md5);
   //Get the image extension
   $avatar = db_fetch_object(db_query('SELECT extension FROM {avatar_approval} '.
     'WHERE md5 = "%s" AND uid = 0', $md5));
   //Get the image
-  $file = variable_get('file_directory_path', 'files') .'/'.
-    variable_get('user_picture_path', 'pictures') . '/' . $md5 . '.' .
-    $avatar->extension;
-  $file = str_replace('//', '/', $file);
+  $file = avatarapproval_get_directory() . $md5 . '.' . $avatar->extension;
   //If the image exists, delete it
   if(file_exists(base_path(). $file)) {;
     file_delete($file);
@@ -447,9 +448,9 @@ function avatarapproval_admin_overview_f
   else if ($type == 'approve') {
     $sql .= 'approved = '. AVATAR_APPROVED;
   }
-  $picture_directory = variable_get('file_directory_path', 'files') .'/'.
-    variable_get('user_picture_path', 'pictures') . '/';
-  $picture_directory = str_replace('//', '/', $picture_directory);
+  //Set pictures directory
+  $picture_directory = avatarapproval_get_directory();
+
   $result = pager_query($sql . tablesort_sql($form['header']['#value']), 50, 0, NULL);
   $avatars = array();
   while ($avatar = db_fetch_object($result)) {
@@ -556,7 +557,7 @@ function theme_avatarapproval_profile($a
   return $avatars;
 }
 
-function avatarapproval_get_status($id){
+function avatarapproval_get_status($id) {
   switch($id){
     case AVATAR_APPROVED:
       return 'avatarapproval_approved';
@@ -568,4 +569,13 @@ function avatarapproval_get_status($id){
       return 'avatarapproval_pending';
     break;
   }
+}
+/**
+ * If the site admin has a trailing / in the file_directory_path, or a leading /
+ * in the user_picture_path, the avatars will not appear in some places.
+ * this function will remove any of the leading or trailing /'s
+ */
+function avatarapproval_get_directory() {
+  return preg_replace('&/+$&', '', variable_get('file_directory_path', 'files'))
+  .'/'.preg_replace('&^/+&', '', preg_replace('&/+$&', '',variable_get('user_picture_path', 'pictures'))) . '/';
 }
\ No newline at end of file
