| 103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
include_once(SP_CTRLPATH . "/googleapi.ctrl.php");
|
|
|
24 |
|
|
|
25 |
# class defines all connection functions
|
|
|
26 |
class ConnectionController extends Controller {
|
|
|
27 |
|
|
|
28 |
var $sourceList = array(
|
|
|
29 |
'google' => 'GoogleAPIController',
|
|
|
30 |
);
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Function to display connections
|
|
|
35 |
*/
|
|
|
36 |
function listConnections($info = ''){
|
|
|
37 |
|
|
|
38 |
$userId = isLoggedIn();
|
|
|
39 |
$sourceList = array();
|
|
|
40 |
$userTokenCtrler = new UserTokenController();
|
|
|
41 |
|
|
|
42 |
// loop through the list
|
|
|
43 |
foreach ($this->sourceList as $name => $class ) {
|
|
|
44 |
|
|
|
45 |
// check connection status
|
|
|
46 |
$tokenInfo = $userTokenCtrler->getUserToken($userId, $name);
|
|
|
47 |
|
|
|
48 |
// if token exists
|
|
|
49 |
if (!empty($tokenInfo['id'])) {
|
|
|
50 |
$status = true;
|
|
|
51 |
} else {
|
|
|
52 |
$status = false;
|
|
|
53 |
|
|
|
54 |
if (SP_DEMO) {
|
|
|
55 |
$authUrlInfo = array('auth_url' => '#');
|
|
|
56 |
} else {
|
|
|
57 |
$sourceCtrler = new $class();
|
|
|
58 |
$authUrlInfo = $sourceCtrler->getAPIAuthUrl($userId);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$sourceList[] = array('name' => $name, 'status' => $status, 'auth_url_info' => $authUrlInfo);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
$this->set('list', $sourceList);
|
|
|
66 |
$this->render('myaccount/connection_list');
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/*
|
|
|
70 |
* process connection return action
|
|
|
71 |
*/
|
|
|
72 |
function processConnectionReturn($info) {
|
|
|
73 |
|
|
|
74 |
$userId = isLoggedIn();
|
|
|
75 |
$className = $this->sourceList[$info['category']];
|
|
|
76 |
|
|
|
77 |
// if class existing for process
|
|
|
78 |
if (!empty($className)) {
|
|
|
79 |
$sourceCtrler = new $className();
|
|
|
80 |
$ret = $sourceCtrler->createUserAuthToken($userId, $info['code']);
|
|
|
81 |
|
|
|
82 |
// if token created successfull
|
|
|
83 |
if ($ret['status']) {
|
|
|
84 |
$this->set('successMsg', "Successfully connected to " . $info['category']);
|
|
|
85 |
} else {
|
|
|
86 |
$this->set('errorMsg', $ret['msg']);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
} else {
|
|
|
90 |
$this->set('errorMsg', "Class not found to process requested action.");
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
$this->listConnections();
|
|
|
94 |
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/*
|
|
|
98 |
* process disconnection action
|
|
|
99 |
*/
|
|
|
100 |
function processDisconnection($info) {
|
|
|
101 |
$userId = isLoggedIn();$className = $this->sourceList[$info['category']];
|
|
|
102 |
|
|
|
103 |
// if class existing for process
|
|
|
104 |
if (class_exists($className)) {
|
|
|
105 |
$sourceCtrler = new $className();
|
|
|
106 |
$ret = $sourceCtrler->removeUserAuthToken($userId);
|
|
|
107 |
$this->set('successMsg', "Successfully disconnected from " . $info['category']);
|
|
|
108 |
} else {
|
|
|
109 |
$this->set('errorMsg', "Class not found to process requested action.");
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
$this->listConnections();
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
?>
|