diff options
author | BlueRaja <BlueRaja.admin@gmail.com> | 2013-06-01 20:10:36 -0500 |
---|---|---|
committer | BlueRaja <BlueRaja.admin@gmail.com> | 2013-06-01 20:10:36 -0500 |
commit | 951330c9f83c8c8ee98f65fdccb5797e2e59d1f3 (patch) | |
tree | fc7b196ca0d91c1c71dcd945aa9667c7af0134fa /includes/HybridAuth/Providers | |
parent | e58a3b8b3702b22c903b02a9b4fa1020d6797459 (diff) | |
download | pathery-951330c9f83c8c8ee98f65fdccb5797e2e59d1f3.tar.xz |
A partial commit of the auth stuff, in case my upcoming changes break anything
Diffstat (limited to 'includes/HybridAuth/Providers')
-rw-r--r-- | includes/HybridAuth/Providers/AOL.php | 16 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Facebook.php | 271 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Foursquare.php | 56 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Google.php | 119 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/LinkedIn.php | 252 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Live.php | 106 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/MySpace.php | 164 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/OpenID.php | 15 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Twitter.php | 204 | ||||
-rw-r--r-- | includes/HybridAuth/Providers/Yahoo.php | 237 |
10 files changed, 1440 insertions, 0 deletions
diff --git a/includes/HybridAuth/Providers/AOL.php b/includes/HybridAuth/Providers/AOL.php new file mode 100644 index 0000000..6fc8761 --- /dev/null +++ b/includes/HybridAuth/Providers/AOL.php @@ -0,0 +1,16 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_AOL provider adapter based on OpenID protocol + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_AOL.html + */ +class Hybrid_Providers_AOL extends Hybrid_Provider_Model_OpenID +{ + var $openidIdentifier = "http://openid.aol.com/"; +} diff --git a/includes/HybridAuth/Providers/Facebook.php b/includes/HybridAuth/Providers/Facebook.php new file mode 100644 index 0000000..fa40c96 --- /dev/null +++ b/includes/HybridAuth/Providers/Facebook.php @@ -0,0 +1,271 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_Facebook provider adapter based on OAuth2 protocol + * + * Hybrid_Providers_Facebook use the Facebook PHP SDK created by Facebook + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Facebook.html + */ +class Hybrid_Providers_Facebook extends Hybrid_Provider_Model +{ + // default permissions, and alot of them. You can change them from the configuration by setting the scope to what you want/need + public $scope = "email, user_about_me, user_birthday, user_hometown, user_website, read_stream, offline_access, publish_stream, read_friendlists"; + + /** + * IDp wrappers initializer + */ + 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) ) { + require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/base_facebook.php"; + require_once Hybrid_Auth::$config["path_libraries"] . "Facebook/facebook.php"; + } + + if ( isset ( Hybrid_Auth::$config["proxy"] ) ) { + BaseFacebook::$CURL_OPTS[CURLOPT_PROXY] = Hybrid_Auth::$config["proxy"]; + } + + $this->api = new Facebook( ARRAY( 'appId' => $this->config["keys"]["id"], 'secret' => $this->config["keys"]["secret"] ) ); + + if ( $this->token("access_token") ) { + $this->api->setAccessToken( $this->token("access_token") ); + $this->api->setExtendedAccessToken(); + $access_token = $this->api->getAccessToken(); + + if( $access_token ){ + $this->token("access_token", $access_token ); + $this->api->setAccessToken( $access_token ); + } + + $this->api->setAccessToken( $this->token("access_token") ); + } + + $this->api->getUser(); + } + + /** + * begin login step + * + * simply call Facebook::require_login(). + */ + function loginBegin() + { + $parameters = array("scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page"); + $optionals = array("scope", "redirect_uri", "display"); + + foreach ($optionals as $parameter){ + if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){ + $parameters[$parameter] = $this->config[$parameter]; + } + } + + // get the login url + $url = $this->api->getLoginUrl( $parameters ); + + // redirect to facebook + Hybrid_Auth::redirect( $url ); + } + + /** + * finish login step + */ + function loginFinish() + { + // in case we get error_reason=user_denied&error=access_denied + if ( isset( $_REQUEST['error'] ) && $_REQUEST['error'] == "access_denied" ){ + throw new Exception( "Authentication failed! The user denied your request.", 5 ); + } + + // try to get the UID of the connected user from fb, should be > 0 + if ( ! $this->api->getUser() ){ + throw new Exception( "Authentication failed! {$this->providerId} returned an invalid user id.", 5 ); + } + + // set user as logged in + $this->setUserConnected(); + + // store facebook access token + $this->token( "access_token", $this->api->getAccessToken() ); + } + + /** + * logout + */ + function logout() + { + $this->api->destroySession(); + + parent::logout(); + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + // request user profile from fb api + try{ + $data = $this->api->api('/me'); + } + catch( FacebookApiException $e ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an error: $e", 6 ); + } + + // if the provider identifier is not recived, we assume the auth has failed + if ( ! isset( $data["id"] ) ){ + throw new Exception( "User profile request failed! {$this->providerId} api returned an invalid response.", 6 ); + } + + # store the user profile. + $this->user->profile->identifier = (array_key_exists('id',$data))?$data['id']:""; + $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->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->description = (array_key_exists('bio',$data))?$data['bio']:""; + $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("hometown",$data)&&array_key_exists("name",$data['hometown']))?$data['hometown']["name"]:""; + + if( array_key_exists('birthday',$data) ) { + list($birthday_month, $birthday_day, $birthday_year) = explode( "/", $data['birthday'] ); + + $this->user->profile->birthDay = (int) $birthday_day; + $this->user->profile->birthMonth = (int) $birthday_month; + $this->user->profile->birthYear = (int) $birthday_year; + } + + return $this->user->profile; + } + + /** + * load the user contacts + */ + function getUserContacts() + { + try{ + $response = $this->api->api('/me/friends'); + } + catch( FacebookApiException $e ){ + throw new Exception( "User contacts request failed! {$this->providerId} returned an error: $e" ); + } + + if( ! $response || ! count( $response["data"] ) ){ + return ARRAY(); + } + + $contacts = ARRAY(); + + foreach( $response["data"] 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 = "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 + */ + function setUserStatus( $status ) + { + $parameters = array(); + + if( is_array( $status ) ){ + $parameters = $status; + } + else{ + $parameters["message"] = $status; + } + + try{ + $response = $this->api->api( "/me/feed", "post", $parameters ); + } + catch( FacebookApiException $e ){ + throw new Exception( "Update user status failed! {$this->providerId} returned an error: $e" ); + } + } + + /** + * load the user latest activity + * - timeline : all the stream + * - me : the user activity only + */ + 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" ); + } + + 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; + } +} diff --git a/includes/HybridAuth/Providers/Foursquare.php b/includes/HybridAuth/Providers/Foursquare.php new file mode 100644 index 0000000..a87cacf --- /dev/null +++ b/includes/HybridAuth/Providers/Foursquare.php @@ -0,0 +1,56 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_Foursquare provider adapter based on OAuth2 protocol + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Foursquare.html + */ +class Hybrid_Providers_Foursquare extends Hybrid_Provider_Model_OAuth2 +{ + /** + * IDp wrappers initializer + */ + function initialize() + { + parent::initialize(); + + // Provider apis end-points + $this->api->api_base_url = "https://api.foursquare.com/v2/"; + $this->api->authorize_url = "https://foursquare.com/oauth2/authenticate"; + $this->api->token_url = "https://foursquare.com/oauth2/access_token"; + + $this->api->sign_token_name = "oauth_token"; + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + $data = $this->api->api( "users/self" ); + + if ( ! isset( $data->response->user->id ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $data = $data->response->user; + + $this->user->profile->identifier = $data->id; + $this->user->profile->firstName = $data->firstName; + $this->user->profile->lastName = $data->lastName; + $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName ); + $this->user->profile->photoURL = $data->photo; + $this->user->profile->profileURL = "https://www.foursquare.com/user/" . $data->id; + $this->user->profile->gender = $data->gender; + $this->user->profile->city = $data->homeCity; + $this->user->profile->email = $data->contact->email; + $this->user->profile->emailVerified = $data->contact->email; + + return $this->user->profile; + } +} diff --git a/includes/HybridAuth/Providers/Google.php b/includes/HybridAuth/Providers/Google.php new file mode 100644 index 0000000..87095a3 --- /dev/null +++ b/includes/HybridAuth/Providers/Google.php @@ -0,0 +1,119 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_Google provider adapter based on OAuth2 protocol + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Google.html + */ +class Hybrid_Providers_Google extends Hybrid_Provider_Model_OAuth2 +{ + // default permissions + public $scope = "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.google.com/m8/feeds/"; + + /** + * IDp wrappers initializer + */ + function initialize() + { + parent::initialize(); + + // Provider api end-points + $this->api->authorize_url = "https://accounts.google.com/o/oauth2/auth"; + $this->api->token_url = "https://accounts.google.com/o/oauth2/token"; + $this->api->token_info_url = "https://www.googleapis.com/oauth2/v1/tokeninfo"; + } + + /** + * begin login step + */ + function loginBegin() + { + $parameters = array("scope" => $this->scope, "access_type" => "offline"); + $optionals = array("scope", "access_type", "redirect_uri", "approval_prompt", "hd"); + + foreach ($optionals as $parameter){ + if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){ + $parameters[$parameter] = $this->config[$parameter]; + } + } + + Hybrid_Auth::redirect( $this->api->authorizeUrl( $parameters ) ); + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + // refresh tokens if needed + $this->refreshToken(); + + // ask google api for user infos + $response = $this->api->api( "https://www.googleapis.com/oauth2/v1/userinfo" ); + + if ( ! isset( $response->id ) || isset( $response->error ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $this->user->profile->identifier = (property_exists($response,'id'))?$response->id:""; + $this->user->profile->firstName = (property_exists($response,'given_name'))?$response->given_name:""; + $this->user->profile->lastName = (property_exists($response,'family_name'))?$response->family_name:""; + $this->user->profile->displayName = (property_exists($response,'name'))?$response->name:""; + $this->user->profile->photoURL = (property_exists($response,'picture'))?$response->picture:""; + $this->user->profile->profileURL = "https://profiles.google.com/" . $this->user->profile->identifier; + $this->user->profile->gender = (property_exists($response,'gender'))?$response->gender:""; + $this->user->profile->email = (property_exists($response,'email'))?$response->email:""; + $this->user->profile->emailVerified = (property_exists($response,'email'))?$response->email:""; + $this->user->profile->language = (property_exists($response,'locale'))?$response->locale:""; + + if( property_exists($response,'birthday') ){ + list($birthday_year, $birthday_month, $birthday_day) = explode( '-', $response->birthday ); + + $this->user->profile->birthDay = (int) $birthday_day; + $this->user->profile->birthMonth = (int) $birthday_month; + $this->user->profile->birthYear = (int) $birthday_year; + } + + return $this->user->profile; + } + + /** + * load the user (Gmail) contacts + * ..toComplete + */ + function getUserContacts() + { + // refresh tokens if needed + $this->refreshToken(); + + if( ! isset( $this->config['contacts_param'] ) ){ + $this->config['contacts_param'] = array( "max-results" => 500 ); + } + + $response = $this->api->api( "https://www.google.com/m8/feeds/contacts/default/full?" + . http_build_query( array_merge( array('alt' => 'json'), $this->config['contacts_param'] ) ) ); + + if( ! $response ){ + return ARRAY(); + } + + $contacts = ARRAY(); + + foreach( $response->feed->entry as $idx => $entry ){ + $uc = new Hybrid_User_Contact(); + + $uc->email = isset($entry->{'gd$email'}[0]->address) ? (string) $entry->{'gd$email'}[0]->address : ''; + $uc->displayName = isset($entry->title->{'$t'}) ? (string) $entry->title->{'$t'} : ''; + $uc->identifier = $uc->email; + + $contacts[] = $uc; + } + + return $contacts; + } +} diff --git a/includes/HybridAuth/Providers/LinkedIn.php b/includes/HybridAuth/Providers/LinkedIn.php new file mode 100644 index 0000000..b7a8f83 --- /dev/null +++ b/includes/HybridAuth/Providers/LinkedIn.php @@ -0,0 +1,252 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_LinkedIn provider adapter based on OAuth1 protocol + * + * Hybrid_Providers_LinkedIn use linkedinPHP library created by fiftyMission Inc. + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_LinkedIn.html + */ +class Hybrid_Providers_LinkedIn extends Hybrid_Provider_Model +{ + /** + * IDp wrappers initializer + */ + function initialize() + { + if ( ! $this->config["keys"]["key"] || ! $this->config["keys"]["secret"] ){ + throw new Exception( "Your application key and secret are required in order to connect to {$this->providerId}.", 4 ); + } + + require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php"; + require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php"; + + $this->api = new LinkedIn( array( 'appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint ) ); + + if( $this->token( "access_token_linkedin" ) ){ + $this->api->setTokenAccess( $this->token( "access_token_linkedin" ) ); + } + } + + /** + * begin login step + */ + function loginBegin() + { + // send a request for a LinkedIn access token + $response = $this->api->retrieveTokenRequest(); + + if( isset( $response['success'] ) && $response['success'] === TRUE ){ + $this->token( "oauth_token", $response['linkedin']['oauth_token'] ); + $this->token( "oauth_token_secret", $response['linkedin']['oauth_token_secret'] ); + + # redirect user to LinkedIn authorisation web page + Hybrid_Auth::redirect( LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token'] ); + } + else{ + throw new Exception( "Authentication failed! {$this->providerId} returned an invalid Token.", 5 ); + } + } + + /** + * finish login step + */ + function loginFinish() + { + $oauth_token = $_REQUEST['oauth_token']; + $oauth_verifier = $_REQUEST['oauth_verifier']; + + if ( ! $oauth_verifier ){ + throw new Exception( "Authentication failed! {$this->providerId} returned an invalid Token.", 5 ); + } + + $response = $this->api->retrieveTokenAccess( $oauth_token, $this->token( "oauth_token_secret" ), $oauth_verifier ); + + if( isset( $response['success'] ) && $response['success'] === TRUE ){ + $this->deleteToken( "oauth_token" ); + $this->deleteToken( "oauth_token_secret" ); + + $this->token( "access_token_linkedin", $response['linkedin'] ); + $this->token( "access_token" , $response['linkedin']['oauth_token'] ); + $this->token( "access_token_secret" , $response['linkedin']['oauth_token_secret'] ); + + // set user as logged in + $this->setUserConnected(); + } + else{ + throw new Exception( "Authentication failed! {$this->providerId} returned an invalid Token.", 5 ); + } + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + try{ + // http://developer.linkedin.com/docs/DOC-1061 + $response = $this->api->profile('~:(id,first-name,last-name,public-profile-url,picture-url,email-address,date-of-birth,phone-numbers,summary)'); + } + catch( LinkedInException $e ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an error: $e", 6 ); + } + + if( isset( $response['success'] ) && $response['success'] === TRUE ){ + $data = @ new SimpleXMLElement( $response['linkedin'] ); + + if ( ! is_object( $data ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid xml data.", 6 ); + } + + $this->user->profile->identifier = (string) $data->{'id'}; + $this->user->profile->firstName = (string) $data->{'first-name'}; + $this->user->profile->lastName = (string) $data->{'last-name'}; + $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName ); + + $this->user->profile->email = (string) $data->{'email-address'}; + $this->user->profile->emailVerified = (string) $data->{'email-address'}; + + $this->user->profile->photoURL = (string) $data->{'picture-url'}; + $this->user->profile->profileURL = (string) $data->{'public-profile-url'}; + $this->user->profile->description = (string) $data->{'summary'}; + + if( $data->{'phone-numbers'} && $data->{'phone-numbers'}->{'phone-number'} ){ + $this->user->profile->phone = (string) $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'}; + } + else{ + $this->user->profile->phone = null; + } + + if( $data->{'date-of-birth'} ){ + $this->user->profile->birthDay = (string) $data->{'date-of-birth'}->day; + $this->user->profile->birthMonth = (string) $data->{'date-of-birth'}->month; + $this->user->profile->birthYear = (string) $data->{'date-of-birth'}->year; + } + + return $this->user->profile; + } + else{ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + } + + /** + * load the user contacts + */ + function getUserContacts() + { + try{ + $response = $this->api->profile('~/connections:(id,first-name,last-name,picture-url,public-profile-url,summary)'); + } + catch( LinkedInException $e ){ + throw new Exception( "User contacts request failed! {$this->providerId} returned an error: $e" ); + } + + if( ! $response || ! $response['success'] ){ + return ARRAY(); + } + + $connections = new SimpleXMLElement( $response['linkedin'] ); + + $contacts = ARRAY(); + + foreach( $connections->person as $connection ) { + $uc = new Hybrid_User_Contact(); + + $uc->identifier = (string) $connection->id; + $uc->displayName = (string) $connection->{'last-name'} . " " . $connection->{'first-name'}; + $uc->profileURL = (string) $connection->{'public-profile-url'}; + $uc->photoURL = (string) $connection->{'picture-url'}; + $uc->description = (string) $connection->{'summary'}; + + $contacts[] = $uc; + } + + return $contacts; + } + + /** + * update user status + */ + function setUserStatus( $status ) + { + $parameters = array(); + $private = true; // share with your connections only + + if( is_array( $status ) ){ + if( isset( $status[0] ) && ! empty( $status[0] ) ) $parameters["title"] = $status[0]; // post title + if( isset( $status[1] ) && ! empty( $status[1] ) ) $parameters["comment"] = $status[1]; // post comment + if( isset( $status[2] ) && ! empty( $status[2] ) ) $parameters["submitted-url"] = $status[2]; // post url + if( isset( $status[3] ) && ! empty( $status[3] ) ) $parameters["submitted-image-url"] = $status[3]; // post picture url + if( isset( $status[4] ) && ! empty( $status[4] ) ) $private = $status[4]; // true or false + } + else{ + $parameters["comment"] = $status; + } + + try{ + $response = $this->api->share( 'new', $parameters, $private ); + } + catch( LinkedInException $e ){ + throw new Exception( "Update user status update failed! {$this->providerId} returned an error: $e" ); + } + + if ( ! $response || ! $response['success'] ) + { + throw new Exception( "Update user status update failed! {$this->providerId} returned an error." ); + } + } + + /** + * load the user latest activity + * - timeline : all the stream + * - me : the user activity only + */ + function getUserActivity( $stream ) + { + try{ + if( $stream == "me" ){ + $response = $this->api->updates( '?type=SHAR&scope=self&count=25' ); + } + else{ + $response = $this->api->updates( '?type=SHAR&count=25' ); + } + } + catch( LinkedInException $e ){ + throw new Exception( "User activity stream request failed! {$this->providerId} returned an error: $e" ); + } + + if( ! $response || ! $response['success'] ){ + return ARRAY(); + } + + $updates = new SimpleXMLElement( $response['linkedin'] ); + + $activities = ARRAY(); + + foreach( $updates->update as $update ) { + $person = $update->{'update-content'}->person; + $share = $update->{'update-content'}->person->{'current-share'}; + + $ua = new Hybrid_User_Activity(); + + $ua->id = (string) $update->id; + $ua->date = (string) $update->timestamp; + $ua->text = (string) $share->{'comment'}; + + $ua->user->identifier = (string) $person->id; + $ua->user->displayName = (string) $person->{'first-name'} . ' ' . $person->{'last-name'}; + $ua->user->profileURL = (string) $person->{'site-standard-profile-request'}->url; + $ua->user->photoURL = NULL; + + $activities[] = $ua; + } + + return $activities; + } +} diff --git a/includes/HybridAuth/Providers/Live.php b/includes/HybridAuth/Providers/Live.php new file mode 100644 index 0000000..1a97291 --- /dev/null +++ b/includes/HybridAuth/Providers/Live.php @@ -0,0 +1,106 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Windows Live OAuth2 Class + * + * @package HybridAuth providers package + * @author Lukasz Koprowski <azram19@gmail.com> + * @version 0.2 + * @license BSD License + */ + +/** + * Hybrid_Providers_Live - Windows Live provider adapter based on OAuth2 protocol + */ +class Hybrid_Providers_Live extends Hybrid_Provider_Model_OAuth2 +{ + // default permissions + public $scope = "wl.basic wl.emails wl.signin wl.share wl.birthday"; + + + /** + * IDp wrappers initializer + */ + function initialize() + { + parent::initialize(); + + // Provider api end-points + $this->api->api_base_url = 'https://apis.live.net/v5.0/'; + $this->api->authorize_url = 'https://login.live.com/oauth20_authorize.srf'; + $this->api->token_url = 'https://login.live.com/oauth20_token.srf'; + + $this->api->curl_authenticate_method = "GET"; + } + + /** + * grab the user profile from the api client + */ + function getUserProfile() + { + $data = $this->api->get( "me" ); + + if ( ! isset( $data->id ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalide response.", 6 ); + } + + $this->user->profile->identifier = (property_exists($data,'id'))?$data->id:""; + $this->user->profile->firstName = (property_exists($data,'first_name'))?$data->first_name:""; + $this->user->profile->lastName = (property_exists($data,'last_name'))?$data->last_name:""; + $this->user->profile->displayName = (property_exists($data,'name'))?trim( $data->name ):""; + $this->user->profile->gender = (property_exists($data,'gender'))?$data->gender:""; + + //wl.basic + $this->user->profile->profileURL = (property_exists($data,'link'))?$data->link:""; + + //wl.emails + $this->user->profile->email = (property_exists($data,'emails'))?$data->emails->account:""; + $this->user->profile->emailVerified = (property_exists($data,'emails'))?$data->emails->account:""; + + //wl.birthday + $this->user->profile->birthDay = (property_exists($data,'birth_day'))?$data->birth_day:""; + $this->user->profile->birthMonth = (property_exists($data,'birth_month'))?$data->birth_month:""; + $this->user->profile->birthYear = (property_exists($data,'birth_year'))?$data->birth_year:""; + + return $this->user->profile; + } + + + /** + * load the current logged in user contacts list from the IDp api client + */ + + /* Windows Live api does not support retrieval of email addresses (only hashes :/) */ + function getUserContacts() + { + $response = $this->api->get( 'me/contacts' ); + + if ( $this->api->http_code != 200 ) + { + throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + if ( ! $response->data && ( $response->error != 0 ) ) + { + return array(); + } + + $contacts = array(); + + foreach( $response->data as $item ) { + $uc = new Hybrid_User_Contact(); + + $uc->identifier = (property_exists($item,'id'))?$item->id:""; + $uc->displayName = (property_exists($item,'name'))?$item->name:""; + + $contacts[] = $uc; + } + + return $contacts; + } +} diff --git a/includes/HybridAuth/Providers/MySpace.php b/includes/HybridAuth/Providers/MySpace.php new file mode 100644 index 0000000..8ce0ffe --- /dev/null +++ b/includes/HybridAuth/Providers/MySpace.php @@ -0,0 +1,164 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_MySpace provider adapter based on OAuth1 protocol + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_MySpace.html + */ +class Hybrid_Providers_MySpace extends Hybrid_Provider_Model_OAuth1 +{ + /** + * IDp wrappers initializer + */ + function initialize() + { + parent::initialize(); + + // Provider api end-points + $this->api->api_endpoint_url = "http://api.myspace.com/v1/"; + $this->api->authorize_url = "http://api.myspace.com/authorize"; + $this->api->request_token_url = "http://api.myspace.com/request_token"; + $this->api->access_token_url = "http://api.myspace.com/access_token"; + } + + /** + * get the connected uid from myspace api + */ + public function getCurrentUserId() + { + $response = $this->api->get( 'http://api.myspace.com/v1/user.json' ); + + if ( ! isset( $response->userId ) ){ + throw new Exception( "User id request failed! {$this->providerId} returned an invalid response." ); + } + + return $response->userId; + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + $userId = $this->getCurrentUserId(); + + $data = $this->api->get( 'http://api.myspace.com/v1/users/' . $userId . '/profile.json' ); + + if ( ! is_object( $data ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $this->user->profile->identifier = $userId; + $this->user->profile->displayName = $data->basicprofile->name; + $this->user->profile->description = $data->aboutme; + $this->user->profile->gender = $data->basicprofile->gender; + $this->user->profile->photoURL = $data->basicprofile->image; + $this->user->profile->profileURL = $data->basicprofile->webUri; + $this->user->profile->age = $data->age; + $this->user->profile->country = $data->country; + $this->user->profile->region = $data->region; + $this->user->profile->city = $data->city; + $this->user->profile->zip = $data->postalcode; + + return $this->user->profile; + } + + /** + * load the user contacts + */ + function getUserContacts() + { + $userId = $this->getCurrentUserId(); + + $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends.json" ); + + if ( ! is_object( $response ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $contacts = ARRAY(); + + foreach( $response->Friends as $item ){ + $uc = new Hybrid_User_Contact(); + + $uc->identifier = $item->userId; + $uc->displayName = $item->name; + $uc->profileURL = $item->webUri; + $uc->photoURL = $item->image; + $uc->description = $item->status; + + $contacts[] = $uc; + } + + return $contacts; + } + + /** + * update user status + */ + function setUserStatus( $status ) + { + // crappy myspace... gonna see this asaic + $userId = $this->getCurrentUserId(); + + $parameters = array( 'status' => $status ); + + $response = $this->api->api( "http://api.myspace.com/v1/users/" . $userId . "/status", 'PUT', $parameters ); + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ) + { + throw new Exception( "Update user status failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) ); + } + } + + /** + * load the user latest activity + * - timeline : all the stream + * - me : the user activity only + */ + function getUserActivity( $stream ) + { + $userId = $this->getCurrentUserId(); + + if( $stream == "me" ){ + $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/status.json" ); + } + else{ + $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends/status.json" ); + } + + if ( ! is_object( $response ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $activities = ARRAY(); + + if( $stream == "me" ){ + // todo + } + else{ + foreach( $response->FriendsStatus as $item ){ + $ua = new Hybrid_User_Activity(); + + $ua->id = $item->statusId; + $ua->date = NULL; // to find out!! + $ua->text = $item->status; + + $ua->user->identifier = $item->user->userId; + $ua->user->displayName = $item->user->name; + $ua->user->profileURL = $item->user->uri; + $ua->user->photoURL = $item->user->image; + + $activities[] = $ua; + } + } + + return $activities; + } +} diff --git a/includes/HybridAuth/Providers/OpenID.php b/includes/HybridAuth/Providers/OpenID.php new file mode 100644 index 0000000..605be74 --- /dev/null +++ b/includes/HybridAuth/Providers/OpenID.php @@ -0,0 +1,15 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Hybrid_Providers_OpenID provider adapter for any idp openid based + * + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_OpenID.html + */ +class Hybrid_Providers_OpenID extends Hybrid_Provider_Model_OpenID +{ +} diff --git a/includes/HybridAuth/Providers/Twitter.php b/includes/HybridAuth/Providers/Twitter.php new file mode 100644 index 0000000..671ba94 --- /dev/null +++ b/includes/HybridAuth/Providers/Twitter.php @@ -0,0 +1,204 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** +* Hybrid_Providers_Twitter provider adapter based on OAuth1 protocol +*/ +class Hybrid_Providers_Twitter extends Hybrid_Provider_Model_OAuth1 +{ + /** + * IDp wrappers initializer + */ + function initialize() + { + parent::initialize(); + + // Provider api end-points + $this->api->api_base_url = "https://api.twitter.com/1.1/"; + $this->api->authorize_url = "https://api.twitter.com/oauth/authenticate"; + $this->api->request_token_url = "https://api.twitter.com/oauth/request_token"; + $this->api->access_token_url = "https://api.twitter.com/oauth/access_token"; + + if ( isset( $this->config['api_version'] ) && $this->config['api_version'] ){ + $this->api->api_base_url = "https://api.twitter.com/{$this->config['api_version']}/"; + } + + if ( isset( $this->config['authorize'] ) && $this->config['authorize'] ){ + $this->api->authorize_url = "https://api.twitter.com/oauth/authorize"; + } + + $this->api->curl_auth_header = false; + } + + /** + * begin login step + */ + function loginBegin() + { + $tokens = $this->api->requestToken( $this->endpoint ); + + // request tokens as recived from provider + $this->request_tokens_raw = $tokens; + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "Authentification failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ), 5 ); + } + + if ( ! isset( $tokens["oauth_token"] ) ){ + throw new Exception( "Authentification failed! {$this->providerId} returned an invalid oauth token.", 5 ); + } + + $this->token( "request_token" , $tokens["oauth_token"] ); + $this->token( "request_token_secret", $tokens["oauth_token_secret"] ); + + // redirect the user to the provider authentication url with force_login + if ( isset( $this->config['force_login'] ) && $this->config['force_login'] ){ + Hybrid_Auth::redirect( $this->api->authorizeUrl( $tokens, array( 'force_login' => true ) ) ); + } + + // else, redirect the user to the provider authentication url + Hybrid_Auth::redirect( $this->api->authorizeUrl( $tokens ) ); + } + + /** + * load the user profile from the IDp api client + */ + function getUserProfile() + { + $response = $this->api->get( 'account/verify_credentials.json' ); + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ), 6 ); + } + + if ( ! is_object( $response ) || ! isset( $response->id ) ){ + throw new Exception( "User profile request failed! {$this->providerId} api returned an invalid response.", 6 ); + } + + # store the user profile. + $this->user->profile->identifier = (property_exists($response,'id'))?$response->id:""; + $this->user->profile->displayName = (property_exists($response,'screen_name'))?$response->screen_name:""; + $this->user->profile->description = (property_exists($response,'description'))?$response->description:""; + $this->user->profile->firstName = (property_exists($response,'name'))?$response->name:""; + $this->user->profile->photoURL = (property_exists($response,'profile_image_url'))?$response->profile_image_url:""; + $this->user->profile->profileURL = (property_exists($response,'screen_name'))?("http://twitter.com/".$response->screen_name):""; + $this->user->profile->webSiteURL = (property_exists($response,'url'))?$response->url:""; + $this->user->profile->region = (property_exists($response,'location'))?$response->location:""; + + return $this->user->profile; + } + + /** + * load the user contacts + */ + function getUserContacts() + { + $parameters = array( 'cursor' => '-1' ); + $response = $this->api->get( 'friends/ids.json', $parameters ); + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "User contacts request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + if( ! $response || ! count( $response->ids ) ){ + return ARRAY(); + } + + // 75 id per time should be okey + $contactsids = array_chunk ( $response->ids, 75 ); + + $contacts = ARRAY(); + + foreach( $contactsids as $chunk ){ + $parameters = array( 'user_id' => implode( ",", $chunk ) ); + $response = $this->api->get( 'users/lookup.json', $parameters ); + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "User contacts request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + if( $response && count( $response ) ){ + foreach( $response as $item ){ + $uc = new Hybrid_User_Contact(); + + $uc->identifier = (property_exists($item,'id'))?$item->id:""; + $uc->displayName = (property_exists($item,'name'))?$item->name:""; + $uc->profileURL = (property_exists($item,'screen_name'))?("http://twitter.com/".$item->screen_name):""; + $uc->photoURL = (property_exists($item,'profile_image_url'))?$item->profile_image_url:""; + $uc->description = (property_exists($item,'description'))?$item->description:""; + + $contacts[] = $uc; + } + } + } + + return $contacts; + } + + /** + * update user status + */ + function setUserStatus( $status ) + { + $parameters = array( 'status' => $status ); + $response = $this->api->post( 'statuses/update.json', $parameters ); + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "Update user status failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) ); + } + } + + /** + * load the user latest activity + * - timeline : all the stream + * - me : the user activity only + * + * by default return the timeline + */ + function getUserActivity( $stream ) + { + if( $stream == "me" ){ + $response = $this->api->get( 'statuses/user_timeline.json' ); + } + else{ + $response = $this->api->get( 'statuses/home_timeline.json' ); + } + + // check the last HTTP status code returned + if ( $this->api->http_code != 200 ){ + throw new Exception( "User activity stream request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + if( ! $response ){ + return ARRAY(); + } + + $activities = ARRAY(); + + foreach( $response as $item ){ + $ua = new Hybrid_User_Activity(); + + $ua->id = (property_exists($item,'id'))?$item->id:""; + $ua->date = (property_exists($item,'created_at'))?strtotime($item->created_at):""; + $ua->text = (property_exists($item,'text'))?$item->text:""; + + $ua->user->identifier = (property_exists($item->user,'id'))?$item->user->id:""; + $ua->user->displayName = (property_exists($item->user,'name'))?$item->user->name:""; + $ua->user->profileURL = (property_exists($item->user,'screen_name'))?("http://twitter.com/".$item->user->screen_name):""; + $ua->user->photoURL = (property_exists($item->user,'profile_image_url'))?$item->user->profile_image_url:""; + + $activities[] = $ua; + } + + return $activities; + } +} diff --git a/includes/HybridAuth/Providers/Yahoo.php b/includes/HybridAuth/Providers/Yahoo.php new file mode 100644 index 0000000..383a3cc --- /dev/null +++ b/includes/HybridAuth/Providers/Yahoo.php @@ -0,0 +1,237 @@ +<?php +/*! +* HybridAuth +* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth +* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html +*/ + +/** + * Yahoo OAuth Class + * + * @package HybridAuth providers package + * @author Lukasz Koprowski <azram19@gmail.com> + * @version 0.2 + * @license BSD License + */ + +/** + * Hybrid_Providers_Yahoo - Yahoo provider adapter based on OAuth1 protocol + */ +class Hybrid_Providers_Yahoo extends Hybrid_Provider_Model_OAuth1 +{ + function initialize() + { + parent::initialize(); + + // Provider api end-points + $this->api->api_base_url = 'http://social.yahooapis.com/v1/'; + $this->api->authorize_url = 'https://api.login.yahoo.com/oauth/v2/request_auth'; + $this->api->request_token_url = 'https://api.login.yahoo.com/oauth/v2/get_request_token'; + $this->api->access_token_url = 'https://api.login.yahoo.com/oauth/v2/get_token'; + } + + function getUserProfile() + { + $userId = $this->getCurrentUserId(); + + $parameters = array(); + $parameters['format'] = 'json'; + + $response = $this->api->get( 'user/' . $userId . '/profile', $parameters ); + + if ( ! isset( $response->profile ) ){ + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); + } + + $data = $response->profile; + + $this->user->profile->identifier = (property_exists($data,'guid'))?$data->guid:""; + $this->user->profile->firstName = (property_exists($data,'givenName'))?$data->givenName:""; + $this->user->profile->lastName = (property_exists($data,'familyName'))?$data->familyName:""; + $this->user->profile->displayName = (property_exists($data,'nickname'))?trim( $data->nickname ):""; + $this->user->profile->profileURL = (property_exists($data,'profileUrl'))?$data->profileUrl:""; + $this->user->profile->gender = (property_exists($data,'gender'))?$data->gender:""; + + if( $this->user->profile->gender == "F" ){ + $this->user->profile->gender = "female"; + } + + if( $this->user->profile->gender == "M" ){ + $this->user->profile->gender = "male"; + } + + if( isset($data->emails) ){ + $email = ""; + foreach( $data->emails as $v ){ + if( isset($v->primary) && $v->primary ) { + $email = (property_exists($v,'handle'))?$v->handle:""; + + break; + } + } + + $this->user->profile->email = $email; + $this->user->profile->emailVerified = $email; + } + + $this->user->profile->age = (property_exists($data,'displayAge'))?$data->displayAge:""; + $this->user->profile->photoURL = (property_exists($data,'image'))?$data->image->imageUrl:""; + + $this->user->profile->address = (property_exists($data,'location'))?$data->location:""; + $this->user->profile->language = (property_exists($data,'lang'))?$data->lang:""; + + return $this->user->profile; + } + + /** + * load the user contacts + */ + function getUserContacts() + { + $userId = $this->getCurrentUserId(); + + $parameters = array(); + $parameters['format'] = 'json'; + $parameters['count'] = 'max'; + + $response = $this->api->get('user/' . $userId . '/contacts', $parameters); + + if ( $this->api->http_code != 200 ) + { + throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + if ( !$response->contacts->contact && ( $response->errcode != 0 ) ) + { + return array(); + } + + $contacts = array(); + + foreach( $response->contacts->contact as $item ) { + $uc = new Hybrid_User_Contact(); + + $uc->identifier = $this->selectGUID( $item ); + $uc->email = $this->selectEmail( $item->fields ); + $uc->displayName = $this->selectName( $item->fields ); + $uc->photoURL = $this->selectPhoto( $item->fields ); + + $contacts[] = $uc; + } + + return $contacts; + } + + /** + * return the user activity stream + */ + function getUserActivity( $stream ) + { + $userId = $this->getCurrentUserId(); + + $parameters = array(); + $parameters['format'] = 'json'; + $parameters['count'] = 'max'; + + $response = $this->api->get('user/' . $userId . '/updates', $parameters); + + if( ! $response->updates || $this->api->http_code != 200 ) + { + throw new Exception( 'User activity request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) ); + } + + $activities = array(); + + foreach( $response->updates as $item ){ + $ua = new Hybrid_User_Activity(); + + $ua->id = (property_exists($item,'collectionID'))?$item->collectionID:""; + $ua->date = (property_exists($item,'lastUpdated'))?$item->lastUpdated:""; + $ua->text = (property_exists($item,'loc_longForm'))?$item->loc_longForm:""; + + $ua->user->identifier = (property_exists($item,'profile_guid'))?$item->profile_guid:""; + $ua->user->displayName = (property_exists($item,'profile_nickname'))?$item->profile_nickname:""; + $ua->user->profileURL = (property_exists($item,'profile_profileUrl'))?$item->profile_profileUrl:""; + $ua->user->photoURL = (property_exists($item,'profile_displayImage'))?$item->profile_displayImage:""; + + $activities[] = $ua; + } + + if( $stream == "me" ){ + $userId = $this->getCurrentUserId(); + $my_activities = array(); + + foreach( $activities as $a ){ + if( $a->user->identifier == $userId ){ + $my_activities[] = $a; + } + } + + return $my_activities; + } + + return $activities; + } + + //-- + + function select($vs, $t) + { + foreach( $vs as $v ){ + if( $v->type == $t ) { + return $v; + } + } + + return NULL; + } + + function selectGUID( $v ) + { + return (property_exists($v,'id'))?$v->id:""; + } + + function selectName( $v ) + { + $s = $this->select($v, 'name'); + + if( ! $s ){ + $s = $this->select($v, 'nickname'); + return ($s)?$s->value:""; + } else { + return ($s)?$s->value->givenName . " " . $s->value->familyName:""; + } + } + + function selectNickame( $v ) + { + $s = $this->select($v, 'nickname'); + return ($s)?$s:""; + } + + function selectPhoto( $v ) + { + $s = $this->select($v, 'guid'); + return ($s)?(property_exists($s,'image')):""; + } + + function selectEmail( $v ) + { + $s = $this->select($v, 'email'); + return ($s)?$s->value:""; + } + + public function getCurrentUserId() + { + $parameters = array(); + $parameters['format'] = 'json'; + + $response = $this->api->get( 'me/guid', $parameters ); + + if ( ! isset( $response->guid->value ) ){ + throw new Exception( "User id request failed! {$this->providerId} returned an invalid response." ); + } + + return $response->guid->value; + } +} |