Файл: Source/auth/Social/Network/Yahoo.php
Строк: 144
<?php
class Social_Network_Yahoo extends Social_Protocol_Model_OAuth {
function init() {
parent::init();
$this->api->api_base_url = 'https://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 Social_Exception( "User profile request failed! $this->network_name: invalidresponse." );
}
$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;
}
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 Social_Exception( 'User contacts request failed! ' . $this->network_name . ' 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 Social_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;
}
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 Social_Exception( 'User activity request failed! ' . $this->network_name . ' error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
}
$activities = array();
foreach( $response->updates as $item ){
$ua = new Social_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 Social_Exception( "User id request failed! $this->network_name: invalid response." );
}
return $response->guid->value;
}
}