nxs_doPublishToWP

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

Description

nxs_doPublishToWP( $postID, $options ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/inc-cl/wp.php  
  1. function nxs_doPublishToWP($postID, $options) { $ntCd = 'WP'; $ntCdL = wp; $ntNm = 'WP Based Blog'; global $plgn_NS_SNAutoPoster; 
  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_doPublishToWP', 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. if (empty($options['imgToUse'])) $options['imgToUse'] = ''; if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  7.  
  8. $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));  
  9. $logNT = '<span style="color:#1A9EE6">WP</span> - '.$options['nName']; 
  10. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  11. if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { 
  12. $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5); 
  13. nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return; 
  14. }  
  15.  
  16. if ($postID=='0') {  
  17. echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $options['wpMsgTFormat'] = 'Test Link from '.$urlToGo; $options['wpMsgFormat'] = 'Test post please ignore';  
  18. } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);  
  19. $options['wpMsgFormat'] = nsFormatMessage($options['wpMsgFormat'], $postID); $options['wpMsgTFormat'] = nsFormatMessage($options['wpMsgTFormat'], $postID);  
  20. //## MyURL - URLToGo code 
  21. if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl; 
  22. if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);  
  23. $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if($addURLParams!='') $urlToGo .= (strpos($urlToGo, '?')!==false?'&':'?').$addURLParams;  
  24. nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));  
  25.  
  26. $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(', ', $tggs);  
  27. $postCats = wp_get_post_categories($postID); $cats = array(); foreach($postCats as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); } // $cats = implode(', ', $catsA); 
  28.  
  29. $extInfo = ' | PostID: '.$postID." - ".(!empty($post) && is_object($post)?$post->post_title:''); 
  30.  
  31. //## Message & Format  
  32. if (trim($options['imgToUse'])!='') $imgURL = $options['imgToUse']; else $imgURL = nxs_getPostImage($postID, 'full');  
  33. $message = array('siteName'=>$blogTitle, 'url'=>$urlToGo, 'imageURL'=>$imgURL, 'tags'=>$tags, 'cats'=>$cats, 'authorName'=>'', 'orID'=>$postID);  
  34. //## Actual Post 
  35. $ntToPost = new nxs_class_SNAP_WP(); $ret = $ntToPost->doPostToNT($options, $message); 
  36. //## Process Results 
  37. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  38. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  39. } else { // ## All Good - log it. 
  40. 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'); }  
  41. else { do_action('nxs_actOnWP', array('postID'=>$postID, 'pgID'=>$ret['postID'], 'wpURL'=>$options['wpURL'], 'ii'=>$ii));  
  42. 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 ($ret['isPosted']=='1') return 200; else return print_r($ret, true);