/users/modules/ohloh/index.php

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