nxs_doPublishToTR

The NextScripts: Social Networks Auto-Poster nxs doPublishToTR function.

Description

nxs_doPublishToTR( $postID, $options ); 

Parameters (2)

0. $postid
The postid.
1. $options
The options.

Usage

  1. if ( !function_exists( 'nxs_doPublishToTR' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/inc-cl/tr.php'; 
  3.  
  4. // The postid. 
  5. $postid = null; 
  6.  
  7. // The options. 
  8. $options = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nxs_doPublishToTR($postid, $options); 
  12.  

Defined (1)

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

/inc-cl/tr.php  
  1. function nxs_doPublishToTR($postID, $options) { $ntCd = 'TR'; $ntCdL = 'tr'; $ntNm = 'Tumblr'; global $plgn_NS_SNAutoPoster; $ytUrl = ''; $imgURL = '';  
  2. if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true)); 
  3. //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTR', array($postID, $options));  
  4. if (empty($options['imgToUse'])) $options['imgToUse'] = ''; if (empty($options['urlToUse'])) $options['urlToUse'] = '';  
  5. if (empty($options['trMsgTFormat'])) $options['trMsgTFormat'] = ''; if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  6. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName'])); 
  7.  
  8. $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();  
  9. $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));  
  10. $logNT = '<span style="color:#014A76">Tumblr</span> - '.$options['nName']; 
  11. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  12. if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { 
  13. $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {  
  14. nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$options['pType']); return; 
  15. }  
  16. //## Format 
  17. if ($postID=='0') { echo "Testing ... <br/><br/>"; $options['trMsgFormat'] = 'Test Post from '.$blogTitle; $msgT = 'Test Post from '.$blogTitle; $options['trPostType']='T';  
  18. $postDate = gmdate("Y-m-d H:i:s")." GMT"; $tags = ''; $urlToGo = '';  
  19. } else{ $post = get_post($postID); if(!$post) return; $options['trMsgFormat'] = nsFormatMessage($options['trMsgFormat'], $postID, $addParams);  
  20. $options['trMsgTFormat'] = nsFormatMessage($options['trMsgTFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));  
  21.  
  22. $tggs = array();  
  23. if ($options['trInclTags']=='1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(', ', $tggs); }  
  24. if ($options['trInclCats']=='1') { $t = wp_get_post_categories($postID); foreach($t as $c) { $cat = get_category($c); $tggs[] = $cat->name; } $tags = implode(', ', $tggs); }  
  25. $postDate = (($options['useOrDate']=='1' && $post->post_date_gmt!='0000-00-00 00:00:00')?$post->post_date_gmt:gmdate("Y-m-d H:i:s", strtotime($post->post_date)))." GMT"; //## Adds date to Tumblr post. Thanks to Kenneth Lecky 
  26.  
  27. if($options['trPostType']=='V') { $vids = nsFindVidsInPost($post); if (count($vids)>0) $ytUrl = $vids[0]; if (trim($ytUrl)=='') $options['trPostType']='T'; } 
  28. if($options['trPostType']=='U') { $aud = nsFindAudioInPost($post); if (count($aud)>0) $aUrl = $aud[0]; if (trim($aUrl)=='') $options['trPostType']='T'; } 
  29. if($options['trPostType']=='I') { if (trim($options['imgToUse'])!='') $imgURL = $options['imgToUse']; else $imgURL = nxs_getPostImage($postID, 'large', $options['trDefImg']);  
  30. if (preg_match("/noImg.\.png/i", $imgURL)) $imgURL = ''; if (trim($imgURL)=='') $options['trPostType']='T';  
  31. //## MyURL - URLToGo code 
  32. $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse'];  
  33. }  
  34. $extInfo = ' | PostID: '.$postID." - ".(isset($post) && is_object($post)?$post->post_title:'').' |'.$options['pType'];  
  35. //## Post  
  36. $message = array('siteName'=>$blogTitle, 'imageURL'=>$imgURL, 'tags'=>$tags, 'url'=>$urlToGo, 'postDate'=>$postDate, 'videoURL'=>$ytUrl); // prr($message); prr($options); die(); 
  37. //## Actual Post 
  38. $ntToPost = new nxs_class_SNAP_TR(); $ret = $ntToPost->doPostToNT($options, $message);  
  39. //## Process Results 
  40. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  41. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  42. } else { // ## All Good - log it. 
  43. if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your '.$logNT.' Page. ', 'social-networks-auto-poster-facebook-twitter-g'); }  
  44. else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'postURL'=>$ret['postURL'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } 
  45. } //prr($ret); 
  46. //## Return Result 
  47. if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);