You are here

function fb_form_friend_selector_autocomplete in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 5.2 fb_form.module \fb_form_friend_selector_autocomplete()
  2. 6.3 fb_form.module \fb_form_friend_selector_autocomplete()
  3. 6.2 fb_form.module \fb_form_friend_selector_autocomplete()

Autocomplete friend names

2 string references to 'fb_form_friend_selector_autocomplete'
fb_form_friend_selector_process in ./fb_form.module
A selector allowing the user to choose from their friends. This must behave differently depending on whether the form is displayed on an FBML canvas page, iframe canvas page, or regular HTML page.
fb_form_menu in ./fb_form.module
Implementation of hook_menu().

File

./fb_form.module, line 293
This module defines facebook-specific form elements for use with Drupal's form API.

Code

function fb_form_friend_selector_autocomplete($string) {

  // Regexp copied from taxonomy_autocomplete
  $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
  preg_match_all($regexp, $string, $preg_matches);
  $typed_names = $preg_matches[1];
  $last_string = trim(array_pop($typed_names));
  $prefix = count($typed_names) ? implode(', ', $typed_names) . ', ' : '';

  // Get list of friends from session
  $result = $_SESSION['fb_form_friend_selector_result'];
  $matches = array();
  if (count($result) && $last_string) {
    foreach ($result as $data) {
      $name = strtolower($data['name']);
      if (strpos($name, strtolower($last_string)) !== FALSE && !in_array($data['name'], $typed_names)) {
        $markup = "<img src={$data[pic_square]} />{$data[name]}";
        $matches[$prefix . $data['name']] = $markup;
      }
    }
  }
  if (count($matches)) {
    print drupal_to_js($matches);
  }
  exit;
}