nxs_doPublishToST

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

Description

nxs_doPublishToST( $postID, $options ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'nxs_doPublishToST' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/inc-cl/st.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_doPublishToST($postid, $options); 
  12.  

Defined (1)

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

/inc-cl/st.php  
  1. function nxs_doPublishToST($postID, $options) { global $plgn_NS_SNAutoPoster; $ntCd = 'ST'; $ntCdL = 'st'; $ntNm = 'SETT'; if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true)); 
  2. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));  
  3. if (empty($options['imgToUse'])) $options['imgToUse'] = ''; if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  4. $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));  
  5. $logNT = '<span style="color:#800000">SETT</span> - '.$options['nName'];  
  6. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  7. if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { 
  8. $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {  
  9. nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return; 
  10. }  
  11. $message = array('message'=>'', 'link'=>'', 'imageURL'=>'', 'videoURL'=>'', 'announce'=>'');  
  12.  
  13. if ($postID=='0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); $message['tags']=''; 
  14. if (!empty($options['defImg'])) $imgURL = $options['defImg']; else $imgURL ="http://direct.gtln.us/img/nxs/NXS-Lama.jpg"; $message['imageURL'] = $imgURL; 
  15. } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $post = get_post($postID); if(!$post) return;  
  16. $isNoImg = false; $tags = ''; 
  17.  
  18. $options['msgFrmt'] = nsFormatMessage($options['msgFrmt'], $postID, $addParams); $options['msgTFrmt'] = nsFormatMessage($options['msgTFrmt'], $postID, $addParams); // $postType = $options['postType']; 
  19.  
  20. //$tggs = array(); if ($options['inclTags']=='1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = '"'.implode('" "', $tggs).'"'; } 
  21.  
  22. if (trim($options['imgToUse'])!='') $imgURL = $options['imgToUse']; else $imgURL = nxs_getPostImage($postID, 'full'); if (preg_match("/noImg.\.png/i", $imgURL)) { $imgURL = ''; $isNoImg = true; } 
  23.  
  24. //## MyURL - URLToGo code 
  25. $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; $message = array('url'=>$urlToGo, 'imageURL'=>$imgURL, 'noImg'=>$isNoImg);  
  26. $extInfo = ' | PostID: '.$postID." - ".(isset($post) && is_object($post)?$post->post_title:'');  
  27. }  
  28. //## Actual Post 
  29. $ntToPost = new nxs_class_SNAP_ST(); $ret = $ntToPost->doPostToNT($options, $message); //prr($ret); 
  30. //## Save Session 
  31. if (empty($options['ck'])) $options['ck'] = ''; 
  32. if (!empty($ret) && is_array($ret) && !empty($ret['ck']) && !empty($ret['ck']) && serialize($ret['ck'])!=$options['ck']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']); 
  33. if (isset($options['ii']) && $options['ii']!=='') { $gOptions[$ntCdL][$options['ii']]['ck'] = serialize($ret['ck']); update_option('NS_SNAutoPoster', $gOptions); }  
  34. else foreach ($gOptions[$ntCdL] as $ii=>$gpn) { $result = array_diff($options, $gpn); 
  35. if (!is_array($result) || count($result)<1) { $gOptions[$ntCdL][$ii]['ck'] = serialize($ret['ck']); $plgn_NS_SNAutoPoster->nxs_options = $gOptions; update_option('NS_SNAutoPoster', $gOptions); break; } 
  36. }  
  37. }  
  38. //## Process Results 
  39. if (!is_array($ret) || empty($ret['isPosted']) || $ret['isPosted']!='1') { //## Error  
  40. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  41. } else { // ## All Good - log it. 
  42. 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'); }  
  43. else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'postURL'=>$ret['postURL'], 'pDate'=>date('Y-m-d H:i:s')));  
  44. $extInfo .= ' | <a href="'.$ret['postURL'].'" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);  
  45. //## Return Result 
  46. if (!empty($ret['isPosted']) && $ret['isPosted']=='1') return 200; else return print_r($ret, true);  
  47.  
  48. }