You are here

function socialmedia_facebook_parser in Social media 7

1 string reference to 'socialmedia_facebook_parser'
socialmedia_facebook_platform_info in ./socialmedia.platforms.inc

File

./socialmedia.platforms.inc, line 106
Defines social media platforms

Code

function socialmedia_facebook_parser($values, $scope = 'site') {
  $profile = array(
    'url' => '',
    'username' => '',
    'userid' => '',
  );
  $str = $values['url'];
  $pattern = '/(?:http:\\/\\/)?(www\\.)*(facebook\\.com\\/)(\\w+)+/i';

  //$pattern = '/^http:\/\/(www\.)?twitter\.com\/(#!\/)?(?<name>[^\/]+)(/\w+)*$/';
  if (!preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE)) {
    if (trim($values['url'])) {
      form_set_error('input_facebook_url', t('Facebook URL invalid.'));
    }
    return FALSE;
  }
  $a = explode('facebook.com/', $str);
  $profile['url'] = 'www.facebook.com/' . $a[1];
  $b = explode('?', $a[1]);
  $c = explode('/', $b[0]);
  if (!isset($b[1]) && $b[0] != 'profile.php') {
    $profile['userid'] = $profile['username'] = $b[0];
  }
  elseif ($b[0] == 'pages') {
    $profile['userid'] = $profile['username'] = $b[1];
  }
  if (isset($values['username']) && trim($values['username'])) {
    $profile['username'] = $values['username'];
  }
  if (isset($profile['username'])) {
    return $profile;
  }
  form_set_error('input_facebook_username', t('Cannot derive username for this type URL. Please provide a username.'));
  return FALSE;
}