Exemplo n.º 1
0
 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('&', '&amp;', $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;
     }
 }
Exemplo n.º 2
0
 function doPostToNT($options, $message)
 {
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['wpUName']) || trim($options['wpPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $pass = substr($options['wpPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['wpPass'], 5)) : $options['wpPass'];
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['wpMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['wpMsgTFormat'], $message);
     }
     if (isset($message['imageURL'])) {
         $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
     } else {
         $imgURL = '';
     }
     $link = urlencode($message['url']);
     $ext = substr($msg, 0, 1000);
     //## Fix missing xmlrpc.php
     if (substr($options['wpURL'], -1) == '/') {
         $options['wpURL'] = substr($options['wpURL'], 0, -1);
     }
     if (substr($options['wpURL'], -10) != 'xmlrpc.php') {
         $options['wpURL'] .= "/xmlrpc.php";
     }
     //## 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-' . $message['orID'] . '.jpg', 'type' => 'image/jpg', 'bits' => new NXS_XMLRPC_Base64($filedata), true);
         $status = $nxsToWPclient->query('metaWeblog.newMediaObject', $message['orID'], $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();
     if (!empty($rwpOpt['software_version'])) {
         $rwpOpt = $rwpOpt['software_version']['value'];
         $rwpOpt = floatval($rwpOpt);
     } else {
         $rwpOpt = 0;
     }
     //prr($rwpOpt);prr($nxsToWPclient);
     //## MAIN Post
     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' => $ext, 'mt_allow_comments' => 1, 'mt_allow_pings' => 1, 'post_type' => 'post', 'mt_keywords' => $message['tags'], 'categories' => $message['cats'], 'custom_fields' => '');
                 $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' => $message['tags'], 'categories' => $message['cats'], 'custom_fields' => '');
                 $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') {
         $badOut['Error'] .= '-=ERROR=- ' . print_r($ret, true);
     } else {
         $wpURL = str_ireplace('/xmlrpc.php', '', $options['wpURL']);
         if (substr($wpURL, -1) == '/') {
             $wpURL = substr($wpURL, 0, -1);
         }
         $wpURL .= '/?p=' . $pid;
         return array('postID' => $pid, 'isPosted' => 1, 'postURL' => $wpURL, 'pDate' => date('Y-m-d H:i:s'));
     }
     return $badOut;
 }
Exemplo n.º 3
0
 function nxs_doPublishToLJ($postID, $options)
 {
     $ntCd = 'LJ';
     $ntCdL = 'lj';
     $ntNm = 'LJ Based Blog';
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLJ',  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:#2097EE">LJ</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;
         }
     }
     $imgURL = nxs_getPostImage($postID);
     $email = $options['ljUName'];
     $pass = substr($options['ljPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ljPass'], 5)) : $options['ljPass'];
     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['ljMsgFormat'];
         $msg = nsFormatMessage($msgFormat, $postID);
         $msgTFormat = $options['ljMsgTFormat'];
         $msgT = nsFormatMessage($msgTFormat, $postID);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     //prr($msg); prr($msgFormat);
     $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
     //## Post
     require_once 'apis/xmlrpc-client.php';
     if ($options['ljSrv'] == 'DW') {
         $server = 'dreamwidth.org';
     } else {
         $server = 'livejournal.com';
     }
     $nxsToLJclient = new NXS_XMLRPC_Client('http://www.' . $server . '/interface/xmlrpc');
     $nxsToLJclient->debug = false;
     $date = time();
     $year = date("Y", $date);
     $mon = date("m", $date);
     $day = date("d", $date);
     $hour = date("G", $date);
     $min = date("i", $date);
     $nxsToLJContent = array("username" => $options['ljUName'], "password" => $pass, "event" => $msg, "subject" => $msgT, "lineendings" => "unix", "year" => $year, "mon" => $mon, "day" => $day, "hour" => $hour, "min" => $min, "ver" => 2);
     if ($options['commID'] != '') {
         $nxsToLJContent["usejournal"] = $options['commID'];
     }
     if ($options['inclTags'] == '1') {
         $t = wp_get_post_tags($postID);
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = $tagA->name;
         }
         $tags = implode(',', $tggs);
         $nxsToLJContent['props'] = array('taglist' => $tags);
     }
     if (!$nxsToLJclient->query('LJ.XMLRPC.postevent', $nxsToLJContent)) {
         $ret = 'Something went wrong - ' . $nxsToLJclient->getErrorCode() . ' : ' . $nxsToLJclient->getErrorMessage();
     } else {
         $ret = 'OK';
     }
     $pid = $nxsToLJclient->getResponse();
     if (is_array($pid)) {
         $pid = $pid['url'];
     } else {
         $ret = 'Something went wrong - NO PID ' . print_r($pid, true);
     }
     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 LiveJournal';
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
         } else {
             nxs_metaMarkAsPosted($postID, 'LJ', $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;
     }
 }