nxs_class_SNAP_TR

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

Defined (1)

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

/inc-cl/tr.api.php  
  1. if (!class_exists("nxs_class_SNAP_TR")) { class nxs_class_SNAP_TR { 
  2.  
  3. var $ntCode = 'TR'; 
  4. var $ntLCode = 'tr';  
  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 doPostToNT($options, $message) { $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>'');  
  11. //## Check settings 
  12. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  13. if (!isset($options['trConsKey']) || trim($options['trConsSec'])=='' || empty($options['trAccessTocken'])) { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  14. if (!isset($options['postType']) && isset($options['trPostType'])) $options['postType'] = $options['trPostType']; //## Compatibility with v <3.2 
  15. if (empty($options['imgSize'])) $options['imgSize'] = ''; if (empty($message['postDate'])) $message['postDate'] = ''; 
  16. if (empty($options['trMsgTFormat'])) $options['trMsgTFormat'] = '%TITLE%';  
  17. //## Format 
  18. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['trMsgFormat'], $message);  
  19. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['trMsgTFormat'], $message); 
  20.  
  21. //## Post  
  22. $options['trURL'] = trim(str_ireplace('http://', '', $options['trURL'])); if (substr($options['trURL'], -1)=='/') $options['trURL'] = substr($options['trURL'], 0, -1); 
  23. require_once('apis/trOAuth.php'); $consumer_key = $options['trConsKey']; $consumer_secret = $options['trConsSec']; 
  24. $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']); //prr($options);  
  25.  
  26. $postArr = array('tags'=>$message['tags'], 'date'=>$message['postDate']); if ($options['fillSrcURL']=='1') $postArr['source_url'] = $message['url'];  
  27. if (isset($message['imageURL'])) $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); else $imgURL = ''; 
  28. // postType 
  29. if ($options['postType']=='I') { $postArr['type'] = 'photo'; $postArr['caption'] = $msg; $postArr['source'] = $imgURL;  
  30. if (!isset($options['cImgURL']) || $options['cImgURL']=='' || $options['cImgURL']=='R' ) $postArr['link'] = $message['url'];  
  31. elseif ($options['cImgURL']=='S' ) { $postArr['link'] = $message['url']; $postArr['link'] = nxs_mkShortURL($postArr['link']);}  
  32. } elseif($options['postType']=='U') { $postArr['type'] = 'audio'; $postArr['caption'] = $msg; $postArr['external_url'] = $aUrl; 
  33. } elseif($options['postType']=='V') { $postArr['type'] = 'video'; $postArr['caption'] = $msg;  
  34. $embedTxt = '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.$message['videoURL'].'" frameborder="0" allowfullscreen></iframe>'; 
  35. $postArr['embed'] = $embedTxt;  
  36. } else { $postArr['title'] = $msgT; $postArr['type'] = 'text'; $postArr['source'] = $message['url']; $postArr['body'] = $msg; }  
  37. $postinfo = $tum_oauth->post("http://api.tumblr.com/v2/blog/".$options['trURL']."/post", $postArr); // prr("http://api.tumblr.com/v2/blog/".$options['trURL']."/post"); prr($postinfo); prr($postArr);  
  38. $code = $postinfo->meta->status;// echo "XX".print_r($code); prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|====");  
  39. if ($code == 201) { return array('postID'=>$postinfo->response->id, 'isPosted'=>1, 'postURL'=>'http://'.$options['trURL']."/post/".$postinfo->response->id, 'pDate'=>date('Y-m-d H:i:s')); }  
  40. else $badOut['Error'] .= $code . " - ".($postinfo->meta->msg).(isset($postinfo->errmsg)?$postinfo->errmsg:'')." | ".print_r($postinfo, true);  
  41. return $badOut;  
  42. }  
  43. }}