1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-11 09:04:38 +02:00

HybridAuth downgraded to v2.7.0 until they get their bugs sorted out.

This commit is contained in:
Cameron
2016-12-08 08:10:46 -08:00
parent 41da542395
commit 24d5e6a6c7
8 changed files with 386 additions and 288 deletions

View File

@@ -15,7 +15,7 @@
*/ */
class Hybrid_Auth { class Hybrid_Auth {
public static $version = "2.8.1"; public static $version = "2.7.0";
/** /**
* Configuration array * Configuration array
@@ -352,9 +352,6 @@ class Hybrid_Auth {
* @param string $mode PHP|JS * @param string $mode PHP|JS
*/ */
public static function redirect($url, $mode = "PHP") { public static function redirect($url, $mode = "PHP") {
if(!$mode){
$mode = 'PHP';
}
Hybrid_Logger::info("Enter Hybrid_Auth::redirect( $url, $mode )"); Hybrid_Logger::info("Enter Hybrid_Auth::redirect( $url, $mode )");
// Ensure session is saved before sending response, see https://github.com/symfony/symfony/pull/12341 // Ensure session is saved before sending response, see https://github.com/symfony/symfony/pull/12341

View File

@@ -153,26 +153,11 @@ class Hybrid_Provider_Adapter {
# for default HybridAuth endpoint url hauth_login_start_url # for default HybridAuth endpoint url hauth_login_start_url
# auth.start required the IDp ID # auth.start required the IDp ID
# auth.time optional login request timestamp # auth.time optional login request timestamp
if (!isset($this->params["login_start"]) ) { $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . ( strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?' ) . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
$this->params["login_start"] = $HYBRID_AUTH_URL_BASE . ( strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?' ) . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
}
# for default HybridAuth endpoint url hauth_login_done_url # for default HybridAuth endpoint url hauth_login_done_url
# auth.done required the IDp ID # auth.done required the IDp ID
if (!isset($this->params["login_done"]) ) { $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . ( strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?' ) . "hauth.done={$this->id}";
$this->params["login_done"] = $HYBRID_AUTH_URL_BASE . ( strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?' ) . "hauth.done={$this->id}";
}
# workaround to solve windows live authentication since microsoft disallowed redirect urls to contain any parameters
# http://mywebsite.com/path_to_hybridauth/?hauth.done=Live will not work
if ($this->id=="Live") {
$this->params["login_done"] = $HYBRID_AUTH_URL_BASE."live.php";
}
# Workaround to fix broken callback urls for the Facebook OAuth client
if ($this->adapter->useSafeUrls) {
$this->params['login_done'] = str_replace('hauth.done', 'hauth_done', $this->params['login_done']);
}
if (isset($this->params["hauth_return_to"])) { if (isset($this->params["hauth_return_to"])) {
Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"]); Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"]);
@@ -239,7 +224,14 @@ class Hybrid_Provider_Adapter {
throw new Exception("Call to undefined function Hybrid_Providers_{$this->id}::$name()."); throw new Exception("Call to undefined function Hybrid_Providers_{$this->id}::$name().");
} }
return call_user_func_array(array($this->adapter, $name), $arguments); $counter = count($arguments);
if ($counter == 1) {
return $this->adapter->$name($arguments[0]);
} elseif ($counter == 2) {
return $this->adapter->$name($arguments[0], $arguments[1]);
} else {
return $this->adapter->$name();
}
} }
/** /**

View File

@@ -64,9 +64,6 @@ abstract class Hybrid_Provider_Model {
*/ */
public $compressed = false; public $compressed = false;
/** @var bool $useSafeUrls Enable this to replace '.' with '_' characters in the callback urls */
public $useSafeUrls = false;
/** /**
* Common providers adapter constructor * Common providers adapter constructor
* *

View File

@@ -1,8 +1,5 @@
<?php <?php
use Facebook\Exceptions\FacebookSDKException;
use Facebook\Facebook as FacebookSDK;
/* ! /* !
* HybridAuth * HybridAuth
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
@@ -11,291 +8,424 @@ use Facebook\Facebook as FacebookSDK;
/** /**
* Hybrid_Providers_Facebook provider adapter based on OAuth2 protocol * Hybrid_Providers_Facebook provider adapter based on OAuth2 protocol
*
* Hybrid_Providers_Facebook use the Facebook PHP SDK created by Facebook * Hybrid_Providers_Facebook use the Facebook PHP SDK created by Facebook
*
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_Facebook.html * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Facebook.html
*/ */
class Hybrid_Providers_Facebook extends Hybrid_Provider_Model { class Hybrid_Providers_Facebook extends Hybrid_Provider_Model {
/** /**
* Default permissions, and a lot of them. You can change them from the configuration by setting the scope to what you want/need. * default permissions, and a lot of them. You can change them from the configuration by setting the scope to what you want/need
* For a complete list see: https://developers.facebook.com/docs/facebook-login/permissions * {@inheritdoc}
* */
* @link https://developers.facebook.com/docs/facebook-login/permissions public $scope = "email, user_about_me, user_birthday, user_hometown, user_location, user_website, publish_actions, read_custom_friendlists";
* @var array $scope
*/
public $scope = ['email', 'user_about_me', 'user_birthday', 'user_hometown', 'user_location', 'user_website', 'publish_actions', 'read_custom_friendlists'];
/** /**
* Provider API client * Provider API client
* * @var Facebook
* @var \Facebook\Facebook */
*/ public $api;
public $api;
public $useSafeUrls = true; /**
* {@inheritdoc}
*/
function initialize() {
if (!$this->config["keys"]["id"] || !$this->config["keys"]["secret"]) {
throw new Exception("Your application id and secret are required in order to connect to {$this->providerId}.", 4);
}
/** if (!class_exists('FacebookApiException', false)) {
* {@inheritdoc} require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/base_facebook.php";
*/ require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/facebook.php";
function initialize() { }
if (!$this->config["keys"]["id"] || !$this->config["keys"]["secret"]) {
throw new Exception("Your application id and secret are required in order to connect to {$this->providerId}.", 4);
}
if (isset($this->config['scope'])) { if (isset(Hybrid_Auth::$config["proxy"])) {
$scope = $this->config['scope']; BaseFacebook::$CURL_OPTS[CURLOPT_PROXY] = Hybrid_Auth::$config["proxy"];
if (is_string($scope)) { }
$scope = explode(",", $scope);
}
$scope = array_map('trim', $scope);
$this->scope = $scope;
}
$trustForwarded = isset($this->config['trustForwarded']) ? (bool)$this->config['trustForwarded'] : false; $trustForwarded = isset($this->config['trustForwarded']) ? (bool) $this->config['trustForwarded'] : false;
$this->api = new Facebook(array('appId' => $this->config["keys"]["id"], 'secret' => $this->config["keys"]["secret"], 'trustForwarded' => $trustForwarded));
$this->api = new FacebookSDK([ if ($this->token("access_token")) {
'app_id' => $this->config["keys"]["id"], $this->api->setAccessToken($this->token("access_token"));
'app_secret' => $this->config["keys"]["secret"], $this->api->setExtendedAccessToken();
'default_graph_version' => 'v2.8', $access_token = $this->api->getAccessToken();
'trustForwarded' => $trustForwarded,
]);
}
/** if ($access_token) {
* {@inheritdoc} $this->token("access_token", $access_token);
*/ $this->api->setAccessToken($access_token);
function loginBegin() { }
$this->endpoint = $this->params['login_done']; $this->api->setAccessToken($this->token("access_token"));
$helper = $this->api->getRedirectLoginHelper(); }
// Use re-request, because this will trigger permissions window if not all permissions are granted. $this->api->getUser();
$url = $helper->getReRequestUrl($this->endpoint, $this->scope); }
// Redirect to Facebook /**
Hybrid_Auth::redirect($url); * {@inheritdoc}
} */
function loginBegin() {
$parameters = array("scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page");
$optionals = array("scope", "redirect_uri", "display", "auth_type");
/** foreach ($optionals as $parameter) {
* {@inheritdoc} if (isset($this->config[$parameter]) && !empty($this->config[$parameter])) {
*/ $parameters[$parameter] = $this->config[$parameter];
function loginFinish() {
$helper = $this->api->getRedirectLoginHelper(); //If the auth_type parameter is used, we need to generate a nonce and include it as a parameter
try { if ($parameter == "auth_type") {
$accessToken = $helper->getAccessToken(); $nonce = md5(uniqid(mt_rand(), true));
} catch (Facebook\Exceptions\FacebookResponseException $e) { $parameters['auth_nonce'] = $nonce;
throw new Hybrid_Exception('Facebook Graph returned an error: ' . $e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
throw new Hybrid_Exception('Facebook SDK returned an error: ' . $e->getMessage());
}
if (!isset($accessToken)) { Hybrid_Auth::storage()->set('fb_auth_nonce', $nonce);
if ($helper->getError()) { }
throw new Hybrid_Exception(sprintf("Could not authorize user, reason: %s (%d)", $helper->getErrorDescription(), $helper->getErrorCode())); }
} else { }
throw new Hybrid_Exception("Could not authorize user. Bad request");
}
}
try { if (isset($this->config['force']) && $this->config['force'] === true) {
// Validate token $parameters['auth_type'] = 'reauthenticate';
$oAuth2Client = $this->api->getOAuth2Client(); $parameters['auth_nonce'] = md5(uniqid(mt_rand(), true));
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
$tokenMetadata->validateAppId($this->config["keys"]["id"]);
$tokenMetadata->validateExpiration();
// Exchanges a short-lived access token for a long-lived one Hybrid_Auth::storage()->set('fb_auth_nonce', $parameters['auth_nonce']);
if (!$accessToken->isLongLived()) { }
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
}
} catch (FacebookSDKException $e) {
throw new Hybrid_Exception($e->getMessage(), 0, $e);
}
$this->setUserConnected(); // get the login url
$this->token("access_token", $accessToken->getValue()); $url = $this->api->getLoginUrl($parameters);
}
/** // redirect to facebook
* {@inheritdoc} Hybrid_Auth::redirect($url);
*/ }
function logout() {
parent::logout();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
function getUserProfile() { function loginFinish() {
try { // in case we get error_reason=user_denied&error=access_denied
$fields = [ if (isset($_REQUEST['error']) && $_REQUEST['error'] == "access_denied") {
'id', throw new Exception("Authentication failed! The user denied your request.", 5);
'name', }
'first_name',
'last_name',
'link',
'website',
'gender',
'locale',
'about',
'email',
'hometown',
'location',
'birthday'
];
$response = $this->api->get('/me?fields=' . implode(',', $fields), $this->token('access_token'));
$data = $response->getDecodedBody();
} catch (FacebookSDKException $e) {
throw new Exception("User profile request failed! {$this->providerId} returned an error: {$e->getMessage()}", 6, $e);
}
// Store the user profile. // in case we are using iOS/Facebook reverse authentication
$this->user->profile->identifier = (array_key_exists('id', $data)) ? $data['id'] : ""; if (isset($_REQUEST['access_token'])) {
$this->user->profile->displayName = (array_key_exists('name', $data)) ? $data['name'] : ""; $this->token("access_token", $_REQUEST['access_token']);
$this->user->profile->firstName = (array_key_exists('first_name', $data)) ? $data['first_name'] : ""; $this->api->setAccessToken($this->token("access_token"));
$this->user->profile->lastName = (array_key_exists('last_name', $data)) ? $data['last_name'] : ""; $this->api->setExtendedAccessToken();
$this->user->profile->photoURL = !empty($this->user->profile->identifier) ? "https://graph.facebook.com/" . $this->user->profile->identifier . "/picture?width=150&height=150" : ''; $access_token = $this->api->getAccessToken();
$this->user->profile->profileURL = (array_key_exists('link', $data)) ? $data['link'] : "";
$this->user->profile->webSiteURL = (array_key_exists('website', $data)) ? $data['website'] : "";
$this->user->profile->gender = (array_key_exists('gender', $data)) ? $data['gender'] : "";
$this->user->profile->language = (array_key_exists('locale', $data)) ? $data['locale'] : "";
$this->user->profile->description = (array_key_exists('about', $data)) ? $data['about'] : "";
$this->user->profile->email = (array_key_exists('email', $data)) ? $data['email'] : "";
$this->user->profile->emailVerified = (array_key_exists('email', $data)) ? $data['email'] : "";
$this->user->profile->region = (array_key_exists("location", $data) && array_key_exists("name", $data['location'])) ? $data['location']["name"] : "";
if (!empty($this->user->profile->region)) { if ($access_token) {
$regionArr = explode(',', $this->user->profile->region); $this->token("access_token", $access_token);
if (count($regionArr) > 1) { $this->api->setAccessToken($access_token);
$this->user->profile->city = trim($regionArr[0]); }
$this->user->profile->country = trim($regionArr[1]);
}
}
if (array_key_exists('birthday', $data)) { $this->api->setAccessToken($this->token("access_token"));
$birtydayPieces = explode('/', $data['birthday']); }
if (count($birtydayPieces) == 1) {
$this->user->profile->birthYear = (int)$birtydayPieces[0];
} elseif (count($birtydayPieces) == 2) {
$this->user->profile->birthMonth = (int)$birtydayPieces[0];
$this->user->profile->birthDay = (int)$birtydayPieces[1];
} elseif (count($birtydayPieces) == 3) {
$this->user->profile->birthMonth = (int)$birtydayPieces[0];
$this->user->profile->birthDay = (int)$birtydayPieces[1];
$this->user->profile->birthYear = (int)$birtydayPieces[2];
}
}
return $this->user->profile; // if auth_type is used, then an auth_nonce is passed back, and we need to check it.
} if (isset($_REQUEST['auth_nonce'])) {
/** $nonce = Hybrid_Auth::storage()->get('fb_auth_nonce');
* Since the Graph API 2.0, the /friends endpoint only returns friend that also use your Facebook app.
* {@inheritdoc}
*/
function getUserContacts() {
$apiCall = '?fields=link,name';
$returnedContacts = [];
$pagedList = true;
while ($pagedList) { //Delete the nonce
try { Hybrid_Auth::storage()->delete('fb_auth_nonce');
$response = $this->api->get('/me/friends' . $apiCall, $this->token('access_token'));
$response = $response->getDecodedBody();
} catch (FacebookSDKException $e) {
throw new Hybrid_Exception("User contacts request failed! {$this->providerId} returned an error {$e->getMessage()}", 0, $e);
}
// Prepare the next call if paging links have been returned if ($_REQUEST['auth_nonce'] != $nonce) {
if (array_key_exists('paging', $response) && array_key_exists('next', $response['paging'])) { throw new Exception("Authentication failed! Invalid nonce used for reauthentication.", 5);
$pagedList = true; }
$next_page = explode('friends', $response['paging']['next']); }
$apiCall = $next_page[1];
} else {
$pagedList = false;
}
// Add the new page contacts // try to get the UID of the connected user from fb, should be > 0
$returnedContacts = array_merge($returnedContacts, $response['data']); if (!$this->api->getUser()) {
} throw new Exception("Authentication failed! {$this->providerId} returned an invalid user id.", 5);
}
$contacts = []; // set user as logged in
$this->setUserConnected();
foreach ($returnedContacts as $item) { // store facebook access token
$this->token("access_token", $this->api->getAccessToken());
}
$uc = new Hybrid_User_Contact(); /**
$uc->identifier = (array_key_exists("id", $item)) ? $item["id"] : ""; * {@inheritdoc}
$uc->displayName = (array_key_exists("name", $item)) ? $item["name"] : ""; */
$uc->profileURL = (array_key_exists("link", $item)) ? $item["link"] : "https://www.facebook.com/profile.php?id=" . $uc->identifier; function logout() {
$uc->photoURL = "https://graph.facebook.com/" . $uc->identifier . "/picture?width=150&height=150"; $this->api->destroySession();
parent::logout();
}
$contacts[] = $uc; /**
} * {@inheritdoc}
*/
function getUserProfile() {
// request user profile from fb api
try {
$fields = array(
'id', 'name', 'first_name', 'last_name', 'link', 'website',
'gender', 'locale', 'about', 'email', 'hometown', 'location',
'birthday'
);
return $contacts; $data = $this->api->api('/me?fields=' . implode(',', $fields));
} } catch (FacebookApiException $e) {
throw new Exception("User profile request failed! {$this->providerId} returned an error: {$e->getMessage()}", 6, $e);
}
/** // if the provider identifier is not received, we assume the auth has failed
* Load the user latest activity, needs 'read_stream' permission if (!isset($data["id"])) {
* throw new Exception("User profile request failed! {$this->providerId} api returned an invalid response: " . Hybrid_Logger::dumpData( $data ), 6);
* @param string $stream Which activity to fetch: }
* - timeline : all the stream
* - me : the user activity only
* {@inheritdoc}
*/
function getUserActivity($stream = 'timeline') {
try {
if ($stream == "me") {
$response = $this->api->get('/me/feed', $this->token('access_token'));
} else {
$response = $this->api->get('/me/home', $this->token('access_token'));
}
} catch (FacebookSDKException $e) {
throw new Hybrid_Exception("User activity stream request failed! {$this->providerId} returned an error: {$e->getMessage()}", 0, $e);
}
if (!$response || !count($response['data'])) { # store the user profile.
return []; $this->user->profile->identifier = (array_key_exists('id', $data)) ? $data['id'] : "";
} $this->user->profile->username = (array_key_exists('username', $data)) ? $data['username'] : "";
$this->user->profile->displayName = (array_key_exists('name', $data)) ? $data['name'] : "";
$this->user->profile->firstName = (array_key_exists('first_name', $data)) ? $data['first_name'] : "";
$this->user->profile->lastName = (array_key_exists('last_name', $data)) ? $data['last_name'] : "";
$this->user->profile->photoURL = "https://graph.facebook.com/" . $this->user->profile->identifier . "/picture?width=150&height=150";
$this->user->profile->coverInfoURL = "https://graph.facebook.com/" . $this->user->profile->identifier . "?fields=cover&access_token=" . $this->api->getAccessToken();
$this->user->profile->profileURL = (array_key_exists('link', $data)) ? $data['link'] : "";
$this->user->profile->webSiteURL = (array_key_exists('website', $data)) ? $data['website'] : "";
$this->user->profile->gender = (array_key_exists('gender', $data)) ? $data['gender'] : "";
$this->user->profile->language = (array_key_exists('locale', $data)) ? $data['locale'] : "";
$this->user->profile->description = (array_key_exists('about', $data)) ? $data['about'] : "";
$this->user->profile->email = (array_key_exists('email', $data)) ? $data['email'] : "";
$this->user->profile->emailVerified = (array_key_exists('email', $data)) ? $data['email'] : "";
$this->user->profile->region = (array_key_exists("location", $data) && array_key_exists("name", $data['location'])) ? $data['location']["name"] : "";
$activities = []; if (!empty($this->user->profile->region)) {
$regionArr = explode(',', $this->user->profile->region);
if (count($regionArr) > 1) {
$this->user->profile->city = trim($regionArr[0]);
$this->user->profile->country = trim($regionArr[1]);
}
}
foreach ($response['data'] as $item) { if (array_key_exists('birthday', $data)) {
list($birthday_month, $birthday_day, $birthday_year) = explode("/", $data['birthday']);
$ua = new Hybrid_User_Activity(); $this->user->profile->birthDay = (int) $birthday_day;
$this->user->profile->birthMonth = (int) $birthday_month;
$this->user->profile->birthYear = (int) $birthday_year;
}
$ua->id = (array_key_exists("id", $item)) ? $item["id"] : ""; return $this->user->profile;
$ua->date = (array_key_exists("created_time", $item)) ? strtotime($item["created_time"]) : ""; }
if ($item["type"] == "video") { /**
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : ""; * Attempt to retrieve the url to the cover image given the coverInfoURL
} *
* @param string $coverInfoURL coverInfoURL variable
* @return string url to the cover image OR blank string
*/
function getCoverURL($coverInfoURL) {
try {
$headers = get_headers($coverInfoURL);
if (substr($headers[0], 9, 3) != "404") {
$coverOBJ = json_decode(file_get_contents($coverInfoURL));
if (array_key_exists('cover', $coverOBJ)) {
return $coverOBJ->cover->source;
}
}
} catch (Exception $e) {
if ($item["type"] == "link") { }
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : "";
}
if (empty($ua->text) && isset($item["story"])) { return "";
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : ""; }
}
if (empty($ua->text) && isset($item["message"])) { /**
$ua->text = (array_key_exists("message", $item)) ? $item["message"] : ""; * {@inheritdoc}
} */
function getUserContacts() {
$apiCall = '?fields=link,name';
$returnedContacts = array();
$pagedList = false;
if (!empty($ua->text)) { do {
$ua->user->identifier = (array_key_exists("id", $item["from"])) ? $item["from"]["id"] : ""; try {
$ua->user->displayName = (array_key_exists("name", $item["from"])) ? $item["from"]["name"] : ""; $response = $this->api->api('/me/friends' . $apiCall);
$ua->user->profileURL = "https://www.facebook.com/profile.php?id=" . $ua->user->identifier; } catch (FacebookApiException $e) {
$ua->user->photoURL = "https://graph.facebook.com/" . $ua->user->identifier . "/picture?type=square"; throw new Exception("User contacts request failed! {$this->providerId} returned an error {$e->getMessage()}", 0, $e);
}
$activities[] = $ua; // Prepare the next call if paging links have been returned
} if (array_key_exists('paging', $response) && array_key_exists('next', $response['paging'])) {
} $pagedList = true;
$next_page = explode('friends', $response['paging']['next']);
$apiCall = $next_page[1];
} else {
$pagedList = false;
}
return $activities; // Add the new page contacts
} $returnedContacts = array_merge($returnedContacts, $response['data']);
} while ($pagedList == true);
$contacts = array();
foreach ($returnedContacts as $item) {
$uc = new Hybrid_User_Contact();
$uc->identifier = (array_key_exists("id", $item)) ? $item["id"] : "";
$uc->displayName = (array_key_exists("name", $item)) ? $item["name"] : "";
$uc->profileURL = (array_key_exists("link", $item)) ? $item["link"] : "https://www.facebook.com/profile.php?id=" . $uc->identifier;
$uc->photoURL = "https://graph.facebook.com/" . $uc->identifier . "/picture?width=150&height=150";
$contacts[] = $uc;
}
return $contacts;
}
/**
* Update user status
*
* @param mixed $status An array describing the status, or string
* @param string $pageid (optional) User page id
* @return array
* @throw Exception
*/
function setUserStatus($status, $pageid = null) {
if (!is_array($status)) {
$status = array('message' => $status);
}
if (is_null($pageid)) {
$pageid = 'me';
// if post on page, get access_token page
} else {
$access_token = null;
foreach ($this->getUserPages(true) as $p) {
if (isset($p['id']) && intval($p['id']) == intval($pageid)) {
$access_token = $p['access_token'];
break;
}
}
if (is_null($access_token)) {
throw new Exception("Update user page failed, page not found or not writable!");
}
$status['access_token'] = $access_token;
}
try {
$response = $this->api->api('/' . $pageid . '/feed', 'post', $status);
} catch (FacebookApiException $e) {
throw new Exception("Update user status failed! {$this->providerId} returned an error {$e->getMessage()}", 0, $e);
}
return $response;
}
/**
* {@inheridoc}
*/
function getUserStatus($postid) {
try {
$postinfo = $this->api->api("/" . $postid);
} catch (FacebookApiException $e) {
throw new Exception("Cannot retrieve user status! {$this->providerId} returned an error: {$e->getMessage()}", 0, $e);
}
return $postinfo;
}
/**
* {@inheridoc}
*/
function getUserPages($writableonly = false) {
if (( isset($this->config['scope']) && strpos($this->config['scope'], 'manage_pages') === false ) || (!isset($this->config['scope']) && strpos($this->scope, 'manage_pages') === false ))
throw new Exception("User status requires manage_page permission!");
try {
$pages = $this->api->api("/me/accounts", 'get');
} catch (FacebookApiException $e) {
throw new Exception("Cannot retrieve user pages! {$this->providerId} returned an error: {$e->getMessage()}", 0, $e);
}
if (!isset($pages['data'])) {
return array();
}
if (!$writableonly) {
return $pages['data'];
}
$wrpages = array();
foreach ($pages['data'] as $p) {
if (isset($p['perms']) && in_array('CREATE_CONTENT', $p['perms'])) {
$wrpages[] = $p;
}
}
return $wrpages;
}
/**
* load the user latest activity
* - timeline : all the stream
* - me : the user activity only
* {@inheritdoc}
*/
function getUserActivity($stream) {
try {
if ($stream == "me") {
$response = $this->api->api('/me/feed');
} else {
$response = $this->api->api('/me/home');
}
} catch (FacebookApiException $e) {
throw new Exception("User activity stream request failed! {$this->providerId} returned an error: {$e->getMessage()}", 0, $e);
}
if (!$response || !count($response['data'])) {
return array();
}
$activities = array();
foreach ($response['data'] as $item) {
if ($stream == "me" && $item["from"]["id"] != $this->api->getUser()) {
continue;
}
$ua = new Hybrid_User_Activity();
$ua->id = (array_key_exists("id", $item)) ? $item["id"] : "";
$ua->date = (array_key_exists("created_time", $item)) ? strtotime($item["created_time"]) : "";
if ($item["type"] == "video") {
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : "";
}
if ($item["type"] == "link") {
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : "";
}
if (empty($ua->text) && isset($item["story"])) {
$ua->text = (array_key_exists("link", $item)) ? $item["link"] : "";
}
if (empty($ua->text) && isset($item["message"])) {
$ua->text = (array_key_exists("message", $item)) ? $item["message"] : "";
}
if (!empty($ua->text)) {
$ua->user->identifier = (array_key_exists("id", $item["from"])) ? $item["from"]["id"] : "";
$ua->user->displayName = (array_key_exists("name", $item["from"])) ? $item["from"]["name"] : "";
$ua->user->profileURL = "https://www.facebook.com/profile.php?id=" . $ua->user->identifier;
$ua->user->photoURL = "https://graph.facebook.com/" . $ua->user->identifier . "/picture?type=square";
$activities[] = $ua;
}
}
return $activities;
}
} }

View File

@@ -158,16 +158,16 @@ class Hybrid_Providers_Google extends Hybrid_Provider_Model_OAuth2 {
} else { } else {
$this->user->profile->webSiteURL = ''; $this->user->profile->webSiteURL = '';
} }
// google API returns age ranges min and/or max as of https://developers.google.com/+/web/api/rest/latest/people#resource // google API returns age ranges or min. age only (with plus.login scope)
if (property_exists($response, 'ageRange')) { if (property_exists($response, 'ageRange')) {
if (property_exists($response->ageRange, 'min') && property_exists($response->ageRange, 'max')) { if (property_exists($response->ageRange, 'min') && property_exists($response->ageRange, 'max')) {
$this->user->profile->age = $response->ageRange->min . ' - ' . $response->ageRange->max; $this->user->profile->age = $response->ageRange->min . ' - ' . $response->ageRange->max;
} else { } else {
if (property_exists($response->ageRange, 'min')) { if (property_exists($response->ageRange, 'min')) {
$this->user->profile->age = '>= ' . $response->ageRange->min; $this->user->profile->age = '> ' . $response->ageRange->min;
} else { } else {
if (property_exists($response->ageRange, 'max')) { if (property_exists($response->ageRange, 'max')) {
$this->user->profile->age = '<= ' . $response->ageRange->max; $this->user->profile->age = '< ' . $response->ageRange->max;
} else { } else {
$this->user->profile->age = ''; $this->user->profile->age = '';
} }

View File

@@ -30,7 +30,7 @@ class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model {
} }
if (empty($this->config['fields'])) { if (empty($this->config['fields'])) {
$this->config['fields'] = array( $this->config['fields'] = [
'id', 'id',
'first-name', 'first-name',
'last-name', 'last-name',
@@ -40,8 +40,7 @@ class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model {
'date-of-birth', 'date-of-birth',
'phone-numbers', 'phone-numbers',
'summary', 'summary',
'positions' ];
);
} }
if (!class_exists('OAuthConsumer', false)) { if (!class_exists('OAuthConsumer', false)) {
@@ -133,11 +132,6 @@ class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model {
$this->user->profile->email = (string) $data->{'email-address'}; $this->user->profile->email = (string) $data->{'email-address'};
$this->user->profile->emailVerified = (string) $data->{'email-address'}; $this->user->profile->emailVerified = (string) $data->{'email-address'};
if ($data->{'positions'}) {
$this->user->profile->job_title = (string) $data->{'positions'}->{'position'}->{'title'};
$this->user->profile->organization_name = (string) $data->{'positions'}->{'position'}->{'company'}->{'name'};
}
if (isset($data->{'picture-url'})) { if (isset($data->{'picture-url'})) {
$this->user->profile->photoURL = (string) $data->{'picture-url'}; $this->user->profile->photoURL = (string) $data->{'picture-url'};

View File

@@ -131,7 +131,6 @@ class Hybrid_Providers_Twitter extends Hybrid_Provider_Model_OAuth1 {
$this->user->profile->webSiteURL = (property_exists($response, 'url')) ? $response->url : ""; $this->user->profile->webSiteURL = (property_exists($response, 'url')) ? $response->url : "";
$this->user->profile->region = (property_exists($response, 'location')) ? $response->location : ""; $this->user->profile->region = (property_exists($response, 'location')) ? $response->location : "";
if($includeEmail) $this->user->profile->email = (property_exists($response, 'email')) ? $response->email : ""; if($includeEmail) $this->user->profile->email = (property_exists($response, 'email')) ? $response->email : "";
if($includeEmail) $this->user->profile->emailVerified = (property_exists($response, 'email')) ? $response->email : "";
return $this->user->profile; return $this->user->profile;
} }

View File

@@ -149,15 +149,4 @@ class Hybrid_User_Profile {
*/ */
public $zip = null; public $zip = null;
/**
* Job title
* @var string
*/
public $job_title = null;
/**
* Organization name
* @var string
*/
public $organization_name = null;
} }