nxs_class_SNAP_KT

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

Defined (1)

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

/inc-cl/kt.api.php  
  1. if (!class_exists("nxs_class_SNAP_KT")) { class nxs_class_SNAP_KT { 
  2.  
  3. var $ntCode = 'KT'; 
  4. var $ntLCode = 'kt';  
  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_getKTHeaders($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['uName']) || trim($options['uPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  21. $email = $options['uName']; $pass = substr($options['uPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['uPass'], 5)):$options['uPass'];  
  22. //## Format 
  23. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['msgFormat'], $message);  
  24. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['msgTFrmt'], $message); 
  25. //###### =============== 
  26.  
  27. $hdrsArr = $this->nxs_getKTHeaders('https://kippt.com/api/clips/', $email, $pass, true); $hdrsArr['X-Kippt-Username'] = $email; $hdrsArr['X-Kippt-API-Token'] = $pass;  
  28. $cnt = wp_remote_get( 'https://kippt.com/api/lists/', array( 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr)); $lists = json_decode($cnt['body'], true);  
  29. foreach ($lists['objects'] as $list) if ($list['slug'] == $options['list']) $listID = $list['resource_uri']; if (empty($listID)) $listID = '';  
  30. $flds = array(); $flds['url']=$message['url']; $flds['notes']=$msg; $flds['title']=$msgT; $flds['list']=$listID; $flds = json_encode($flds); // prr($flds);  
  31. $cnt = wp_remote_post( 'https://kippt.com/api/clips/', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));  
  32. if (is_wp_error($cnt) || empty($cnt['body']) || $cnt['response']['code']!='201') return "ERROR: ".print_r($cnt, true); 
  33.  
  34. //prr($cnt['body']); 
  35.  
  36. //## Return  
  37. if (stripos($cnt['body'], '"resource_uri": "')!==false) {  
  38. $pid = CutFromTo($cnt['body'], '"resource_uri": "', '"'); $purl = 'https://kippt.com'.CutFromTo($cnt['body'], '"app_url": "', '"'); 
  39. return array('postID'=>$pid, 'isPosted'=>1, 'postURL'=>$purl, 'pDate'=>date('Y-m-d H:i:s'));  
  40. } else { $badOut['Error'] .= print_r($cnt, true);  
  41. return $badOut; 
  42. }}