-
Notifications
You must be signed in to change notification settings - Fork 2
/
exchange-data.php
318 lines (284 loc) · 13.2 KB
/
exchange-data.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
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* wgBacklinks module for xoops
*
* @copyright module for xoops
* @license GPL 2.0 or later
* @package wgbacklinks
* @author Goffy - Wedega.com - Email:<[email protected]> - Website:<https://wedega.com>
*/
use Xmf\Request;
include __DIR__ . '/header.php';
$ptype = Request::getString('ptype');
// check provider key against providers website
// called by: admin/provider.php (class/provider.php) from client website
if ($ptype == 'check-provider-key') {
$provider_key = Request::getString('provider_key');
if ($provider_key == $helper->getConfig('wgbacklinks_modkey')) {
echo 'valid-provider-key';
} else {
echo 'invalid-provider-key';
}
}
// check client key against clients website
// called by: admin/client.php (class/client.php) from provider website
if ($ptype == 'check-client-key') {
$client_key = Request::getString('client_key');
if ($client_key == $helper->getConfig('wgbacklinks_modkey')) {
echo 'valid-client-key';
} else {
echo 'invalid-client-key';
}
}
// check provider registration at the client and add new, if not existing
// called by: clients.php from provider website
if ($ptype == 'add-provider') {
$client_key = Request::getString('client_key');
$client_url = Request::getString('client_url');
$provider_key = Request::getString('provider_key');
if ($client_key == $helper->getConfig('wgbacklinks_modkey')) {
$crit_provider = new \CriteriaCompo();
$crit_provider->add(new \Criteria('provider_key', $provider_key));
$providersCount = $providersHandler->getCount($crit_provider);
if ($providersCount == 0) {
// add this provider to table provider
$provider_name = Request::getString('provider_name');
$provider_url = Request::getString('provider_url');
$provider_submitter = Request::getString('provider_submitter');
$providersObj = $providersHandler->create();
$providersObj->setVar('provider_name', $provider_name);
$providersObj->setVar('provider_url', $provider_url);
$providersObj->setVar('provider_key', $provider_key);
$providersObj->setVar('provider_submitter', $provider_submitter);
$providersObj->setVar('provider_date_created', \time());
// Insert Data
if ($providersHandler->insert($providersObj)) {
echo 'success-' . $ptype;
} else {
$result_text = \str_replace('%p', $provider_name, \_MA_WGBACKLINKS_EXCHANGE_ERR_ADD_PROVIDER);
$result_text = \str_replace('%c', $client_url, $result_text);
$result_text = \str_replace('%e', $providersObj->getHtmlErrors(), $result_text);
}
} else {
echo $ptype . ':provider-exists';
}
} else {
echo \_MA_WGBACKLINKS_EXCHANGE_ERR_INVALID_CKEY;
}
}
// check provider registration at the client website and delete, if existing
// called by: admin/clients.php (class/clients.php) from provider website
if ($ptype == 'delete-provider') {
$client_key = Request::getString('client_key');
$client_url = Request::getString('client_url');
$provider_key = Request::getString('provider_key');
$provider_name = Request::getString('provider_name');
if ($client_key == $helper->getConfig('wgbacklinks_modkey')) {
$crit_provider = new \CriteriaCompo();
$crit_provider->add(new \Criteria('provider_key', $provider_key));
$providersCount = $providersHandler->getCount($crit_provider);
if ($providersCount > 0) {
// delete this provider from table providers
$providerId = 0;
$providersAll = $providersHandler->getall($crit_provider);
foreach (\array_keys($providersAll) as $i) {
$providerId = $providersAll[$i]->getVar('provider_id');
}
if ($providerId > 0) {
$providersObj = $providersHandler->get($providerId);
if ($providersHandler->delete($providersObj)) {
echo 'success-' . $ptype;
} else {
$result_text = \str_replace('%p', $provider_name, \_MA_WGBACKLINKS_EXCHANGE_ERR_DEL_PROVIDER);
$result_text = \str_replace('%c', $client_url, $result_text);
$result_text = \str_replace('%e', $providersObj->getHtmlErrors(), $result_text);
echo $result_text;
}
} else {
echo 'invalid criteria for get provider';
}
} else {
echo $ptype . ':provider-not-exists';
}
} else {
echo \_MA_WGBACKLINKS_EXCHANGE_ERR_INVALID_CKEY;
}
}
// check client registration at the provider website and add new, if not existing
// called by: admin/provider.php (class/provider.php) from client website
if ($ptype == 'add-client') {
$provider_url = Request::getString('provider_url');
$provider_key = Request::getString('provider_key');
$client_url = Request::getString('client_url');
$client_key = Request::getString('client_key');
$client_addsite = Request::getString('client_addsite');
$client_sitename = Request::getString('client_sitename');
$client_slogan = Request::getString('client_slogan');
$pcsubmitter = Request::getString('pcsubmitter');
if ($provider_key == $helper->getConfig('wgbacklinks_modkey')) {
$crit_client = new \CriteriaCompo();
$crit_client->add(new \Criteria('client_key', $client_key));
$clientsCount = $clientsHandler->getCount($crit_client);
if ($clientsCount == 0) {
// add this client to table client
$clientsObj = $clientsHandler->create();
// Set Vars
$clientsObj->setVar('client_url', $client_url);
$clientsObj->setVar('client_key', $client_key);
$clientsObj->setVar('client_submitter', $pcsubmitter);
$clientsObj->setVar('client_date_created', \time());
// Insert Data
if ($clientsHandler->insert($clientsObj)) {
if ($client_addsite > 0) {
$sitesObj = $sitesHandler->create();
// Set Vars
$sitesObj->setVar('site_name', $client_sitename);
$sitesObj->setVar('site_descr', $client_slogan);
$sitesObj->setVar('site_url', $client_url);
$sitesObj->setVar('site_uniqueid', md5(\substr(str_shuffle("!$%&/=?_-;:,.0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 50)));
$sitesObj->setVar('site_active', '1');
$sitesObj->setVar('site_shared', '0');
$sitesObj->setVar('site_submitter', $pcsubmitter);
$sitesObj->setVar('site_date_created', \time());
// Insert Data
if ($sitesHandler->insert($sitesObj)) {
echo 'success-' . $ptype;
} else {
$result_text = \str_replace('%p', $provider_url, \_MA_WGBACKLINKS_EXCHANGE_ERR_PROV_ADD_SITE);
$result_text = \str_replace('%c', $client_url, $result_text);
$result_text = \str_replace('%e', $clientsObj->getHtmlErrors(), $result_text);
echo $result_text;
}
}
} else {
$result_text = \str_replace('%p', $provider_url, \_MA_WGBACKLINKS_EXCHANGE_ERR_ADD_CLIENT);
$result_text = \str_replace('%c', $client_url, $result_text);
$result_text = \str_replace('%e', $clientsObj->getHtmlErrors(), $result_text);
echo $result_text;
}
} else {
echo $ptype . ':client-exists';
}
} else {
echo \_MA_WGBACKLINKS_EXCHANGE_ERR_INVALID_PKEY;
}
}
// check client registration at the provider and delete, if existing
// called by: admin/provider.php (class/provider.php) from client website
if ($ptype == 'delete-client') {
$client_key = Request::getString('client_key');
$client_url = Request::getString('client_url');
$provider_key = Request::getString('provider_key');
$provider_name = Request::getString('provider_name');
if ($provider_key == $helper->getConfig('wgbacklinks_modkey')) {
$crit_client = new \CriteriaCompo();
$crit_client->add(new \Criteria('client_key', $client_key));
$clientsCount = $clientsHandler->getCount($crit_client);
if ($clientsCount > 0) {
// delete this client from table clients
$clientId = 0;
$clientsAll = $clientsHandler->getall($crit_client);
foreach (\array_keys($clientsAll) as $i) {
$clientId = $clientsAll[$i]->getVar('client_id');
}
if ($clientId > 0) {
$clientsObj = $clientsHandler->get($clientId);
if ($clientsHandler->delete($clientsObj)) {
echo 'success-' . $ptype;
} else {
$result_text = \str_replace('%p', $provider_name, \_MA_WGBACKLINKS_EXCHANGE_ERR_DEL_CLIENT);
$result_text = \str_replace('%c', $client_url, $result_text);
$result_text = \str_replace('%e', $clientsObj->getHtmlErrors(), $result_text);
echo $result_text;
}
} else {
echo 'invalid criteria for get client';
}
} else {
echo $ptype . ':client-not-exists';
}
} else {
echo \_MA_WGBACKLINKS_EXCHANGE_ERR_INVALID_PKEY;
}
}
// register sites to client database:
// if site exists, data will updated
// if site doesn't exist, site will be added
// called by: admin/sites.php (class/sites.php) from provider website
if ($ptype == 'share-site') {
// check first clientkey
$client_key = Request::getString('client_key');
$client_url = Request::getString('client_url');
if ($client_key == $helper->getConfig('wgbacklinks_modkey')) {
// valid key given by provider
$psite_name = Request::getString('site_name');
$psite_descr = Request::getString('site_descr');
$psite_url = Request::getString('site_url');
$psite_uniqueid = Request::getString('site_uniqueid');
$psite_active = Request::getString('site_active');
$psite_submitter = Request::getString('site_submitter');
$site_id = 0;
$crit_site = new \CriteriaCompo();
$crit_site->add(new \Criteria('site_uniqueid', $psite_uniqueid));
$sitesAll = $sitesHandler->getall($crit_site);
foreach (\array_keys($sitesAll) as $i) {
$site_id = $sitesAll[$i]->getVar('site_id');
unset($site);
}
if ($site_id > 0) {
// existing site, update
$result = 'updated ' . $client_key;
$sitesObj = $sitesHandler->get($site_id);
} else {
// new site
if ($psite_active > 0) {
// site is active, add new site
$result = 'added ' . $client_key;
$sitesObj = $sitesHandler->create();
}
}
if ($psite_active == 0) {
// site is not active
// delete, if exisiting
if ($site_id > 0) {
if ($sitesHandler->delete($sitesObj)) {
$result = 'deleted ' . $client_key;
} else {
$result = \str_replace('%s', $psite_name, \_MA_WGBACKLINKS_EXCHANGE_ERR_DELETE_SITE);
$result = \str_replace('%c', $client_url, $result);
}
} else {
$result = 'skipped ' . $client_key;
}
echo $result;
} else {
// add or update existing site
// Set Vars
$sitesObj->setVar('site_name', $psite_name);
$sitesObj->setVar('site_url', $psite_url);
$sitesObj->setVar('site_uniqueid', $psite_uniqueid);
$sitesObj->setVar('site_submitter', $psite_submitter);
$sitesObj->setVar('site_date_created', \time());
$sitesObj->setVar('site_active', $psite_active);
$sitesObj->setVar('site_descr', $psite_descr);
// Insert Data
if ($sitesHandler->insert($sitesObj)) {
echo $result;
} else {
$result_text = \str_replace('%s', $psite_name, \_MA_WGBACKLINKS_EXCHANGE_ERR_ADD_SITE);
echo \str_replace('%c', $client_url, $result_text);
}
}
} else {
echo \_MA_WGBACKLINKS_EXCHANGE_ERR_INVALID_CKEY;
}
}