nxs_class_SNAP_DL

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

Defined (1)

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

/inc-cl/dl.api.php  
  1. if (!class_exists("nxs_class_SNAP_DL")) { class nxs_class_SNAP_DL { 
  2.  
  3. var $ntCode = 'DL'; 
  4. var $ntLCode = 'dl';  
  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_getDLHeaders($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.  
  18. function getHeaders($ref, $org='', $post=false, $aj=false) { $hdrsArr = array();  
  19. $hdrsArr['Cache-Control']='max-age=0'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref; 
  20. $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.22 Safari/537.36';  
  21. if($post==='j') $hdrsArr['Content-Type']='application/json;charset=UTF-8'; elseif($post===true) $hdrsArr['Content-Type']='application/x-www-form-urlencoded'; 
  22. if($aj===true) $hdrsArr['X-Requested-With']='XMLHttpRequest'; if ($org!='') $hdrsArr['Origin']=$org;  
  23. $hdrsArr['Accept']='text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';// $hdrsArr['DNT']='1'; 
  24. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate, sdch';  
  25. $hdrsArr['Accept-Language']='en-US, en;q=0.8'; return $hdrsArr;  
  26.  
  27. function doPostToNT($options, $message) { $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  28. //## Check settings 
  29. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  30. if (!isset($options['dlUName']) || trim($options['dlPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  31. $email = $options['dlUName']; $pass = substr($options['dlPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['dlPass'], 5)):$options['dlPass'];  
  32. //## Format 
  33. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['dlMsgFormat'], $message);  
  34. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['dlMsgTFormat'], $message); $tags = nsTrnc($message['tags'], 195, ', ', ''); 
  35.  
  36. $link = $message['url']; $desc = substr($msgT, 0, 250); $ext = substr($msg, 0, 1000);  
  37. $hdrsArr = $this->getHeaders('https://delicious.com', 'https://delicious.com', true); $flds = array('username'=>$email, 'password'=>base64_encode(strrev($pass))); 
  38. $cnt = wp_remote_post( 'https://avosapi.delicious.com/api/v1/account/login', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body'=>$flds, 'headers' => $hdrsArr) );  
  39. if (is_nxs_error($cnt)) { $badOut = "ERROR (Login Form): ".print_r($rep, true); return $badOut; } $rep = json_decode($cnt['body'], true);  
  40.  
  41. if ($rep['status']!='success') { $badOut = "ERROR (Login): ".print_r($rep, true); return $badOut; } $ck = $cnt['cookies']; 
  42. $flds = array('url'=>$link, 'description'=>$desc, 'tags'=>$tags, 'note'=>$ext, 'replace'=>'true', 'private'=>'false', 'share'=>''); 
  43. $advSts = array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body'=>$flds, 'cookies' => $ck, 'headers' => $hdrsArr); //prr($advSts); 
  44. $cnt = wp_remote_post( 'https://avosapi.delicious.com/api/v1/posts/addoredit', $advSts );  
  45. if (is_nxs_error($cnt)) { $badOut = "ERROR (Login Form): ".print_r($rep, true); return $badOut; } $rep = json_decode($cnt['body'], true);  
  46. if ($rep['status']!='success') { $badOut = "ERROR (Login): ".print_r($rep, true); return $badOut; }  
  47. return array('postID'=>md5($message['url']), 'isPosted'=>1, 'postURL'=>'https://delicious.com/link/'.md5($message['url']), 'pDate'=>date('Y-m-d H:i:s'));  
  48. }  
  49. }}