nxs_class_SNAP_RD

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

Defined (1)

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

/inc-cl/rd.api.php  
  1. if (!class_exists("nxs_class_SNAP_RD")) { class nxs_class_SNAP_RD { 
  2.  
  3. var $ntCode = 'RD'; 
  4. var $ntLCode = 'rd'; 
  5.  
  6. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); // return false; 
  7. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  8. return $out; 
  9. }  
  10. function doPostToNT($options, $message) { global $nxs_urlLen; $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  11. //## Check settings 
  12. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  13. if (!isset($options['rdUName']) || trim($options['rdUName'])=='' || !isset($options['rdPass']) || trim($options['rdPass'])=='') { $badOut['Error'] = 'No username/password Found'; return $badOut; }  
  14. //## Format Post 
  15. if (!empty($message['pTitle'])) $title = $message['pTitle']; else $title = nxs_doFormatMsg($options['rdTitleFormat'], $message); $title = nsTrnc($title, 300);  
  16. if (!empty($message['pText'])) $text = $message['pText']; else $text = nxs_doFormatMsg($options['rdTextFormat'], $message);  
  17. //## Make Post  
  18. $pass = substr($options['rdPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['rdPass'], 5)):$options['rdPass']; $hdrsArr = '';  
  19. $loginInfo = doConnectToRD($options['rdUName'], $pass); if (!is_array($loginInfo)) { $badOut['Error'] = print_r($loginInfo, true)." - ERROR"; return $badOut; }  
  20. $mh = $loginInfo['mh']; $ck = $loginInfo['ck']; $post = array('uh'=>$mh, 'sr'=>$options['rdSubReddit'], 'title'=>$title, 'save'=>true);  
  21. if ($options['postType']=='A') { $post['url'] = $message['url']; $post['kind']='link'; $retNum = 16; } else { $post['text'] = $text; $post['kind']='self'; $retNum = 10; }  
  22. $url = "http://www.reddit.com/api/submit"; $postParams = array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'extension'=>'json', 'headers' => $hdrsArr, 'body' => $post, 'cookies' => $ck);  
  23. $response = wp_remote_post($url, $postParams); // prr($postParams); prr($response); 
  24. if (is_wp_error($response)) { $badOut['Error'] = print_r($response, true)." - ERROR"; return $badOut; }  
  25. $response = json_decode($response['body'], true); $rdNewPostID = 'http://www.reddit.com'; // prr($response); 
  26.  
  27. if (!isset($response['jquery']) || !is_array($response['jquery'])) { $badOut['Error'] = print_r($response, true)." - ERROR"; return $badOut; }  
  28. $r = $response['jquery']; if (is_array($r[$retNum][3]) && count($r[$retNum][3])>0 && stripos($r[$retNum][3][0], 'http://')!==false) $rdNewPostID = $r[$retNum][3][0];  
  29. if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3])>0 && stripos($r[18][3][0], 'error.BAD_CAPTCHA')!==false ) { $badOut['Error'] = "ERROR: Post Rejected. Reddit thinks that you don't have rights to post here"; return $badOut; }  
  30. if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3])>0 && stripos($r[18][3][0], 'error')!==false ) { $badOut['Error'] = "ERROR: ".$r[18][3][0]; return $badOut; }  
  31. if (is_array($r[$retNum][3]) && count($r[$retNum][3])>0 && stripos($r[$retNum][3][0], 'http://')===false) { $badOut['Error'] = print_r($r[$retNum][3][0], true)." - ERROR"; return $badOut; }  
  32. if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3])>0 && stripos($r[18][3][0], 'already been submitted')!==false ) $rdNewPostID .= str_ireplace('?already_submitted=true', '', $r[10][3][0]);  
  33. // echo "ID:".$rdNewPostID; 
  34. if ($rdNewPostID!='http://www.reddit.com') {  
  35. return array('postID'=>$rdNewPostID, 'isPosted'=>1, 'postURL'=>$rdNewPostID, 'pDate'=>date('Y-m-d H:i:s'));  
  36. } else { $badOut['Error'] .= print_r($tmhOAuth->response['response'], true)." MSG:".print_r($msg, true);  
  37. return $badOut; 
  38. return $badOut; 
  39. }  
  40.  
  41. }}