faceBot /plugins/fBGifts/includes/fBGifts.class.php

Language PHP Lines 512
MD5 Hash e607bfa95111b9c9cfed911e72af46bb
Repository https://github.com/RadicalLinux/faceBot.git View Raw File View Project SPDX
  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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
class fBGifts
{
	var $userId, $_fBGiftsDBM, $error, $settings, $cookie;

	private function _fBGifts_checkDB()
	{
		if(!empty($this->error))
		{
			AddLog2($this->error);
			return;
		}
		$q = @$this->_fBGiftsDBM->query('SELECT * FROM settings LIMIT 1');
		if($q === false)
		{
			AddLog2('Creating Settings Table');
			$fvSQL = 'CREATE TABLE
						settings (
						settings_name CHAR(250) PRIMARY KEY,
						settings_value TEXT
			)';
			$this->_fBGiftsDBM->queryExec($fvSQL);
			$fvSQL = "INSERT INTO settings(settings_name,settings_value) values('userid','" . $this->userId . "')";
			$this->_fBGiftsDBM->queryExec($fvSQL);

		}
		$q = @$this->_fBGiftsDBM->query('SELECT * FROM knownapps LIMIT 1');
		if($q === false)
		{
			AddLog2('Creating knownapps Table');
			$fvSQL = 'CREATE TABLE
						knownapps (
						knownapps_appid TEXT PRIMARY KEY,
						knownapps_name TEXT,
						knownapps_canaccept INTEGER DEFAULT 1,
						knownapps_canreturn INTEGER DEFAULT 0
			)';
			$this->_fBGiftsDBM->queryExec($fvSQL);

		}
		$q = @$this->_fBGiftsDBM->query('SELECT * FROM giftlog LIMIT 1');
		if($q === false)
		{
			AddLog2('Creating giftlog Table');
			$fvSQL = 'CREATE TABLE
						giftlog (
						giftlog_id INTEGER PRIMARY KEY,
						giftlog_timestamp NUMERIC DEFAULT 0,
						giftlog_appname TEXT,
						giftlog_text TEXT,
						giftlog_link TEXT,
						giftlog_accept INTEGER DEFAULT 0,
						giftlog_return INTEGER DEFAULT 0
			)';
			$this->_fBGiftsDBM->queryExec($fvSQL);
		}

	}

	//Function fBGifts class initializer
	function fBGifts($inittype = '')
	{
		$this->userId = $_SESSION['userId'];

		if(!is_numeric($this->userId))
		{
			$this->error = "faceBot Not Initialized/User Unknown";
			return;
		}

		//Open Databases
		$this->_fBGiftsDBM = new SQLiteDatabase(fBGifts_Path . PluginF(fBGifts_Main));
		if(!$this->_fBGiftsDBM)
		{
			$this->error = 'fBGifts - Database Error';
			return;
		}

		//Get Settings
		$this->settings = $this->fBGetSettings();

		//Load the world from Z*
		if($this->settings === false)
		{
			$this->_fBGifts_checkDB();//Database doesn't exist, create
		}
		$this->_fBUpdateSettings();//Insert initial settings
		if ($inittype != 'formload')
		{
			$this->_fBGetCookie();
			AddLog2('fBGifts: facebook Cookie Location: ' . $this->cookie);
			$this->_acceptGifts();
		}
	}

	function fBGetSettings()
	{
		$fvSQL = 'SELECT * FROM settings';
		@$q = $this->_fBGiftsDBM->query($fvSQL);
		if($q !== false)
		{
			$results = $q->fetchAll(SQLITE_ASSOC);
			foreach($results as $item)
			{
				$newresults[$item['settings_name']] = $item['settings_value'];
			}
			return $newresults;
		}
		return false;
	}

	function fBGetKnownApps()
	{
		$fvSQL = 'SELECT * FROM knownapps ORDER BY knownapps_name';
		$q = $this->_fBGiftsDBM->query($fvSQL);
		if($q !== false)
		{
			$results = $q->fetchAll(SQLITE_ASSOC);
			return $results;
		}
		return false;
	}

