nxs_class_SNAP_ST

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

Defined (1)

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

/inc-cl/st.api.php  
  1. if (!class_exists("nxs_class_SNAP_ST")) { class nxs_class_SNAP_ST { 
  2.  
  3. var $ntCode = 'ST'; 
  4. var $ntLCode = 'st'; 
  5.  
  6. function createFile($imgURL) { 
  7. $remImgURL = urldecode($imgURL); $urlParced = pathinfo($remImgURL); $remImgURLFilename = $urlParced['basename'];  
  8. $imgData = wp_remote_get($remImgURL); if (is_wp_error($imgData)) { $badOut['Error'] = print_r($imgData, true)." - ERROR"; return $badOut; }  
  9. $imgData = $imgData['body']; 
  10. $tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));  
  11. if (!is_writable($tmp)) return "Your temporary folder or file (file - ".$tmp.") is not witable. Can't upload images to Flickr"; 
  12. rename($tmp, $tmp.='.png'); register_shutdown_function(create_function('', "unlink('{$tmp}');"));  
  13. file_put_contents($tmp, $imgData); if (!$tmp) return 'You must specify a path to a file'; if (!file_exists($tmp)) return 'File path specified does not exist'; 
  14. if (!is_readable($tmp)) return 'File path specified is not readable';  
  15. // $data['name'] = basename($tmp); 
  16. return "@$tmp"; 
  17.  
  18.  
  19. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); // return false; 
  20. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  21. return $out; 
  22.  
  23. function doPostToNT($options, $message) { global $nxs_urlLen; $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  24. //## Check settings 
  25. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  26. if (!isset($options['uPass']) || trim($options['uPass'])=='') { $badOut['Error'] = 'Not Authorized'; return $badOut; }  
  27. if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  28. //## Format Post 
  29. if (!empty($message['pText'])) $text = $message['pText']; else $text = nxs_doFormatMsg($options['msgFrmt'], $message);  
  30. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['msgTFrmt'], $message); 
  31. //## Make Post  
  32. if (isset($message['imageURL'])) $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); else $imgURL = '';  
  33. //## Make Post  
  34. if (!empty($options['ck'])) $ck = maybe_unserialize($options['ck']); $pass = substr($options['uPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['uPass'], 5)):$options['uPass']; 
  35. $nt = new nxsAPI_ST(); $nt->debug = false; if (!empty($ck)) $nt->ck = $ck; $loginErr = $nt->connect($options['uName'], $pass);  
  36. if (!$loginErr) { $post = array('url'=>$message['url'], 'toURL'=>$options['mgzURL'], 'imgURL'=>$imgURL, 'title'=>$msgT, 'text'=>$text ); $ret = $nt->post($post);  
  37. if (is_array($ret)) { $ret['ck'] = $nt->ck; return $ret; } else return print_r($ret, true); 
  38. } else return print_r($loginErr, true);  
  39. }  
  40. }}