-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproviderManager.php
421 lines (338 loc) Β· 10.7 KB
/
providerManager.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
// μλΉμ€ κ΄λ¦¬λ₯Ό μν ν΄λμ€
class socialxeProviderManager{
var $master_provider = null;
// μΈμ€ν΄μ€
function getInstance(&$sessionManager){
static $instance;
if (!isset($instance)) $instance = new socialxeProviderManager($sessionManager);
return $instance;
}
// μμ±μ
function socialxeProviderManager(&$sessionManager){
// μΈμ
κ΄λ¦¬μ μ μ₯
$this->session = $sessionManager;
// μ 곡νλ μλΉμ€
$this->provider_list = array('xe', 'twitter', 'me2day', 'facebook', 'google');
// κ° μλΉμ€ ν΄λμ€
$this->provider['xe'] = &socialxeProviderXE::getInstance($this->session);
$this->provider['twitter'] = &socialxeProviderTwitter::getInstance($this->session);
$this->provider['me2day'] = &socialxeProviderMe2day::getInstance($this->session);
$this->provider['facebook'] = &socialxeProviderFacebook::getInstance($this->session);
$this->provider['google'] = &socialxeProviderGoogle::getInstance($this->session);
}
// νκ²½ μ€μ κ° μΈν
function setConfig($config){
if ($this->config) return;
$this->config = $config;
$this->init();
}
// μ΄κΈ°ν
function init(){
// λΆκ³μ μ€μ
$slave_provider = $this->session->getSession('slave');
if ($slave_provider)
$this->setSlaveProvider($slave_provider);
// λνκ³μ μ€μ
$master_provider = $this->session->getSession('master');
if ($master_provider)
$this->setMasterProvider($master_provider, true);
else
$this->setNextMasterProvider();
// 보νμ©! λν κ³μ νμΈ
if (!$this->getMasterProvider())
$this->setNextMasterProvider();
}
// μ 곡νλ μ 체 μλΉμ€ λͺ©λ‘
function getFullProviderList(){
return $this->provider_list;
}
// μ 곡νλ μλΉμ€ λͺ©λ‘(νκ²½μ€μ μμ μ νν κ²λ§)
function getProviderList(){
static $result;
// μ΄λ―Έ νΈμΆ λ μ μλ€λ©΄, μ μ₯λ κ° λ°ν
if(!is_array($result)) {
$provider_list = $this->getFullProviderList();
$result = array();
foreach($provider_list as $provider){
if ($this->config->select_service[$provider] == 'Y'){
$result[] = $provider;
}
}
}
return $result;
}
// μ 곡νλ μλΉμ€ μ¬λΆ νμΈ
function inProvider($provider){
return in_array($provider, $this->getProviderList());
}
// λ‘κ·ΈμΈ
function doLogin($provider, $access, $account){
$result = new Object();
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider)){
$result->setError(-1);
return $result->setMessage('msg_invalid_provider');
}
// λ‘κ·ΈμΈ μ²λ¦¬
$this->provider[$provider]->doLogin($access, $account);
// λνκ³μ μ€μ
if (count($this->getLoggedProviderList()) == 1){
$this->setMasterProvider($provider);
}
return $result;
}
// λ‘κ·Έμμ
function doLogout($provider){
$result = new Object();
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider)){
$result->setError(-1);
return $result->setMessage('msg_invalid_provider');
}
// λ‘κ·Έμμ μ²λ¦¬
$this->provider[$provider]->doLogout();
// λνκ³μ μ€μ
if ($this->getMasterProvider() == $provider)
$this->setNextMasterProvider();
// λΆκ³μ μ€μ
if ($this->getSlaveProvider() == $provider)
$this->setNextSlaveProvider();
return $result;
}
// μ λΆ λ‘κ·Έμμ
function doFullLogout(){
$full_provider_list = $this->getFullProviderList();
foreach($full_provider_list as $provider){
$this->provider[$provider]->doLogout();
}
$this->clearMasterProvider();
$this->clearSlaveProvider();
}
// λ‘κ·ΈμΈ μ¬λΆ μ±ν¬
function syncLogin(){
foreach($this->getProviderList() as $provider){
$this->provider[$provider]->syncLogin();
}
// λ€μ μ΄κΈ°ν
$this->init();
}
// λ‘κ·ΈμΈ μ¬λΆ
function isLogged($provider){
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->isLogged();
}
// λ‘κ·ΈμΈλ μλΉμ€ 리μ€νΈ
function getLoggedProviderList(){
$result = array();
foreach($this->getProviderList() as $provider){
if ($this->provider[$provider]->isLogged()){
$result[] = $provider;
}
}
return $result;
}
// λνκ³μ μ€μ
function setMasterProvider($provider, $init = false){
$result = new Object();
if (!$provider){
$this->setNextMasterProvider();
return $result;
}
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider) && $provider != 'xe'){
$result->setError(-1);
return $result->setMessage('msg_invalid_provider');
}
// XEλ₯Ό μ¬μ©νκ³
// XEκ° λ‘κ·ΈμΈλμ΄ μμΌλ©΄ λ°μ§μ§ λ§κ³ XEλ₯Ό λνκ³μ μΌλ‘ λ§λ λ€.
if ($this->inProvider('xe') && $this->provider['xe']->isLogged()){
// λΆκ³μ μ΄ μμΌλ©΄ μ§κΈ λν κ³μ μ
if (!$this->getSlaveProvider() && $init){
if ($provider == 'xe')
$this->setNextSlaveProvider();
else
$this->setSlaveProvider($provider);
}
// XE λ‘κ·ΈμΈ μνμμλ μμ²μ λΆκ³μ μΌλ‘ λκΈ΄λ€.
else{
$this->setSlaveProvider($provider);
}
$provider = 'xe';
}
// XE λ‘κ·ΈμΈ μνκ° μλλ° μΈμ
μ XEλ‘ λμ΄ μμΌλ©΄ λΆκ³μ μ λνκ³μ μΌλ‘ λ§λ λ€.
else if ($provider == 'xe'){
$this->setMasterProvider($this->getSlaveProvider());
$this->clearSlaveProvider();
return $result;
}
// λ‘κ·ΈμΈλμ΄ μλμ§ νμΈ
if ($this->isLogged($provider)){
// λνκ³μ μ€μ
$this->master_provider = $provider;
$this->session->setSession('master', $provider);
}else{
$this->setNextMasterProvider();
}
return $result;
}
// λ€μ λνκ³μ μ€μ
function setNextMasterProvider(){
// λν κ³μ μ νμ¬ λ‘κ·ΈμΈλ μλΉμ€ μ€ κ·Έλ₯ 첫λ²μ§Έλ‘ μ ννλ€.
$logged_provider_list = $this->getLoggedProviderList();
if (count($logged_provider_list)){
$this->setMasterProvider($logged_provider_list[0]);
}else{
$this->clearMasterProvider();
}
}
// λν κ³μ μμ
function clearMasterProvider(){
$this->master_provider = null;
$this->session->clearSession('master');
}
// λΆκ³μ μ€μ
function setSlaveProvider($provider){
$result = new Object();
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider) || $provider == 'xe'){
$result->setError(-1);
return $result->setMessage('msg_invalid_provider');
}
// λ‘κ·ΈμΈλμ΄ μλμ§ νμΈ
if ($this->isLogged($provider)){
// XE λ‘κ·ΈμΈμ΄ μλλ©΄ λ
if ($this->provider['xe']->isLogged()){
// λΆκ³μ μ€μ
$this->slave_provider = $provider;
$this->session->setSession('slave', $provider);
}else{
$this->clearSlaveProvider();
}
}else{
$this->setNextSlaveProvider();
}
return $result;
}
// λΆκ³μ μμ
function clearSlaveProvider(){
$this->slave_provider = null;
$this->session->clearSession('slave');
}
// λ€μ λΆκ³μ μ€μ
function setNextSlaveProvider(){
// λΆκ³μ μ νμ¬ λ‘κ·ΈμΈλ μλΉμ€ μ€ κ·Έλ₯ 첫λ²μ§Έλ‘ μ ννλ€.
$logged_provider_list = $this->getLoggedProviderList();
if (count($logged_provider_list)){
if ($logged_provider_list[0] != 'xe')
$this->setSlaveProvider($logged_provider_list[0]);
else if ($logged_provider_list[1])
$this->setSlaveProvider($logged_provider_list[1]);
else
$this->clearSlaveProvider();
}else{
$this->clearSlaveProvider();
}
}
// λνκ³μ
function getMasterProvider(){
return $this->master_provider;
}
// λΆκ³μ
function getSlaveProvider(){
return $this->slave_provider;
}
// ν΄λΉ μλΉμ€μ νμ¬ λ‘κ·ΈμΈ μμ΄λ
function getProviderID($provider){
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getId();
}
// ν΄λΉ μλΉμ€μ νμ¬ λ‘κ·ΈμΈ λλ€μ
function getProviderNickName($provider){
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getNickName();
}
// λνκ³μ μ μμ΄λ
function getMasterProviderId(){
// λνκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getMasterProvider())) return;
// λνκ³μ μ μμ΄λ
return $this->provider[$this->getMasterProvider()]->getId();
}
// λνκ³μ μ λλ€μ
function getMasterProviderNickName(){
// λνκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getMasterProvider())) return;
// λνκ³μ μ λλ€μ
return $this->provider[$this->getMasterProvider()]->getNickName();
}
// λνκ³μ μ νλ‘ν μ΄λ―Έμ§
function getMasterProviderProfileImage(){
// λνκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getMasterProvider())) return;
// λνκ³μ μ λλ€μ
return $this->provider[$this->getMasterProvider()]->getProfileImage();
}
// λΆκ³μ μ μμ΄λ
function getSlaveProviderId(){
// λΆκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getSlaveProvider())) return;
// λΆκ³μ μ μμ΄λ
return $this->provider[$this->getSlaveProvider()]->getId();
}
// λΆκ³μ μ λλ€μ
function getSlaveProviderNickName(){
// λΆκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getSlaveProvider())) return;
// λΆκ³μ μ λλ€μ
return $this->provider[$this->getSlaveProvider()]->getNickName();
}
// λΆκ³μ μ νλ‘ν μ΄λ―Έμ§
function getSlaveProviderProfileImage(){
// λΆκ³μ μ΄ μ€μ λμλμ§ νμΈ
if (!$this->inProvider($this->getSlaveProvider())) return;
// λΆκ³μ μ λλ€μ
return $this->provider[$this->getSlaveProvider()]->getProfileImage();
}
// μ‘μΈμ€ μ 보 μ»κΈ°
function getAccess($provider){
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getAccess();
}
// μ¬μ©μ μ 보 μ»κΈ°
function getAccount($provider){
// μ 곡νλ μλΉμ€μΈμ§ νμΈ
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getAccount();
}
// μ‘μΈμ€ μ 보 ν΅μΌλ‘ μ»κΈ°
function getAccesses(){
$result = array();
foreach($this->provider_list as $provider){
$result[$provider] = $this->provider[$provider]->getAccess();
}
return $result;
}
// μμ
μλΉμ€ λ§ν¬
function getAuthorLink($provider, $id, $nick_name){
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getAuthorLink($id, $nick_name);
}
// μμ
μλΉμ€μ 리ν νμμΌλ‘ λ°ν
function getReplyPrefix($provider, $id, $nick_name){
if (!$this->inProvider($provider)) return;
return $this->provider[$provider]->getReplyPrefix($id, $nick_name);
}
// κ° μμ
μλΉμ€μ 리ν νμμ΄ λ€μ΄μλμ§ νμΈ
function getReplyProviderList($content){
$result = Array();
foreach($this->provider_list as $provider){
if ($this->provider[$provider]->isContainReply($content)){
$result[] = $provider;
}
}
return $result;
}
}
?>