nxsAPI_DA

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

Defined (1)

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

/inc-cl/da.api.php  
  1. if (!class_exists('nxsAPI_DA')) {class nxsAPI_DA{ var $ck = array(); var $mh = ''; var $debug = false; 
  2. function headers($ref, $org='', $post=false, $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/42.0.2311.39 Safari/537.36'; 
  5. if($post==true) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';  
  6. if($aj==true) $hdrsArr['X-Requested-With']='XMLHttpRequest';  
  7. if ($org!='') $hdrsArr['Origin']=$org;  
  8. $hdrsArr['Accept']='text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';// $hdrsArr['DNT']='1'; 
  9. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate, sdch';  
  10. $hdrsArr['Accept-Language']='en-US, en;q=0.8'; return $hdrsArr;  
  11. function check() { $ck = $this->ck; if (!empty($ck) && is_array($ck)) { $hdrsArr = $this->headers('https://www.deviantart.com'); if ($this->debug) echo "[DA] Checking....;<br/>\r\n"; 
  12. $rep = nxs_remote_get('https://www.deviantart.com', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck));  
  13. if (is_wp_error($rep)) { $badOut = print_r($rep, true)." - ERROR https://www.deviantart.com is not accessible. "; return $badOut; }  
  14. $ck2 = $rep['cookies']; for($i=0;$i<count($ck);$i++) if ($ck[$i]->name=='userinfo') $ck[$i]->value = urlencode($ck2[0]->value); $this->ck = $ck; 
  15. if (is_nxs_error($rep)) return false; $contents = $rep['body']; //if ($this->debug) prr($contents); 
  16. $mh = CutFromTo($rep['body'], '$(\'#logoutme\').submit();">', 'data-ga_click_event'); $mh = CutFromTo($mh, 'href="', '"'); $this->mh = $mh; 
  17. return stripos($contents, 'https://www.deviantart.com/users/logout')!==false; 
  18. } else return false; 
  19. function connect($u, $p) { $badOut = 'Error: '; 
  20. //## Check if alrady IN 
  21. if (!$this->check()) { if ($this->debug) echo "[DA] NO Saved Data;<br/>\r\n"; 
  22. $url = "https://www.deviantart.com/users/login"; $hdrsArr = $this->headers('http://www.deviantart.com/'); 
  23. $rep = wp_remote_get($url, array( 'headers' => $hdrsArr, 'httpversion' => '1.1')); if (is_wp_error($rep)) { $badOut = print_r($rep, true)." - ERROR Login 1"; return $badOut; } $ck = $rep['cookies']; 
  24. $rTok = CutFromTo($rep['body'], 'name="validate_token" value="', '"'); $rKey = CutFromTo($rep['body'], 'name="validate_key" value="', '"'); $ck[0]->value = urlencode($ck[0]->value); 
  25. $hdrsArr = $this->headers('https://www.deviantart.com/users/login', 'https://www.deviantart.com/', true); 
  26. $flds = array('ref' => 'https://www.deviantart.com/users/loggedin', 'username' => $u, 'password' => $p, 'remember_me' => '1', 'validate_token' => $rTok, 'validate_key' => $rKey); 
  27. $response = wp_remote_post( $url, array( 'method' => 'POST', 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'headers' => $hdrsArr, 'body' => $flds));  
  28. if (is_wp_error($response)) { $badOut = print_r($response, true)." - ERROR Login 2"; return $badOut; }  
  29. $ck = $response['cookies']; for($i=0;$i<4;$i++) $ck[$i]->value = urlencode($ck[$i]->value);  
  30. if (isset($response['headers']['location']) && stripos($response['headers']['location'], 'wrong-password')!==false ) { $badOut = "Wrong Password - ERROR"; return $badOut; }  
  31. if (isset($response['headers']['location']) && ( $response['headers']['location']=='http://www.deviantart.com' || $response['headers']['location']=='https://www.deviantart.com/users/loggedin')) {  
  32. $hdrsArr = $this->headers('http://www.deviantart.com'); $rep = wp_remote_get( 'http://www.deviantart.com', array( 'headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck));// die(); prr($rep);  
  33. if (is_wp_error($rep)) { $badOut = print_r($rep, true)." - ERROR Login 3"; return $badOut; }  
  34. $mh = CutFromTo($rep['body'], '$(\'#logoutme\').submit();">', 'data-ga_click_event'); $mh = CutFromTo($mh, 'href="', '"'); 
  35. $ck2 = $rep['cookies']; for($i=0;$i<count($ck);$i++) if ($ck[$i]->name=='userinfo') $ck[$i]->value = urlencode($ck2[0]->value); $this->ck = $ck; $this->mh = $mh; return false; 
  36. } else $badOut = print_r($response, true)." - ERROR Login 4"; return $badOut;  
  37. } else { if ($this->debug) echo "[DA] Saved Data is OK;<br/>\r\n"; return false; } 
  38. function post($post) { $ck = $this->ck; $mh = $this->mh; $hdrsArr = $this->headers('http://www.deviantart.com/'); $badOut = ''; 
  39. $advSets = array( 'headers' => $hdrsArr, 'cookies' => $ck); // prr($advSets); 
  40. $rep = wp_remote_get( $mh.'/journal/?edit', $advSets); if (is_wp_error($rep)) { $badOut = print_r($rep, true)." - ERROR Post 1"; return $badOut; }  
  41. $contents = CutFromTo($rep['body'], '<h3 class="journal-editor-create">', '</form>'); // prr($contents);  
  42. $md = array(); while (stripos($contents, '"hidden"')!==false) {$contents = substr($contents, stripos($contents, '"hidden"')+8); $name = trim(CutFromTo($contents, 'name="', '"')); 
  43. if (!in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($contents, 'value="', '"')); $flds[$name]= urldecode (nxs_decodeEntities($val)); } 
  44. } $flds['subject'] = nsTrnc(nxs_decodeEntities($post['title']), 50); $flds['body'] = trim($post['text']); $flds['song'] = '';  
  45. $flds['game'] = ''; $flds['book'] = ''; $flds['food'] = ''; $flds['movie'] = ''; $flds['drink'] = ''; $flds['flip'] = '0'; $flds['featured'] = '1';  
  46. $flds['portal'] = '1'; $flds['skinlabel'] = 'No+skin'; $flds['jheader'] = ''; $flds['jcss'] = ''; $flds['jfooter'] = '';  
  47. $ck2 = $rep['cookies']; for($i=0;$i<count($ck);$i++) if ($ck[$i]->name=='userinfo') $ck[$i]->value = urlencode($ck2[0]->value);  
  48. $fldsOut = http_build_query ($flds); $fldsOut = str_replace('No%2Bskin', 'No+skin', $fldsOut); $ckk = array(); for($i=0;$i<count($ck);$i++)  
  49. if ($ck[$i]->name=='userinfo' || $ck[$i]->name=='auth') {$ckk[] = $ck[$i]; if ($ck[$i]->name=='userinfo') $ui = $ck[$i]->value; } $ck = $ckk; sleep(6); //## Important.  
  50. $pid = CutFromTo($contents, '"pageviewID":"', '"'); $iid = CutFromTo($contents, '"requestid":"', '"');  
  51. $dflds = array('ui'=>$ui, 'pid'=>$pid, 'iid'=>$iid.'-i7ex4avh-1.0', 't'=>'json'); $dfldsq = http_build_query($dflds);  
  52. $dfldsq1 = 'ui='.$ui.'&c%5B%5D=%22Stash%22%2C%22create_journal%22%2C%5B%2235020854%22%2C%22'.urlencode($flds['subject']).'%22%2C%22'.urlencode($flds['subject']).'%22%2C%22-1%22%2C%7B%7D%5D&pid='.$pid.'&iid='.$iid.'-i7exlgzv-1.0&t=json';  
  53. $hdrsArr = $this->headers($mh.'/journal/?edit', $mh, true); $advSets = array( 'method' => 'POST', 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ck);  
  54. $advSets['body'] = $dfldsq1; $rep = wp_remote_post($mh.'/global/difi/?', $advSets); //prr($mh.'/global/difi/?'); prr($advSets); prr($rep);  
  55. if (is_wp_error($rep)) { $badOut = print_r($rep, true)." - ERROR DFI 1"; return $badOut; } $cnt = $rep['body'];  
  56. if (stripos($cnt, '"status":"SUCCESS"')===false || stripos($cnt, '"args":["')===false) { $badOut = print_r($cnt, true)." - ERROR DFI 1.1"; return $badOut; } else $npid = CutFromTo($cnt, '"args":["', '"'); 
  57. $dfldsq2 = 'ui='.$ui.'&c%5B%5D=%22Deviation%22%2C%22DeleteSingle%22%2C%5B%'.$npid.'%22%2C%221%22%5D&pid='.$pid.'&iid='.$iid.'-i7exlgzv-1.0&t=json'; 
  58. $advSets['body'] = $dfldsq2; $rep = wp_remote_post($mh.'/global/difi/?', $advSets); // sleep(6); //## Important. //prr($advSets); prr($rep); die(); 
  59. $advSets['body'] = $fldsOut; $response = wp_remote_post($mh.'/journal/?edit', $advSets); //prr($mh.'/journal/?edit'); prr($advSets); prr($response); 
  60. if ($response['response']['code']=='200' && stripos($response['body'], 'field_error')!==false) { $eRRMsg = CutFromTo($response['body'], 'field_error', '</div>'); $eRRMsg = trim(strip_tags(CutFromTo($eRRMsg."|GGG|", '>', '|GGG|'))); 
  61. $badOut = "POST Error: ".$eRRMsg; return $badOut; 
  62. }  
  63. if ($response['response']['code']=='302') { $hdrsArr = $this->headers($mh); 
  64. $rep = wp_remote_get( $mh.'/journal/', array( 'headers' => $hdrsArr, 'cookies' => $ck));  
  65. $daNewPostURL = CutFromTo($rep['body'], 'a data-deviationid="', '</a>'); $daNewPostURL = CutFromTo($daNewPostURL, 'href="', '"'); $daNewPostID = CutFromTo($rep['body'], 'a data-deviationid="', '"');  
  66. return array('postID'=>$daNewPostID, 'isPosted'=>1, 'postURL'=>$daNewPostURL, 'pDate'=>date('Y-m-d H:i:s'));  
  67. } else { $badOut .= 'Somethibng is not right'; 
  68. return $badOut; 
  69. return $badOut;  
  70.  
  71. } }