function nxs_snapPublishTo($postArr, $type = '', $aj = false) { global $plgn_NS_SNAutoPoster, $nxs_snapAvNts, $blog_id, $nxs_tpWMPU; // echo " | nxs_doSMAS2 | "; prr($postArr); if (is_object($postArr)) { $postID = $postArr->ID; } else { $postID = $postArr; } $isPost = isset($_POST["snapEdIT"]); if ($isPost) { $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID); } if (function_exists('nxs_doSMAS2')) { nxs_doSMAS2($postArr, $type, $aj); return; } else { if (!isset($plgn_NS_SNAutoPoster)) { return; } $options = $plgn_NS_SNAutoPoster->nxs_options; $ltype = strtolower($type); if ($nxs_tpWMPU == 'S') { switch_to_blog(1); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); $options = $plgn_NS_SNAutoPoster->nxs_options; restore_current_blog(); } if (!isset($options['nxsHTDP']) || $options['nxsHTDP'] == 'S') { if (isset($_POST["snapEdIT"]) && $_POST["snapEdIT"] == '1') { $publtype = 'S'; $delay = rand(2, 10); } else { $publtype = 'A'; } } else { $publtype = 'I'; } nxs_addToLogN('BG', 'Start =- ', '', '------=========#### NEW AUTO-POST REQUEST ' . ($blog_id > 1 ? 'BlogID:' . $blog_id : '') . ' PostID:(' . $postID . ') ' . ($publtype == 'S' ? 'Scheduled +' . $delay : ($publtype == 'A' ? 'Non Human' : 'Immediate')) . ' ####=========------'); $post = get_post($postID); $args = array('public' => true, '_builtin' => false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) { $post_types = get_post_types($args, $output, $operator); } $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted == '1') { nxs_addToLogN('W', 'Skipped', '', 'Already Autoposted - Post ID:(' . $postID . ')'); return; } $snap_isEdIT = get_post_meta($postID, 'snapEdIT', true); if ($snap_isEdIT != '1') { $doPost = true; $exclCats = maybe_unserialize($options['exclCats']); $postCats = wp_get_post_categories($postID); foreach ($postCats as $pCat) { if (is_array($exclCats) && in_array($pCat, $exclCats)) { $doPost = false; } else { $doPost = true; break; } } if (!$doPost) { nxs_addToLogN('I', 'Skipped', '', 'Non-Human Post - Category Excluded - Post ID:(' . $postID . ')'); return; } } if ($options['nxsCPTSeld'] != '') { $nxsCPTSeld = unserialize($options['nxsCPTSeld']); } else { $nxsCPTSeld = array_keys($post_types); } //prr($nxsCPTSeld); if ($post->post_type == 'post' || $options['useForPages'] == '1' && $post->post_type == 'page' || in_array($post->post_type, $post_types) && in_array($post->post_type, $nxsCPTSeld)) { foreach ($nxs_snapAvNts as $avNt) { if (count($options[$avNt['lcode']]) > 0) { $clName = 'nxs_snapClass' . $avNt['code']; if ($isPost && isset($_POST[$avNt['lcode']])) { $po = $_POST[$avNt['lcode']]; } else { $po = get_post_meta($postID, 'snap' . $avNt['code'], true); $po = maybe_unserialize($po); } if (isset($po) && is_array($po)) { $isPostMeta = true; } else { $isPostMeta = false; $po = $options[$avNt['lcode']]; } delete_post_meta($postID, 'snap_isAutoPosted'); add_post_meta($postID, 'snap_isAutoPosted', '1'); $optMt = $options[$avNt['lcode']][0]; if ($isPostMeta) { $ntClInst = new $clName(); $optMt = $ntClInst->adjMetaOpt($optMt, $po[0]); } if ($snap_isEdIT != '1') { $doPost = true; if ($optMt['catSel'] == '1' && trim($optMt['catSelEd']) != '') { $inclCats = explode(',', $optMt['catSelEd']); foreach ($postCats as $pCat) { if (!in_array($pCat, $inclCats)) { $doPost = false; } else { $doPost = true; break; } } if (!$doPost) { nxs_addToLogN('I', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '[Non-Human Post] - Individual Category Excluded - Post ID:(' . $postID . ')'); return; } } } if ($optMt['do' . $avNt['code']] == '1') { $optMt['ii'] = 0; if ($publtype == 'A' && ($optMt['nMin'] > 0 || $optMt['nHrs'] > 0 || $optMt['nTime'] != '')) { $publtype = 'S'; } if ($publtype == 'S') { if (isset($optMt['nHrs']) && isset($optMt['nMin']) && ($optMt['nHrs'] > 0 || $optMt['nMin'] > 0)) { $delay = $optMt['nMin'] * 60 + $optMt['nHrs'] * 3600; nxs_addToLogN('I', 'Delayed', $avNt['name'] . ' (' . $optMt['nName'] . ')', 'Post has been delayed for ' . $delay . ' Seconds (' . ($optMt['nHrs'] > 0 ? $optMt['nHrs'] . ' Hours' : '') . " " . ($optMt['nMin'] > 0 ? $optMt['nMin'] . ' Minutes' : '') . ')'); } else { $delay = rand(2, 10); } $optMt['timeToRun'] = time() + $delay; $args = array($postID, $optMt); wp_schedule_single_event($optMt['timeToRun'], 'ns_doPublishTo' . $avNt['code'], $args); nxs_addToLogN('BI', 'Scheduled', $avNt['name'] . ' (' . $optMt['nName'] . ')', ' PostID:(' . $postID . ')'); } else { $fname = 'nxs_doPublishTo' . $avNt['code']; $fname($postID, $optMt); } } else { nxs_addToLogN('GR', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '-=[Unchecked Account]=- - PostID:' . $postID . ''); } } } } } if ($isS) { restore_current_blog(); } }
function nxs_doPublishToYT($postID, $options) { $ntCd = 'YT'; $ntCdL = 'yt'; $ntNm = 'YouTube'; $post = ''; global $nxs_gCookiesArr; $vUrl = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // $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)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } if (empty($options['ytGPPageID'])) { $options['ytGPPageID'] = ''; } // if (empty($options['imgSize'])) $options['imgSize'] = ''; 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') { $options['ytMsgFormat'] = 'Test Post, Please Ignore'; } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $options['ytMsgFormat'] = nsFormatMessage($options['ytMsgFormat'], $postID, $addParams); // prr($msg); echo $postID; } $extInfo = ' | PostID: ' . $postID . " - " . (is_object($post) ? $post->post_title : ''); //## Message & Format $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vUrl = $vids[0]; } $message = array('siteName' => $blogTitle, 'videoURL' => $vUrl); //## Actual Post $ntToPost = new nxs_class_SNAP_YT(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToLI($postID, $options) { global $nxs_gCookiesArr; $ntCd = 'LI'; $ntCdL = 'li'; $ntNm = 'LinkedIn'; $urlDescr = ''; $myurl = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000058">LinkedIn</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; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $imgURL = ''; // prr($options); if ($postID == '0') { echo "Testing ... <br/><br/>"; $options['liMsgFormatT'] = 'Test Post from ' . $blogTitle; $urlToGo = home_url(); $options['liMsgFormat'] = 'Test Post from ' . $blogTitle . " " . $urlToGo; $title = $blogTitle; } else { $post = get_post($postID); if (!$post) { return; } $options['liMsgFormat'] = nsFormatMessage($options['liMsgFormat'], $postID, $addParams); $options['liMsgFormatT'] = nsTrnc(nsFormatMessage($options['liMsgFormatT'], $postID, $addParams), 200); //## MyURL - URLToGo code $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; $title = nsTrnc($post->post_title, 200); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); if (empty($options['postType'])) { if ((int) $options['liAttch'] == 1 || $isNew) { $options['postType'] = 'A'; } } if ($options['postType'] == 'A' || $options['postType'] == 'I') { if (trim($options['liMsgAFrmt']) != '') { $urlDescr = nsFormatMessage($options['liMsgAFrmt'], $postID, $addParams); } else { $urlDescr = trim(apply_filters('the_content', $post->post_excerpt)); if ($urlDescr == '') { $urlDescr = apply_filters('the_content', $post->post_content); } } if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full'); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } $urlDescr = strip_tags($urlDescr); $urlDescr = nxs_decodeEntitiesFull($urlDescr); $urlDescr = nxs_html_to_utf8($urlDescr); $urlDescr = nsTrnc($urlDescr, 300); } } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); //$images = array(nxs_getPostImage($postID, 'thumb'), nxs_getPostImage($postID, 'medium'), nxs_getPostImage($postID, 'full'), nxs_getPostImage($postID, 'original')); $message = array('url' => $urlToGo, 'surl' => $urlToGo, 'urlDescr' => $urlDescr, 'urlTitle' => $title, 'title' => $title, 'imageURL' => $imgURL, 'videoCode' => '', 'videoURL' => '', 'siteName' => $blogTitle, 'cats' => '', 'authorName' => ''); //## Actual Post $ntToPost = new nxs_class_SNAP_LI(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { $extInfo .= ' | ' . $ret['postID']; // ## All Good - log it. 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'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'postID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); if (!empty($ret['postURL'])) { $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; } nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doConnectToSU($u, $p) { global $nxs_suCkArray; $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/', false, false); // echo "LOGGIN"; $response = wp_remote_get('https://www.stumbleupon.com/login', array('headers' => $hdrsArr)); $p = substr($p, 0, 16); if (is_wp_error($response)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($response, true), ''); return "Connection ERROR. Please see log"; } $contents = $response['body']; $ckArr = $response['cookies']; //$response['body'] = htmlentities($response['body']); prr($response); die(); $frmTxt = CutFromTo($contents, '<form id="login-form"', '</form>'); $md = array(); $flds = array(); $mids = ''; // prr($frmTxt); while (stripos($frmTxt, '<input') !== false) { $inpField = trim(CutFromTo($frmTxt, '<input', '>')); $name = trim(CutFromTo($inpField, 'name="', '"')); if (stripos($inpField, '"hidden"') !== false && $name != '' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField, 'value="', '"')); $flds[$name] = $val; $mids .= "&" . $name . "=" . $val; } $frmTxt = substr($frmTxt, stripos($frmTxt, '<input') + 8); } $flds['user'] = $u; $flds['pass'] = $p; $flds['remember'] = 'true'; $flds['nativeSubmit'] = '0'; $flds['_method'] = 'create'; $flds['_output'] = 'Json'; $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/login', true, true); $r2 = wp_remote_post('https://www.stumbleupon.com/login?_nospa=true', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr)); if (is_wp_error($r2)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($r2, true), ''); return "Connection ERROR. Please see log"; } $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); //prr($flds); prr($ckArr); prr($r2); prr($ckArr); if (is_array($r2) && !empty($r2['response']['code']) && $r2['response']['code'] == '302') { $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/login', false, false); $r2 = wp_remote_get('https://www.stumbleupon.com/settings/profile/', array('timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); if (is_wp_error($r2)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($r2, true), ''); return "Connection ERROR. Please see log"; } //prr($r2); if (stripos($r2['body'], '<a href="#" class="logout ') !== false) { $nxs_suCkArray = $ckArr; return false; } } $resp = json_decode($r2['body'], true); if ($resp['_success'] == '1') { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_suCkArray = $ckArr; return false; } elseif (isset($resp['_reason'])) { return $resp['_reason']; } else { return "ERROR"; } }
function nxs_doPublishToBG($postID, $options) { $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //$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/>"; $options['bgMsgTFormat'] = 'Test Post from ' . htmlentities($blogTitle); $link = home_url(); $options['bgMsgFormat'] = 'Test Post from ' . $blogTitle . " " . $link; } else { $post = get_post($postID); if (!$post) { return; } $options['bgMsgFormat'] = nsFormatMessage($options['bgMsgFormat'], $postID, $addParams); $options['bgMsgTFormat'] = nsFormatMessage($options['bgMsgTFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); //## Actual POST Code 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 (substr($tags, -1) == ',') { $tags = substr($tags, 0, -1); } if (substr($tags, -1) == '"') { $tags = substr($tags, 0, -1); } //## Set Message $message = array('title' => '', 'announce' => '', 'text' => '', 'url' => '', 'surl' => '', 'urlDescr' => '', 'urlTitle' => '', 'imageURL' => array(), 'videoCode' => '', 'videoURL' => '', 'siteName' => $blogTitle, 'tags' => $tags, 'cats' => '', 'authorName' => ''); //## Actual Post $ntToPost = new nxs_class_SNAP_BG(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
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; } }
function nxs_doPublishToVB($postID, $options) { global $nxs_vbCkArray, $plgn_NS_SNAutoPoster; $ntCd = 'VB'; $ntCdL = 'vb'; $ntNm = 'vBulletin'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToVB', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">vBulletin</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/>"; $urlToGo = home_url(); $options['vbMsgFormat'] = 'Test Message from ' . $urlToGo; $options['vbMsgTFormat'] = 'Test Link from ' . $urlToGo; } else { $post = get_post($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $options['vbMsgFormat'] = nsFormatMessage($options['vbMsgFormat'], $postID, $addParams); $options['vbMsgTFormat'] = nsFormatMessage($options['vbMsgTFormat'], $postID, $addParams); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if ($addURLParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addURLParams; } } $dusername = $options['vbUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500)); $extInfo = ' | PostID: ' . $postID . " - " . (!empty($post) && is_object($post) ? $post->post_title : ''); //## Message & Format if ($options['vbInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(', ', $tggs); /* $tags = str_replace(' ','+',$tags); */ } else { $tags = ''; } $message = array('siteName' => $blogTitle, 'tags' => $tags); //## Actual Post $ntToPost = new nxs_class_SNAP_VB(); $ret = $ntToPost->doPostToNT($options, $message); //## Save Session if (empty($options['vkSvC']) || serialize($nxs_vbCkArray) != $options['vbSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['vb'][$options['ii']]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['vb'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['vb'][$ii]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } } } } //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToTW($postID, $options) { $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $imgData = ''; $imgURL = ''; global $plgn_NS_SNAutoPoster, $nxs_urlLen; $nxs_urlLen = 0; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW', array($postID, $options)); $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (!empty($gOptions['nxsHTSpace'])) { $htS = $gOptions['nxsHTSpace']; } else { $htS = ''; } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#00FFFF">Twitter</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' . ' |' . $options['pType']); return; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $uln = 0; $extInfo = ' | PostID: ' . $postID; if ($options['attchImg'] == '1') { if (!empty($options['imgToUse'])) { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if (trim($imgURL) == '') { $options['attchImg'] = 0; } else { $imgURL = str_replace(' ', '%20', $imgURL); $hdrsArr['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'; $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'sslverify' => false); $imgData = wp_remote_get($imgURL, $advSet); if (is_wp_error($imgData) || empty($imgData['body']) || !empty($imgData['headers']['content-length']) && (int) $imgData['headers']['content-length'] < 200) { $options['attchImg'] = 0; nxs_addToLogN('E', 'Error', $logNT, 'Could not get image (' . $imgURL . '), will post without it - Error:' . print_r($imgData, true), $extInfo); } else { $imgData = $imgData['body']; } } } if ($options['attchImg'] == '1' && $imgData != '') { $twLim = 117; } else { $twLim = 140; } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155); $uln = nxs_strLen($msg); } else { $post = get_post($postID); if (!$post) { return; } $twMsgFormat = $options['twMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title . ' |' . $options['pType']; if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) { $twLim = $twLim - 22; } if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $twLim = $twLim - nxs_strLen($aun); } $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl); $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); $noRepl = str_ireplace("%SURL%", "", $noRepl); $noRepl = str_ireplace("%TEXT%", "", $noRepl); $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl); $noRepl = str_ireplace("%EXCERPT%", "", $noRepl); $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $noRepl = str_ireplace("%TAGS%", "", $noRepl); $noRepl = str_ireplace("%CATS%", "", $noRepl); $noRepl = preg_replace('/%H?C(F|T)-[a-zA-Z0-9_]+%/', '', $noRepl); $twLim = $twLim - nxs_strLen($noRepl); // prr($noRepl); $pTitle = nxs_doQTrans($post->post_title); if ($post->post_excerpt != "") { $exrText = nxs_doQTrans($post->post_excerpt); } else { $exrText = nxs_doQTrans($post->post_content); } $pText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $exrText) : $exrText; $pRawText = nxs_doQTrans($post->post_content); $pFullText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $pRawText) : $pRawText; if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) { $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) { $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) { $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) { $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText)); } if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) { } else { $tggs[] = '#' . $frmTag; } } $tags = implode(' ', $tggs); $tgsTwLim = $twLim - 20; $tags = nsTrnc($tags, $tgsTwLim, " ", ""); $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat); $twLim = $twLim - nxs_strLen($tags); } if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) { $t = wp_get_post_categories($postID); $ctts = array(); foreach ($t as $c) { $cat = get_category($c); //$frmTag = trim(str_replace(' ','', str_replace(' ',' ',str_ireplace('&','&',trim(ucwords($cat->name)))))); prr($frmTag); $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $cat->name))))))); if (stripos($pTitle, $cat->name) !== false) { $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle); } elseif (stripos($pTitle, $frmTag) !== false) { $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle); } if (stripos($pText, $cat->name) !== false) { $pText = str_ireplace($cat->name, '#' . $frmTag, $pText); } elseif (stripos($pText, $frmTag) !== false) { $pText = str_ireplace($frmTag, '#' . $frmTag, $pText); } if (stripos($pFullText, $cat->name) !== false) { $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText); } elseif (stripos($pFullText, $frmTag) !== false) { $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText); } if (stripos($pRawText, $cat->name) !== false) { $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText); } elseif (stripos($pRawText, $frmTag) !== false) { $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText); } if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) { } else { $ctts[] = '#' . $frmTag; } } $cats = implode(' ', $ctts); $tgsTwLim = $twLim - 20; $cats = nsTrnc($cats, $tgsTwLim, " ", ""); $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat); $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat); $twLim = $twLim - nxs_strLen($cats); } if (preg_match('/%H?CT-[a-zA-Z0-9_]+%/', $twMsgFormat)) { $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $twMsgFormat)); $mout = ''; foreach ($msgA as $mms) { if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = wp_get_post_terms($postID, $mGr, array("fields" => "names")); if (is_nxs_error($cfItem)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $mGr . '|' . print_r($cfItem, true), $extInfo); } else { $tggs = array(); foreach ($cfItem as $frmTag) { $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $frmTag))))))); $tggs[] = '#' . $frmTag; } $cfItem = implode(' ', $tggs); $twLim = $twLim - nxs_strLen($cfItem); $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms); } } $mout .= $mms; } $twMsgFormat = $mout; } $twMsgFormat = str_ireplace(" ", " ", $twMsgFormat); if (stripos($twMsgFormat, '%TITLE%') !== false) { if (stripos($pTitle, '.co.uk') !== false) { $twLim = $twLim - 14; } if (stripos($pTitle, '.com') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.net') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.org') !== false) { $twLim = $twLim - 16; } $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8'); //$ttlTwLim = $twLim-20; $ttlTwLim = $twLim; $pTitle = nsTrnc($pTitle, $ttlTwLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($pTitle); } if (stripos($twMsgFormat, '%SITENAME%') !== false) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($siteTitle); } if (stripos($twMsgFormat, '%TEXT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%EXCERPT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%ANNOUNCE%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%ANNOUNCE%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) { $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 140, " ", "..."); $exrText = nsTrnc($exrText, $twLim); $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat); $twLim = $twLim - nxs_strLen($exrText); } if (stripos($twMsgFormat, '%FULLTEXT%') !== false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pFullText); } if (stripos($twMsgFormat, '%RAWTEXT%') !== false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pRawText); } $msg = nsFormatMessage($twMsgFormat, $postID, $addParams); } $msg = str_replace('&#039;', "'", $msg); $msg = str_replace(''', "'", $msg); $msg = str_replace('#039;', "'", $msg); $msg = str_replace('#039', "'", $msg); $msg = str_replace('&#8217;', "'", $msg); $msg = str_replace('’', "'", $msg); $msg = str_replace('#8217;', "'", $msg); $msg = str_replace('#8217', "'", $msg); $msg = str_replace('&#8220;', '"', $msg); $msg = str_replace('“', '"', $msg); $msg = str_replace('#8220;', '"', $msg); $msg = str_replace('#8220', "'", $msg); $msg = str_replace('&#8221;', '"', $msg); $msg = str_replace('”', '"', $msg); $msg = str_replace('#8221;', '"', $msg); $msg = str_replace('#8221', "'", $msg); $msg = str_replace('&#8212;', '-', $msg); $msg = str_replace('—', '-', $msg); $msg = str_replace('#8212;', '-', $msg); $msg = str_replace('#8212', "-", $msg); $msg = nxs_decodeEntitiesFull($msg); $message = array('message' => $msg, 'img' => $imgData, 'urlLength' => $nxs_urlLen); $options['twMsgFormat'] = $msg; //## This meta field is created by the indieweb taxonomy plugin - by David Peach $response = get_post_meta($postID, 'response', true); if (!empty($response)) { $reply_url = $response['url']; if (!empty($reply_url) && strpos($reply_url, 'twitter.com')) { $explode_at_domain = explode('twitter.com/', $reply_url); $twitter_path = end($explode_at_domain); $exploded_path = explode('/', $twitter_path); $options['in_reply_to_id'] = end($exploded_path); } } //prr($options); //## Actual Post $ntToPost = new nxs_class_SNAP_TW(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_addToRI($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToSC($postID, $options) { global $plgn_NS_SNAutoPoster; $ntCd = 'SC'; $ntCdL = 'sc'; $ntNm = 'Scoop.It'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">Scoop.It</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' . ' |' . $uqID); return; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $postType = $options['postType']; $isNoImg = false; $tags = ''; $options['msgFrmt'] = nsFormatMessage($options['msgFrmt'], $postID, $addParams); $options['msgTFrmt'] = nsFormatMessage($options['msgTFrmt'], $postID, $addParams); $tggs = array(); if ($options['inclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = $tggs; } if ($postType == 'A') { if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'medium'); } } if ($postType == 'I') { if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full'); } } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; $isNoImg = true; } //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if ($addURLParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addURLParams; } $message = array('url' => $urlToGo, 'imageURL' => $imgURL, 'noImg' => $isNoImg, 'tags' => $tags); $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); } //## Actual Post $ntToPost = new nxs_class_SNAP_SC(); $ret = $ntToPost->doPostToNT($options, $message); //prr($ret); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_addToLog($nt, $type, $msg, $extInfo = '') { nxs_addToLogN($nt, $type, $msg, $extInfo); }
function nxs_doPublishToTR($postID, $options) { $ntCd = 'TR'; $ntCdL = 'tr'; $ntNm = 'Tumblr'; //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTR', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#014A76">Tumblr</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' . ' |' . $options['pType']); return; } } //## Format if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . $blogTitle; $msgT = 'Test Post from ' . $blogTitle; $options['trPostType'] == 'T'; } else { $post = get_post($postID); if (!$post) { return; } $trMsgFormat = $options['trMsgFormat']; $msg = nsFormatMessage($trMsgFormat, $postID); $trMsgTFormat = $options['trMsgTFormat']; $msgT = nsFormatMessage($trMsgTFormat, $postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } //prr($options); die(); //## Post require_once 'apis/trOAuth.php'; $consumer_key = $options['trConsKey']; $consumer_secret = $options['trConsSec']; $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']); //prr($options); $trURL = trim(str_ireplace('http://', '', $options['trURL'])); if (substr($trURL, -1) == '/') { $trURL = substr($trURL, 0, -1); } $tggs = array(); if ($options['trInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); } if ($options['trInclCats'] == '1') { $t = wp_get_post_categories($postID); foreach ($t as $c) { $cat = get_category($c); $tggs[] = $cat->name; } $tags = implode(',', $tggs); } $postDate = ($post->post_date_gmt != '0000-00-00 00:00:00' ? $post->post_date_gmt : gmdate("Y-m-d H:i:s", strtotime($post->post_date))) . " GMT"; //## Adds date to Tumblr post. Thanks to Kenneth Lecky $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title . ' |' . $options['pType']; $postArr = array('tags' => $tags, 'date' => $postDate); if ($options['trPostType'] == 'V') { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $ytUrl = $vids[0]; } if (trim($ytUrl) == '') { $options['trPostType'] = 'T'; } } if ($options['trPostType'] == 'U') { $aud = nsFindAudioInPost($post); if (count($aud) > 0) { $aUrl = $aud[0]; } if (trim($aUrl) == '') { $options['trPostType'] = 'T'; } } if ($options['trPostType'] == 'I') { $imgURL = nxs_getPostImage($postID, 'large', $options['trDefImg']); if (trim($imgURL) == '') { $options['trPostType'] = 'T'; } } if ($options['trPostType'] == 'I') { $postArr['type'] = 'photo'; $postArr['caption'] = $msg; $postArr['source'] = $imgURL; if (!isset($options['cImgURL']) || $options['cImgURL'] == '' || $options['cImgURL'] == 'R') { $postArr['link'] = get_permalink($postID); } elseif ($options['cImgURL'] == 'S') { $postArr['link'] = get_permalink($postID); $postArr['link'] = nxs_mkShortURL($postArr['link']); } } elseif ($options['trPostType'] == 'U') { $postArr['type'] = 'audio'; $postArr['caption'] = $msg; $postArr['external_url'] = $aUrl; } elseif ($options['trPostType'] == 'V') { $postArr['type'] = 'video'; $postArr['caption'] = $msg; $embedTxt = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $ytUrl . '" frameborder="0" allowfullscreen></iframe>'; $postArr['embed'] = $embedTxt; } else { $postArr['title'] = $msgT; $postArr['type'] = 'text'; $postArr['source'] = get_permalink($postID); $postArr['body'] = $msg; } $postinfo = $tum_oauth->post("http://api.tumblr.com/v2/blog/" . $trURL . "/post", $postArr); // prr($postinfo); prr($postArr); $code = $postinfo->meta->status; // echo "XX".print_r($code); prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|===="); if ($code == 201) { if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Tumblr Page. <br/> Result:'; prr($postinfo->meta); } else { nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); nxs_metaMarkAsPosted($postID, 'TR', $options['ii'], array('isPosted' => '1', 'pgID' => $postinfo->response->id, 'pDate' => date('Y-m-d H:i:s'))); } } else { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($postinfo, true), $extInfo); if ($postID == '0') { prr($postinfo); } $code .= " - " . $postinfo->meta->msg . $postinfo->errmsg; } return $code; }
function nxs_doPublishToWP($postID, $options) { $ntCd = 'WP'; $ntCdL = 'wp'; $ntNm = 'WP Based Blog'; global $plgn_NS_SNAutoPoster; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToWP', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#1A9EE6">WP</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/>"; $urlToGo = home_url(); $options['wpMsgTFormat'] = 'Test Link from ' . $urlToGo; $options['wpMsgFormat'] = 'Test post please ignore'; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $options['wpMsgFormat'] = nsFormatMessage($options['wpMsgFormat'], $postID); $options['wpMsgTFormat'] = nsFormatMessage($options['wpMsgTFormat'], $postID); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if ($addURLParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addURLParams; } nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); $postCats = wp_get_post_categories($postID); $cats = array(); foreach ($postCats as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); } // $cats = implode(',',$catsA); $extInfo = ' | PostID: ' . $postID . " - " . (!empty($post) && is_object($post) ? $post->post_title : ''); //## Message & Format if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full'); } $message = array('siteName' => $blogTitle, 'url' => $urlToGo, 'imageURL' => $imgURL, 'tags' => $tags, 'cats' => $cats, 'authorName' => '', 'orID' => $postID); //## Actual Post $ntToPost = new nxs_class_SNAP_WP(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. 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'); } else { do_action('nxs_actOnWP', array('postID' => $postID, 'pgID' => $ret['postID'], 'wpURL' => $options['wpURL'], 'ii' => $ii)); 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_do_post_from_query() { nxs_cron_check(); // nxs_addToLogN('A', 'Debug info only. - Cron Time', 'X', '', $extInfo); if (stripos($_SERVER["REQUEST_URI"], 'wp-cron.php') !== false) { nxs_rePoster(); } //## Run Reposter. $options = get_option('NS_SNAutoPoster'); $quPosts = maybe_unserialize(get_option('NSX_PostsQuery')); if (!is_array($quPosts)) { $quPosts = array(); } if ($options['quLimit'] != '1' || count($quPosts) < 1) { return; } $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS; $hasChanged = false; $postToPost = array_shift($quPosts); $pstEvrySec = $options['quDays'] * 86400 + $options['quHrs'] * 3600 + $options['quMins'] * 60; $rndSec = $options['quLimitRndMins'] * 60; $nxTime = !empty($options['quNxTime']) ? $options['quNxTime'] : $currTime + $pstEvrySec; $extInfo = 'Query Time:' . date_i18n('Y-m-d H:i:s', $options['quNxTime']) . "|Previous Time:" . date_i18n('Y-m-d H:i:s', $options['quLastShTime']); if (empty($options['quNxTime']) || $nxTime < $currTime) { $hasChanged = true; } // Do Post if ($hasChanged) { //## Do Post nxs_addToLogN('A', '**POST STARTED** NXSPoster - WP CRON - Post from Query - Post ID: ' . $postToPost, '', 'Curr Time: ' . date_i18n('Y-m-d H:i:s', $currTime) . '~', $extInfo); $options['quLastShTime'] = $currTime; $rndTime = rand(0 - $rndSec, $rndSec); $options['quNxTime'] = $currTime + $pstEvrySec + $rndTime; if ($options['nxsOverLimit'] == 'D') { $dateC = date("d"); $dayN = date("d", $nxTime); if ($dayN != $dateC) { $quPosts = array(); } } update_option('NSX_PostsQuery', $quPosts); update_option('NS_SNAutoPoster', $options); nxs_snapPublishTo($postToPost, '', true); nxs_addToLogN('A', '**POST FINISHED** NXSPoster - WP CRON - Post from Query - Post ID: ' . $postToPost, '', '-=Time=- ' . $currTime, $extInfo); } }
function nxs_doPublishToWP($postID, $options) { $ntCd = 'WP'; $ntCdL = 'wp'; $ntNm = 'WP Based Blog'; //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToWP', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#1A9EE6">WP</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; } } $imgURL = nxs_getPostImage($postID); $email = $options['wpUName']; $pass = substr($options['wpPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['wpPass'], 5)) : $options['wpPass']; if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from ' . $link; $msg = 'Test post please ignore'; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $msgFormat = $options['wpMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $msgTFormat = $options['wpMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $dusername = $options['wpUName']; $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000)); $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); $postCats = wp_get_post_categories($postID); $cats = array(); foreach ($postCats as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); } // $cats = implode(',',$catsA); //## Post require_once 'apis/xmlrpc-client.php'; $nxsToWPclient = new NXS_XMLRPC_Client($options['wpURL']); $nxsToWPclient->debug = false; if ($imgURL !== '' && stripos($imgURL, 'http') !== false) { // $handle = fopen($imgURL, "rb"); $filedata = ''; while (!feof($handle)) {$filedata .= fread($handle, 8192);} fclose($handle); $filedata = wp_remote_get($imgURL); if (!is_wp_error($filedata)) { $filedata = $filedata['body']; } // echo "AWC?"; $data = array('name' => 'image-' . $postID . '.jpg', 'type' => 'image/jpg', 'bits' => new NXS_XMLRPC_Base64($filedata), true); $status = $nxsToWPclient->query('metaWeblog.newMediaObject', $postID, $options['wpUName'], $pass, $data); $imgResp = $nxsToWPclient->getResponse(); $gid = $imgResp['id']; } else { $gid = ''; } $params = array(0, $options['wpUName'], $pass, array('software_version')); if (!$nxsToWPclient->query('wp.getOptions', $params)) { $ret = 'Something went wrong - ' . $nxsToWPclient->getErrorCode() . ' : ' . $nxsToWPclient->getErrorMessage(); } else { $ret = 'OK'; } $rwpOpt = $nxsToWPclient->getResponse(); $rwpOpt = $rwpOpt['software_version']['value']; $rwpOpt = floatval($rwpOpt); //prr($rwpOpt);prr($nxsToWPclient); $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($rwpOpt == 0) { $errMsg = $nxsToWPclient->getErrorMessage(); if ($errMsg != '') { $ret = $errMsg; } else { $ret = 'XMLRPC is not found or not active. WP admin - Settings - Writing - Enable XML-RPC'; } } else { if ($rwpOpt < 3.0) { $ret = 'XMLRPC is too OLD - ' . $rwpOpt . ' You need at least 3.0'; } else { if ($rwpOpt > 3.3) { $nxsToWPContent = array('title' => $msgT, 'description' => $msg, 'post_status' => 'draft', 'mt_excerpt' => $post->post_excerpt, 'mt_allow_comments' => 1, 'mt_allow_pings' => 1, 'post_type' => 'post', 'mt_keywords' => $tags, 'categories' => $cats, 'custom_fields' => $customfields); $params = array(0, $options['wpUName'], $pass, $nxsToWPContent, true); if (!$nxsToWPclient->query('metaWeblog.newPost', $params)) { $ret = 'Something went wrong - ' . $nxsToWPclient->getErrorCode() . ' : ' . $nxsToWPclient->getErrorMessage(); } else { $ret = 'OK'; } $pid = $nxsToWPclient->getResponse(); if ($gid != '') { $nxsToWPContent = array('post_thumbnail' => $gid); $params = array(0, $options['wpUName'], $pass, $pid, $nxsToWPContent, true); if (!$nxsToWPclient->query('wp.editPost', $params)) { $ret = 'Something went wrong - ' . $nxsToWPclient->getErrorCode() . ' : ' . $nxsToWPclient->getErrorMessage(); } else { $ret = 'OK'; } } $nxsToWPContent = array('post_status' => 'publish'); $params = array(0, $options['wpUName'], $pass, $pid, $nxsToWPContent, true); if (!$nxsToWPclient->query('wp.editPost', $params)) { $ret = 'Something went wrong - ' . $nxsToWPclient->getErrorCode() . ' : ' . $nxsToWPclient->getErrorMessage(); } else { $ret = 'OK'; } } else { $nxsToWPContent = array('title' => $msgT, 'description' => $msg, 'post_status' => 'publish', 'mt_allow_comments' => 1, 'mt_allow_pings' => 1, 'post_type' => 'post', 'mt_keywords' => $tags, 'categories' => $cats, 'custom_fields' => $customfields); $params = array(0, $options['wpUName'], $pass, $nxsToWPContent, true); if (!$nxsToWPclient->query('metaWeblog.newPost', $params)) { $ret = 'Something went wrong - ' . $nxsToWPclient->getErrorCode() . ' : ' . $nxsToWPclient->getErrorMessage(); } else { $ret = 'OK'; } $pid = $nxsToWPclient->getResponse(); } } } if ($ret != 'OK') { if ($postID == '0') { echo $ret; } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { if ($postID == '0') { echo 'OK - Message Posted, please see your WP Blog'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else { nxs_metaMarkAsPosted($postID, 'WP', $options['ii'], array('isPosted' => '1', 'pgID' => $pid, 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } if ($ret == 'OK') { return 200; } else { return $ret; } }
function nxs_doNewNPPost($options) { global $nxs_snapAvNts, $nxs_plurl; $postResults = ''; if (!empty($_POST['mNts']) && is_array($_POST['mNts'])) { nxs_addToLogN('S', '-=== New Form Post requested ===-', 'Form', count($_POST['mNts']) . ' Networks', print_r($_POST['mNts'], true)); $message = array('title' => '', 'text' => '', 'siteName' => '', 'url' => '', 'imageURL' => '', 'videoURL' => '', 'tags' => '', 'urlDescr' => '', 'urlTitle' => ''); if (get_magic_quotes_gpc() || $_POST['nxs_mqTest'] == "\\'") { $_POST['mText'] = stripslashes($_POST['mText']); $_POST['mTitle'] = stripslashes($_POST['mTitle']); } $message['pText'] = $_POST['mText']; $message['pTitle'] = $_POST['mTitle']; //## Get URL info if (!empty($_POST['mLink']) && substr($_POST['mLink'], 0, 4) == 'http') { $message['url'] = $_POST['mLink']; $flds = array('id' => $message['url'], 'scrape' => 'true'); $response = wp_remote_post('https://graph.facebook.com/v2.3/', array('body' => $flds)); if (is_wp_error($response)) { $badOut['Error'] = print_r($response, true) . " - ERROR"; } else { $response = json_decode($response['body'], true); if (!empty($response['description'])) { $message['urlDescr'] = $response['description']; } if (!empty($response['title'])) { $message['urlTitle'] = $response['title']; } if (!empty($response['site_name'])) { $message['siteName'] = $response['site_name']; } if (!empty($response['image'][0]['url'])) { $message['imageURL'] = $response['image'][0]['url']; } } } if (!empty($_POST['mImg']) && substr($_POST['mImg'], 0, 4) == 'http') { $message['imageURL'] = $_POST['mImg']; } foreach ($_POST['mNts'] as $ntC) { $ntA = explode('--', $ntC); $ntOpts = $options[$ntA[0]][$ntA[1]]; if (!empty($ntOpts) && is_array($ntOpts)) { $logNT = $ntA[0]; $clName = 'nxs_class_SNAP_' . strtoupper($logNT); $logNT = '<span style="color:#800000">' . strtoupper($logNT) . '</span> - ' . $ntOpts['nName']; $ntOpts['postType'] = $_POST['mType']; $ntToPost = new $clName(); $ret = $ntToPost->doPostToNT($ntOpts, $message); if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), ''); $postResults .= $logNT . " - Error (Please see log)<br/>"; } else { // ## All Good - log it. if (!empty($ret['postURL'])) { $extInfo = '<a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; } nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); $postResults .= $logNT . " - OK - " . $extInfo . "<br/>"; } } } echo "Done. Results:<br/> " . $postResults; } }
function nxs_doPublishToGP($postID, $options) { $ntCd = 'GP'; $ntCdL = 'gp'; $ntNm = 'Google+'; 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">Google+</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' . ' |' . $uqID); return; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['link'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $gpMsgFormat = $options['gpMsgFormat']; $gpPostType = $options['postType']; $msg = nsFormatMessage($gpMsgFormat, $postID); // prr($msg); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($gpPostType == 'I') { $vids = nsFindVidsInPost($post, false); if (count($vids) > 0) { $ytCode = $vids[0]; } if (trim($ytCode) == '') { $options['trPostType'] = 'T'; } } if ($gpPostType == 'A') { $imgURL = nxs_getPostImage($postID, 'medium'); } if ($gpPostType == 'I') { $imgURL = nxs_getPostImage($postID, 'full'); } $message = array('message' => $msg, 'link' => get_permalink($postID), 'imageURL' => $imgURL, 'videoCode' => $ytCode); } //## Actual Post $ntToPost = new nxs_class_SNAP_GB(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToPN($postID, $options) { global $nxs_gCookiesArr; $ntCd = 'PN'; $ntCdL = 'pn'; $ntNm = 'Pinterest'; // $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_doPublishToPN', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#FA5069">Pinterest</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); $isAttachVid = $options['isAttachVid']; $isAttachVid = '1'; 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; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . $blogTitle; $link = home_url(); if ($options['pnDefImg'] != '') { $imgURL = $options['pnDefImg']; } else { $imgURL = "http://direct.gtln.us/img/nxs/NextScriptsLogoT.png"; } } else { $post = get_post($postID); if (!$post) { return; } $pnMsgFormat = $options['pnMsgFormat']; $msg = nsFormatMessage($pnMsgFormat, $postID); $link = get_permalink($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $imgURL = nxs_getPostImage($postID, 'large', $options['pnDefImg']); //prr($options); echo $imgURL."######"; // echo "WW".$postID."|"; if ($isAttachVid == '1') { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vidURL = 'http://www.youtube.com/v/' . $vids[0]; $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/0.jpg'; } } } $email = $options['pnUName']; $boardID = $options['pnBoard']; $pass = substr($options['pnPass'], 0, 5) == 'g9c1a' ? nsx_doDecode(substr($options['pnPass'], 5)) : $options['pnPass']; // prr($boardID); prr($_POST); die(); if (isset($options['pnSvC'])) { $nxs_gCookiesArr = maybe_unserialize($options['pnSvC']); } $loginError = true; if (is_array($nxs_gCookiesArr)) { $loginError = doCheckPinterest(); } $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($loginError !== false) { $loginError = doConnectToPinterest($email, $pass); } if ($loginError !== false) { echo $loginError; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true), $extInfo); return "BAD USER/PASS"; } if (serialize($nxs_gCookiesArr) != $options['pnSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']); if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['pn'][$options['ii']]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['pn'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['pn'][$ii]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); break; } } } } // echo "PN SET:".$msg."|".$imgURL."|".$link."|".$boardID; if (preg_match('/\\$(\\d+\\.\\d+)/', $msg, $matches)) { $price = $matches[0]; } $ret = doPostToPinterest($msg, $imgURL, $link, $boardID, 'TITLE WHERE IS IT?', $price, $link . "/GTH/"); if ($ret == 'OK') { $ret = array("code" => "OK", "post_id" => ''); } if (!is_array($ret) && $ret != 'OK') { if ($postID == '0') { echo $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 'OK - Message Posted, please see your Pinterest Page'; } else { nxs_metaMarkAsPosted($postID, 'PN', $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; } }
function nxs_doPublishToRD($postID, $options) { $ntCd = 'RD'; $ntCdL = 'rd'; $ntNm = 'Reddit'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">Reddit</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); 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; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $rdPostType = $options['postType']; $options['rdTitleFormat'] = nsFormatMessage($options['rdTitleFormat'], $postID); $options['rdTextFormat'] = nsFormatMessage($options['rdTextFormat'], $postID); // prr($msg); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; $message = array('message' => $options['rdTextFormat'], 'url' => $urlToGo, 'title' => $options['rdTitleFormat']); } //## Actual Post $ntToPost = new nxs_class_SNAP_RD(); $ret = $ntToPost->doPostToNT($options, $message); // echo "~~~"; prr($ret); echo "+++"; //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. 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'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToTW($postID, $options) { $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $img = ''; $imgURL = ''; global $nxs_urlLen; $nxs_urlLen = 0; //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#00FFFF">Twitter</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' . ' |' . $options['pType']); return; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $uln = 0; if ($options['attchImg'] == '1') { $imgURL = nxs_getPostImage($postID); if (trim($imgURL) == '') { $options['attchImg'] = 0; } else { if (ini_get('allow_url_fopen')) { if (@getimagesize($imgURL) !== false) { $img = wp_remote_get($imgURL); if ($img['headers']['content-length'] < 200) { $options['attchImg'] = 0; } else { if (is_wp_error($img)) { $options['attchImg'] = 0; } else { $img = $img['body']; } } } else { $options['attchImg'] = 0; } } else { $img = wp_remote_get($imgURL); if (is_wp_error($img)) { $options['attchImg'] = 0; } elseif (isset($img['body']) && trim($img['body']) != '') { $img = $img['body']; } else { $options['attchImg'] = 0; } } } if ($options['attchImg'] == 0) { nxs_addToLogN('E', 'Error', $logNT, 'Could not get image, will post without it', $extInfo); } } if ($options['attchImg'] == '1' && $img != '') { $twLim = 118; } else { $twLim = 140; } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155); $uln = nxs_strLen($msg); } else { $post = get_post($postID); if (!$post) { return; } $twMsgFormat = $options['twMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) { $twLim = $twLim - 22; } if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $twLim = $twLim - nxs_strLen($aun); } $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl); $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); $noRepl = str_ireplace("%SURL%", "", $noRepl); $noRepl = str_ireplace("%TEXT%", "", $noRepl); $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl); $noRepl = str_ireplace("%EXCERPT%", "", $noRepl); $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - nxs_strLen($noRepl); $pTitle = $title = $post->post_title; if ($post->post_excerpt != "") { $exrText = $post->post_excerpt; } else { $exrText = $post->post_content; } $pText = apply_filters('the_content', $exrText); $pRawText = $post->post_content; $pFullText = apply_filters('the_content', $pRawText); if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $frmTag = trim(str_replace(' ', '', preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) { $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) { $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) { $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) { $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText)); } if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) { } else { $tggs[] = '#' . $frmTag; } } $tags = implode(' ', $tggs); while (count($tags) > $twLim - 10) { array_pop($tggs); $tags = implode(' ', $tggs); } $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat); $twLim = $twLim - nxs_strLen($tags); } if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) { $t = wp_get_post_categories($postID); $ctts = array(); foreach ($t as $c) { $cat = get_category($c); $frmTag = trim(str_replace(' ', '', str_replace(' ', ' ', str_ireplace('&', '&', trim(ucwords($cat->name)))))); if (stripos($pTitle, $cat->name) !== false) { $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle); } elseif (stripos($pTitle, $frmTag) !== false) { $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle); } if (stripos($pText, $cat->name) !== false) { $pText = str_ireplace($cat->name, '#' . $frmTag, $pText); } elseif (stripos($pText, $frmTag) !== false) { $pText = str_ireplace($frmTag, '#' . $frmTag, $pText); } if (stripos($pFullText, $cat->name) !== false) { $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText); } elseif (stripos($pFullText, $frmTag) !== false) { $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText); } if (stripos($pRawText, $cat->name) !== false) { $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText); } elseif (stripos($pRawText, $frmTag) !== false) { $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText); } if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) { } else { $ctts[] = '#' . $frmTag; } } $cats = implode(' ', $ctts); while (count($cats) > $twLim - 10) { array_pop($ctts); $cats = implode(' ', $ctts); } $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat); $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat); $twLim = $twLim - nxs_strLen($cats); } if (stripos($twMsgFormat, '%TITLE%') !== false) { if (stripos($pTitle, '.co.uk') !== false) { $twLim = $twLim - 14; } if (stripos($pTitle, '.com') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.net') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.org') !== false) { $twLim = $twLim - 16; } $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8'); $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($pTitle); } if (stripos($twMsgFormat, '%SITENAME%') !== false) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($siteTitle); } if (stripos($twMsgFormat, '%TEXT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%EXCERPT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) { $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 300, " ", "..."); $exrText = nsTrnc($exrText, $twLim); $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat); $twLim = $twLim - nxs_strLen($exrText); } if (stripos($twMsgFormat, '%FULLTEXT%') !== false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pFullText); } if (stripos($twMsgFormat, '%RAWTEXT%') !== false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pRawText); } $msg = nsFormatMessage($twMsgFormat, $postID); } $message = array('message' => $msg, 'img' => $img, 'urlLength' => $nxs_urlLen); //## Actual Post $ntToPost = new nxs_class_SNAP_TW(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToFB($postID, $options) { global $ShownAds; $ntCd = 'FB'; $ntCdL = 'fb'; $ntNm = 'Facebook'; $dsc = ''; $vidURL = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } if (!class_exists('nxs_class_SNAP_FB')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No Facebook API Lib Detected', ''); return "No Facebook API Lib Detected"; } $fbWhere = 'feed'; $page_id = $options['fbPgID']; if (isset($ShownAds)) { $ShownAdsL = $ShownAds; } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); //## Some Common stuff if (empty($options['postType']) && !empty($options['fbPostType'])) { $options['postType'] = $options['fbPostType']; unset($options['fbPostType']); } //## Compatibility with v <3.2 if (empty($options['postType']) && !empty($options['PostType'])) { $pt = $options['PostType']; unset($options['PostType']); $options['postType'] = $pt; } //## Compatibility with v <3.2 $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#0000FF">Facebook</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' . ' |' . $options['pType']); return; } } //## Make the post if (isset($options['qTLng'])) { $lng = $options['qTLng']; } else { $lng = ''; } if (!isset($options['fbAppPageAuthToken'])) { $options['fbAppPageAuthToken'] = ''; } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } //## Initiate Posting Array $message = array('message' => '', 'link' => '', 'title' => '', 'description' => '', 'imageURL' => '', 'videoURL' => '', 'siteName' => $blogTitle); $imgURL = ''; if ($postID == '0') { $options['fbMsgFormat'] = 'Test Post, Please Ignore'; $dsc = 'Test Post, Description'; $urlTitle = 'Test Post - Title'; $urlToGo = home_url(); } else { $post = get_post($postID); if (!$post) { return; } $msg = nsFormatMessage($options['fbMsgFormat'], $postID, $addParams); $fbPostType = $options['postType']; if ($fbPostType == 'A') { $fbPostType = (int) $options['fbAttch'] == 2 ? 'S' : 'A'; } $isAttachVidFB = $options['fbAttchAsVid']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? nxs_doQTrans($post->post_title, $lng) : '') . ' |' . $options['pType']; if ($fbPostType == 'A') { $imgURL = nxs_getPostImage($postID, 'medium'); } // prr($options); echo "PP - ".$postID; prr($src); if ($fbPostType == 'I' || $fbPostType == 'S') { $imgURL = nxs_getPostImage($postID, 'full'); } // prr($options); echo "PP - ".$postID; prr($src); if ($fbPostType == 'A' || $fbPostType == 'S') { //## AUTO - Get Post Descr from SEO Plugins or make it. if (trim($options['fbMsgAFrmt']) != '') { $dsc = nsFormatMessage($options['fbMsgAFrmt'], $postID, $addParams); } else { if (function_exists('aioseop_mrt_fix_meta') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_aioseop_description', true)); } if (function_exists('wpseo_admin_init') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true)); } if (function_exists('wpseo_admin_init') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true)); } if ($dsc == '') { $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))); } if ($dsc == '') { $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng)); } if ($dsc == '') { $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng))); } if ($dsc == '') { $dsc = trim(nxs_doQTrans($post->post_content, $lng)); } if ($dsc == '') { $dsc = get_bloginfo('description'); } } $dsc = strip_tags(strip_shortcodes($dsc)); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nsTrnc($dsc, 900, ' '); } $msg = str_replace('<br>', "\n", $msg); $msg = str_replace('<br/>', "\n", $msg); $msg = str_replace('<br />', "\n", $msg); $msg = str_ireplace('<3', '<3', $msg); $msg = str_ireplace('<(', '<(', $msg); //## FB Smiles FIX. $msg = strip_tags($msg); $msg = nxs_decodeEntitiesFull($msg); $msg = str_ireplace(''', "'", $msg); $msg = str_ireplace('&039;', "'", $msg); $msg = str_ireplace(''', "'", $msg); $msg = str_ireplace('<3', '<3', $msg); $msg = str_ireplace('<(', '<(', $msg); //## FB Smiles FIX 2. if ($isAttachVidFB == '1') { $vids = nsFindVidsInPost($post, false); if (count($vids) > 0) { if (strlen($vids[0]) == 11) { $vidURL = 'http://www.youtube.com/v/' . $vids[0]; $imgURL = nsGetYTThumb($vids[0]); } if (strlen($vids[0]) == 8) { $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id=' . $vids[0] . '&autoplay=1'; $apiURL = "http://vimeo.com/api/v2/video/" . $vids[0] . ".json?callback=showThumb"; $json = wp_remote_get($apiURL); if (!is_wp_error($json)) { $json = $json['body']; $json = str_replace('showThumb(', '', $json); $json = str_replace('])', ']', $json); $json = json_decode($json, true); $imgURL = $json[0]['thumbnail_large']; } } } } if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = 'http://www.noimage.faketld'; } //$imgURL = 'http://cdn.gtln.us/img/t1x1.gif'; //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } if ($addParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addParams; } //prr($options); $urlTitle = nxs_doQTrans($post->post_title, $lng); $options['fbMsgFormat'] = $msg; $urlTitle = strip_tags(strip_shortcodes($urlTitle)); } $message = array('url' => $urlToGo, 'urlTitle' => $urlTitle, 'urlDescr' => $dsc, 'imageURL' => $imgURL, 'videoURL' => $vidURL, 'siteName' => $blogTitle); if (isset($ShownAds)) { $ShownAds = $ShownAdsL; } // FIX for the quick-adsense plugin //## Actual Post $ntToPost = new nxs_class_SNAP_FB(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_addToRI($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToDA($postID, $options) { $ntCd = 'DA'; $ntCdL = 'da'; $ntNm = 'deviantART'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">deviantART</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' . ' |' . $uqID); return; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $options['daTitleFormat'] = nsFormatMessage($options['daTitleFormat'], $postID, $addParams); $options['daTextFormat'] = nsFormatMessage($options['daTextFormat'], $postID, $addParams); // prr($options['daTextFormat']); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); } //## Actual Post $ntToPost = new nxs_class_SNAP_DA(); $ret = $ntToPost->doPostToNT($options, $message); // echo "~~~"; prr($ret); echo "+++"; //## Save Session if (empty($options['ck'])) { $options['ck'] = ''; } if (!empty($ret) && is_array($ret) && !empty($ret['ck']) && !empty($ret['ck']) && serialize($ret['ck']) != $options['ck']) { $options['ck'] = serialize($ret['ck']); $options['mh'] = serialize($ret['mh']); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['da'][$ii] = $options; nxs_settings_save($nxs_gOptions); } } //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. 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'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToPN($postID, $options) { global $nxs_gCookiesArr, $plgn_NS_SNAutoPoster; $ntCd = 'PN'; $ntCdL = 'pn'; $ntNm = 'Pinterest'; $price = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // $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_doPublishToPN', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } if (empty($options['cImgURL'])) { $options['cImgURL'] = 'R'; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#FA5069">Pinterest</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); $isAttachVid = $options['isAttachVid']; 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/>"; $options['pnMsgFormat'] = 'Test Post from ' . $blogTitle; $urlToGo = home_url(); if ($options['pnDefImg'] != '') { $imgURL = $options['pnDefImg']; } else { $imgURL = "http://direct.gtln.us/img/nxs/NXS-Lama.jpg"; } } else { $post = get_post($postID); if (!$post) { return; } $options['pnMsgFormat'] = nsFormatMessage($options['pnMsgFormat'], $postID, $addParams); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } if ($addParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addParams; } if (is_object($post)) { $urlToGo = apply_filters('nxs_adjust_ex_url', $urlToGo, $post->post_content); } if (!empty($options['imgToUse'])) { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full', $options['pnDefImg']); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if ($isAttachVid == '1') { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vidURL = 'http://www.youtube.com/v/' . $vids[0]; $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/0.jpg'; } } $extInfo = ' | PostID: ' . $postID . " - " . is_object($post) ? $post->post_title : ''; } if ($options['cImgURL'] == 'S') { $options['cImgURL'] = 'R'; } //## Pinterest no longer allows shorthened URLs. //## Post $message = array('siteName' => $blogTitle, 'tags' => '', 'url' => $urlToGo, 'imageURL' => $imgURL); // prr($message); //## Actual Post $ntToPost = new nxs_class_SNAP_PN(); $ret = $ntToPost->doPostToNT($options, $message); //## Save Session if (serialize($nxs_gCookiesArr) != $options['ck']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']); if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['pn'][$options['ii']]['ck'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['pn'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['pn'][$ii]['ck'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); break; } } } } //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //prr($ret); //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToVK($postID, $options) { global $ShownAds, $nxs_vkCkArray; $ntCd = 'VK'; $ntCdL = 'vk'; $ntNm = 'vKontakte(VK)'; $vidURL = ''; $imgVURL = ''; $dsc = ''; $lng = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToVK', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">vKontakte</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' . ' |' . $options['pType']); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $msg = 'Test Link from ' . $urlToGo; } else { $post = get_post($postID); if (!$post) { return; } $options['msgFrmt'] = nxs_decodeEntitiesFull(strip_tags(nsFormatMessage($options['msgFrmt'], $postID, $addParams))); //## MyURL - URLToGo code $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . (is_object($post) ? $post->post_title : '') . ' |' . $options['pType']; //## Message & Format if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full'); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if (function_exists('nxs_doPostToVK')) { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { if (strlen($vids[0]) == 11) { $vidURL = 'http://www.youtube.com/watch?v=' . $vids[0]; $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/maxresdefault.jpg'; } if (strlen($vids[0]) == 8) { $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id=' . $vids[0] . '&autoplay=1'; //$mssg['source'] = 'http://player.vimeo.com/video/'.$vids[0]; $apiURL = "http://vimeo.com/api/v2/video/" . $vids[0] . ".json?callback=showThumb"; $json = wp_remote_get($apiURL); if (!is_wp_error($json)) { $json = $json['body']; $json = str_replace('showThumb(', '', $json); $json = str_replace('])', ']', $json); $json = json_decode($json, true); $imgVURL = $json[0]['thumbnail_large']; } } } } if (!empty($options['attchAsVid']) && $options['attchAsVid'] == '1' && trim($imgVURL) != '') { $imgURL = $imgVURL; } if ($options['postType'] == 'A') { if (trim($options['msgAFormat']) != '') { $dsc = nsFormatMessage($options['msgAFormat'], $postID, $addParams); } else { if (function_exists('aioseop_mrt_fix_meta') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_aioseop_description', true)); } if (function_exists('wpseo_admin_init') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true)); } if (function_exists('wpseo_admin_init') && $dsc == '') { $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true)); } if (is_object($post) && $dsc == '') { $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))); } if ($dsc == '') { $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng)); } if (is_object($post) && $dsc == '') { $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng))); } if ($dsc == '') { $dsc = trim(nxs_doQTrans($post->post_content, $lng)); } if (is_object($post) && $dsc == '') { $dsc = get_bloginfo('description'); } } $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nsTrnc($dsc, 900, ' '); } else { $dsc = ''; } $message = array('siteName' => $blogTitle, 'url' => $urlToGo, 'imageURL' => $imgURL, 'videoURL' => $vidURL, 'urlTitle' => nxs_decodeEntitiesFull(nxs_doQTrans($post->post_title, $lng)), 'urlDescr' => $dsc); //## Actual Post $ntToPost = new nxs_class_SNAP_VK(); $ret = $ntToPost->doPostToNT($options, $message); //## Check Phone Req Return if (is_string($ret) && stripos($ret, 'Phone verification required:') !== false) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $phtext = str_ireplace('Phone verification required: ', '', $ret); $ret .= ". Please refresh/reload the SNAP settings page and enter your phone."; $gOptions['vk'][$ii]['vkPhReq'] = $phtext; update_option('NS_SNAutoPoster', $gOptions); if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true) . " - BAD USER/PASS", $extInfo); return " -= BAD USER/PASS - Phone verification required =- "; } //## Save Session if (empty($options['vkSvC']) || serialize($nxs_vkCkArray) != $options['vkSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['vk'][$options['ii']]['vkSvC'] = serialize($nxs_vkCkArray); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['vk'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['vk'][$ii]['vkSvC'] = serialize($nxs_vkCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } } } } //## Process Results if (is_array($ret) && !empty($ret['err'])) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToTR($postID, $options) { $ntCd = 'TR'; $ntCdL = 'tr'; $ntNm = 'Tumblr'; global $plgn_NS_SNAutoPoster; $ytUrl = ''; $imgURL = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTR', array($postID, $options)); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['urlToUse'])) { $options['urlToUse'] = ''; } if (empty($options['trMsgTFormat'])) { $options['trMsgTFormat'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#014A76">Tumblr</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' . ' |' . $options['pType']); return; } } //## Format if ($postID == '0') { echo "Testing ... <br/><br/>"; $options['trMsgFormat'] = 'Test Post from ' . $blogTitle; $msgT = 'Test Post from ' . $blogTitle; $options['trPostType'] = 'T'; $postDate = gmdate("Y-m-d H:i:s") . " GMT"; $tags = ''; $urlToGo = ''; } else { $post = get_post($postID); if (!$post) { return; } $options['trMsgFormat'] = nsFormatMessage($options['trMsgFormat'], $postID, $addParams); $options['trMsgTFormat'] = nsFormatMessage($options['trMsgTFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $tggs = array(); if ($options['trInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); } if ($options['trInclCats'] == '1') { $t = wp_get_post_categories($postID); foreach ($t as $c) { $cat = get_category($c); $tggs[] = $cat->name; } $tags = implode(',', $tggs); } $postDate = ($options['useOrDate'] == '1' && $post->post_date_gmt != '0000-00-00 00:00:00' ? $post->post_date_gmt : gmdate("Y-m-d H:i:s", strtotime($post->post_date))) . " GMT"; //## Adds date to Tumblr post. Thanks to Kenneth Lecky if ($options['trPostType'] == 'V') { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $ytUrl = $vids[0]; } if (trim($ytUrl) == '') { $options['trPostType'] = 'T'; } } if ($options['trPostType'] == 'U') { $aud = nsFindAudioInPost($post); if (count($aud) > 0) { $aUrl = $aud[0]; } if (trim($aUrl) == '') { $options['trPostType'] = 'T'; } } if ($options['trPostType'] == 'I') { if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'large', $options['trDefImg']); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if (trim($imgURL) == '') { $options['trPostType'] = 'T'; } } //## MyURL - URLToGo code $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : '') . ' |' . $options['pType']; //## Post $message = array('siteName' => $blogTitle, 'imageURL' => $imgURL, 'tags' => $tags, 'url' => $urlToGo, 'postDate' => $postDate, 'videoURL' => $ytUrl); // prr($message); prr($options); die(); //## Actual Post $ntToPost = new nxs_class_SNAP_TR(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //prr($ret); //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToKT($postID, $options) { global $nxs_ktCkArray; $ntCd = 'KT'; $ntCdL = 'kt'; $ntNm = 'Kippt'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDI', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">Kippt</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'); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $options['msgFormat'] = 'Test Message from ' . $link; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $options['msgFrmt'] = nsFormatMessage($options['msgFrmt'], $postID, $addParams); $options['msgTFrmt'] = nsFormatMessage($options['msgTFrmt'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); //## Create and Format message $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); $tags = str_replace(' ', '+', $tags); $message = array('url' => $link, 'surl' => $link, 'siteName' => $blogTitle, 'tags' => $tags); //## Actual Post $ntToPost = new nxs_class_SNAP_KT(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. 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'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToDL($postID, $options) { $ntCd = 'DL'; $ntCdL = 'dl'; $ntNm = 'Delicious'; // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDL', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">Delicious</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'); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from ' . $link; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $msgFormat = $options['dlMsgFormat']; $msgTFormat = $options['dlMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; $dusername = $options['dlUName']; $pass = substr($options['dlPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['dlPass'], 5)) : $options['dlPass']; $api = "api.del.icio.us/v1"; $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000)); $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = urlencode(implode(',', $tggs)); $tags = str_replace(' ', '+', $tags); $apicall = "https://{$api}/posts/add?red=api&url={$link}&description={$desc}&extended={$ext}&tags={$tags}"; $hdrsArr = nxs_getDLHeaders($dusername . ':' . $pass); $cnt = wp_remote_get($apicall, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr)); // prr($cnt); if (is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out') !== false) { sleep(10); $cnt = wp_remote_get($apicall, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr)); } } if (is_wp_error($cnt)) { $ret = 'Something went wrong - ' . "http://{$dusername}:*********@{$api}/posts/add?&url={$link}&description={$desc}&extended={$ext}&tags={$tags}"; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $ret . "ERR: " . print_r($cnt, true), $extInfo); } else { if (is_array($cnt) && stripos($cnt['body'], 'code="done"') !== false) { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'DL', $options['ii'], array('isPosted' => '1', 'pgID' => 'DL', 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } elseif (is_array($cnt) && $cnt['body'] == '<?xml version="1.0" encoding="UTF-8"?>') { $ret = 'It looks like Delicious API is Down'; nxs_addToLogN('E', 'Error', $logNT, 'It looks like Delicious API is Down', $extInfo); } elseif (is_array($cnt) && stripos($cnt['body'], 'item already exists') !== false) { $ret = '..All good, but this link has already been bookmarked..'; nxs_addToLogN('S', 'Skipped', $logNT, 'All good, but this link has already been bookmarked', $extInfo); } else { if ($cnt['response']['code'] == '401') { $ret = " Incorrect Username/Password "; } else { $ret = 'Something went wrong - ' . "https://{$dusername}:*********@{$api}/posts/add?&url={$link}&description={$desc}&extended={$ext}&tags={$tags}"; } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $ret . "ERR: " . print_r($cnt, true), $extInfo); } } if ($ret != 'OK') { if ($postID == '0') { echo $ret; } } else { if ($postID == '0') { echo 'OK - Message Posted, please see your Delicious Page'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } } if ($ret == 'OK') { return 200; } else { return $ret; } }
function nxs_doPublishToFL($postID, $options) { $ntCd = 'FL'; $ntCdL = 'fl'; $ntNm = 'Flickr'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">Flickr</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; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => '', 'announce' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); $message['tags'] = ''; if ($options['defImg'] != '') { $imgURL = $options['defImg']; } else { $imgURL = "http://direct.gtln.us/img/nxs/NXS-Lama.jpg"; } $message['imageURL'] = $imgURL; } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $isNoImg = false; $tags = ''; $options['msgFrmt'] = nsFormatMessage($options['msgFrmt'], $postID, $addParams); $options['msgTFrmt'] = nsFormatMessage($options['msgTFrmt'], $postID, $addParams); $tggs = array(); if ($options['inclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = '"' . implode('" "', $tggs) . '"'; } $imgURL = nxs_getPostImage($postID, 'full'); if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; $isNoImg = true; } $options = nxs_getURL($options, $postID); $urlToGo = $options['urlToUse']; $message = array('url' => $urlToGo, 'imageURL' => $imgURL, 'noImg' => $isNoImg, 'tags' => $tags); $lat = get_post_meta($postID, 'geo_latitude', true); $long = get_post_meta($postID, 'geo_longitude', true); if (!empty($lat) && !empty($long)) { $message['latitude'] = $lat; $message['longitude'] = $long; } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); } //## Actual Post $ntToPost = new nxs_class_SNAP_FL(); $ret = $ntToPost->doPostToNT($options, $message); //prr($ret); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doConnectToSU($u, $p) { global $nxs_suCkArray; $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/', false, false); // echo "LOGGIN"; $response = wp_remote_get('http://www.stumbleupon.com', array('headers' => $hdrsArr)); $p = substr($p, 0, 16); if (is_wp_error($response)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($response, true), ''); return "Connection ERROR. Please see log"; } $contents = $response['body']; $ckArr = $response['cookies']; //$response['body'] = htmlentities($response['body']); prr($response); die(); $flds = array(); $flds['username'] = $u; $flds['password'] = $p; $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com', true, true); $r2 = wp_remote_post('https://www.stumbleupon.com/api/v2_0/auth/login', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr)); //prr($flds); prr($ckArr); prr($r2); prr($ckArr); if (is_wp_error($r2)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($r2, true), ''); return "Connection ERROR (2). Please see log"; } if (stripos($r2['body'], ',"_error":"Invalid username') !== false) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($r2['body'], true), ''); return "Invalid username or password"; } if (stripos($r2['body'], '"_success":true') !== false) { $ckArr[] = new WP_Http_Cookie(array('name' => 'SU_REMEMBER', 'value' => urlencode(CutFromTo($r2['body'], '"},"su_remember":"', '"')))); $ckArr[] = new WP_Http_Cookie(array('name' => 'seulepage', 'value' => 'oui')); $nxs_suCkArray = $ckArr; return false; } else { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($r2, true), ''); return "Connection ERROR (3). Please see log"; } }
function nsFormatMessage($msg, $postID, $addURLParams = '', $lng = '') { global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen; $post = get_post($postID); $options = $plgn_NS_SNAutoPoster->nxs_options; if (!empty($options['brokenCntFilters'])) { $msg = str_replace('%FULLTITLE%', '%TITLE%', $msg); $msg = str_replace('%PANNOUNCE%', '%ANNOUNCE%', $msg); $msg = str_replace('%PANNOUNCER%', '%ANNOUNCER%', $msg); $msg = str_replace('%EXCERPT%', '%RAWEXCERPT%', $msg); $msg = str_replace('%FULLTEXT%', '%RAWTEXT%', $msg); } if (!empty($options['nxsHTSpace'])) { $htS = $options['nxsHTSpace']; } else { $htS = ''; } if (!empty($options['nxsHTSepar'])) { $htSep = $options['nxsHTSepar']; } else { $htSep = ', '; } $htSep = str_replace('_', ' ', $htSep); $htSep = str_replace('c', ',', $htSep); // if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams']; $msg = str_replace('%TEXT%', '%EXCERPT%', $msg); $msg = str_replace('%RAWEXTEXT%', '%RAWEXCERPT%', $msg); $msg = stripcslashes($msg); if (isset($ShownAds)) { $ShownAdsL = $ShownAds; } // $msg = htmlspecialchars(stripcslashes($msg)); $msg = nxs_doSpin($msg); if (preg_match('/%URL%/', $msg)) { $url = get_permalink($postID); if ($addURLParams != '') { $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams; } $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg); } if (preg_match('/%MYURL%/', $msg)) { $url = get_post_meta($postID, 'snap_MYURL', true); if ($addURLParams != '') { $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams; } $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%MYURL%", $url, $msg); } // prr($msg); if (preg_match('/%SURL%/', $msg)) { $url = get_permalink($postID); if ($addURLParams != '') { $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams; } $url = nxs_mkShortURL($url, $postID); $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%SURL%", $url, $msg); } if (preg_match('/%ORID%/', $msg)) { $msg = str_ireplace("%ORID%", $postID, $msg); } if (preg_match('/%IMG%/', $msg)) { $imgURL = nxs_getPostImage($postID); $msg = str_ireplace("%IMG%", $imgURL, $msg); } if (preg_match('/%TITLE%/', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $msg = str_ireplace("%TITLE%", $title, $msg); } if (preg_match('/%FULLTITLE%/', $msg)) { $title = apply_filters('the_title', nxs_doQTrans($post->post_title, $lng)); $msg = str_ireplace("%FULLTITLE%", $title, $msg); } if (preg_match('/%STITLE%/', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $title = substr($title, 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); } if (preg_match('/%AUTHORNAME%/', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $msg = str_ireplace("%AUTHORNAME%", $aun, $msg); } if (preg_match('/%AUTHORTWNAME%/', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('twitter', $aun); $msg = str_ireplace("%AUTHORTWNAME%", $aun, $msg); } if (preg_match('/%ANNOUNCE%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng); $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); if (stripos($postContent, '#####!--more--!#####') !== false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[0]; } else { $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', ''); } $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg); } if (preg_match('/%PANNOUNCE%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); if (stripos($postContent, '#####!--more--!#####') !== false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[0]; } else { $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', ''); } $msg = str_ireplace("%PANNOUNCE%", $postContent, $msg); } if (preg_match('/%ANNOUNCER%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng); $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); if (stripos($postContent, '#####!--more--!#####') !== false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[1]; } else { $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent); } $msg = str_ireplace("%ANNOUNCER%", $postContent, $msg); } if (preg_match('/%PANNOUNCER%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); if (stripos($postContent, '#####!--more--!#####') !== false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[1]; } else { $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent); } $msg = str_ireplace("%PANNOUNCER%", $postContent, $msg); } if (preg_match('/%EXCERPT%/', $msg)) { if ($post->post_excerpt != "") { $excerpt = strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)))); } else { $excerpt = nsTrnc(strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)))), 300, " ", "..."); } $msg = str_ireplace("%EXCERPT%", $excerpt, $msg); } if (preg_match('/%RAWEXCERPT%/', $msg)) { if ($post->post_excerpt != "") { $excerpt = strip_tags(strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng))); } else { $excerpt = nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "..."); } $msg = str_ireplace("%RAWEXCERPT%", $excerpt, $msg); } if (preg_match('/%RAWEXCERPTHTML%/', $msg)) { if ($post->post_excerpt != "") { $excerpt = strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng)); } else { $excerpt = nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "..."); } $msg = str_ireplace("%RAWEXCERPTHTML%", $excerpt, $msg); } if (preg_match('/%TAGS%/', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(', ', $tggs); $msg = str_ireplace("%TAGS%", $tags, $msg); } if (preg_match('/%CATS%/', $msg)) { $t = wp_get_post_categories($postID); $cats = array(); foreach ($t as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); } $ctts = implode(', ', $cats); $msg = str_ireplace("%CATS%", $ctts, $msg); } if (preg_match('/%HCATS%/', $msg)) { $t = wp_get_post_categories($postID); $cats = array(); foreach ($t as $c) { $cat = get_category($c); $cats[] = "#" . trim(str_replace(' ', $htS, str_replace(' ', ' ', trim(str_ireplace('&', '', str_ireplace('&', '', $cat->name)))))); } $ctts = implode($htSep, $cats); $msg = str_ireplace("%HCATS%", $ctts, $msg); } if (preg_match('/%HTAGS%/', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $tggs[] = "#" . trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); } $tags = implode($htSep, $tggs); $msg = str_ireplace("%HTAGS%", $tags, $msg); } if (preg_match('/%+CF-[a-zA-Z0-9-_]+%/', $msg)) { $msgA = explode('%CF', $msg); $mout = ''; foreach ($msgA as $mms) { if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = get_post_meta($postID, $mGr, true); $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms); } $mout .= $mms; } $msg = $mout; } $mm = array(); if (preg_match_all('/%H?CT-[a-zA-Z0-9_]+%/', $msg, $mm)) { $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $msg)); $mout = ''; $i = 0; foreach ($msgA as $mms) { if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) { $h = strpos($mm[0][$i], '%HCT-') !== false; $i++; $mGr = CutFromTo($mms, '-', '%'); $cfItem = wp_get_post_terms($postID, $mGr, array("fields" => "names")); if (is_nxs_error($cfItem)) { nxs_addToLogN('E', 'Error', 'MSG', '-=ERROR=- ' . $mGr . '|' . print_r($cfItem, true), ''); $mms = str_ireplace("-" . $mGr . "%", '', $mms); } else { $tggs = array(); foreach ($cfItem as $frmTag) { if ($h) { $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&', '', $frmTag))))))); } $tggs[] = ($h ? '#' : '') . $frmTag; } $cfItem = implode(' ', $tggs); $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms); } } $mout .= $mms; } $msg = $mout; } if (preg_match('/%FULLTEXT%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); $msg = str_ireplace("%FULLTEXT%", $postContent, $msg); } if (preg_match('/%RAWTEXT%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng); $msg = str_ireplace("%RAWTEXT%", $postContent, $msg); } if (preg_match('/%SITENAME%/', $msg)) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $msg = str_ireplace("%SITENAME%", $siteTitle, $msg); } if (isset($ShownAds)) { $ShownAds = $ShownAdsL; } // FIX for the quick-adsense plugin return trim($msg); }
function nxs_doPublishToLI($postID, $options) { global $nxs_gCookiesArr; $ntCd = 'LI'; $ntCdL = 'li'; $ntNm = 'LinkedIn'; //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000058">LinkedIn</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; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } // prr($options); if ($postID == '0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from ' . $blogTitle; $link = home_url(); $msg = 'Test Post from ' . $blogTitle . " " . $link; $isAttachLI = ''; $title = $blogTitle; } else { $post = get_post($postID); if (!$post) { return; } $liMsgFormat = $options['liMsgFormat']; $msg = nsFormatMessage($liMsgFormat, $postID); $msgT = nsFormatMessage($options['liMsgFormatT'], $postID); $link = get_permalink($postID); $isAttachLI = $options['liAttch']; $title = nsTrnc($post->post_title, 200); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; $msgT = nsTrnc($msgT, 200); if ($isAttachLI == '1') { $src = nxs_getPostImage($postID); $dsc = trim(apply_filters('the_content', $post->post_excerpt)); if ($dsc == '') { $dsc = apply_filters('the_content', $post->post_content); } $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nxs_html_to_utf8($dsc); $dsc = nsTrnc($dsc, 300); } $msg = nxs_html_to_utf8($msg); $msgT = nxs_html_to_utf8($msgT); if (function_exists("doConnectToLinkedIn") && $options['ulName'] != '' && $options['uPass'] != '') { $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']); if ($auth !== false) { die($auth); } $to = $options['uPage'] != '' ? $options['uPage'] : 'http://www.linkedin.com/home'; $lnk = array(); $msg = str_ireplace(' ', ' ', $msg); $msg = nsTrnc(strip_tags($msg), 700); if ($postID == '0') { $lnk['title'] = get_bloginfo('name'); $lnk['desc'] = get_bloginfo('description'); $lnk['url'] = home_url(); } else { if ($isAttachLI == '1') { $lnk['title'] = nsTrnc(strip_tags($post->post_title), 200); $lnk['postTitle'] = $msgT; $lnk['desc'] = $dsc; $lnk['url'] = get_permalink($postID); $lnk['img'] = $src; } } //prr($msg); $ret = doPostToLinkedIn($msg, $lnk, $to); $liPostID = $options['uPage']; } else { require_once 'apis/liOAuth.php'; $linkedin = new nsx_LinkedIn($options['liAPIKey'], $options['liAPISec']); $linkedin->oauth_verifier = $options['liOAuthVerifier']; $linkedin->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1); $linkedin->access_token = new nsx_trOAuthConsumer($options['liAccessToken'], $options['liAccessTokenSecret'], 1); $msg = nsTrnc($msg, 700); if ($options['grpID'] != '') { try { // prr($msgT); prr($msg); prr($options['grpID']); prr($src); prr($dsc); $purl = get_permalink($postID); prr($purl); if ($isAttachLI == '1') { $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], get_permalink($postID), $src, $dsc); } else { $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']); } $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID']; } catch (Exception $o) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . "Linkedin Status couldn't be updated! - " . print_r($o, true)); $ret = "ERROR:" . print_r($o, true); } } else { try { if ($isAttachLI == '1') { $ret = $linkedin->postShare($msg, nsTrnc($post->post_title, 200), get_permalink($postID), $src, $dsc); } else { $ret = $linkedin->postShare($msg); } } catch (Exception $o) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . "<br/>Linkedin Status couldn't be updated! - " . print_r($o, true)); $ret = "ERROR:" . print_r($o, true); } } //$liPostID = $linkedin->getCurrentShare(); prr($liPostID); if ($liPostID == '') { $liPostID = $options['liUserInfo']; } } if (stripos($ret, 'update-url') !== false) { $liPostID = CutFromTo($ret, '<update-url>', '</update-url>'); $ret = '201'; } if ($ret != '201') { if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { if ($postID == '0') { echo 'OK - Linkedin status updated successfully'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else { nxs_metaMarkAsPosted($postID, 'LI', $options['ii'], array('isPosted' => '1', 'pgID' => $liPostID, 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } if ($ret == '201') { return true; } else { return 'Something Wrong'; } }