nxs_doPublishToPK

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

Description

nxs_doPublishToPK( $postID, $options ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/inc-cl/pk.php  
  1. function nxs_doPublishToPK($postID, $options) { $ntCd = 'PK'; $ntCdL = 'pk'; $ntNm = 'Plurk'; if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true)); 
  2. //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPK', array($postID, $options));  
  3. $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();  
  4. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName'])); 
  5. if (empty($options['imgToUse'])) $options['imgToUse'] = ''; if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  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:#014A76">Plurk</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. //## Format 
  15. if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle; $msgT = 'Test Post from '.$blogTitle;} 
  16. else { $post = get_post($postID); if(!$post) return; $twMsgFormat = $options['pkMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $twLim = 180; 
  17. $extInfo = ' | PostID: '.$postID." - ".$post->post_title; 
  18.  
  19. if (stripos($twMsgFormat, '%URL%')!==false || stripos($twMsgFormat, '%SURL%')!==false) $twLim = $twLim - 5;  
  20. if (stripos($twMsgFormat, '%AUTHORNAME%')!==false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $twLim = $twLim - strlen($aun); }  
  21.  
  22. $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl);$noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); 
  23. $noRepl = str_ireplace("%SURL%", "", $noRepl);$noRepl = str_ireplace("%TEXT%", "", $noRepl);$noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);$noRepl = str_ireplace("%EXCERPT%", "", $noRepl); 
  24. $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - strlen($noRepl);  
  25.  
  26. $pTitle = $title = $post->post_title; 
  27. if ($post->post_excerpt!="") $pText = apply_filters('the_content', $post->post_excerpt); else $pText= apply_filters('the_content', $post->post_content); 
  28. $pFullText = apply_filters('the_content', $post->post_content); $pRawText = $post->post_content;  
  29.  
  30. if (stripos($twMsgFormat, '%TITLE%')!==false) { $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - strlen($pTitle); }  
  31. if (stripos($twMsgFormat, '%SITENAME%')!==false) { 
  32. $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - strlen($siteTitle); 
  33. }  
  34. if (stripos($twMsgFormat, '%EXCERPT%')!==false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); 
  35. $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - strlen($pText); 
  36. if (stripos($twMsgFormat, '%FULLTEXT%')!==false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - strlen($pFullText); }  
  37. if (stripos($twMsgFormat, '%RAWTEXT%')!==false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - strlen($pRawText); }  
  38. $options['pkMsgFormat'] = nsFormatMessage($twMsgFormat, $postID, $addParams);  
  39. }  
  40. if (isset($options['attchImg']) && $options['attchImg']=='1' ) if (!empty($options['imgToUse'])) $imgURL = $options['imgToUse']; else $imgURL = nxs_getPostImage($postID, 'full'); else $imgURL=''; 
  41. if (preg_match("/noImg.\.png/i", $imgURL)) $imgURL = '';  
  42. //## Post  
  43. $message = array('siteName'=>$blogTitle, 'tags'=>'', 'imageURL'=>$imgURL);// prr($message); 
  44. //## Actual Post 
  45. $ntToPost = new nxs_class_SNAP_PK(); $ret = $ntToPost->doPostToNT($options, $message); 
  46. //## Process Results 
  47. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  48. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  49. } else { // ## All Good - log it. 
  50. 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'); }  
  51. 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); } 
  52. //## Return Result 
  53. if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);