nxsAPI_ST

The NextScripts: Social Networks Auto-Poster nxsAPI ST class.

Defined (1)

The class is defined in the following location(s).

/inc-cl/st.api.php  
  1. if (!class_exists('nxsAPI_ST')) {class nxsAPI_ST{ var $ck = array(); var $debug = false; 
  2. function headers($ref, $org='', $type='GET', $aj=false) { $hdrsArr = array();  
  3. $hdrsArr['Cache-Control']='max-age=0'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref; 
  4. $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.22 Safari/537.36';  
  5. if($type=='JSON') $hdrsArr['Content-Type']='application/json;charset=UTF-8'; elseif($type=='POST') $hdrsArr['Content-Type']='application/x-www-form-urlencoded'; 
  6. if($aj===true) $hdrsArr['X-Requested-With']='XMLHttpRequest'; if ($org!='') $hdrsArr['Origin']=$org;  
  7. if ($type=='GET') $hdrsArr['Accept']='text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8'; else $hdrsArr['Accept']='*/*'; 
  8. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate, sdch';  
  9. $hdrsArr['Accept-Language']='en-US, en;q=0.8'; return $hdrsArr;  
  10. function makeSlug($str) { $str = strtolower($str); $str = preg_replace('/[^a-zA-Z0-9]/i', ' ', $str); $str = trim($str); $str = preg_replace('/\s+/', ' ', $str); $str = preg_replace('/\s+/', '-', $str); return $str;} 
  11. function check() { $ck = $this->ck; $sslverify = false; if (!empty($ck) && is_array($ck)) { $hdrsArr = $this->headers('https://sett.com'); if ($this->debug) echo "[ST] Checking....;<br/>\r\n"; 
  12. $rep = nxs_remote_get('http://sett.com/', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify));  
  13. if (is_nxs_error($rep)) return false; $ck = $rep['cookies']; $contents = $rep['body']; //if ($this->debug) prr($contents); 
  14. return stripos($contents, 'data-url="')!==false; 
  15. } else return false; 
  16. function connect($u, $p) { $badOut = 'Error: ';  
  17. //## Check if alrady IN 
  18. if (!$this->check()) { if ($this->debug) echo "[ST] NO Saved Data;<br/>\r\n"; $sslverify = false; $llURL = 'https://sett.com/login.php?email='.urlencode($u).'&pw='.urlencode($p).'&remember=on&undefined=Log+in'; 
  19. $hdrsArr = $this->headers('http://sett.com/'); $rep = nxs_remote_get('http://sett.com/', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'sslverify'=>$sslverify)); 
  20. if (is_nxs_error($rep)) { $badOut = "ERROR (Login Form): ".print_r($rep, true); return $badOut; } if ($rep['response']['code']!='200') { $badOut = "ERROR (Login Form): ".print_r($rep, true); return $badOut; } 
  21. $ck = $rep['cookies']; $rep = nxs_remote_get($llURL, array('headers' => $hdrsArr, 'cookies' => $ck, 'httpversion' => '1.1', 'sslverify'=>$sslverify));  
  22. if (is_nxs_error($rep)) { $badOut = print_r($rep, true); if (stripos($badOut, 'Operation timed out')!==false) return "Invalid login email!"; else return "ERROR (Login Form 2): ".$badOut; }  
  23. if ($rep['response']['code']!='200') { $badOut = "ERROR (Login Form 2): ".print_r($rep, true); return $badOut; } //prr($rep); 
  24. if ($rep['response']['code']=='200') { $content = $rep['body']; if (stripos($content, '{"user":{"')!==false) { $ck = $rep['cookies']; $this->ck = $ck; $loginArr = json_decode($content, true); /** prr($loginArr); */ return false;} 
  25. if (stripos($content, '{"errors":[')!==false) { $loginArr = json_decode($content, true); $err = $loginArr['errors'][0]['title']; return "Error: ".$err." | \r\n<br/>\r\n".print_r($loginArr, true); } 
  26. } return "ERROR (Login): ".$badOut.print_r($rep, true); 
  27. } else { if ($this->debug) echo "[TH] Saved Data is OK;<br/>\r\n"; return false; } 
  28. function post($post) { $ck = $this->ck; $sslverify = false; $oneTime = '0R4qFyHCMAYYclyZQFNYrOkq4uy4mN5'; $enText = nxs_AesCtr::encrypt($post['text'], $oneTime, 256); $blogID = ''; 
  29. $hdrsArr = $this->headers('http://sett.com/'); $rep = nxs_remote_get('http://sett.com/'.$post['toURL'], array('headers' => $hdrsArr, 'timeout' => 45, 'cookies' => $ck, 'httpversion' => '1.1', 'sslverify'=>$sslverify)); 
  30. if (is_nxs_error($rep)) { $badOut = "ERROR (Blog URL): ".print_r($rep, true); return $badOut; } $content = $rep['body'];  
  31. if (stripos($content, 'window.site_id =')!==false) $blogID = trim(CutFromTo($content, 'window.site_id =', ';')); if (empty($blogID)) return "ERROR (NO Blog ID found): "; 
  32.  
  33. //if ($_GET('page')=='NextScripts_SNAP.php') prr($admURL); 
  34.  
  35. $hdrsArr = $this->headers('http://sett.com', 'http://sett.com', 'POST'); $flds = array('text'=>$enText); 
  36. $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'sslverify'=>$sslverify, 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds); //prr($advSet); 
  37. $rep = nxs_remote_post('http://sett.com/storetext.php', $advSet); if (is_nxs_error($rep)) { $badOut = "ERROR (Post Post):".print_r($rep, true); return $badOut; }  
  38. if (stripos($rep['body'], '{"id":')!==false) { $textPush = json_decode($rep['body'], true); } else { $badOut = "ERROR (Post Post):".print_r($rep, true); return $badOut; }  
  39. $pURL = 'https://sett.com/newpost.php?autosave=0&context=&is_html=&offset=&one_time=&parent_uid=&promote=&site=&submit_visible=1&to=&uid=&title='.urlencode($post['title']).'&url='.$this->makeSlug($post['title']).'&category=&allow_comments=1&allow_promoting=1&allow_indexing=1&subscribe=1&context=false&is_html=false&offset=-4&parent_uid=&promote=1&site_id='.$blogID.'&type=post&uid=&one_time='.$oneTime.'&text_id='.$textPush['id'].'&text_hash='.$textPush['hash']; $ck=nxsClnCookies($ck); 
  40. $hdrsArr = $this->headers('http://sett.com/'.$post['toURL']); $rep = nxs_remote_get($pURL, array('headers' => $hdrsArr, 'timeout' => 45, 'cookies' => $ck, 'httpversion' => '1.1', 'sslverify'=>$sslverify)); 
  41. if (is_nxs_error($rep)) { $badOut = "ERROR (Post Info): ".print_r($rep, true); return $badOut; }  
  42. if ($rep['response']['code']=='200') { $content = $rep['body'];  
  43. if (stripos($content, '{"errors":[')!==false) { $loginArr = json_decode($content, true); $err = $loginArr['errors'][0]['title']; return "Error: ".$err." | \r\n<br/>\r\n".print_r($loginArr, true); } 
  44.  
  45. if (stripos($rep['body'], '{"uid":')!==false) {$content = json_decode($rep['body'], true); return array('isPosted'=>'1', 'postID'=>$content['uid'], 'postURL'=>'http://sett.com/'.$post['toURL']."/".$content['uid'], 'pDate'=>date('Y-m-d H:i:s'));} 
  46. return 'Error: '.print_r($rep, true);  
  47. }  
  48. }}