$data = json_decode($body);
if (is_object($data))
{
$profile->loadArray($data);
if (isset($data->given_name) && $data->given_name != '')
$profile->set('first_name', $data->given_name);
else
{
// No given name, need to return something so Joomla doesn't choke
// In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
$profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
// If a name isn't set, then the 'name' field from Google is the email address.
// Can't use this as the full name or we'll have irate users.
$profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
}
}
$data = json_decode($body, true);
$profile->loadObject($data);
if (isset($data->given_name) && $data->given_name != '')
$profile->set('first_name', $data->given_name);
else
{
// No given name, need to return something so Joomla doesn't choke
// In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
$profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
// If a name isn't set, then the 'name' field from Google is the email address.
// Can't use this as the full name or we'll have irate users.
$profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
}
public function fetchProfile($socialId, $fields)
{
if (!is_array($fields))
$fields = array($fields);
$profile = new JFBConnectProfileDataGoogle();
if (!empty($fields))
{
if ($this->provider->client->isAuthenticated())
{
//Get OAuth2 fields first
$url = 'https://www.googleapis.com/oauth2/v2/userinfo';
$data = $this->provider->client->query($url);
$body = JFBConnectUtilities::getResponseBody($data);
$data = json_decode($body, true);
$profile->loadObject($data);
if (isset($data->given_name) && $data->given_name != '')
$profile->set('first_name', $data->given_name);
else
{
// No given name, need to return something so Joomla doesn't choke
// In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
$profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
// If a name isn't set, then the 'name' field from Google is the email address.
// Can't use this as the full name or we'll have irate users.
$profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
}
}
}
return $profile;
}
static function getLinkWithItemId($link, $itemId)
{
$app = Factory::getApplication();
$router = $app->getRouter();
if ($link)
{
if ($router->getMode() == JROUTER_MODE_SEF)
$url = 'index.php?Itemid=' . $itemId;
else
$url = $link . '&Itemid=' . $itemId;
}
else
$url = '';
return $url;
}
static function getLinkWithItemId($link, $itemId)
{
$app = Factory::getApplication();
$router = $app->getRouter();
if ($link)
{
$isSef = JVERSION < 4.0 ? $router->getMode() == JROUTER_MODE_SEF : $app->get('sef');
if ($isSef)
$url = 'index.php?Itemid=' . $itemId;
else
$url = $link . '&Itemid=' . $itemId;
}
else
$url = '';
return $url;
}
Join our newsletter to get alerts for Joomla releases, tips and tricks and extension updates.