function socialmedia_googleplus_parser in Social media 7
1 string reference to 'socialmedia_googleplus_parser'
File
- ./
socialmedia.platforms.inc, line 346 - Defines social media platforms
Code
function socialmedia_googleplus_parser($values, $scope = 'site') {
$profile = array(
'url' => '',
'username' => '',
'userid' => '',
);
$str = $values['url'];
// check +name format
$pattern = '/(?:http(?:s)?:\\/\\/)?(plus\\.)(google\\.com\\/)?(\\+)(\\w+)+/i';
if (preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE)) {
$a = explode('plus.google.com/', $str);
$profile['url'] = 'plus.google.com/' . $a[1];
$b = explode('/', $a[1]);
// check if + format name is used
if (substr($b[0], 0, 1) == '+') {
$profile['userid'] = $b[0];
$values['username'] = substr($b[0], 1);
}
}
else {
// check numeric id format.
$pattern = '/(?:http(?:s)?:\\/\\/)?(plus\\.)(google\\.com\\/)?([0-9]*)/i';
if (!preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE)) {
if (trim($values['url']) && !isset($matches[3][0])) {
form_set_error('input_googleplus_url', t('Google+ URL invalid.'));
}
return FALSE;
}
$a = explode('plus.google.com/', $str);
$profile['url'] = 'plus.google.com/' . $a[1];
$profile['userid'] = $matches[3][0];
}
if (isset($values['username']) && trim($values['username'])) {
$profile['username'] = $values['username'];
}
if (isset($profile['username'])) {
return $profile;
}
form_set_error('input_googleplus_username', t('Cannot derive username for this type URL. Please provide a username.'));
return FALSE;
}