예제 #1
0
파일: li.php 프로젝트: JalpMi/v2contact
 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('&nbsp;', ' ', $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';
     }
 }
예제 #2
0
 function doPostToNT($options, $message)
 {
     $badOut = array('postID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     $liPostID = '';
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if ((!isset($options['ulName']) || trim($options['uPass']) == '') && empty($options['liOAuthVerifier'])) {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     if (empty($options['liMsgFormatT'])) {
         $options['liMsgFormatT'] = '%TITLE%';
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['liMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['liMsgFormatT'], $message);
     }
     if ($options['liAttch'] == '1') {
         if (isset($message['imageURL'])) {
             $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
         } else {
             $imgURL = '';
         }
         if (preg_match("/noImg.\\.png/i", $imgURL)) {
             $imgURL = '';
         }
         if (!empty($message['urlDescr'])) {
             $dsc = $message['urlDescr'];
         } else {
             $dsc = $msg;
         }
         $dsc = strip_tags($dsc);
         $dsc = nxs_decodeEntitiesFull($dsc);
         $dsc = nxs_html_to_utf8($dsc);
         $dsc = nsTrnc($dsc, 300);
     }
     $msg = strip_tags($msg);
     $msg = nxs_html_to_utf8($msg);
     $msgT = nxs_html_to_utf8($msgT);
     $urlToGo = $message['url'];
     if (function_exists("doConnectToLinkedIn") && $options['ulName'] != '' && $options['uPass'] != '') {
         $dusername = $options['ulName'];
         $pass = substr($options['uPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['uPass'], 5)) : $options['uPass'];
         // ??? Do we need that??????
         $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']);
         if ($auth != false) {
             $badOut['Error'] .= "|Auth Error - " . $auth;
             return $badOut;
         }
         $to = $options['uPage'] != '' ? $options['uPage'] : 'http://www.linkedin.com/home';
         $lnk = array();
         $msg = str_ireplace('&nbsp;', ' ', $msg);
         $msg = nsTrnc(strip_tags($msg), 700);
         if ($options['liAttch'] == '1') {
             $lnk['title'] = $message['urlTitle'];
             $lnk['postTitle'] = $msgT;
             $lnk['desc'] = $message['urlDescr'];
             $lnk['url'] = $urlToGo;
             $lnk['img'] = $imgURL;
         }
         $ret = doPostToLinkedIn($msg, $lnk, $to);
         $liPostID = $options['uPage'];
     } else {
         if ($options['isV2']) {
             //## V2
             if ($options['grpID'] != '') {
                 try {
                     if ($msgT == '') {
                         $msgT = ' ';
                     }
                     if ($options['liAttch'] == '1') {
                         $ret = $this->postToGroup($options['liAccessToken'], $msg, $msgT, $options['grpID'], str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $this->postToGroup($options['liAccessToken'], $msg, $msgT, $options['grpID']);
                     }
                     $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID'];
                 } catch (Exception $o) {
                     $ret = "ERROR: " . print_r($o, true);
                 }
             } else {
                 //echo $msg ."|". nsTrnc($msgT, 200) ."|". $urlToGo ."|". $imgURL ."|". $dsc;
                 if ($options['liAttch'] == '1') {
                     $ret = $this->postShare($options['liAccessToken'], $msg, nsTrnc($msgT, 200), str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                 } else {
                     $ret = $this->postShare($options['liAccessToken'], $msg);
                 }
             }
         } else {
             //## V1
             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);
             //prr($urlToGo);  $urlToGo = urlencode($urlToGo);   prr($urlToGo); die();
             if ($options['grpID'] != '') {
                 try {
                     if ($msgT == '') {
                         $msgT = ' ';
                     }
                     if ($options['liAttch'] == '1') {
                         $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']);
                     }
                     $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID'];
                     if ($ret == '201') {
                         $ret = array('updateUrl' => $liPostID);
                     }
                 } catch (Exception $o) {
                     $ret = "ERROR: " . print_r($o, true);
                 }
             } else {
                 //echo $msg ."|". nsTrnc($msgT, 200) ."|". $urlToGo ."|". $imgURL ."|". $dsc;
                 try {
                     if ($options['liAttch'] == '1') {
                         $ret = $linkedin->postShare($msg, nsTrnc($msgT, 200), str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $linkedin->postShare($msg);
                     }
                 } catch (Exception $o) {
                     $ret = "ERROR:" . print_r($o, true);
                 }
             }
         }
         if ($liPostID == '') {
             $liPostID = $options['liUserInfo'];
         }
     }
     // prr($ret);
     if (!is_array($ret) && stripos($ret, '<update-url>') !== false) {
         $rurl = CutFromTo($ret, '<update-url>', '</update-url>');
         $ret = array('updateUrl' => $rurl);
     }
     if (is_array($ret) && !empty($ret['updateUrl'])) {
         if (stripos($ret['updateUrl'], 'topic=') !== false) {
             $liPostID = CutFromTo($ret['updateUrl'], 'topic=', '&');
         } else {
             $liPostID = '';
         }
         return array('isPosted' => '1', 'postID' => $liPostID, 'postURL' => $ret['updateUrl'], 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($ret, true);
     }
     return $badOut;
 }