/users/modules/ohloh/index.php
PHP | 84 lines | 64 code | 11 blank | 9 comment | 2 complexity | dc1e6aca03b37c4350823e62b669e6e5 MD5 | raw file
1<?php 2/** 3 * @package StartupAPI 4 * @subpackage Authentication 5 */ 6require_once(dirname(dirname(dirname(__FILE__))).'/OAuthModule.php'); 7 8class OhlohAuthenticationModule extends OAuthAuthenticationModule 9{ 10 protected $userCredentialsClass = 'OhlohUserCredentials'; 11 12 public function __construct($oAuthConsumerKey, $oAuthConsumerSecret) 13 { 14 parent::__construct( 15 'Ohloh', 16 'http://www.ohloh.com', 17 $oAuthConsumerKey, 18 $oAuthConsumerSecret, 19 'http://www.ohloh.net/oauth/request_token', 20 'https://api.twitter.com/oauth/access_token', 21 'http://www.ohloh.net/oauth/access_token', 22 array('HMAC-SHA1'), 23 'http://www.ohloh.com', 24 null, 25 null, 26 null, 27# UserConfig::$USERSROOTURL.'/modules/twitter/login-button.png', 28# UserConfig::$USERSROOTURL.'/modules/twitter/login-button.png', 29# UserConfig::$USERSROOTURL.'/modules/twitter/login-button.png', 30 array( 31 array(5001, "Logged in using Ohloh account", 1), 32 array(5002, "Added Ohloh account", 1), 33 array(5003, "Removed Ohloh account", 0), 34 array(5004, "Registered using Ohloh account", 1), 35 ) 36 ); 37 } 38 39 public function getID() 40 { 41 return "ohloh"; 42 } 43 44 public function getLegendColor() 45 { 46 return "868686"; 47 } 48 49 public function getTitle() 50 { 51 return "Ohloh"; 52 } 53 54 public function getIdentity($oauth_user_id) { 55 // get twitter handle 56 $request = new OAuthRequester('http://www.ohloh.net/accounts/me.xml', 'GET'); 57 $result = $request->doRequest($oauth_user_id); 58 59 if ($result['code'] == 200) { 60 $raw_xml = $result['body']; 61 $xml = new SimpleXMLElement($raw_xml); 62 63 // todo add more fields 64 return array( 65 'id' => (string)$xml->id, 66 'name' => (string)$xml->name 67 ); 68 } 69 70 return null; 71 } 72 73 protected function renderUserInfo($serialized_userinfo) { 74 $user_info = unserialize($serialized_userinfo); 75 ?><a href="http://www.ohloh.net/accounts/<?php echo UserTools::escape($user_info['id']); ?>" target="_blank"><?php echo UserTools::escape($user_info['name']); ?></a> 76 <?php 77 } 78} 79 80class OhlohUserCredentials extends OAuthUserCredentials { 81 public function getHTML() { 82 return '<a href="http://www.ohloh.net/accounts/'.UserTools::escape($user_info['id']).'" target="_blank">@'.$this->userinfo['name'].'</a>'; 83 } 84}