function nxs_doPublishToSU($postID, $options) { global $nxs_suCkArray; $ntCd = 'SU'; $ntCdL = 'su'; $ntNm = 'StumbleUpon'; //$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_doPublishToSU', 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">StumbleUpon</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['reset'] != '1' && $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; } } $suCat = $options['suCat']; // if (function_exists("get_post_thumbnail_id") ){ $src = wp_get_attachment_image_src(get_post_thumbnail_id($postID), 'thumbnail'); $src = $src[0];} $email = $options['suUName']; $pass = substr($options['suPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['suPass'], 5)) : $options['suPass']; if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Link from ' . $link; } else { $post = get_post($postID); if (!$post) { return; } $msgFormat = $options['suMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $link = get_permalink($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $dusername = $options['suUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500)); $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($options['suInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = urlencode(implode(',', $tggs)); $tags = str_replace(' ', '+', $tags); } else { $tags = ''; } if (isset($options['suSvC'])) { $nxs_suCkArray = maybe_unserialize($options['suSvC']); } $loginError = true; if (is_array($nxs_suCkArray)) { $loginError = nxs_doCheckSU(); } if ($loginError != false) { $loginError = nxs_doConnectToSU($email, $pass); } if (serialize($nxs_suCkArray) != $options['suSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['su'][$options['ii']]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['su'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['su'][$ii]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } } } } if ($loginError !== false) { if ($postID == '0') { prr($loginError); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true) . " - BAD USER/PASS", $extInfo); return " -= BAD USER/PASS =- "; } $ret = nxs_doPostToSU($msg, $link, $options['suCat'], $tags, $options['nsfw'] == '1'); // $extInfo .= "++".$msg."|".$link."|".$options['suCat']."|".$tags."|".$options['nsfw']; if ($ret == 'OK') { $ret = array("code" => "OK", "post_id" => ''); } if (!is_array($ret) && $ret != 'OK') { if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } elseif ($ret['code'] == 'OK') { if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo ' OK - Message Posted, please see your StumbleUpon Page '; } else { nxs_metaMarkAsPosted($postID, 'SU', $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; } } else { if ($options['reset'] == '1') { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR TRY #2=- ' . print_r($ret, true), $extInfo . $options['reset']); return "ERROR = " . print_r($ret, true); } else { $options['reset'] = '1'; $options['suSvC'] = ''; return nxs_doPublishToSU($postID, $options); } } }
function nxs_rePostToSU_ajax() { check_ajax_referer('nxsSsPageWPN'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster'); foreach ($options['su'] as $ii => $two) { if ($ii == $_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) { $gppo = get_post_meta($postID, 'snapSU', true); $gppo = maybe_unserialize($gppo); // prr($gppo); if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])) { $ntClInst = new nxs_snapClassSU(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); } $result = nxs_doPublishToSU($postID, $two); if ($result == 200) { die("Successfully sent your post to StumbleUpon."); } else { die($result); } } } }