From 2e98ae4ebf8954a69ee3f15a3d36bfc16e3ad671 Mon Sep 17 00:00:00 2001
From: mrded <mrded@556088.no-reply.drupal.org>
Date: Thu, 3 Oct 2013 16:23:57 +0100
Subject: [PATCH] Profile picture from Facebook

---
 includes/fboauth.fboauth.inc |  4 ++++
 includes/fboauth.field.inc   | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/includes/fboauth.fboauth.inc b/includes/fboauth.fboauth.inc
index cc4b87e..ae1ec9d 100644
--- a/includes/fboauth.fboauth.inc
+++ b/includes/fboauth.fboauth.inc
@@ -483,6 +483,10 @@ function fboauth_user_properties($include_common = FALSE) {
       'permission' => 'user_work_history',
       'label' => t('Work history'),
     ),
+    'picture' => array(
+      'label' => t('Profile picture'),
+      'field_types' => array('image'),
+    ),
   );
 
   // Common properties. Always defined so that modules may alter if needed.
diff --git a/includes/fboauth.field.inc b/includes/fboauth.field.inc
index 353def7..28c211c 100644
--- a/includes/fboauth.field.inc
+++ b/includes/fboauth.field.inc
@@ -110,6 +110,10 @@ function fboauth_field_convert_info() {
       'label' => t('Date'),
       'callback' => 'fboauth_field_convert_date',
     ),
+    'image' => array(
+      'label' => t('Image'),
+      'callback' => 'fboauth_field_convert_image',
+    ),
   );
   drupal_alter('fboauth_field_convert_info', $convert_info);
   return $convert_info;
@@ -203,3 +207,26 @@ function fboauth_field_convert_date($facebook_property_name, $fbuser, $field, $i
   }
   return $value;
 }
+
+/**
+ * Facebook data conversion function.
+ */
+function fboauth_field_convert_image($facebook_property_name, $fbuser, $field, $instance) {
+  $file = NULL;
+
+  if ($facebook_property_name == 'picture') {
+    // 1000px width should be enough.
+    if ($image = file_get_contents("http://graph.facebook.com/$fbuser->id/picture?width=1000")) {
+      $destination = file_field_widget_uri($field, $instance) . "/$fbuser->id.jpg";
+
+      $file = file_save_data($image, $destination, FILE_EXISTS_REPLACE);
+
+      if (is_object($file)) {
+        $file->status = 1;
+        $file = (array)file_save($file);
+      }
+    }
+  }
+
+  return $file;
+}
-- 
1.7.12.4 (Apple Git-37)

