Skip to content

Commit

Permalink
add Murmur Pixnet Plurk and updates some others providers
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridauth committed Nov 30, 2011
1 parent 2a0053e commit fc7b517
Show file tree
Hide file tree
Showing 4 changed files with 3,827 additions and 0 deletions.
194 changes: 194 additions & 0 deletions additional-providers/hybridauth-murmur/Providers/Murmur.php
@@ -0,0 +1,194 @@
<?php
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
*/

/**
* Murmur OAuth Class
*
* @package HybridAuth additional providers package
* @author RB Lin <xtheme@gmail.com>
* @version 1.2
* @license BSD License
*/

/**
* Murmur provider adapter based on OAuth1 protocol
*
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_Murmur.html
*/
class Hybrid_Providers_Murmur extends Hybrid_Provider_Model_OAuth1
{
function initialize()
{
parent::initialize();

// Provider api end-points
$this->api->api_base_url = 'http://api.murmur.tw/1/';
$this->api->authorize_url = 'http://api.murmur.tw/oauth/authorize';
$this->api->request_token_url = 'http://api.murmur.tw/oauth/request_token';
$this->api->access_token_url = 'http://api.murmur.tw/oauth/access_token';
}

/**
* for Murmur we need to override loginBegin() as the auth url is: $tokens['xoauth_request_auth_url']
*/
/*function loginBegin()
{
// Get a new request token
$tokens = $this->api->requestToken( $this->endpoint );
if ( ! isset( $tokens ) ){
throw new Exception( 'Authentification failed! '.$this->providerId.' returned an invalid Request Token.', 5 );
}
$this->token( 'request_token' , $tokens['oauth_token'] );
$this->token( 'request_token_secret', $tokens['oauth_token_secret'] );
# Build authorize link & redirect user to provider authorisation web page
Hybrid_Auth::redirect( $tokens['xoauth_request_auth_url'] );
}*/

/**
* 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 );
}

$this->user->profile->identifier = @ $response->id;
$this->user->profile->displayName = @ $response->name;
$this->user->profile->description = @ $response->description;
$this->user->profile->firstName = @ $response->name;
$this->user->profile->photoURL = @ $response->profile_image_url;
$this->user->profile->profileURL = 'http://murmur.tw/' . $response->screen_name;
$this->user->profile->webSiteURL = @ $response->url;
$this->user->profile->region = @ $response->location;
$this->user->profile->city = @ $response->location;
$this->user->profile->age = @ $response->age;
$this->user->profile->language = @ $response->lang;

return $this->user->profile;
}

/**
* load the user contacts
*/
function getUserContacts()
{
$response = $this->api->get('statuses/friends.json');

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 ) {
return array();
}

$contacts = array();

foreach( $response as $item ) {
$uc = new Hybrid_User_Contact();

$uc->identifier = @ $item->id;
$uc->displayName = @ $item->name;
$uc->profileURL = 'http://murmur.tw/' . $response->screen_name;
$uc->photoURL = @ $item->profile_image_url;

$contacts[] = $uc;
}

return $contacts;

}

/**
* update user status
*/
function setUserStatus( $status )
{
$parameters = array();
$parameters['status'] = $status;

$response = $this->api->post('statuses/update.json', $parameters);

if ( $this->api->http_code != 200 )
{
throw new Exception( 'Update user status failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
}

return $response;
}

/**
* load the user latest activity
* - timeline : all the stream
* - me : the user activity only
*/
function getUserActivity( $stream )
{
if ( $stream == 'me' ) {
$url = 'statuses/home_timeline.json';
} else {
$url = 'statuses/friends.json';
}

$response = $this->api->get($url);

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();

if ( $stream == 'me' ) {
foreach ( $response as $item ) {
$ua = new Hybrid_User_Activity();
$ua->id = @ $item->id;
$ua->date = @ $item->timestamp;
$ua->text = @ $item->text;
$ua->user->identifier = @ $item->user->id;
$ua->user->displayName = @ $item->user->name;
$ua->user->profileURL = 'http://murmur.tw/' . $item->user->screen_name;
$ua->user->photoURL = @ $item->user->profile_image_url;

$activities[] = $ua;
}
} else {
foreach ( $response->news as $item ) {
if ($item->content_type == 'blog') {
$ua = new Hybrid_User_Activity();
$ua->id = @ $item->status->id;
$ua->date = @ $item->status->public_at;
$ua->text = @ $item->status->text;
$ua->user->identifier = @ $item->id;
$ua->user->displayName = @ $item->name;
$ua->user->profileURL = 'http://murmur.tw/' . $item->screen_name;
$ua->user->photoURL = @ $item->profile_image_url;

$activities[] = $ua;
}
}
}

return $activities;
}
}
199 changes: 199 additions & 0 deletions additional-providers/hybridauth-pixnet/Providers/Pixnet.php
@@ -0,0 +1,199 @@
<?php
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
*/

