You are here

function _fb_admin_parse_textfield in Drupal for Facebook 7.4

This unlikely helper function speeds copy and paste from facebook. Allows user to put both id and secret in one textfield.

3 calls to _fb_admin_parse_textfield()
fb_admin_add_token_form_validate in ./fb.admin.inc
fb_admin_application_edit_form_validate in ./fb.admin.inc
Form validation.
fb_admin_app_select_form_validate in ./fb.admin.inc

File

./fb.admin.inc, line 399

Code

function _fb_admin_parse_textfield($text) {
  $id = NULL;
  $secret = NULL;
  $token = NULL;
  $split = preg_split('/\\s+/', $text);

  // Note explode(' ', $text) not sufficient.  Need to handle spaces or tabs.
  // First figure out what was submitted.
  if (count($split) > 1) {
    foreach ($split as $item) {
      if (is_numeric($item)) {
        $id = trim($item);
      }
      else {
        $secret = trim($item);
      }
    }
  }
  elseif (is_numeric($text)) {
    $id = $text;
  }
  else {
    $token = $text;
  }

  // Get app token if possible.
  if ($id && $secret) {
    $token = fb_admin_get_app_token($id, $secret);
  }
  return array(
    $id,
    $secret,
    $token ? $token : FB_TOKEN_NONE,
  );
}