	function fBGetLogs()
	{
		$fvSQL = 'SELECT * FROM giftlog ORDER BY giftlog_timestamp DESC';
		$q = $this->_fBGiftsDBM->query($fvSQL);
		if($q !== false)
		{
			$results = $q->fetchAll(SQLITE_ASSOC);
			return $results;
		}
		return false;
	}

	function fBDeleteLog()
	{
		$fvSQL = 'DELETE FROM giftlog';
		$q = $this->_fBGiftsDBM->query($fvSQL);
		return;
	}

	function fnMakeTime($ctime)
	{
		$days = $ctime / 86400;
		if ($days > 1)
		{
			$days = intval($days);
			$ctime = $ctime - ($days * 86400);
			$timestr = $days . ' days ';
		}
		$hours = $ctime / 3600;
		if ($hours > 1)
		{
			$hours = intval($hours);
			$ctime = $ctime - ($hours * 3600);
			$timestr .= $hours . ' hrs ';
		}
		$minutes = $ctime / 60;
		if ($minutes > 1)
		{
			$minutes = intval($minutes);
			$timestr .= $minutes . ' min';
		}
		return $timestr;
	}

	function fBDoSettings($postvars)
	{
		unset($postvars['submit']);
		$giftopts = serialize($postvars);
		$fvSQL = "INSERT OR REPLACE INTO settings(settings_name,settings_value) values('giftopts','$giftopts');";
		$this->_fBGiftsDBM->queryExec($fvSQL);
	}

