nxs_class_SNAP_IP

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

Defined (1)

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

/inc-cl/ip.api.php  
  1. if (!class_exists("nxs_class_SNAP_IP")) { class nxs_class_SNAP_IP { 
  2.  
  3. var $ntCode = 'IP'; 
  4. var $ntLCode = 'ip';  
  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_getIPHeaders($up) { $hdrsArr = array();  
  11. $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';  
  12. $hdrsArr['User-Agent']='SNAP for Wordpress; Ver 3'; 
  13. $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1'; 
  14. $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up"); 
  15. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate';  
  16. $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; 
  17. function doPostToNT($options, $message) { $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  18. //## Check settings 
  19. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  20. if (!isset($options['ipUName']) || trim($options['ipPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  21. $dusername = $options['ipUName']; $pass = (substr($options['ipPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ipPass'], 5)):$options['ipPass']); 
  22. //## Format 
  23. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['ipMsgFormat'], $message);  
  24. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['ipMsgTFormat'], $message);  
  25. $link = urlencode($message['url']); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000)); $tags = $message['tags'];  
  26. if (!(preg_match("@^(https?|ftp)://[^\s/$.?#].[^\s]*$@iS", $message['url']))) return 'Error: Unvalid URL: '.$message['url'];  
  27. $apicall = "https://www.instapaper.com/api/add?red=api&url=$link&title=$desc&selection=$ext"; 
  28. $hdrsArr = $this->nxs_getIPHeaders($dusername.':'.$pass); $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );// prr($cnt); 
  29.  
  30. if(is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out')!==false) { sleep(10);  
  31. $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );} 
  32. }  
  33. if(is_wp_error($cnt)) $ret = 'Something went wrong - '.print_r($cnt, true); else {  
  34. if (is_array($cnt) && stripos($cnt['body'], 'bookmark_id')!==false) return array('postID'=>CutFromTo($cnt['body'], '"bookmark_id": ', '}'), 'isPosted'=>1, 'postURL'=>'IP', 'pDate'=>date('Y-m-d H:i:s')); 
  35. else { $ret = "Error: "; if ( is_array($cnt) && $cnt['response']['code']=='401') $ret .= " Incorrect Username/Password "; else $ret .= print_r($cnt, true); $ret .= $cnt['response']['message']; } 
  36. } $badOut['Error'] .= $ret; return $badOut; 
  37. }  
  38. }}