nxs_class_SNAP_LJ

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

Defined (1)

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

/inc-cl/lj.api.php  
  1. if (!class_exists("nxs_class_SNAP_LJ")) { class nxs_class_SNAP_LJ { 
  2.  
  3. var $ntCode = 'LJ'; 
  4. var $ntLCode = 'lj';  
  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_getLJHeaders($up) { $hdrsArr = array();  
  11. $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';  
  12. $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version; 
  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['ljUName']) || trim($options['ljPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  21. $pass = (substr($options['ljPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ljPass'], 5)):$options['ljPass']); 
  22. //## Format 
  23. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['ljMsgFormat'], $message);  
  24. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['ljMsgTFormat'], $message);  
  25.  
  26. require_once ('apis/xmlrpc-client.php'); if (!empty($options['ljSrv']) && $options['ljSrv']=='DW') $server = 'dreamwidth.org'; else $server = 'livejournal.com';  
  27. $nxsToLJclient = new NXS_XMLRPC_Client('http://www.'.$server.'/interface/xmlrpc'); $nxsToLJclient->debug = false;  
  28.  
  29. $date = time(); $year = date("Y", $date); $mon = date("m", $date); $day = date("d", $date); $hour = date("G", $date); $min = date("i", $date); 
  30. $nxsToLJContent = array( "username" => $options['ljUName'], "password" => $pass, "event" => $msg, "subject" => $msgT, "lineendings" => "unix", "year" => $year, "mon" => $mon, "day" => $day, "hour" => $hour, "min" => $min, "ver" => 2);  
  31. if (!empty($options['commID']) && $options['commID']!='') $nxsToLJContent["usejournal"] = $options['commID'];  
  32. if (!empty($options['inclTags']) && $options['inclTags']=='1' && !empty($message['tags'])) $nxsToLJContent['props'] = array('taglist' => $message['tags']);  
  33. // prr($nxsToLJContent); 
  34. if (!$nxsToLJclient->query('LJ.XMLRPC.postevent', $nxsToLJContent)) { prr($nxsToLJclient); $ret = 'Something went wrong - '.$nxsToLJclient->getErrorCode().' : '.$nxsToLJclient->getErrorMessage();} else $ret = 'OK';  
  35. $pid = $nxsToLJclient->getResponse();  
  36. if (is_array($pid) && !empty($pid['url'])) return array('postID'=>$pid['url'], 'isPosted'=>1, 'postURL'=>$pid['url'], 'pDate'=>date('Y-m-d H:i:s'));  
  37. else $badOut['Error'] .= 'Something went wrong - NO PID '.print_r($pid, true);  
  38. return $badOut;  
  39. }  
  40. }}