You are here

function socialmedia_twitter_parser in Social media 7

1 string reference to 'socialmedia_twitter_parser'
socialmedia_twitter_platform_info in ./socialmedia.platforms.inc

File

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

Code

function socialmedia_twitter_parser($values, $scope = 'site') {
  $profile = array(
    'url' => '',
    'username' => '',
    'userid' => '',
  );
  $str = $values['url'];
  $pattern = '/(?:http:\\/\\/)?(www\\.)*(twitter\\.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_twitter_url', t('Twitter profile URL invalid.'));
    }
    return FALSE;
  }
  $profile['url'] = $matches[2][0] . $matches[4][0];
  $profile['userid'] = $profile['username'] = isset($values['username']) && $values['username'] ? $values['username'] : $matches[4][0];
  if (isset($values['username']) && trim($values['username'])) {
    $profile['username'] = $values['username'];
  }
  if (isset($values['user_timeline_widget_id']) && trim($values['user_timeline_widget_id'])) {
    $profile['user_timeline_widget_id'] = $values['user_timeline_widget_id'];
  }
  return $profile;
}