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; } $email = $options['ytUName']; $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); } $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass, 'YT'); if (!$loginError) { $result = $nt->postYT($msg, $options['ytPageID'], $message['videoURL'], $options['ytGPPageID']); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('yt', $options['ii'], $nt->ck, 'ck'); } return $result; }
function nxs_rePostToBG_ajax() { check_ajax_referer('nxsSsPageWPN'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true); global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) { return; } $options = $plgn_NS_SNAutoPoster->nxs_options; foreach ($options['bg'] as $ii => $po) { if ($ii == $_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj'; $mpo = get_post_meta($postID, 'snapBG', true); $mpo = maybe_unserialize($mpo); if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii])) { $ntClInst = new nxs_snapClassBG(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); } $result = nxs_doPublishToBG($postID, $po); if ($result === 200) { nxs_save_glbNtwrks('bg', $ii, 1, 'bgOK'); } if ($result == 200) { die("Successfully sent your post to Blogger."); } else { die($result); } } } }
function doPostToNT($options, $message) { $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => ''); $lnk = ''; //## Check API Lib // if (!function_exists('doPostToGooglePlus')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php'); if (!function_exists('doPostToGooglePlus')) { $badOut['Error'] = 'Google+ API Library not found'; return $badOut; } //## Check settings if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } if (!isset($options['gpUName']) || trim($options['gpPass']) == '') { $badOut['Error'] = 'Not Configured'; return $badOut; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } //## Make Post $gpPostType = $options['postType']; if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['gpMsgFormat'], $message); } // Make "message default" if ($gpPostType == 'I' || $gpPostType == 'A') { if (isset($message['imageURL'])) { $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); } else { $imgURL = ''; } } $email = $options['gpUName']; $pass = substr($options['gpPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['gpPass'], 5)) : $options['gpPass']; $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass); if (!$loginError) { if ($gpPostType == 'A') { $lnk = $message['url']; } elseif ($gpPostType == 'I') { $lnk = array(); if ($imgURL != '') { $lnk['img'] = $imgURL; } if ($imgURL == '' && $message['noImg'] === true) { $lnk['img'] = ''; } if (!empty($message['videoURL'])) { $lnk['video'] = $message['videoURL']; } } $pageID = ''; $comPgID = ''; $comPGCatID = ''; //if (!empty($options['gpPageID']) && empty($options['gpCommID'])) $pageID = $options['gpPageID']; if (!empty($options['gpPageID'])) { $pageID = $options['gpPageID']; } if (!empty($options['gpCommID'])) { $comPgID = $options['gpCommID']; $comPGCatID = $options['gpCCat']; } $result = $nt->postGP($msg, $lnk, $pageID, $comPgID, $comPGCatID); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('gp', $options['ii'], $nt->ck, 'ck'); } return $result; }
function doPostToNT($options, $message) { $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => ''); // prr($message); prr($options); //## Check API Lib //if (!function_exists('doConnectToBlogger')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php'); //## Check settings if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } if ((!isset($options['bgUName']) || empty($options['bgPass'])) && empty($options['AccessToken'])) { $badOut['Error'] = 'Not Configured'; return $badOut; } //## Format if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['bgMsgFormat'], $message); } if (!empty($message['pTitle'])) { $msgT = $message['pTitle']; } else { $msgT = nxs_doFormatMsg($options['bgMsgTFormat'], $message); } if ($options['bgInclTags'] == '1') { $tags = nsTrnc($message['tags'], 195, ',', ''); } else { $tags = ''; } //## Check/Fix HTML if (class_exists('DOMDocument')) { $doc = new DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' . $msg); $doc->encoding = 'UTF-8'; $msg = $doc->saveHTML(); $msg = CutFromTo($msg, '<body>', '</body>'); $msg = preg_replace('/<br(.*?)\\/?>/', '<br$1/>', $msg); $msg = preg_replace('/<img(.*?)\\/?>/', '<img$1/>', $msg); require 'apis/htmlNumTable.php'; if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); } } $msg = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $msg); $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg); $nxshf = new NXS_HtmlFixer(); $nxshf->debug = false; $msg = $nxshf->getFixedHtml($msg); $msg = str_replace("\r\n", "\n", $msg); $msg = str_replace("\n\r", "\n", $msg); $msg = str_replace("\r", "\n", $msg); $msg = str_replace("\n", "<br/>", $msg); //## Make Post $email = $options['bgUName']; $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass']; $blogID = $options['bgBlogID']; // prr($msgT); prr($msg); die(); if (class_exists('nxsAPI_GP') && !empty($options['bgUName']) && empty($options['APIKey'])) { $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass, 'BG'); if (!$loginError) { $result = $nt->postBG($blogID, $msgT, $msg, $tags); // prr($result); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('bg', $options['ii'], $nt->ck, 'ck'); } return $result; } else { //## Refresh token if (function_exists('get_option')) { $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS; } else { $currTime = time(); } if ($options['AccessTokenExp'] < $currTime) { $tknURL = 'https://www.googleapis.com/oauth2/v3/token?refresh_token=' . $options['RefreshToken'] . '&client_id=' . $options['APIKey'] . '&client_secret=' . $options['APISec'] . '&grant_type=refresh_token'; $response = wp_remote_post($tknURL); $resp = json_decode($response['body'], true); $options['AccessToken'] = $resp['access_token']; $options['AccessTokenExp'] = $currTime + $resp['expires_in']; nxs_save_glbNtwrks('bg', $options['ii'], $resp['access_token'], 'AccessTokenExp'); nxs_save_glbNtwrks('bg', $options['ii'], $options['AccessTokenExp'], 'AccessTokenExp'); //nxs_addToLogN('S', 'Test', $logNT, 'Token Refreshed '.date('Y-m-d H:i:s',$options['AccessTokenExp'])."|".$tknURL.$options['AccessToken'].print_r($response, true)); } //## Post $post = array("kind" => "blogger#post", "blog" => array("id" => $blogID), "title" => $msgT, "content" => $msg); $post = json_encode($post); // prr($post); $hdrsArr = array('Content-Type' => 'application/json'); $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $post); $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/' . $blogID . '/posts?access_token=' . $options['AccessToken'] . ''; $ret = ''; $response = wp_remote_post($tknURL, $advSet); //prr($tknURL); prr($response); if (is_object($response) && isset($response->errors)) { $badOut['Error'] = print_r($response, true); } else { $ret = json_decode($response['body'], true); } //prr($ret); if (is_array($ret) && !empty($ret['id'])) { return array('postID' => $ret['id'], 'isPosted' => 1, 'postURL' => $ret['url'], 'pDate' => date('Y-m-d H:i:s')); } else { $badOut['Error'] .= "Error: " . print_r($ret, true); return $badOut; } } //## Return if (is_array($ret) && $ret['post_id'] != '') { return array('postID' => $ret['post_id'], 'isPosted' => 1, 'postURL' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')); } else { $badOut['Error'] .= print_r($ret, true); return $badOut; } }