nxs_doPublishToVB

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

Description

nxs_doPublishToVB( $postID, $options ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/inc-cl/vb.php  
  1. function nxs_doPublishToVB($postID, $options) { global $nxs_vbCkArray, $plgn_NS_SNAutoPoster; $ntCd = 'VB'; $ntCdL = 'vb'; $ntNm = 'vBulletin'; 
  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_doPublishToVB', array($postID, $options));  
  4. $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();  
  5. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName'])); 
  6.  
  7. $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));  
  8. $logNT = '<span style="color:#000080">vBulletin</span> - '.$options['nName'];  
  9. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  10. if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { 
  11. $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5); 
  12. nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return; 
  13. }  
  14.  
  15.  
  16. if ($postID=='0') { echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $options['vbMsgFormat'] = 'Test Message from '.$urlToGo; $options['vbMsgTFormat'] = 'Test Link from '.$urlToGo; }  
  17. else { $post = get_post($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));  
  18. $options['vbMsgFormat'] = nsFormatMessage($options['vbMsgFormat'], $postID, $addParams); $options['vbMsgTFormat'] = nsFormatMessage($options['vbMsgTFormat'], $postID, $addParams); 
  19. //## MyURL - URLToGo code 
  20. if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl; 
  21. if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);  
  22. $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if($addURLParams!='') $urlToGo .= (strpos($urlToGo, '?')!==false?'&':'?').$addURLParams; 
  23. $dusername = $options['vbUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));  
  24. $extInfo = ' | PostID: '.$postID." - ".(!empty($post) && is_object($post)?$post->post_title:''); 
  25.  
  26. //## Message & Format  
  27. if ($options['vbInclTags']=='1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = (implode(', ', $tggs)); /** $tags = str_replace(' ', '+', $tags); */ } else $tags = ''; 
  28. $message = array('siteName'=>$blogTitle, 'tags'=>$tags);  
  29. //## Actual Post 
  30. $ntToPost = new nxs_class_SNAP_VB(); $ret = $ntToPost->doPostToNT($options, $message); 
  31. //## Save Session 
  32. if (empty($options['vkSvC']) || serialize($nxs_vbCkArray)!=$options['vbSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; 
  33. if (isset($options['ii']) && $options['ii']!=='') { $gOptions['vb'][$options['ii']]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); } 
  34. else foreach ($gOptions['vb'] as $ii=>$gpn) { $result = array_diff($options, $gpn);  
  35. if (!is_array($result) || count($result)<1) { $gOptions['vb'][$ii]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } 
  36. }  
  37. //## Process Results 
  38. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  39. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  40. } else { // ## All Good - log it. 
  41. 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'); }  
  42. else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } 
  43. //## Return Result 
  44. if (!empty($ret['isPosted']) && $ret['isPosted']=='1') return 200; else return print_r($ret, true);