function doPostToNT($options, $message) { $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => ''); //## Check settings if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } if (!isset($options['ytUName']) || trim($options['ytPass']) == '') { $badOut['Error'] = 'Not Configured'; return $badOut; } $pass = substr($options['ytPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ytPass'], 5)) : $options['ytPass']; //## Format if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['ytMsgFormat'], $message); } $loginError = doConnectToGooglePlus2($options['ytUName'], $pass, 'YT'); if ($loginError !== false) { return "BAD USER/PASS - " . $loginError; } $ret = doPostToYouTube($msg, $options['ytPageID'], $message['videoURL'], $options['ytGPPageID']); //prr($ret); if ($ret == 'OK') { $ret = array("code" => "OK", "post_id" => ''); } if (!is_array($ret) && $ret != 'OK') { $badOut['Error'] .= 'Something went wrong - NO PID ' . print_r($ret, true); } else { return array('postID' => $ret['post_id'], 'isPosted' => 1, 'postURL' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')); } return $badOut; }
function nxs_doPublishToYT($postID, $options) { $ntCd = 'YT'; $ntCdL = 'yt'; $ntNm = 'YouTube'; global $nxs_gCookiesArr; // $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_doPublishToYT', array($postID, $options)); if (!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected"; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">YouTube</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') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } } $ytMsgFormat = $options['ytMsgFormat']; $msg = nsFormatMessage($ytMsgFormat, $postID); // prr($msg); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; $email = $options['ytUName']; $pass = substr($options['ytPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ytPass'], 5)) : $options['ytPass']; $loginError = doConnectToGooglePlus2($email, $pass, 'YT'); if ($loginError !== false) { if ($postID == '0') { echo $loginError; } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true) . " - BAD USER/PASS", $extInfo); return "BAD USER/PASS"; } $url = get_permalink($postID); if (trim($url) == '') { $url = home_url(); } $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vUrl = $vids[0]; } $ret = doPostToYouTube($msg, $options['ytPageID'], $vUrl); //prr($ret); if ($ret == 'OK') { $ret = array("code" => "OK", "post_id" => ''); } if (!is_array($ret) && $ret != 'OK') { if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your YouTube Page', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, 'YT', $options['ii'], array('isPosted' => '1', 'pgID' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } if ($ret['code'] == 'OK') { return 200; } else { return $ret; } }