You are here

function fboauth_field_convert_list in Facebook OAuth (FBOAuth) 7

Same name and namespace in other branches
  1. 7.2 includes/fboauth.field.inc \fboauth_field_convert_list()

Facebook data conversion function.

Select the best value from a list field based on a Facebook property value.

1 string reference to 'fboauth_field_convert_list'
fboauth_field_convert_info in includes/fboauth.field.inc
Provide a callback map for converting Facebook data to fields.

File

includes/fboauth.field.inc, line 247
Facebook to Field module mapping.

Code

function fboauth_field_convert_list($facebook_property_name, $fbuser, $field, $instance) {

  // We can't import anything other than strings into selects.
  if (!isset($fbuser->{$facebook_property_name}) || empty($facebook_property_name) || !is_string($fbuser->{$facebook_property_name})) {
    return;
  }

  // Mapping options is tricky business. We loop through all available
  // options and choose the closest one to match the incoming value.
  $options = list_allowed_values($field);
  $best_match = 0.0;
  $best_option = NULL;
  $fb_option = is_string($fbuser->{$facebook_property_name}) ? $fbuser->{$facebook_property_name} : '';
  $match_fb = strtolower($fbuser->{$facebook_property_name});
  foreach ($options as $key => $option) {
    $option = trim($option);
    $match_option = strtolower($option);
    $this_match = 0;
    similar_text($match_option, $match_fb, $this_match);
    if ($this_match > $best_match) {
      $best_match = $this_match;
      $best_option = $option;
      $best_key = $key;
    }
  }
  return isset($best_key) ? array(
    'value' => $best_key,
  ) : NULL;
}