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_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; }