nxs_doPublishToYT

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

Description

nxs_doPublishToYT( $postID, $options ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/inc-cl/yt.php  
  1. function nxs_doPublishToYT($postID, $options) { $ntCd = 'YT'; $ntCdL = 'yt'; $ntNm = 'YouTube'; $post = ''; global $nxs_gCookiesArr; $vUrl = ''; 
  2. if (!is_array($options)) $options = maybe_unserialize(get_post_meta($postID, $options, true)); 
  3. // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');  
  4. //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToYT', array($postID, $options)); 
  5. $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));  
  6. $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();  
  7. if (empty($options['ytGPPageID'])) $options['ytGPPageID'] = ''; // if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  8. if(!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected";} 
  9. $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));  
  10. $logNT = '<span style="color:#800000">YouTube</span> - '.$options['nName'];  
  11. $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);  
  12. if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { 
  13. $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5); 
  14. nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return; 
  15. }  
  16. if ($postID=='0') $options['ytMsgFormat'] = 'Test Post, Please Ignore'; else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $post = get_post($postID); if(!$post) return; 
  17. $options['ytMsgFormat'] = nsFormatMessage($options['ytMsgFormat'], $postID, $addParams);// prr($msg); echo $postID; 
  18. $extInfo = ' | PostID: '.$postID." - ".(is_object($post)?$post->post_title:''); 
  19.  
  20. //## Message & Format  
  21. $vids = nsFindVidsInPost($post); if (count($vids)>0) $vUrl = $vids[0]; 
  22. $message = array('siteName'=>$blogTitle, 'videoURL'=>$vUrl);  
  23. //## Actual Post 
  24. $ntToPost = new nxs_class_SNAP_YT(); $ret = $ntToPost->doPostToNT($options, $message); 
  25. //## Process Results 
  26. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  27. if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);  
  28. } else { // ## All Good - log it. 
  29. 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'); }  
  30. 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); } 
  31. }  
  32. //## Return Result 
  33. if (is_array($ret) && !empty($ret['isPosted']) && $ret['isPosted']=='1') return 200; else return print_r($ret, true);  
  34. }