PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/RadicalLinux/faceBot
PHP | 512 lines | 459 code | 28 blank | 25 comment | 63 complexity | 19605c1e7cf25e6d8e0aeef228d0deca MD5 | raw file
  1. <?php
  2. class fBGifts
  3. {
  4. var $userId, $_fBGiftsDBM, $error, $settings, $cookie;
  5. private function _fBGifts_checkDB()
  6. {
  7. if(!empty($this->error))
  8. {
  9. AddLog2($this->error);
  10. return;
  11. }
  12. $q = @$this->_fBGiftsDBM->query('SELECT * FROM settings LIMIT 1');
  13. if($q === false)
  14. {
  15. AddLog2('Creating Settings Table');
  16. $fvSQL = 'CREATE TABLE
  17. settings (
  18. settings_name CHAR(250) PRIMARY KEY,
  19. settings_value TEXT
  20. )';
  21. $this->_fBGiftsDBM->queryExec($fvSQL);
  22. $fvSQL = "INSERT INTO settings(settings_name,settings_value) values('userid','" . $this->userId . "')";
  23. $this->_fBGiftsDBM->queryExec($fvSQL);
  24. }
  25. $q = @$this->_fBGiftsDBM->query('SELECT * FROM knownapps LIMIT 1');
  26. if($q === false)
  27. {
  28. AddLog2('Creating knownapps Table');
  29. $fvSQL = 'CREATE TABLE
  30. knownapps (
  31. knownapps_appid TEXT PRIMARY KEY,
  32. knownapps_name TEXT,
  33. knownapps_canaccept INTEGER DEFAULT 1,
  34. knownapps_canreturn INTEGER DEFAULT 0
  35. )';
  36. $this->_fBGiftsDBM->queryExec($fvSQL);
  37. }
  38. $q = @$this->_fBGiftsDBM->query('SELECT * FROM giftlog LIMIT 1');
  39. if($q === false)
  40. {
  41. AddLog2('Creating giftlog Table');
  42. $fvSQL = 'CREATE TABLE
  43. giftlog (
  44. giftlog_id INTEGER PRIMARY KEY,
  45. giftlog_timestamp NUMERIC DEFAULT 0,
  46. giftlog_appname TEXT,
  47. giftlog_text TEXT,
  48. giftlog_link TEXT,
  49. giftlog_accept INTEGER DEFAULT 0,
  50. giftlog_return INTEGER DEFAULT 0
  51. )';
  52. $this->_fBGiftsDBM->queryExec($fvSQL);
  53. }
  54. }
  55. //Function fBGifts class initializer
  56. function fBGifts($inittype = '')
  57. {
  58. $this->userId = $_SESSION['userId'];
  59. if(!is_numeric($this->userId))
  60. {
  61. $this->error = "faceBot Not Initialized/User Unknown";
  62. return;
  63. }
  64. //Open Databases
  65. $this->_fBGiftsDBM = new SQLiteDatabase(fBGifts_Path . PluginF(fBGifts_Main));
  66. if(!$this->_fBGiftsDBM)
  67. {
  68. $this->error = 'fBGifts - Database Error';
  69. return;
  70. }
  71. //Get Settings
  72. $this->settings = $this->fBGetSettings();
  73. //Load the world from Z*
  74. if($this->settings === false)
  75. {
  76. $this->_fBGifts_checkDB();//Database doesn't exist, create
  77. }
  78. $this->_fBUpdateSettings();//Insert initial settings
  79. if ($inittype != 'formload')
  80. {
  81. $this->_fBGetCookie();
  82. AddLog2('fBGifts: facebook Cookie Location: ' . $this->cookie);
  83. $this->_acceptGifts();
  84. }
  85. }
  86. function fBGetSettings()
  87. {
  88. $fvSQL = 'SELECT * FROM settings';
  89. @$q = $this->_fBGiftsDBM->query($fvSQL);
  90. if($q !== false)
  91. {
  92. $results = $q->fetchAll(SQLITE_ASSOC);
  93. foreach($results as $item)
  94. {
  95. $newresults[$item['settings_name']] = $item['settings_value'];
  96. }
  97. return $newresults;
  98. }
  99. return false;
  100. }
  101. function fBGetKnownApps()
  102. {
  103. $fvSQL = 'SELECT * FROM knownapps ORDER BY knownapps_name';
  104. $q = $this->_fBGiftsDBM->query($fvSQL);
  105. if($q !== false)
  106. {
  107. $results = $q->fetchAll(SQLITE_ASSOC);
  108. return $results;
  109. }
  110. return false;
  111. }
  112. function fBGetLogs()
  113. {
  114. $fvSQL = 'SELECT * FROM giftlog ORDER BY giftlog_timestamp DESC';
  115. $q = $this->_fBGiftsDBM->query($fvSQL);
  116. if($q !== false)
  117. {
  118. $results = $q->fetchAll(SQLITE_ASSOC);
  119. return $results;
  120. }
  121. return false;
  122. }
  123. function fBDeleteLog()
  124. {
  125. $fvSQL = 'DELETE FROM giftlog';
  126. $q = $this->_fBGiftsDBM->query($fvSQL);
  127. return;
  128. }
  129. function fnMakeTime($ctime)
  130. {
  131. $days = $ctime / 86400;
  132. if ($days > 1)
  133. {
  134. $days = intval($days);
  135. $ctime = $ctime - ($days * 86400);
  136. $timestr = $days . ' days ';
  137. }
  138. $hours = $ctime / 3600;
  139. if ($hours > 1)
  140. {
  141. $hours = intval($hours);
  142. $ctime = $ctime - ($hours * 3600);
  143. $timestr .= $hours . ' hrs ';
  144. }
  145. $minutes = $ctime / 60;
  146. if ($minutes > 1)
  147. {
  148. $minutes = intval($minutes);
  149. $timestr .= $minutes . ' min';
  150. }
  151. return $timestr;
  152. }
  153. function fBDoSettings($postvars)
  154. {
  155. unset($postvars['submit']);
  156. $giftopts = serialize($postvars);
  157. $fvSQL = "INSERT OR REPLACE INTO settings(settings_name,settings_value) values('giftopts','$giftopts');";
  158. $this->_fBGiftsDBM->queryExec($fvSQL);
  159. }
  160. private function _fBUpdateSettings()
  161. {
  162. $fvSQL = "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  163. "values('102452128776','FarmVille', '1', '1'); ";
  164. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  165. "values('101539264719','Café World', '1', '0'); ";
  166. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  167. "values('201278444497','FrontierVille', '1', '0'); ";
  168. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  169. "values('234860566661','Treasure Isle', '1', '1'); ";
  170. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  171. "values('10979261223','Mafia Wars Game', '1', '0'); ";
  172. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  173. "values('46755028429','Castle Age', '1', '0'); ";
  174. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  175. "values('271022655694','Haven', '1', '0'); ";
  176. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  177. "values('26947445683','Country Life', '1', '1'); ";
  178. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  179. "values('167746316127','Zoo World', '1', '1'); ";
  180. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  181. "values('56748925791','Farm Town', '1', '0'); ";
  182. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  183. "values('2389801228','Texas HoldEm Poker', '1', '1'); ";
  184. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  185. "values('151044809337','FishVille', '1', '1'); ";
  186. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  187. "values('25287267406','Vampire Wars', '1', '0'); ";
  188. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  189. "values('342684208824','Backyard Monsters', '1', '0'); ";
  190. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  191. "values('163965423072','Social City', '1', '0'); ";
  192. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  193. "values('8630423715','Sorority Life', '1', '0'); ";
  194. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  195. "values('43016202276','Restaurant City', '1', '1'); ";
  196. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  197. "values('165747315075','Country Story', '1', '1'); ";
  198. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  199. "values('121763384533823','Country Life (lite)', '1', '1'); ";
  200. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  201. "values('163576248142','PetVille', '1', '1'); ";
  202. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  203. "values('2405948328','Likeness', '1', '1'); ";
  204. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  205. "values('14852940614','Birthday cards', '1', '1'); ";
  206. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  207. "values('2339854854','Horoscopes', '1', '1'); ";
  208. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  209. "values('2345673396','Hug Me', '1', '1'); ";
  210. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  211. "values('2601240224','RockYou Live', '1', '1'); ";
  212. $fvSQL .= "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept, knownapps_canreturn) " .
  213. "values('156383461049284','Farmville-Chinese', '1', '1'); ";
  214. $this->_fBGiftsDBM->queryExec($fvSQL);
  215. //$fvSQL = "INSERT OR REPLACE INTO settings(settings_name,settings_value) values('higherLevelStep','" . $farm3 . "')";
  216. //$this->_fBGiftsDBM->queryExec($fvSQL);
  217. }
  218. private function _fBGetCookie()
  219. {
  220. $newcookiestr = trim(file_get_contents($_SESSION['base_path'] . $_SESSION['userId'] . '_cookie.txt'));
  221. return $newcookiestr;
  222. }
  223. private function _getGifts()
  224. {
  225. $response = $this->_fBGiftsGet("http://apps.facebook.com/reqs.php");
  226. //AddLog2($response);
  227. if (empty($response)) { return; }
  228. preg_match_all('/action="\/ajax\/reqs\.php" method="post".*?<\/form>/ims', $response, $result);
  229. $giftRequests = array();
  230. foreach($result[0] as $key => $form) {
  231. preg_match_all('/name="([^"]*)" value="([^"]*)"/ims', $form, $nameVals);
  232. preg_match_all('/<input[^>]*value="([^\"]*)"[^>]*name="actions\[([^>]*)][^>]*>?/ims', $form, $actions);
  233. preg_match_all('/<a href="http:\/\/apps\.facebook\.com\/.*?>(.*?)<\/a>/ims', $form, $appNameVals);
  234. preg_match_all('/name="fb_dtsg" value="([^"]*)"/ims', $form, $DTSGVals);
  235. preg_match_all('/<span fb_protected="true" class="fb_protected_wrapper">(.*?)<\/span>/ims', $form, $giftText);
  236. @$giftInfo = trim(strip_tags($giftText[1][0]));
  237. $appId = '';
  238. $postVars = array();
  239. for($i = 0; $i < count($nameVals[1]); $i++) {
  240. if($nameVals[1][$i] == 'params[app_id]') $appId = $nameVals[2][$i];
  241. $postVars[$nameVals[1][$i]] = urlencode(html_entity_decode($nameVals[2][$i], ENT_QUOTES, 'UTF-8'));
  242. }
  243. //if($vAppId<>'102452128776') continue;
  244. $actionName = '';
  245. $actionUrl = '';
  246. for($i = 0; $i < count($actions[1]); $i++) {
  247. if($actions[2][$i]<>'reject') {
  248. $actionName = $actions[1][$i];
  249. $actionUrl = html_entity_decode($actions[2][$i]);
  250. $postVars['actions['.urlencode(html_entity_decode($actions[2][$i], ENT_QUOTES, 'UTF-8')).']'] = str_replace('+', '%20', urlencode($actions[1][$i]));
  251. break;
  252. }
  253. }
  254. $appName = '';
  255. if(count($appNameVals) > 0) {
  256. @$appName = $appNameVals[1][0];
  257. }
  258. if(count($DTSGVals) > 0) {
  259. $DTSG = $DTSGVals[1][0];
  260. }
  261. if (!empty($appName)) {
  262. $postVars['post_form_id_source'] = 'AsyncRequest';
  263. $giftRequests[$key] = array();
  264. $giftRequests[$key]['name'] = utf8_decode($appName);
  265. $giftRequests[$key]['app_id'] = $appId;
  266. $giftRequests[$key]['app_name'] = utf8_decode($appName);
  267. $giftRequests[$key]['action_name'] = $actionName;
  268. $giftRequests[$key]['gift_text'] = $giftInfo;
  269. $giftRequests[$key]['action_url'] = $actionUrl;
  270. $giftRequests[$key]['post_data'] = $postVars;
  271. $giftRequests[$key]['fb_dtsg'] = $DTSG;
  272. $appName = utf8_decode($appName);
  273. if (!empty($giftRequests[$key]['app_id']) && !empty($giftRequests[$key]['app_name']))
  274. {
  275. $fvSQL = "INSERT OR IGNORE INTO knownapps(knownapps_appid, knownapps_name, knownapps_canaccept) values('$appId','$appName',1)";
  276. $this->_fBGiftsDBM->queryExec($fvSQL);
  277. }
  278. }
  279. }
  280. return $giftRequests;
  281. }
  282. private function _fBGiftsPost($url, $postData='')
  283. {
  284. $fields_string = '';
  285. if (is_array($postData)) {
  286. foreach($postData as $key=>$value) {
  287. if ($value != null) {
  288. @$fields_string .= $key.'='.$value.'&';
  289. } else {
  290. @$fields_string .= $key.'&';
  291. }
  292. }
  293. //AddLog2($url);
  294. rtrim($fields_string,'&');
  295. //AddLog2($fields_string);
  296. $ch = curl_init();
  297. curl_setopt($ch, CURLOPT_URL, $url);
  298. curl_setopt($ch, CURLOPT_HEADER, 0);
  299. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  300. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  301. curl_setopt($ch, CURLOPT_POST, count($postData));
  302. curl_setopt($ch, CURLOPT_TIMEOUT, 45);
  303. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  304. 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)');
  305. curl_setopt($ch, CURLOPT_COOKIE, $this->_fBGetCookie());
  306. curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
  307. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-US', 'Pragma: no-cache'));
  308. if ($_SESSION['use_proxy']) {
  309. curl_setopt($ch, CURLOPT_PROXY, trim($_SESSION['proxy_settings'][0]));
  310. curl_setopt($ch, CURLOPT_PROXYPORT, intval($_SESSION['proxy_settings'][1]));
  311. if (isset($_SESSION['proxy_settings'][2]) && isset($_SESSION['proxy_settings'][3])) { // is set proxy user and password
  312. $authorization = trim($_SESSION['proxy_settings'][2]) . ':' . trim($_SESSION['proxy_settings'][3]);
  313. curl_setopt($ch, CURLOPT_PROXYUSERPWD, $authorization);
  314. curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
  315. }
  316. }
  317. $response = curl_exec($ch);
  318. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  319. if($httpCode == 404) {
  320. AddLog2("fBGifts: Error 404/Page Not Found");
  321. return;
  322. }
  323. if($httpCode == 500) {
  324. AddLog2("fBGifts: Error 500/Internal Server Error");
  325. return;
  326. }
  327. if(empty($response)) {
  328. AddLog2("fBGifts: Empty Response Returned");
  329. return;
  330. }
  331. curl_close ($ch);
  332. return $response;
  333. }
  334. return;
  335. }
  336. private function _fBGiftsGet($url = '')
  337. {
  338. $ch = curl_init();
  339. curl_setopt($ch, CURLOPT_URL, $url);
  340. curl_setopt($ch, CURLOPT_HEADER, 0);
  341. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  342. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  343. curl_setopt($ch, CURLOPT_TIMEOUT, 45);
  344. 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)');
  345. curl_setopt($ch, CURLOPT_COOKIE, $this->_fBGetCookie());
  346. curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
  347. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-US', 'Pragma: no-cache'));
  348. if ($_SESSION['use_proxy']) {
  349. curl_setopt($ch, CURLOPT_PROXY, trim($_SESSION['proxy_settings'][0]));
  350. curl_setopt($ch, CURLOPT_PROXYPORT, intval($_SESSION['proxy_settings'][1]));
  351. if (isset($_SESSION['proxy_settings'][2]) && isset($_SESSION['proxy_settings'][3])) { // is set proxy user and password
  352. $authorization = trim($_SESSION['proxy_settings'][2]) . ':' . trim($_SESSION['proxy_settings'][3]);
  353. curl_setopt($ch, CURLOPT_PROXYUSERPWD, $authorization);
  354. curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
  355. }
  356. }
  357. $response = curl_exec($ch);
  358. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  359. if($httpCode == 404) {
  360. AddLog2("fBGifts: Error 404/Page Not Found");
  361. return;
  362. }
  363. if($httpCode == 500) {
  364. AddLog2("fBGifts: Error 500/Internal Server Error");
  365. return;
  366. }
  367. if(empty($response)) {
  368. AddLog2("fBGifts: Empty Response Returned");
  369. return;
  370. }
  371. curl_close ($ch);
  372. return $response;
  373. }
  374. private function _acceptGifts()
  375. {
  376. $giftReqs = $this->_getGifts();
  377. $gBCount = count(unserialize(fBGetDataStore('ingiftbox')));
  378. $cBCount = count(unserialize(fBGetDataStore('inconbox')));
  379. AddLog2('fBGifts: '.count($giftReqs).' Gifts On Gift Page');
  380. $giftSettings = unserialize($this->settings['giftopts']);
  381. if(is_array($giftReqs)) {
  382. if(count($giftReqs)>0) {
  383. $count=0;
  384. foreach($giftReqs as $key => $data) {
  385. if (!isset($giftSettings[$data['app_id'] . '_accept'])) continue;
  386. if ((($gBCount + $cBCount) >= 500) && $data['app_id'] == '102452128776')
  387. {
  388. AddLog2('fBGifts: Giftbox or Consumable Box Full, Skipping Farmville Gift');
  389. continue;
  390. } elseif ($data['app_id'] == '102452128776') { $gBCount++; }
  391. $count++;
  392. $accepted = 0;
  393. $returned = 0;
  394. //Remove Link From Gifts Page
  395. $discard = $this->_fBGiftsPost("http://www.facebook.com/ajax/reqs.php?__a=1", $data['post_data']);
  396. //file_put_contents('debug/data.txt', print_r($data,true), FILE_APPEND);
  397. //Submit the link to goto the page
  398. $giftAction = $this->_fBGiftsGet($data['action_url']);
  399. //file_put_contents('debug/data.txt', $giftAction, FILE_APPEND);
  400. if (!empty($giftAction)) {
  401. $accepted = 1;
  402. AddLog2("[$count] fBGifts: Accept Gift From " . $data['app_name'] . ' - Success');
  403. } else {
  404. $accepted = 9;
  405. AddLog2("[$count] fBGifts: Accept Gift From " . $data['app_name'] . ' - Failed');
  406. }
  407. if (isset($giftSettings[$data['app_id'] . '_return']) && $accepted == 1) {
  408. preg_match_all('/class="fb_protected_wrapper"><form(.*?)<\/div>/ims', $giftAction, $forms);
  409. foreach($forms[0] as $key => $form) {
  410. if(stripos($form, "thank you") !== false || stripos($form, 'send to') !== false || stripos($form, 'é€') !== false) {
  411. $postdata = array();
  412. $arr1 = '';
  413. $arr2 = '';
  414. preg_match_all('/.*action="([^"]*)".*/ims', $form, $acts);
  415. preg_match_all('/.*giftRecipient=([^&]*).*type="([^"]*)".*content="([^"]*)".*id="([^"]*)".*post_form_id=([^&]*).*/ims', $form, $fields);
  416. preg_match('/content="([^"]*)"/sim', $form, $content);
  417. //AddLog2(print_r($content,true));
  418. $form = html_entity_decode($form);
  419. preg_match_all('/PlatformInvite.*\{(.*)\}/sim', $form, $newfields);
  420. $newdata = str_replace('"', '', $newfields[1][0]);
  421. $arr1 = explode(',', $newdata);
  422. foreach ($arr1 as $tmpdata)
  423. {
  424. $tmp = explode(':', $tmpdata);
  425. $arr2[$tmp[0]] = $tmp[1];
  426. }
  427. $postdata['app_id'] = $data['app_id'];
  428. $postdata['to_ids[0]'] = $arr2['prefill'];
  429. $postdata['request_type'] = urlencode($arr2['request_type']);
  430. $postdata['invite'] = $arr2['invite'];
  431. $postdata['content'] = urlencode($content[1]);
  432. $postdata['preview'] = 'true';
  433. $postdata['is_multi'] = $arr2['is_multi'];
  434. $postdata['is_in_canvas'] = $arr2['is_in_canvas'];
  435. $postdata['form_id'] = $arr2['request_form'];
  436. $postdata['prefill'] = 'true';
  437. $postdata['message'] = '';
  438. $postdata['donot_send'] = 'false';
  439. $postdata['include_ci'] = $arr2['include_ci'];
  440. $postdata['__d'] = 1;
  441. $postdata['post_form_id'] = $fields[5][0];
  442. $postdata['fb_dtsg'] = $data['fb_dtsg'];
  443. $postdata['lsd'] = null;
  444. $postdata['post_form_id_source'] = 'AsyncRequest';
  445. $discard = $this->_fBGiftsPost("http://apps.facebook.com/fbml/ajax/prompt_send.php?__a=1", $postdata);
  446. //file_put_contents('debug/discard.txt', $discard, FILE_APPEND);
  447. //unset($postdata['request_type']);
  448. //$postdata['&request_type'] = urlencode($arr2['request_type']);
  449. $postdata['preview'] = 'false';
  450. $retGift = $this->_fBGiftsPost("http://apps.facebook.com/fbml/ajax/prompt_send.php?__a=1", $postdata);
  451. //AddLog2($acts[1][0]);
  452. $retGift2 = $this->_fBGiftsPost(html_entity_decode($acts[1][0]), array());
  453. if (stripos(strip_tags($retGift),'"error":0')) {
  454. $returned = 1;
  455. AddLog2("[$count] fBGifts: Returned Gift From " . $data['app_name'] . ' - Success');
  456. } else {
  457. $returned = 9;
  458. AddLog2("[$count] fBGifts: Returned Gift From " . $data['app_name'] . ' - Failed');
  459. }
  460. //file_put_contents('debug/postdata.txt', print_r($postdata,true), FILE_APPEND);
  461. //file_put_contents('debug/formdata.txt', print_r($form,true), FILE_APPEND);
  462. //file_put_contents('debug/giftaction.txt', $giftAction, FILE_APPEND);
  463. //file_put_contents('debug/returngift.txt', $retGift, FILE_APPEND);
  464. //file_put_contents('debug/returngift2.txt', $retGift2, FILE_APPEND);
  465. //sleep(500);
  466. break;
  467. }
  468. }
  469. }
  470. $data['gift_text'] = str_replace("'", "''", @$data['gift_text']);
  471. $fvSQL = "INSERT INTO giftlog(giftlog_timestamp, giftlog_appname, giftlog_text, giftlog_link, giftlog_accept, giftlog_return) " .
  472. "values('" . time() . "','" . $data['app_name'] . "','" . $data['gift_text'] . "','" . $data['action_url'] . "','$accepted', '$returned')";
  473. $this->_fBGiftsDBM->queryExec($fvSQL, $error);
  474. if (!empty($error)) {
  475. AddLog2 ($error . " " . $fvSQL);
  476. }
  477. }
  478. }
  479. }
  480. }
  481. }
  482. ?>