function socialmedia_linkedin_parser in Social media 7
1 string reference to 'socialmedia_linkedin_parser'
File
- ./
socialmedia.platforms.inc, line 516 - Defines social media platforms
Code
function socialmedia_linkedin_parser($values, $scope = 'site') {
$profile = array(
'url' => '',
'username' => '',
'userid' => '',
);
$str = $values['url'];
$pattern = '/(?:http:\\/\\/)?(www\\.)*(linkedin\\.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_linkedin_url', t('LinkedIn URL invalid.'));
}
return FALSE;
}
$a = explode('linkedin.com/', $str);
$profile['url'] = 'www.linkedin.com/' . $a[1];
if (strpos($a[1], 'in/') === 0) {
$profile['userid'] = $profile['username'] = substr($a[1], 3);
}
else {
if (strpos($a[1], 'company/') === 0) {
$profile['userid'] = $profile['username'] = substr($a[1], 8);
$profile['type'] = 'company';
}
else {
if (strpos($a[1], 'groups/') === 0) {
// extract group id is encoded in query string value gid
$c = explode('gid=', $str);
$d = explode('&', $c[1]);
$profile['userid'] = $profile['username'] = $d[0];
$profile['type'] = 'group';
}
}
}
if (isset($values['username']) && trim($values['username'])) {
$profile['username'] = $values['username'];
}
if (isset($profile['username'])) {
return $profile;
}
form_set_error('input_linkedin_username', t('Cannot derive username for this type URL. Please provide a username.'));
return FALSE;
}