nxs_class_SNAP_VB

The NextScripts: Social Networks Auto-Poster nxs class SNAP VB class.

Defined (1)

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

/inc-cl/vb.api.php  
  1. if (!class_exists("nxs_class_SNAP_VB")) { class nxs_class_SNAP_VB { 
  2.  
  3. var $ntCode = 'VB'; 
  4. var $ntLCode = 'vb';  
  5.  
  6. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); 
  7. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  8. return $out; 
  9. }  
  10. function nxs_getVBHeaders($ref, $post=false) { $hdrsArr = array();  
  11. $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref; 
  12. $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11'; 
  13. if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';  
  14. $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';  
  15. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate, sdch'; $hdrsArr['Accept-Language']='en-US, en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1, utf-8;q=0.7, *;q=0.3'; return $hdrsArr; 
  16. function nxs_doCheckVB($url) { global $nxs_vbCkArray; $hdrsArr = $this->nxs_getVBHeaders($url); $ckArr = $nxs_vbCkArray;  
  17. $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));  
  18. if (stripos($response['body'], 'logouthash=')===false) return 'Bad Saved Login';  
  19. if ( stripos($response['body'], 'usercp.php')!==false && stripos($response['body'], 'logouthash')!==false) { /**echo "You are IN"; */ return false;  
  20. } else return 'No Saved Login'; 
  21. return false;  
  22. function nxs_doConnectToVB($u, $p, $url) { global $nxs_vbCkArray; $hdrsArr = $this->nxs_getVBHeaders($url); $mids = '';// echo "LOGGIN"; 
  23. $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => '')); if(is_wp_error($response)) return "Invalid Connection. ".print_r($response, true); 
  24. $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die(); 
  25. $ckArr = $response['cookies']; $mdhashLoc = stripos($contents, 'md5hash(vb_login_password'); 
  26. if ($mdhashLoc===false) return "No VB found"; 
  27. $frmTxt = CutFromTo($contents, 'md5hash(vb_login_password', '</form>'); $md = array(); $flds = array(); 
  28. while (stripos($frmTxt, '<input')!==false) { $inpField = trim(CutFromTo($frmTxt, '<input', '>')); $name = trim(CutFromTo($inpField, 'name="', '"')); 
  29. if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField, 'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;} 
  30. $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8); 
  31. } $flds['vb_login_username'] = $u; $flds['vb_login_md5password'] = md5($p); $flds['vb_login_md5password_utf'] = md5($p); $flds['cookieuser'] = '1'; $flds['do'] = 'login';  
  32.  
  33. // $logURL = substr($contents, $mdhashLoc-250, 250); $logURL = CutFromTo($logURL, 'action="', '"');  
  34. if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents, 'base href="', '"')); else { $uarr = explode('/', $url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);} 
  35. $hdrsArr = $this->nxs_getVBHeaders($url, true); 
  36. $r2 = wp_remote_post( $baseURL.'login.php?do=login', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr)); // prr($r2); 
  37. if (stripos($r2['body'], 'exec_refresh()')!==false) { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_vbCkArray = $ckArr; return false; } else return "Bad Username/Password"; 
  38. }  
  39. function nxs_doPostToVB($url, $subj, $msg, $lnk, $tags) { global $nxs_vbCkArray; $hdrsArr = $this->nxs_getVBHeaders($url); $ckArr = $nxs_vbCkArray; $mids=''; 
  40. $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));  
  41. if(is_wp_error($response)) return "Invalid Connection. ".print_r($response, true); 
  42. $contents = $response['body']; // $response['body'] = htmlentities($response['body']); prr($response); die(); 
  43. if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents, 'base href="', '"')); else { $uarr = explode('/', $url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);} 
  44. if (stripos($contents, 'newthread.php?do=newthread')!==false) $mdd='t'; elseif (stripos($contents, 'newreply.php?')!==false) $mdd='p'; else return "No Thread/Post Controls found"; 
  45.  
  46. if ($mdd=='t') { $fid = CutFromTo($contents, 'newthread.php?do=newthread', '"'); // echo $baseURL.'newthread.php?do=newthread'.str_replace('&', '&', $fid); 
  47. $response = wp_remote_get( $baseURL.'newthread.php?do=newthread'.str_replace('&', '&', $fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body']; 
  48. $frmTxt = CutFromTo($contents, 'newthread.php?do=postthread', '</form>'); $md = array(); $flds = array(); //prr($frmTxt); 
  49. while (stripos($frmTxt, '<input')!==false) { $inpField = trim(CutFromTo($frmTxt, '<input', '>')); $name = trim(CutFromTo($inpField, 'name="', '"'));  
  50. if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField, 'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;} 
  51. $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8); 
  52. } $flds['subject'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postthread'; $flds['taglist'] = $tags; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+New+Thread';  
  53. $smURL = $baseURL.'newthread.php?do=postthread'.str_replace('&', '&', $fid); 
  54. } //prr($flds); 
  55. if ($mdd=='p') { $fid = CutFromTo($contents, 'newreply.php?do=newreply', '"'); 
  56. $response = wp_remote_get( $baseURL.'newreply.php?do=newreply'.str_replace('&', '&', $fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body']; 
  57. $frmTxt = CutFromTo($contents, 'newreply.php?do=postreply', '</form>'); $md = array(); $flds = array(); //prr($frmTxt); 
  58.  
  59. while (stripos($frmTxt, '<input')!==false) { $inpField = trim(CutFromTo($frmTxt, '<input', '>')); $name = trim(CutFromTo($inpField, 'name="', '"'));  
  60. if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField, 'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;} 
  61. $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8); 
  62. } $flds['title'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postreply'; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+Reply';  
  63. $smURL = $baseURL.'newreply.php?do=postreply'.str_replace('&', '&', $fid); 
  64. } //prr($flds); 
  65. $r2 = wp_remote_post( $smURL, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr)); 
  66. // prr($r2['response']); prr(htmlentities($r2['body'])); $r2['body'] = ''; prr($r2); die(); 
  67. if(is_wp_error($r2)) return "Invalid Connection. ".print_r($r2, true);  
  68. if (stripos($r2['body'], 'tag can only be ')!==false) { $lgLim = trim(CutFromTo($r2['body'], 'tag can only be ', ' characters')); $flds['taglist'] = substr($flds['taglist'], 0, $lgLim);  
  69. $r2 = wp_remote_post( $smURL, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr)); 
  70. if(is_wp_error($r2)) return "Invalid Connection. ".print_r($r2, true);  
  71. if (stripos($r2['body'], 'errorblock')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'errorblock', '</div>'))); 
  72. if (stripos($r2['body'], 'exec_refresh()')!==false && stripos($r2['body'], 'blockrow restore">')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'blockrow restore">', '</p>'))); 
  73. if (stripos($r2['body'], '<error>')!==false) return trim(strip_tags( CutFromTo($r2['body'], '<error>', '</error>'))); 
  74. if ( $r2['response']['code']=='302' || $r2['response']['code']=='303') { return array("code"=>"OK", "post_id"=>$r2['headers']['location']); } 
  75. if (stripos($r2['body'], '<newpostid>')!==false || stripos($r2['body'], 'postbit postid="')!==false ) return 'OK'; 
  76. return "Something wrong - Error: ".print_r($r2, true);  
  77.  
  78. function doPostToNT($options, $message) { $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); global $nxs_vbCkArray;  
  79. //## Check settings 
  80. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  81. if (!isset($options['vbUName']) || trim($options['vbPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  82. $pass = (substr($options['vbPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['vbPass'], 5)):$options['vbPass']);  
  83. //## Format 
  84. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['vbMsgFormat'], $message);  
  85. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['vbMsgTFormat'], $message); 
  86. $urlToGo = (!empty($message['url']))?$message['url']:'';  
  87. //## Post 
  88. if (isset($options['vbSvC'])) $nxs_vbCkArray = maybe_unserialize( $options['vbSvC']); $loginError = true; 
  89. if (is_array($nxs_vbCkArray)) $loginError = $this->nxs_doCheckVB( $options['vbURL']); if ($loginError!==false) $loginError = $this->nxs_doConnectToVB( $options['vbUName'], $pass, $options['vbURL']);  
  90. if ($loginError!==false) return "ERROR - BAD USER/PASS - ".print_r($loginError, true);  
  91. $ret = $this->nxs_doPostToVB($options['vbURL'], $msgT, $msg, $urlToGo, $message['tags']);  
  92.  
  93. if ( (!is_array($ret)) && $ret!='OK') $badOut['Error'] .= 'Something went wrong - '.print_r($ret, true); else return array('postID'=>$ret['post_id'], 'isPosted'=>1, 'postURL'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s'));  
  94. return $badOut;  
  95. }  
  96. }}