You are here

function socialmedia_tumblr_parser in Social media 7

1 string reference to 'socialmedia_tumblr_parser'
socialmedia_tumblr_platform_info in ./socialmedia.platforms.inc

File

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

Code

function socialmedia_tumblr_parser($values, $scope = 'site') {
  $profile = array(
    'url' => '',
    'username' => '',
    'userid' => '',
  );
  $str = $values['url'];
  $pattern = '/(?:http:\\/\\/)?(www\\.)*(tumblr\\.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_tumblr_url', t('Tumblr profile URL invalid.'));
    }
    return FALSE;
  }
  $profile['url'] = $matches[1][0] . $matches[2][0];
  $profile['userid'] = $profile['username'] = isset($values['username']) && $values['username'] ? $values['username'] : $matches[1][0];
  return FALSE;
}