class_cloudregister.php
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: class_cloudregister.php 33799 2013-08-15 02:29:22Z nemohou $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
Cloud::loadFile('Service_Client_Cloud');
class Cloud_Register extends Cloud_Service_Client_Cloud {
public $appIdentifier;
public $pluginid;
protected $lang;
public function __construct($appIdentifier, $pluginid, $startStep, $debug = false) {
global $_G;
parent::__construct($debug);
$this->appIdentifier = $appIdentifier;
$this->pluginid = $pluginid;
$step = !empty($_GET['step']) ? authcode($_GET['step'], 'DECODE', $_G['config']['security']['authkey']) : $startStep;
$method = 'step_'.$step;
$this->lang = lang('cloud_register');
if(!empty($_GET['skip'])) {
return false;
}
if(method_exists($this, $method)) {
return $this->$method();
} else {
return false;
}
}
private function _step($v) {
global $_G;
return rawurlencode(authcode($v, 'ENCODE', $_G['config']['security']['authkey'], 3600));
}
private function _msg($message, $extra = '') {
if(defined('ADMINSCRIPT')) {
cpmsg($message, '', 'succeed', array(), ($extra ? $extra.'<br />' : '').'<br /><a href="'.ADMINSCRIPT.'?action=plugins">'.$this->lang['back'].'</a>');
} else {
showmessage($message.'<br />'.$extra, $url, $values, array('alert' => 'info'));
}
}
private function step_appOpenFormView() {
global $_G;
$submiturl = $_G['siteurl'].ADMINSCRIPT.'?action=plugins&operation=enable&pluginid='.$this->pluginid.'&formhash='.FORMHASH.'&step='.$this->_step('appOpenWithRegister');
$fromurl = $_G['siteurl'].ADMINSCRIPT.'?action=plugins';
$data = $this->appOpenFormView($this->appIdentifier, $submiturl, $fromurl);
if($data) {
echo $data;
exit;
}
$this->step_appOpenWithRegister();
}
private function step_appOpenWithRegister() {
global $_G;
$return = $this->appOpenWithRegister($this->appIdentifier, $_GET['extra']);
if($return['errCode']) {
if($return['errCode'] == '1000') {
$this->step_bindQQ();
} else {
$this->_msg($return['errMessage']);
}
}
if($return['result']) {
if($return['result']['sId'] && $return['result']['sKey']) {
C::t('common_setting')->update_batch(array('my_siteid' => $return['result']['sId'], 'my_sitekey' => $return['result']['sKey']));
updatecache('setting');
}
if($return['result']['needBindQQ']) {
$this->step_bindQQ();
}
}
$this->step_over();
}
private function step_bindQQ() {
global $_G;
$fromurl = $_G['siteurl'].ADMINSCRIPT.'?frame=no&action=plugins&operation=enable&pluginid='.$this->pluginid.'&formhash='.FORMHASH.'&step='.$this->_step('bindQQBack');
$url = $this->bindQQ($this->appIdentifier, $fromurl, $_GET['extra']);
$script = '<script type="text/javascript">function BindQQ() {var url = \''.$url.'\';var left = (window.screen.width - 700) / 2;var top = (window.screen.height - 460) / 2;var A=window.open(url, \'TencentLogin\', \'left=\'+left+\',top=\'+top+\',width=700,height=460,menubar=0,scrollbars=1,resizable=1,status=1,titlebar=0,toolbar=0,scrollbars=0,location=1\');}</script>';
$this->_msg($this->lang['bindqq'], $script.$this->lang['bindqq_link']);
}
private function step_bindQQBack() {
$stepurl = $_G['siteurl'].ADMINSCRIPT.'?action=plugins&operation=enable&pluginid='.$this->pluginid.'&formhash='.FORMHASH.'&step='.$this->_step('appOpenWithRegister');
if($_GET['extra']) {
$utilService = Cloud::loadClass('Service_Util');
$stepurl .= '&'.$utilService->httpBuildQuery(array('extra' => $_GET['extra']), '', '&');
}
echo '<script type="text/javascript">if(window.opener) {window.opener.location.href=\''.$stepurl.'\';};window.close();</script>';
exit;
}
private function step_over() {
return true;
}
private function step_appCloseReasonsView() {
$submiturl = $_G['siteurl'].ADMINSCRIPT.'?action=plugins&operation=disable&pluginid='.$this->pluginid.'&formhash='.FORMHASH.'&step='.$this->_step('appClose');
$fromurl = $_G['siteurl'].ADMINSCRIPT.'?action=plugins';
$data = $this->appCloseReasonsView($this->appIdentifier, $submiturl, $fromurl);
if($data) {
echo $data;
exit;
}
$this->step_over();
}
private function step_appClose() {
$return = $this->appClose($this->appIdentifier);
if($return['errCode']) {
$this->_msg($return['errMessage']);
}
$this->step_over();
}
}
?>