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']) || trim($options['bgPass']) == '') { $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 (function_exists("doConnectToBlogger")) { $auth = doConnectToBlogger($email, $pass); if ($auth !== false) { $ret = $auth; } else { $ret = doPostToBlogger($blogID, $msgT, $msg, $tags); } } else { $auth = $this->nsBloggerGetAuth($email, $pass); if ($auth === false) { $ret = 'Incorrect Username/Password'; } else { if (is_array($auth)) { $ret = $auth['error']; } else { $msgT = str_ireplace('&', '&', $msgT); $msgT = utf8_encode(str_ireplace('&', '&', $msgT)); $msg = utf8_encode($msg); $ret = $this->nsBloggerNewPost($auth, $blogID, $msgT, $msg); } } } //## 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; } }
function nxs_doPublishToBG($postID, $options) { $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; // $uqID = uniqid('BG_'); //$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_doPublishToBG', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'ACCNAME' => $options['nName'], 'POSTID' => $postID)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#F87907">' . $ntNm . '</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') { nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate'); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from ' . htmlentities($blogTitle); $link = home_url(); $msg = 'Test Post from ' . $blogTitle . " " . $link; } else { $post = get_post($postID); if (!$post) { return; } $msgFormat = $options['bgMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID, $addParams); $link = get_permalink($postID); $msgTFormat = $options['bgMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . nxs_doQTrans($post->post_title, $lng); //## Actual POST Code $email = $options['bgUName']; $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass']; $blogID = $options['bgBlogID']; //echo "###".$auth."|".$blogID."|".$msgT."|".$msg; if ($options['bgInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode('","', $tggs); $tags = nsTrnc($tags, 195, ',', ''); } if (substr($tags, -1) == '"') { $tags = substr($tags, 0, -1); } 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_once 'apis/htmlNumTable.php'; if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); } } // prr($text); // prr($msg); echo " =HT= "; $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); // prr($msg); die(); if (function_exists("doConnectToBlogger")) { $auth = doConnectToBlogger($email, $pass); if ($auth !== false) { $ret = $auth; } else { $ret = doPostToBlogger($blogID, $msgT, $msg, $tags); } } else { $auth = nsBloggerGetAuth($email, $pass); if ($auth === false) { $ret = 'Incorrect Username/Password'; } else { $msgT = str_ireplace('&', '&', $msgT); $msgT = utf8_encode(str_ireplace('&', '&', $msgT)); $msg = utf8_encode($msg); $ret = nsBloggerNewPost($auth, $blogID, $msgT, $msg); } } //## /Actual POST Code if (!is_array($ret) && $ret != 'OK') { if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . strip_tags(print_r($ret, true)), $extInfo); return $ret; } else { if ($postID == '0') { echo 'OK - Message Posted, please see your ' . $ntNm . ' Page '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); return 201; } else { nxs_metaMarkAsPosted($postID, $ntCd, $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); } return 200; } }