/**
* Pixnet OAuth Class
*
* @package HybridAuth additional providers package
* @author RB Lin <xtheme@gmail.com>
* @version 1.2
* @license BSD License
*/

/**
* Pixnet provider adapter based on OAuth1 protocol
*
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_Pixnet.html
*/
class Hybrid_Providers_Pixnet extends Hybrid_Provider_Model_OAuth1
{
function initialize()
{
parent::initialize();

// Provider api end-points
$this->api->api_base_url = 'http://emma.pixnet.cc/';
$this->api->authorize_url = 'http://emma.pixnet.cc/oauth/authorize';
$this->api->request_token_url = 'http://emma.pixnet.cc/oauth/request_token';
$this->api->access_token_url = 'http://emma.pixnet.cc/oauth/access_token';

// for access_token need to POST data instead of using GET
$this->api->access_token_method = 'POST';
}

/**
* load the user profile from the IDp api client
*/
function getUserProfile()
{
$response = $this->api->get('account');

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 ) )
{
throw new Exception( 'User profile request failed! ' . $this->providerId . ' api returned an invalid response.', 6 );
}

$this->user->profile->identifier = @ $response->account->identity;
$this->user->profile->displayName = @ $response->account->name;
$this->user->profile->profileURL = @ $response->account->link;
$this->user->profile->photoURL = @ $response->account->cavatar;

switch ( $response->account->gender ) {
case 'M': $this->user->profile->gender = 'male'; break;
case 'F': $this->user->profile->gender = 'female'; break;
}

if ( isset( $response->account->birth ) ) {
$this->user->profile->birthDay = substr($response->account->birth, 6);
$this->user->profile->birthMonth = substr($response->account->birth, 4, 2);
$this->user->profile->birthYear = substr($response->account->birth, 0, 4);
}

return $this->user->profile;
}

/**
* load the user contacts
*/
function getUserContacts()
{
$response = $this->api->get('friendships');

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 ( empty( $response->friend_pairs ) || ( $response->error != 0 ) )
{
return array();
}

$contacts = array();

foreach( $response->friend_pairs as $item ) {
$uc = new Hybrid_User_Contact();

$uc->identifier = @ $item->id;
$uc->displayName = @ $item->display_name;
$uc->profileURL = 'http://' . strtolower( $item->user_name ) . '.pixnet.net/blog';

$contacts[] = $uc;
}

return $contacts;

}

/**
* update user status
*/
function setUserStatus( $status )
{
$parameters = array();

if ( is_array( $status ) ) {
if ( isset( $status[0] ) && ! empty( $status[0] ) ) $parameters['title'] = $status[0];
if ( isset( $status[1] ) && ! empty( $status[1] ) ) $parameters['body'] = $status[1];
if ( isset( $status[2] ) && ! empty( $status[2] ) ) $parameters['status'] = $status[2];
} else {
$parameters['title'] = 'Title';
$parameters['body'] = $status;
$parameters['status'] = '1'; // 文章狀態, 0: 刪除, 1: 草稿, 2: 公開, 3: 密碼, 4: 隱藏, 5: 好友, 7: 共同作者
}

$response = $this->api->post('blog/articles', $parameters);

if ( $this->api->http_code != 200 )
{
throw new Exception( 'Update user status failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
}

return $response;
}

/**
* load the user latest activity
* - timeline : all the stream
* - me : the user activity only
*/
function getUserActivity( $stream )
{
$parameters = array();

if ( $stream == 'me' ) {
$url = 'blog/articles';
} else {
$parameters['group_type'] = 'friend';
$url = 'friend/news';
}

$response = $this->api->get($url, $parameters);

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 ) );
}

$activities = array();

if ( $stream == 'me' ) {
if ( ! $response || ! count( $response->articles ) ) {
return array();
}

foreach ( $response->articles as $item ) {
$ua = new Hybrid_User_Activity();
$ua->id = @ $item->id;
$ua->date = @ $item->public_at;
$ua->text = @ $item->title;
$ua->user->identifier = @ $item->user->name;
$ua->user->displayName = @ $item->user->display_name;
$ua->user->profileURL = @ $item->user->link;
$ua->user->photoURL = @ $item->user->cavatar;

$activities[] = $ua;
}
} else {
if ( ! $response || ! count( $response->news ) ) {
return array();
}

foreach ( $response->news as $item ) {
if ($item->content_type == 'blog') {
$ua = new Hybrid_User_Activity();
$ua->id = @ $item->blog_article->id;
$ua->date = @ $item->blog_article->public_at;
$ua->text = @ $item->blog_article->title;
$ua->user->identifier = @ $item->user->name;
$ua->user->displayName = @ $item->user->display_name;
$ua->user->profileURL = @ $item->user->link;
$ua->user->photoURL = @ $item->user->cavatar;

$activities[] = $ua;
}
}
}

return $activities;
}
}

0 comments on commit fc7b517

Please sign in to comment.