# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- 23
+++ /var/www/saprbw/sites/all/modules/contrib/fboauth/fboauth.module
@@ -278,8 +278,32 @@
     ))
   ->execute();
   }
+  $loggedin_account = user_load($uid); //load user, all user fields & fbuid
+  // Check if the logged in user has a picture saved & has linked their FB account through fboauth
+    if(is_null($loggedin_account->picture) && !empty($fbid)) {
+      $picture_directory =  file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
+      if(file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY)){
+        $picture_result = drupal_http_request('https://graph.facebook.com/' . $fbid . '/picture?type=large');
+        $picture_path = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $loggedin_account->uid . '-' . REQUEST_TIME . '.jpg');
+        $picture_file = file_save_data($picture_result->data, $picture_path, FILE_EXISTS_REPLACE);
+        // Check to make sure the picture isn't too large for the site settings.
+        $max_dimensions = variable_get('user_picture_dimensions', '85x85');
+        file_validate_image_resolution($picture_file, $max_dimensions);
+        // Update the user record.
+        $picture_file->uid = $loggedin_account->uid;
+        $picture_file = file_save($picture_file);
+        file_usage_add($picture_file, 'user', 'user', $loggedin_account->uid);
+        db_update('users')
+          ->fields(array(
+          'picture' => $picture_file->fid,
+          ))
+          ->condition('uid', $loggedin_account->uid)
+          ->execute();
 }
+  }
 
+}
+
 /**
  * Output a Facebook link.
  *

