PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/source/plugin/renren/class/connect.class.php

https://bitbucket.org/renren_platform/renren-api-discuz-sdk/
PHP | 86 lines | 76 code | 10 blank | 0 comment | 16 complexity | 8e03b09cc81a392cea810846aa003c55 MD5 | raw file
  1. <?php
  2. if(!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. require_once './source/plugin/renren/renren.function.php';
  6. class renren_connect {
  7. var $session = array( 'session_key' => '',
  8. 'user'=>'',
  9. 'ss'=>'',
  10. 'expires'=>''
  11. );
  12. var $api_key = '';
  13. var $secret = '';
  14. var $sig = '';
  15. var $rr_uid;
  16. var $dz_uid;
  17. function &instance() {
  18. static $object;
  19. if(empty($object)) {
  20. $object = new renren_connect();
  21. }
  22. return $object;
  23. }
  24. function renren_connect() {
  25. global $_G;
  26. loadcache('plugin');
  27. $this->api_key = $_G['cache']['plugin']['renren']['api_key'];
  28. $this->secret = $_G['cache']['plugin']['renren']['secret'];
  29. }
  30. function init($discuz_uid='',$dz_username,$email,$avatar,$password) {
  31. $this->_init_session();
  32. $this->sig = getgpc($this->api_key, 'C');
  33. if($this->verify()) {
  34. $this->rr_uid = $this->session['user'];
  35. $this->dz_uid = rr_get_bind_dz_uid($this->rr_uid);
  36. if(empty($this->dz_uid) && empty($discuz_uid))
  37. $this->dz_uid = rr_register($this->rr_uid,$dz_username,$email,$avatar,$password);
  38. if(empty($discuz_uid) || $discuz_uid == $this->dz_uid) {
  39. $GLOBALS['_G']['renren']['session'] = $this->session;
  40. $GLOBALS['_G']['renren']['rr_uid'] = $this->rr_uid;
  41. $GLOBALS['_G']['renren']['dz_uid'] = $this->dz_uid;
  42. $GLOBALS['_G']['renren']['api_key'] = $this->api_key;
  43. $GLOBALS['_G']['renren']['secret'] = $this->secret;
  44. }
  45. }
  46. }
  47. function inits($discuz_uid='') {
  48. $this->_init_session();
  49. $this->sig = getgpc($this->api_key, 'C');
  50. if($this->verify()) {
  51. $this->rr_uid = $this->session['user'];
  52. $this->dz_uid = rr_get_bind_dz_uid($this->rr_uid);
  53. if(empty($discuz_uid) || $discuz_uid == $this->dz_uid) {
  54. $GLOBALS['_G']['renren']['session'] = $this->session;
  55. $GLOBALS['_G']['renren']['rr_uid'] = $this->rr_uid;
  56. $GLOBALS['_G']['renren']['dz_uid'] = $this->dz_uid;
  57. $GLOBALS['_G']['renren']['api_key'] = $this->api_key;
  58. $GLOBALS['_G']['renren']['secret'] = $this->secret;
  59. }
  60. }
  61. }
  62. function _init_session() {
  63. foreach(array_keys($this->session) as $key) {
  64. $this->session[$key] = getgpc($this->api_key.'_'.$key, 'C');
  65. }
  66. }
  67. function verify() {
  68. $time =date();
  69. if(empty($this->session['expires']) || $time > intval($this->session['expires']) ) {
  70. return false;
  71. } else {
  72. return rr_generate_sig($this->session, $this->secret) == $this->sig;
  73. }
  74. }
  75. }
  76. ?>