nxs_doPublishToSU

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

Description

nxs_doPublishToSU( $postID, $options ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/inc-cl/su.php  
  1. function nxs_doPublishToSU($postID, $options) { global $nxs_suCkArray; $ntCd = 'SU'; $ntCdL = 'su'; $ntNm = 'StumbleUpon'; if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true)); 
  2. //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');  
  3. //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToSU', array($postID, $options));  
  4. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));  
  5. $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();  
  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">StumbleUpon</span> - '.$options['nName'];  
  9. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  10. /** Check is still nessesary or redo 
  11. if ($options['reset'] != '1' && $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. $suCat = $options['suCat'];  
  16. // if (function_exists("get_post_thumbnail_id") ) { $src = wp_get_attachment_image_src(get_post_thumbnail_id($postID), 'thumbnail'); $src = $src[0];}  
  17. if ($postID=='0') { echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $options['suMsgFormat'] = 'Test Link from '.$urlToGo; } else { $post = get_post($postID); if(!$post) return; 
  18. $options['suMsgFormat'] = nsFormatMessage($options['suMsgFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); 
  19. //## MyURL - URLToGo code 
  20. $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; 
  21. }  
  22. $dusername = $options['suUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));  
  23. if ($options['suInclTags']=='1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(', ', $tggs)); $tags = str_replace(' ', '+', $tags); } else $tags = ''; 
  24. $extInfo = ' | PostID: '.$postID." - ".(isset($post) && is_object($post)?$post->post_title:''); 
  25. //## Post  
  26. $message = array('siteName'=>$blogTitle, 'tags'=>$tags, 'url'=>$urlToGo); 
  27. //## Actual Post 
  28. $ntToPost = new nxs_class_SNAP_SU(); $ret = $ntToPost->doPostToNT($options, $message); 
  29. //## Save Session 
  30. if (serialize($nxs_suCkArray)!=$options['suSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; 
  31. if (isset($options['ii']) && $options['ii']!=='') { $gOptions['su'][$options['ii']]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); } 
  32. else foreach ($gOptions['su'] as $ii=>$gpn) { $result = array_diff($options, $gpn);  
  33. if (!is_array($result) || count($result)<1) { $gOptions['su'][$ii]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } 
  34. }  
  35. }  
  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 { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'postURL'=>$ret['postURL'], 'pDate'=>date('Y-m-d H:i:s')));  
  42. $extInfo .= ' | <a href="'.$ret['postURL'].'" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } 
  43. } //prr($ret); 
  44. //## Return Result 
  45. if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);