nxs_class_SNAP_DI

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

Defined (1)

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

/inc-cl/di.api.php  
  1. if (!class_exists("nxs_class_SNAP_DI")) { class nxs_class_SNAP_DI { 
  2.  
  3. var $ntCode = 'DI'; 
  4. var $ntLCode = 'di';  
  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_getDIHeaders($ref, $uname, $pass, $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. $hdrsArr['Authorization']= 'Basic '.base64_encode($uname.':'.$pass); 
  16. $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; 
  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['diUName']) || trim($options['diPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  21. $email = $options['diUName']; $pass = substr($options['diPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['diPass'], 5)):$options['diPass3'];  
  22. //## Format 
  23. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['diMsgFormat'], $message);  
  24. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['diMsgTFormat'], $message);  
  25. $flds = array(); $flds['key']=$options['diAPIKey']; $flds['url']=$message['url']; $flds['title']=nsTrnc($msgT, 250); $flds['desc']=nsTrnc($msg, 250); $flds['tags']=$message['tags']; $flds['shared']='yes'; // prr($flds); die(); 
  26. $hdrsArr = $this->nxs_getDIHeaders('https://www.diigo.com/api/v2/bookmarks', $email, $pass, true); 
  27. $cnt = wp_remote_post( 'https://www.diigo.com/api/v2/bookmarks', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));  
  28. //## Return  
  29. if (is_array($cnt) && stripos($cnt['body'], '"code":1')!==false) {  
  30. return array('postID'=>'DI', 'isPosted'=>1, 'postURL'=>'DI', 'pDate'=>date('Y-m-d H:i:s'));  
  31. } else { $badOut['Error'] .= print_r($cnt, true);  
  32. return $badOut; 
  33. }}