	private function _fBUpdateSettings()
	{
		$fvSQL = "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('102452128776','FarmVille', '1', '1'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('101539264719','Café World', '1', '0'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('201278444497','FrontierVille', '1', '0'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('234860566661','Treasure Isle', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('10979261223','Mafia Wars Game', '1', '0'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('46755028429','Castle Age', '1', '0'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('271022655694','Haven', '1', '0'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('26947445683','Country Life', '1', '1'); ";																			
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('167746316127','Zoo World', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('56748925791','Farm Town', '1', '0'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('2389801228','Texas HoldEm Poker', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('151044809337','FishVille', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('25287267406','Vampire Wars', '1', '0'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('342684208824','Backyard Monsters', '1', '0'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('163965423072','Social City', '1', '0'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('8630423715','Sorority Life', '1', '0'); ";		
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('43016202276','Restaurant City', '1', '1'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('165747315075','Country Story', '1', '1'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('121763384533823','Country Life (lite)', '1', '1'); ";		
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('163576248142','PetVille', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('2405948328','Likeness', '1', '1'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('14852940614','Birthday cards', '1', '1'); ";	
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('2339854854','Horoscopes', '1', '1'); ";
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('2345673396','Hug Me', '1', '1'); ";		
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('2601240224','RockYou Live', '1', '1'); ";			
		$fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
						"values('156383461049284','Farmville-Chinese', '1', '1'); ";	
		
		$this->_fBGiftsDBM->queryExec($fvSQL);

		//$fvSQL = "INSERT OR REPLACE INTO settings(settings_name,settings_value) values('higherLevelStep','" . $farm3 . "')";
		//$this->_fBGiftsDBM->queryExec($fvSQL);

	}

	private function _fBGetCookie()
	{

		$newcookiestr = trim(file_get_contents($_SESSION['base_path'] .  $_SESSION['userId'] . '_cookie.txt'));
		return $newcookiestr;
	}

	private function _getGifts()
	{
		$response = $this->_fBGiftsGet("http://apps.facebook.com/reqs.php");
		//AddLog2($response);
		if (empty($response)) { return; }
		preg_match_all('/action="\/ajax\/reqs\.php" method="post".*?<\/form>/ims', $response, $result);
		$giftRequests = array();
		foreach($result[0] as $key => $form) {
			preg_match_all('/name="([^"]*)" value="([^"]*)"/ims', $form, $nameVals);
			preg_match_all('/<input[^>]*value="([^\"]*)"[^>]*name="actions\[([^>]*)][^>]*>?/ims', $form, $actions);
			preg_match_all('/<a href="http:\/\/apps\.facebook\.com\/.*?>(.*?)<\/a>/ims', $form, $appNameVals);
			preg_match_all('/name="fb_dtsg" value="([^"]*)"/ims', $form, $DTSGVals);
			preg_match_all('/<span fb_protected="true" class="fb_protected_wrapper">(.*?)<\/span>/ims', $form, $giftText);
			@$giftInfo = trim(strip_tags($giftText[1][0]));
			$appId = '';
			$postVars = array();
			for($i = 0; $i < count($nameVals[1]); $i++) {
				if($nameVals[1][$i] == 'params[app_id]') $appId = $nameVals[2][$i];
				$postVars[$nameVals[1][$i]] = urlencode(html_entity_decode($nameVals[2][$i], ENT_QUOTES, 'UTF-8'));
			}
			//if($vAppId<>'102452128776') continue;
			$actionName = '';
			$actionUrl = '';
			for($i = 0; $i < count($actions[1]); $i++) {
				if($actions[2][$i]<>'reject') {
					$actionName = $actions[1][$i];
					$actionUrl = html_entity_decode($actions[2][$i]);
					$postVars['actions['.urlencode(html_entity_decode($actions[2][$i], ENT_QUOTES, 'UTF-8')).']'] = str_replace('+', '%20', urlencode($actions[1][$i]));
					break;
				}
			}
			$appName = '';
			if(count($appNameVals) > 0) {
				@$appName = $appNameVals[1][0];
			}
			if(count($DTSGVals) > 0) {
				$DTSG = $DTSGVals[1][0];
			}
			if (!empty($appName)) {
				$postVars['post_form_id_source'] = 'AsyncRequest';
				$giftRequests[$key] = array();
				$giftRequests[$key]['name'] = utf8_decode($appName);
				$giftRequests[$key]['app_id'] = $appId;
				$giftRequests[$key]['app_name'] = utf8_decode($appName);
				$giftRequests[$key]['action_name'] = $actionName;
				$giftRequests[$key]['gift_text'] = $giftInfo;
				$giftRequests[$key]['action_url'] = $actionUrl;
				$giftRequests[$key]['post_data'] = $postVars;
				$giftRequests[$key]['fb_dtsg'] = $DTSG;
				$appName = utf8_decode($appName);
				if (!empty($giftRequests[$key]['app_id']) && !empty($giftRequests[$key]['app_name']))
				{
					$fvSQL = "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept) values('$appId','$appName',1)";
					$this->_fBGiftsDBM->queryExec($fvSQL);
				}
			}
		}
		return $giftRequests;
	}

	private function _fBGiftsPost($url, $postData='')
	{
		$fields_string = '';
		if (is_array($postData)) {
			foreach($postData as $key=>$value) {
				if ($value != null) {
					@$fields_string .= $key.'='.$value.'&';
				} else {
					@$fields_string .= $key.'&';
				}
			}
			//AddLog2($url);
			rtrim($fields_string,'&');
			//AddLog2($fields_string);
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, count($postData));
			curl_setopt($ch, CURLOPT_TIMEOUT, 45);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
			curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)');
			curl_setopt($ch, CURLOPT_COOKIE, $this->_fBGetCookie());
			curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-US', 'Pragma: no-cache'));
			if ($_SESSION['use_proxy']) {
				curl_setopt($ch, CURLOPT_PROXY, trim($_SESSION['proxy_settings'][0]));
				curl_setopt($ch, CURLOPT_PROXYPORT, intval($_SESSION['proxy_settings'][1]));
				if (isset($_SESSION['proxy_settings'][2]) && isset($_SESSION['proxy_settings'][3])) { // is set proxy user and password
					$authorization = trim($_SESSION['proxy_settings'][2]) . ':' . trim($_SESSION['proxy_settings'][3]);
					curl_setopt($ch, CURLOPT_PROXYUSERPWD, $authorization);
					curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
				}
			}
			$response = curl_exec($ch);
			$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
			if($httpCode == 404) {
				AddLog2("fBGifts: Error 404/Page Not Found");
				return;
			}
			if($httpCode == 500) {
				AddLog2("fBGifts: Error 500/Internal Server Error");
				return;
			}
			if(empty($response)) {
				AddLog2("fBGifts: Empty Response Returned");
				return;
			}
			curl_close ($ch);
			return $response;
		}
		return;
	}

	private function _fBGiftsGet($url = '')
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 45);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)');
		curl_setopt($ch, CURLOPT_COOKIE, $this->_fBGetCookie());
		curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-US', 'Pragma: no-cache'));
		if ($_SESSION['use_proxy']) {
			curl_setopt($ch, CURLOPT_PROXY, trim($_SESSION['proxy_settings'][0]));
			curl_setopt($ch, CURLOPT_PROXYPORT, intval($_SESSION['proxy_settings'][1]));
			if (isset($_SESSION['proxy_settings'][2]) && isset($_SESSION['proxy_settings'][3])) { // is set proxy user and password
				$authorization = trim($_SESSION['proxy_settings'][2]) . ':' . trim($_SESSION['proxy_settings'][3]);
				curl_setopt($ch, CURLOPT_PROXYUSERPWD, $authorization);
				curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
			}
		}
		$response = curl_exec($ch);
		$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		if($httpCode == 404) {
			AddLog2("fBGifts: Error 404/Page Not Found");
			return;
		}
		if($httpCode == 500) {
			AddLog2("fBGifts: Error 500/Internal Server Error");
			return;
		}
		if(empty($response)) {
			AddLog2("fBGifts: Empty Response Returned");
			return;
		}
		curl_close ($ch);
		return $response;
	}


	private function _acceptGifts()
	{

		$giftReqs = $this->_getGifts();
		$gBCount = count(unserialize(fBGetDataStore('ingiftbox')));
		$cBCount = count(unserialize(fBGetDataStore('inconbox')));
		AddLog2('fBGifts: '.count($giftReqs).' Gifts On Gift Page');
		$giftSettings = unserialize($this->settings['giftopts']);
		if(is_array($giftReqs)) {
			if(count($giftReqs)>0) {
				$count=0;
				foreach($giftReqs as $key => $data) {
					if (!isset($giftSettings[$data['app_id'] . '_accept'])) continue;
					if ((($gBCount + $cBCount) >= 500) && $data['app_id'] == '102452128776')
					{
						AddLog2('fBGifts: Giftbox or Consumable Box Full, Skipping Farmville Gift');
						continue;
					} elseif ($data['app_id'] == '102452128776') { $gBCount++; }
					$count++;
					$accepted = 0;
					$returned = 0;
					//Remove Link From Gifts Page
					
					$discard = $this->_fBGiftsPost("http://www.facebook.com/ajax/reqs.php?__a=1", $data['post_data']);
					//file_put_contents('debug/data.txt', print_r($data,true), FILE_APPEND);
					//Submit the link to goto the page
					$giftAction = $this->_fBGiftsGet($data['action_url']);
					//file_put_contents('debug/data.txt', $giftAction, FILE_APPEND);
					if (!empty($giftAction)) {
						$accepted = 1;
						AddLog2("[$count] fBGifts: Accept Gift From " . $data['app_name'] . ' - Success');
					} else {
						$accepted = 9;
						AddLog2("[$count] fBGifts: Accept Gift From " . $data['app_name'] . ' - Failed');
					}
					if (isset($giftSettings[$data['app_id'] . '_return']) && $accepted == 1) {
						preg_match_all('/class="fb_protected_wrapper"><form(.*?)<\/div>/ims', $giftAction, $forms);
						foreach($forms[0] as $key => $form) {
							if(stripos($form, "thank you") !== false || stripos($form, 'send to') !== false || stripos($form, 'é€') !== false) {
								$postdata = array();
								$arr1 = '';
								$arr2 = '';
								preg_match_all('/.*action="([^"]*)".*/ims', $form, $acts);
								preg_match_all('/.*giftRecipient=([^&]*).*type="([^"]*)".*content="([^"]*)".*id="([^"]*)".*post_form_id=([^&]*).*/ims', $form, $fields);
								preg_match('/content="([^"]*)"/sim', $form, $content);
								//AddLog2(print_r($content,true));
								$form = html_entity_decode($form);
								preg_match_all('/PlatformInvite.*\{(.*)\}/sim', $form, $newfields);
								$newdata = str_replace('"', '', $newfields[1][0]);
								$arr1 = explode(',', $newdata);
								foreach ($arr1 as $tmpdata)
								{
									$tmp = explode(':', $tmpdata);
									$arr2[$tmp[0]] = $tmp[1];
								}
								$postdata['app_id'] = $data['app_id'];
								$postdata['to_ids[0]'] = $arr2['prefill'];
								$postdata['request_type'] = urlencode($arr2['request_type']);
								$postdata['invite'] = $arr2['invite'];
								$postdata['content'] = urlencode($content[1]);
								$postdata['preview'] = 'true';
								$postdata['is_multi'] = $arr2['is_multi'];
								$postdata['is_in_canvas'] = $arr2['is_in_canvas'];
								$postdata['form_id'] = $arr2['request_form'];
								$postdata['prefill'] = 'true';
								$postdata['message'] = '';
								$postdata['donot_send'] = 'false';
								$postdata['include_ci'] = $arr2['include_ci'];
								$postdata['__d'] = 1;
								$postdata['post_form_id'] = $fields[5][0];
								$postdata['fb_dtsg'] = $data['fb_dtsg'];
								$postdata['lsd'] = null;
								$postdata['post_form_id_source'] = 'AsyncRequest';
								$discard = $this->_fBGiftsPost("http://apps.facebook.com/fbml/ajax/prompt_send.php?__a=1", $postdata);
								//file_put_contents('debug/discard.txt', $discard, FILE_APPEND);
								//unset($postdata['request_type']);
								//$postdata['&request_type'] = urlencode($arr2['request_type']);
								$postdata['preview'] = 'false';
								$retGift = $this->_fBGiftsPost("http://apps.facebook.com/fbml/ajax/prompt_send.php?__a=1", $postdata);
								//AddLog2($acts[1][0]);
								$retGift2 = $this->_fBGiftsPost(html_entity_decode($acts[1][0]), array());
								if (stripos(strip_tags($retGift),'"error":0')) {
									$returned = 1;
									AddLog2("[$count] fBGifts: Returned Gift From " . $data['app_name'] . ' - Success');
								} else {
									$returned = 9;
									AddLog2("[$count] fBGifts: Returned Gift From " . $data['app_name'] . ' - Failed');
								}
								//file_put_contents('debug/postdata.txt', print_r($postdata,true), FILE_APPEND);
								//file_put_contents('debug/formdata.txt', print_r($form,true), FILE_APPEND);
								//file_put_contents('debug/giftaction.txt', $giftAction, FILE_APPEND);
								//file_put_contents('debug/returngift.txt', $retGift, FILE_APPEND);
								//file_put_contents('debug/returngift2.txt', $retGift2, FILE_APPEND);
								//sleep(500);
								break;
							}
						}
					}
					$data['gift_text'] = str_replace("'", "''", @$data['gift_text']);
					$fvSQL = "INSERT INTO giftlog(giftlog_timestamp, giftlog_appname, giftlog_text, giftlog_link, giftlog_accept, giftlog_return) " .
											"values('" . time() . "','" . $data['app_name'] . "','" . $data['gift_text'] . "','" . $data['action_url'] . "','$accepted', '$returned')";
					$this->_fBGiftsDBM->queryExec($fvSQL, $error);
					if (!empty($error)) {
						AddLog2 ($error . " " . $fvSQL);
					}
				}
			}
		}

	}
}

?>
Back to Top