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