nxs_doPublishToBG
The NextScripts: Social Networks Auto-Poster nxs doPublishToBG function.
Description
Parameters (2)
- 0. $postid
- The postid.
- 1. $options
- The options.
Usage
if ( !function_exists( 'nxs_doPublishToBG' ) ) { require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/inc-cl/bg.php'; } // The postid. $postid = null; // The options. $options = null; // NOTICE! Understand what this does before running. $result = nxs_doPublishToBG($postid, $options);
Defined (1)
The function is defined in the following location(s).
- /inc-cl/bg.php
- function nxs_doPublishToBG($postID, $options) { $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true));
- //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
- // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG', array($postID, $options));
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
- $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'ACCNAME'=>$options['nName'], 'POSTID'=>$postID));
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
- $logNT = '<span style="color:#F87907">'.$ntNm.'</span> - '.$options['nName'];
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
- }
- }
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $options['bgMsgTFormat'] = 'Test Post from '.htmlentities($blogTitle); $link = home_url(); $options['bgMsgFormat'] = 'Test Post from '.$blogTitle. ' <a href="'.$link.'">'.$link.'</a>'; }
- else { $post = get_post($postID); if(!$post) return; $options['bgMsgFormat'] = nsFormatMessage($options['bgMsgFormat'], $postID, $addParams);
- $options['bgMsgTFormat'] = nsFormatMessage($options['bgMsgTFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
- }
- $extInfo = ' | PostID: '.$postID." - ".(isset($post) && is_object($post)?$post->post_title:'');
- //## Actual POST Code
- if ($options['bgInclTags']=='1') {$t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode('", "', $tggs); $tags = nsTrnc($tags, 195, ', ', ''); }
- if (substr($tags, -1)=='"') $tags = substr($tags, 0, -1); if (substr($tags, -1)==', ') $tags = substr($tags, 0, -1); if (substr($tags, -1)=='"') $tags = substr($tags, 0, -1);
- //## Set Message
- $message = array('title'=>'', 'announce'=>'', 'text'=>'', 'url'=>'', 'surl'=>'', 'urlDescr'=>'', 'urlTitle'=>'', 'imageURL' => array(), 'videoCode'=>'', 'videoURL'=>'', 'siteName'=>$blogTitle, 'tags'=>$tags, 'cats'=>'', 'authorName'=>'');
- //## Actual Post
- $ntToPost = new nxs_class_SNAP_BG(); $ret = $ntToPost->doPostToNT($options, $message);
- //## Process Results
- if (!is_array($ret) || $ret['isPosted']!='1') { //## Error
- if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
- } else { // ## All Good - log it.
- 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'); }
- else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s')));
- $extInfo .= ' | <a href="'.$ret['postURL'].'" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
- }
- //## Return Result
- if (!empty($ret['isPosted']) && $ret['isPosted']=='1') return 200; else return print_r($ret, true);
- }