示例#1
0
 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 doPostToGooglePlus2($msg, $lnk = '', $pageID = '') {
		$rnds = rndString ( 13 );
		$pageID = trim ( $pageID );
		if (function_exists ( 'nxs_decodeEntitiesFull' ))
			$msg = nxs_decodeEntitiesFull ( $msg );
		if (function_exists ( 'nxs_html_to_utf8' ))
			$msg = nxs_html_to_utf8 ( $msg );
		$msg = str_replace ( '<br>', "_NXSZZNXS_5Cn", $msg );
		$msg = str_replace ( '<br/>', "_NXSZZNXS_5Cn", $msg );
		$msg = str_replace ( '<br />', "_NXSZZNXS_5Cn", $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", "_NXSZZNXS_5Cn", $msg );
		$msg = urlencode ( strip_tags ( $msg ) );
		$msg = str_replace ( "_NXSZZNXS_5Cn", "%5Cn", $msg );
		$msg = str_replace ( '+', '%20', $msg );
		$msg = str_replace ( '%0A%0A', '%20', $msg );
		$msg = str_replace ( '%0A', '', $msg );
		$msg = str_replace ( '%0D', '%5C', $msg );
		if (trim ( $lnk ['img'] ) != '') {
			$img = getCurlPageX ( $lnk ['img'], '', false );
			if ($img ['http_code'] == '200')
				$lnk ['imgType'] = urlencode ( $img ['content_type'] );
			else
				$lnk ['img'] = '';
		}
		$lnk ['img'] = urlencode ( $lnk ['img'] );
		$lnk ['link'] = urlencode ( $lnk ['link'] );
		$lnk ['fav'] = urlencode ( $lnk ['fav'] );
		$lnk ['domain'] = urlencode ( $lnk ['domain'] );
		
		$lnk ['title'] = (str_replace ( Array (
				"\n",
				"\r" 
		), ' ', $lnk ['title'] ));
		// $lnk['title'] = mysql_real_escape_string($lnk['title']); $lnk['title'] = mysql_real_escape_string($lnk['title']); $lnk['title'] = mysql_real_escape_string($lnk['title']);
		$lnk ['title'] = rawurlencode ( addslashes ( $lnk ['title'] ) ); // ## Yes mysql_real_escape_string has to be called 3 times. The message should have 7 escape slashes /. Why G? Why?
		
		$lnk ['txt'] = (str_replace ( Array (
				"\n",
				"\r" 
		), ' ', $lnk ['txt'] ));
		// $lnk['txt'] = mysql_real_escape_string($lnk['txt']); $lnk['txt'] = mysql_real_escape_string($lnk['txt']); $lnk['txt'] = mysql_real_escape_string($lnk['txt']);
		$lnk ['txt'] = rawurlencode ( addslashes ( $lnk ['txt'] ) ); // ## Yes mysql_real_escape_string has to be called 3 times. The message should have 7 escape slashes /. Why G? Why?
		$refPage = 'https://plus.google.com/b/' . $pageID . '/'; // prr($lnk);
		if ($pageID != '') { // ## Posting to Page
			$gpp = 'https://plus.google.com/b/' . $pageID . '/_/sharebox/post/?spam=20&_reqid=647379&rt=j';
			$contents = getCurlPageX ( $refPage, '', false ); // prr($contents); die();
		} else { // ## Posting to Profile
			$gpp = 'https://plus.google.com/_/sharebox/post/?spam=20&_reqid=1203718&rt=j';
			$contents = getCurlPageX ( 'https://plus.google.com/', '', false );
			$pageID = CutFromTo ( $contents ['content'], "key: '2'", "]" );
			$pageID = CutFromTo ( $pageID, 'https://plus.google.com/', '"' );
		} // echo $lnk['txt'];
		if ($contents ['http_code'] == '400')
			return "Invalid Sharebox Page. Something is wrong, please contact support";
		$at = CutFromTo ( $contents ['content'], 'csi.gstatic.com/csi","', '",' ); // prr($lnk);
		                                                                       
		// ## URL
		if (trim ( $lnk ['link'] ) != '')
			$spar = "f.req=%5B%22" . $msg . "%22%2C%22oz%" . $pageID . "." . $rnds . ".0%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5C%22%5Bnull%2Cnull%2Cnull%2C%5C%5C%5C%22" . $lnk ['title'] . "%5C%5C%5C%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22NextScripts%5C%5C%5C%22%2C%5C%5C%5C%22owner%5C%5C%5C%22%5D%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5C%5C%5C%22" . str_replace ( '%5C', '%5C%5C%5C%5C%5C%5C%5C', $lnk ['txt'] ) . "%5C%5C%5C%22%2Cnull%2Cnull%2C%5Bnull%2C%5C%5C%5C%22" . $lnk ['link'] . "%5C%5C%5C%22%2Cnull%2C%5C%5C%5C%22text%2Fhtml%5C%5C%5C%22%2C%5C%5C%5C%22document%5C%5C%5C%22%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22" . $lnk ['fav'] . "%5C%5C%5C%22%2Cnull%2Cnull%5D%2C%5Bnull%2C%5C%5C%5C%22" . $lnk ['fav'] . "%5C%5C%5C%22%2Cnull%2Cnull%5D%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22%5C%5C%5C%22%2C%5C%5C%5C%22http%3A%2F%2Fgoogle.com%2Fprofiles%2Fmedia%2Fprovider%5C%5C%5C%22%2C%5C%5C%5C%22%5C%5C%5C%22%5D%5D%5D%5C%22%2C%5C%22%5Bnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5Bnull%2C%5C%5C%5C%22" . $lnk ['img'] . "%5C%5C%5C%22%5D%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5Bnull%2C%5C%5C%5C%22" . $lnk ['link'] . "%5C%5C%5C%22%2Cnull%2C%5C%5C%5C%22" . $lnk ['imgType'] . "%5C%5C%5C%22%2C%5C%5C%5C%22photo%5C%5C%5C%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C200%2C150%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22" . $lnk ['img'] . "%5C%5C%5C%22%2Cnull%2Cnull%5D%2C%5Bnull%2C%5C%5C%5C%22" . $lnk ['img'] . "%5C%5C%5C%22%2Cnull%2Cnull%5D%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22images%5C%5C%5C%22%2C%5C%5C%5C%22http%3A%2F%2Fgoogle.com%2Fprofiles%2Fmedia%2Fprovider%5C%5C%5C%22%2C%5C%5C%5C%22%5C%5C%5C%22%5D%5D%5D%5C%22%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cfalse%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B35%2C1%2C0%5D%2C%22" . $lnk ['link'] . "%22%2Cnull%2C%7B%2229646191%22%3A%5B%22" . $lnk ['link'] . "%22%2C%22" . $lnk ['img'] . "%22%2C%22" . $lnk ['title'] . "%22%2C%22" . $lnk ['txt'] . "%22%2Cnull%2C%5B%22%2F%2Fimages1-focus-opensocial.googleusercontent.com%2Fgadgets%2Fproxy%3Furl%3D" . $lnk ['img'] . "%26container%3Dfocus%26gadget%3Da%26rewriteMime%3Dimage%2F*%26refresh%3D31536000%26resize_h%3D150%26resize_w%3D150%26no_expand%3D1%22%2C150%2C150%5D%2C%22" . $lnk ['fav'] . "%22%2C%5B%5B%5B5%2C0%5D%2Cnull%2Cnull%2C%7B%2227219582%22%3A%5Bnull%2Cnull%2Cnull%2C%22NextScripts%22%5D%7D%5D%5D%5D%7D%5D%2Cnull%2C%5B%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%5D%5D&at=" . $at . "&";
			
			// ## Image
		elseif (trim ( $lnk ['img'] ) != '') {
			$remImgURL = urldecode ( $lnk ['img'] );
			$urlParced = pathinfo ( $remImgURL );
			$remImgURLFilename = $urlParced ['basename'];
			$imgData = getCurlPageX ( $remImgURL, '', false );
			$imgdSize = $imgData ['download_content_length'];
			$imgData = $imgData ['content'];
			$iflds = '{"protocolVersion":"0.8","createSessionRequest":{"fields":[{"external":{"name":"file","filename":"' . $remImgURLFilename . '","put":{},"size":' . $imgdSize . '}},{"inlined":{"name":"batchid","content":"1350593121640","contentType":"text/plain"}},{"inlined":{"name":"client","content":"sharebox","contentType":"text/plain"}},{"inlined":{"name":"disable_asbe_notification","content":"true","contentType":"text/plain"}},{"inlined":{"name":"streamid","content":"updates","contentType":"text/plain"}},{"inlined":{"name":"use_upload_size_pref","content":"true","contentType":"text/plain"}},{"inlined":{"name":"album_abs_position","content":"0","contentType":"text/plain"}}]}}';
			$imgReqCnt = getCurlPageX ( 'https://plus.google.com/_/upload/photos/resumable?authuser=0', '', false, $iflds );
			$gUplURL = str_replace ( '\u0026', '&', CutFromTo ( $imgReqCnt ['content'], 'putInfo":{"url":"', '"' ) );
			$gUplID = CutFromTo ( $imgReqCnt ['content'], 'upload_id":"', '"' );
			$imgUplCnt = getCurlPageX ( $gUplURL, '', true, $imgData );
			$imgUplCnt = json_decode ( $imgUplCnt, true );
			$infoArray = $imgUplCnt ['sessionStatus'] ['additionalInfo'] ['uploader_service.GoogleRupioAdditionalInfo'] ['completionInfo'] ['customerSpecificInfo'];
			$albumID = $infoArray ['albumid'];
			$photoid = $infoArray ['photoid'];
			$imgUrl = urlencode ( $infoArray ['url'] );
			$imgTitie = $infoArray ['title'];
			$width = $infoArray ['width'];
			$height = $infoArray ['height'];
			$userID = $infoArray ['username'];
			$intID = $infoArray ['albumPageUrl'];
			$intID = str_replace ( 'https://picasaweb.google.com/', '', $intID );
			$intID = str_replace ( $userID, '', $intID );
			$intID = str_replace ( '/', '', $intID );
			
			$spar = "f.req=%5B%22" . $msg . "%22%2C%22oz%3A" . $pageID . "." . $rnds . "%22%2Cnull%2C%22" . $albumID . "%22%2Cnull%2Cnull%2C%22%5B%5C%22%5Bnull%2Cnull%2Cnull%2C%5C%5C%5C%22%5C%5C%5C%22%2Cnull%2C%5Bnull%2C%5C%5C%5C%22" . $imgUrl . "%5C%5C%5C%22%2C" . $height . "%2C" . $width . "%5D%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5C%5C%5C%22" . $imgTitie . "%5C%5C%5C%22%2Cnull%2Cnull%2C%5Bnull%2C%5C%5C%5C%22https%3A%2F%2Fpicasaweb.google.com%2F" . $userID . "%2F" . $intID . "%23" . $photoid . "%5C%5C%5C%22%2Cnull%2C%5C%5C%5C%22image%2Fjpeg%5C%5C%5C%22%2C%5C%5C%5C%22image%5C%5C%5C%22%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22" . $imgUrl . "%5C%5C%5C%22%2C120%2C165.51724137931035%5D%2C%5Bnull%2C%5C%5C%5C%22" . $imgUrl . "%5C%5C%5C%22%2C120%2C165.51724137931035%5D%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5Bnull%2C%5C%5C%5C%22picasa%5C%5C%5C%22%2C%5C%5C%5C%22http%3A%2F%2Fgoogle.com%2Fprofiles%2Fmedia%2Fprovider%5C%5C%5C%22%2C%5C%5C%5C%22%5C%5C%5C%22%5D%2C%5Bnull%2C%5C%5C%5C%22albumid%3D" . $albumID . "%26photoid%3D" . $photoid . "%5C%5C%5C%22%2C%5C%5C%5C%22http%3A%2F%2Fgoogle.com%2Fprofiles%2Fmedia%2Fonepick_media_id%5C%5C%5C%22%2C%5C%5C%5C%22%5C%5C%5C%22%5D%5D%5D%5C%22%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2C%22" . $userID . "%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Ctrue%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B249%2C18%2C1%2C0%5D%2Cnull%2Cnull%2Cnull%2C%7B%2227639957%22%3A%5B%5B%22https%3A%2F%2Fpicasaweb.google.com%2F" . $userID . "%2F" . $intID . "%23" . $photoid . "%22%2C%22" . $imgTitie . "%22%2C%22%22%2C%22" . $imgUrl . "%22%2Cnull%2C%5B%22" . $imgUrl . "%22%2C497%2C373%2Cnull%2Cnull%2Cnull%2Cnull%2C145%2C%5B1%2C%22" . $imgUrl . "%22%5D%5D%2Cnull%2C%22200%22%2C%22" . $height . "%22%2C" . $width . "%2C145%2Cnull%2C%22picasaweb.google.com%22%5D%2C%22" . $userID . "%22%2Cnull%2C%22" . $photoid . "%22%2Cnull%2Cnull%2C%22" . $imgUrl . "%22%2Cnull%2Cnull%2C%22https%3A%2F%2Fpicasaweb.google.com%2F" . $userID . "%2F" . $intID . "%23" . $photoid . "%22%2Cnull%2C%22albumid%3D" . $albumID . "%26photoid%3D" . $photoid . "%22%5D%7D%5D%2Cnull%2C%5B%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%2Cnull%5D%5D&at=" . $at . "&"; // echo $spar;
		} 		

		// ## Just Message
		else
			$spar = "f.req=%5B%22" . $msg . "%22%2C%22oz%3A" . $pageID . "." . $rnds . "%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5D%22%2Cnull%2C%22%7B%5C%22aclEntries%5C%22%3A%5B%7B%5C%22scope%5C%22%3A%7B%5C%22scopeType%5C%22%3A%5C%22anyone%5C%22%2C%5C%22name%5C%22%3A%5C%22Anyone%5C%22%2C%5C%22id%5C%22%3A%5C%22anyone%5C%22%2C%5C%22me%5C%22%3Atrue%2C%5C%22requiresKey%5C%22%3Afalse%7D%2C%5C%22role%5C%22%3A20%7D%2C%7B%5C%22scope%5C%22%3A%7B%5C%22scopeType%5C%22%3A%5C%22anyone%5C%22%2C%5C%22name%5C%22%3A%5C%22Anyone%5C%22%2C%5C%22id%5C%22%3A%5C%22anyone%5C%22%2C%5C%22me%5C%22%3Atrue%2C%5C%22requiresKey%5C%22%3Afalse%7D%2C%5C%22role%5C%22%3A60%7D%5D%7D%22%2Ctrue%2C%5B%5D%2Cfalse%2Cfalse%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D&at=" . $at . "&";
		
		$spar = str_ireplace ( '+', '%20', $spar );
		$spar = str_ireplace ( ':', '%3A', $spar );
		
		$contents = getCurlPageX ( $gpp, $refPage, false, $spar ); // prr($contents);
		if ($contents ['http_code'] == '403')
			return "Error: You are not authorized to publish to this page";
		if ($contents ['http_code'] == '404')
			return "Error: Page you are posting is not found.<br/><br/> If you have entered your page ID as 117008619877691455570/117008619877691455570, please remove the second copy. It should be one number only - 117008619877691455570";
		if ($contents ['http_code'] == '400')
			return "Error: Something is wrong, please contact support";
		if ($contents ['http_code'] == '200')
			return "OK";
	}
示例#3
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';
     }
 }
 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 (empty($options['postType'])) {
         if ((int) $options['liAttch'] == 1 || $isNew) {
             $options['postType'] = 'A';
         }
     }
     if ($options['postType'] == 'A' || $options['postType'] == 'I') {
         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'] : 'https://www.linkedin.com/home';
         $lnk = array();
         $msg = str_ireplace('&nbsp;', ' ', $msg);
         $msg = nsTrnc(strip_tags($msg), 700);
         $lnk['postTitle'] = $msgT;
         if ($options['postType'] == 'A') {
             $lnk['title'] = $message['urlTitle'];
             $lnk['desc'] = $message['urlDescr'];
             $lnk['url'] = $urlToGo;
             $lnk['img'] = $imgURL;
             $lnk['postType'] = 'A';
         }
         if ($options['postType'] == 'I') {
             $lnk['title'] = '';
             $lnk['desc'] = '';
             $lnk['url'] = $imgURL;
             $lnk['img'] = $imgURL;
             $lnk['postType'] = 'I';
             $lnk['postTitle'] = $msgT;
         }
         if ($options['postType'] == 'T') {
             $lnk['postType'] = 'T';
         }
         global $nxs_gCookiesArr;
         $li = new nxsAPI_LI();
         $li->debug = false;
         if (!empty($nxs_gCookiesArr)) {
             $li->ck = $nxs_gCookiesArr;
         }
         $ret = $li->post($msg, $lnk, $to);
         if (is_array($ret) && !empty($ret['isPosted'])) {
             return $ret;
         }
         $liPostID = $options['uPage'];
     } else {
         if (!empty($options['isV2'])) {
             //## V2
             if ($options['grpID'] != '') {
                 try {
                     if ($msgT == '') {
                         $msgT = ' ';
                     }
                     if ($options['postType'] == 'A') {
                         $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['postType'] == 'A') {
                     $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['postType'] == 'A') {
                         $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['postType'] == 'A') {
                         $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;
 }
 function postGP($msg, $lnk='', $pageID='', $commPageID='', $commPageCatID=''){ $rnds = rndString(13); $sslverify = false; $ck = $this->ck; $hdrsArr = $this->headers('');
   $pageID = trim($pageID); $commPageID = trim($commPageID); $ownerID = ''; $bigCode = '';  $isPostToPage = $pageID!=''; $isPostToComm = $commPageID!='';   
   if (function_exists('nxs_decodeEntitiesFull')) $msg = nxs_decodeEntitiesFull($msg); if (function_exists('nxs_html_to_utf8')) $msg = nxs_html_to_utf8($msg);
   $msg = str_replace('<br>', "_NXSZZNXS_5Cn", $msg); $msg = str_replace('<br/>', "_NXSZZNXS_5Cn", $msg); $msg = str_replace('<br />', "_NXSZZNXS_5Cn", $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", "_NXSZZNXS_5Cn", $msg);  $msg = str_replace('"', '\"', $msg); 
   $msg = urlencode(strip_tags($msg)); $msg = str_replace("_NXSZZNXS_5Cn", "%5Cn", $msg);  
   $msg = str_replace('+', '%20', $msg); $msg = str_replace('%0A%0A', '%20', $msg); $msg = str_replace('%0A', '', $msg); $msg = str_replace('%0D', '%5C', $msg);
   if (!empty($lnk) && !is_array($lnk)) $lnk = $this->urlInfo($lnk);
   if ($lnk=='') $lnk = array('img'=>'', 'link'=>'', 'fav'=>'', 'domain'=>'', 'title'=>'', 'txt'=>'');
   if (!isset($lnk['link']) && !empty($lnk['img'])) { $hdrsArr = $this->headers(''); unset($hdrsArr['Connection']); $rep = nxs_remote_get($lnk['img'], array('headers' => $hdrsArr, 'httpversion' => '1.1', 'sslverify'=>$sslverify)); 
     if (is_nxs_error($rep)) $lnk['img']=''; elseif ($rep['response']['code']=='200' && !empty($rep['headers']['content-type']) && stripos($rep['headers']['content-type'],'text/html')===false) {    
       if (!empty($rep['headers']['content-length']))  $imgdSize = $rep['headers']['content-length'];
       if ((empty($imgdSize) || $imgdSize == '-1') && !empty($rep['headers']['size_download'])) $imgdSize = $rep['headers']['size_download'];
       if ((empty($imgdSize) || $imgdSize == '-1')){ $ch = curl_init($lnk['img']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE);
         $data = curl_exec($ch);  $imgdSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); curl_close($ch);  
       } 
       if ((empty($imgdSize) || $imgdSize == '-1')) $imgdSize =  strlen($rep['body']);
       $urlParced = pathinfo($lnk['img']); $remImgURL = $lnk['img']; $remImgURLFilename = nxs_mkImgNm(nxs_clFN($urlParced['basename']), $rep['headers']['content-type']);  $imgData = $rep['body'];        
     } else $lnk['img']=''; 
   }
   if (isset($lnk['img'])) $lnk['img'] = urlencode($lnk['img']); if (isset($lnk['link'])) $lnk['link'] = urlencode($lnk['link']); 
   if (isset($lnk['fav'])) $lnk['fav'] = urlencode($lnk['fav']); if (isset($lnk['domain'])) $lnk['domain'] = urlencode($lnk['domain']);      
   if (isset($lnk['title'])) { $lnk['title'] = (str_replace(Array("\n", "\r"), ' ', $lnk['title']));  $lnk['title'] = rawurlencode(addslashes($lnk['title'])); }    
   if (isset($lnk['txt'])) { $lnk['txt'] = (str_replace(Array("\n", "\r"), ' ', $lnk['txt'])); $lnk['txt'] = rawurlencode( addslashes($lnk['txt'])); }
   $refPage = 'https://plus.google.com/b/'.$pageID.'/'; $rndReqID = rand(1203718, 647379); $rndSpamID = rand(4, 52);
   if ($commPageID!='') { //## Posting to Community      
     if ($pageID!='') $pgIDT = 'u/0/b/'.$pageID.'/'; else $pgIDT = '';
     $gpp = 'https://plus.google.com/'.$pgIDT.'_/sharebox/post/?spam='.$rndSpamID.'&_reqid='.$rndReqID.'&rt=j';            
     $rep = nxs_remote_get('https://plus.google.com/communities/'.$commPageID, array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify)); 
     if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR commPageID"; return $badOut; } /* if (!empty($rep['cookies'])) $ck = $rep['cookies']; */ $contents = $rep['body'];
     if (trim($commPageCatID)!='') $commPageID2 = $commPageCatID; else {$commPageID2 = CutFromTo($contents, "AF_initDataCallback({key: '60',", '</script>'); $commPageID2 = CutFromTo($commPageID2, ',,[[["', '"'); }
   } elseif ($pageID!='') { //## Posting to Page
     $gpp = 'https://plus.google.com/b/'.$pageID.'/_/sharebox/post/?spam='.$rndSpamID.'&_reqid='.$rndReqID.'&rt=j';    
     $rep = nxs_remote_get($refPage, array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify)); 
     if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR pageID"; return $badOut; } /* if (!empty($rep['cookies'])) $ck = $rep['cookies']; */ $contents = $rep['body'];
   } else { //## Posting to Profile      
     $gpp = 'https://plus.google.com/u/0/_/sharebox/post/?spam='.$rndSpamID.'&soc-app=1&cid=0&soc-platform=1&hl=en&rt=j'; 
     $rep = nxs_remote_get('https://plus.google.com/', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify)); 
     if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR Main Page"; return $badOut; } /* if (!empty($rep['cookies'])) $ck = $rep['cookies']; */ $contents = $rep['body'];
     $pageID = CutFromTo($contents, "key: '2'", "]"); /* $pageID = CutFromTo($pageID, 'https://plus.google.com/', '"'); */ $pageID = CutFromTo($pageID, 'data:["', '"');  $refPage = 'https://plus.google.com/'; 
     $refPage = 'https://plus.google.com/_/scs/apps-static/_/js/k=oz.home.en.JYkOx2--Oes.O';     
     //unset($nxs_gCookiesArr['GAPS']); unset($nxs_gCookiesArr['GALX']); unset($nxs_gCookiesArr['RMME']); unset($nxs_gCookiesArr['LSID']);  // We migh still need it ?????
   } // echo $lnk['txt'];         
   if ($rep['response']['code']=='400') return "Invalid Sharebox Page. Something is wrong, please contact support";
   if (stripos($contents,'csi.gstatic.com/csi","')!==false) $at = CutFromTo($contents, 'csi.gstatic.com/csi","', '",'); else {        
     $rep = nxs_remote_get('https://plus.google.com/', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify)); 
     if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR CSI"; return $badOut; } /* if (!empty($rep['cookies'])) $ck = $rep['cookies']; */ $contents = $rep['body']; // prr($rep);
     if (stripos($contents,'csi.gstatic.com/csi","')!==false) $at = CutFromTo($contents, 'csi.gstatic.com/csi","', '",');  else return "Error (NXS): Lost Login info. Please contact support";
   } // prr($lnk);
   //## URL     
   if (!isset($lnk['txt'])) $lnk['txt'] = '';     $txttxt = $lnk['txt'];  $txtStxt = str_replace('%5C', '%5C%5C%5C%5C%5C%5C%5C', $lnk['txt']);
   if ($isPostToComm) $proOrCommTxt = "%5B%22".$commPageID."%22%2C%22".$commPageID2."%22%5D%5D%2C%5B%5B%5Bnull%2Cnull%2Cnull%2C%5B%22".$commPageID."%22%5D%5D%5D"; else $proOrCommTxt = "%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%2Cnull";        
   if (!empty($lnk['link']) && isset($lnk['arr']) ) { 
     $urlInfo = urlencode(str_replace('\/', '/', str_replace('##-KXKZK-##', '\""', str_replace('""', 'null', str_replace('\""', '##-KXKZK-##', json_encode($lnk['arr'])))))); 
     $urlInfo = str_replace('ZZZZIYYYIZZZ', '',$urlInfo);
     $spar="f.req=%5B%22".$msg."%22%2C%22oz%3A".$pageID.".".$rnds.".0%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2C".$urlInfo."%2Cnull%2C%5B".$proOrCommTxt."%5D%2Cnull%2Cnull%2C2%2Cnull%2Cnull%2Cnull%2C%22!".$bigCode."%22%2Cnull%2Cnull%2Cnull%2C%5B%5D%2C%5B%5Btrue%5D%5D%2Cnull%2C%5B%5D%5D&at=".$at."&";
     
   }
   //## Video - was here, but now video works like link. So link could be used. 
   //## Image
   elseif(!empty($lnk['img']) && !empty($imgData)) { $pgAddFlds = '';
    //if($isPostToPage) $pgAddFlds = '{"inlined":{"name":"effective_id","content":"'.$pageID.'","contentType":"text/plain"}},{"inlined":{"name":"owner_name","content":"'.$pageID.'","contentType":"text/plain"}},'; else $pgAddFlds = '';
    if ($isPostToComm) $proOrCommTxt = "%5B%22".$commPageID."%22%2C%22".$commPageID2."%22%5D%5D%2C%5B%5B%5Bnull%2Cnull%2Cnull%2C%5B%22".$commPageID."%22%5D%5D%5D"; else $proOrCommTxt = "%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%2Cnull";        
    //if (!$isPostToComm) $pgAddFlds = '{"inlined":{"name":"effective_id","content":"'.$pageID.'","contentType":"text/plain"}},{"inlined":{"name":"owner_name","content":"'.$pageID.'","contentType":"text/plain"}},'; else $pgAddFlds = '';
    $iflds = '{"protocolVersion":"0.8","createSessionRequest":{"fields":[{"external":{"name":"file","filename":"'.$remImgURLFilename.'","put":{},"size":'.$imgdSize.'}},{"inlined":{"name":"use_upload_size_pref","content":"true","contentType":"text/plain"}},{"inlined":{"name":"batchid","content":"1389803229361","contentType":"text/plain"}},{"inlined":{"name":"client","content":"sharebox","contentType":"text/plain"}},{"inlined":{"name":"disable_asbe_notification","content":"true","contentType":"text/plain"}},{"inlined":{"name":"album_mode","content":"temporary","contentType":"text/plain"}},'.$pgAddFlds.'{"inlined":{"name":"album_abs_position","content":"0","contentType":"text/plain"}}]}}';
           
    $hdrsArr = $this->headers('', 'https://plus.google.com', 'POST', true); $hdrsArr['X-GUploader-Client-Info']='mechanism=scotty xhr resumable; clientVersion=58505203'; 
    $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $iflds, 'sslverify'=>$sslverify);// prr($advSet);
    $imgReqCnt = nxs_remote_post('https://plus.google.com/_/upload/photos/resumable?authuser=0', $advSet); if (is_nxs_error($imgReqCnt)) {  $badOut = print_r($imgReqCnt, true)." - ERROR IMG"; return $badOut; } //prr($imgReqCnt);
    $gUplURL = str_replace('\u0026', '&', CutFromTo($imgReqCnt['body'], 'putInfo":{"url":"', '"'));  $gUplID = CutFromTo($imgReqCnt['body'], 'upload_id":"', '"');      
    
    $hdrsArr = $this->headers('', 'https://plus.google.com', 'PUT', true); $hdrsArr['X-GUploader-No-308']='yes'; $hdrsArr['X-HTTP-Method-Override']='PUT'; 
    $hdrsArr['Expect']=''; $hdrsArr['Content-Type']='application/octet-stream'; 
    $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $imgData, 'sslverify'=>$sslverify);// prr($advSet);
    $imgUplCnt = nxs_remote_post($gUplURL, $advSet); if (is_nxs_error($imgUplCnt)) {  $badOut = print_r($imgUplCnt, true)." - ERROR IMG Upl (Upl URL: ".$gUplURL.", IMG URL: ".urldecode($lnk['img']).", FileName: ".$remImgURLFilename.", FIlesize: ".$imgdSize.")"; return $badOut; } 
    $imgUplCnt = json_decode($imgUplCnt['body'], true);   if (empty($imgUplCnt)) return "Can't upload image: ".$remImgURL;
    if (is_array($imgUplCnt) && isset($imgUplCnt['errorMessage']) && is_array($imgUplCnt['errorMessage']) ) return "Error (500): ".print_r($imgUplCnt['errorMessage'], true);     
    $infoArray = $imgUplCnt['sessionStatus']['additionalInfo']['uploader_service.GoogleRupioAdditionalInfo']['completionInfo']['customerSpecificInfo'];     
    $albumID = $infoArray['albumid']; $photoid =  $infoArray['photoid']; // $albumID = "5969185467353784753";
    $imgUrl = urlencode($infoArray['url']); $imgTitie = $infoArray['title'];          
    $imgUrlX = str_ireplace('https:', '', $infoArray['url']); $imgUrlX = str_ireplace('//lh4.', '//lh3.', $imgUrlX); $imgUrlX = urlencode(str_ireplace('http:', '', $imgUrlX));
    $width = $infoArray['width']; $height = $infoArray['height']; $userID = $infoArray['username'];      
    $intID = $infoArray['albumPageUrl'];  $intID = str_replace('https://picasaweb.google.com/','', $intID);  $intID = str_replace($userID,'', $intID); $intID = str_replace('/','', $intID); // prr($infoArray);
    $spar="f.req=%5B%22".$msg."%22%2C%22oz%3A".$pageID.".".$rnds.".4%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B344%2C339%2C338%2C336%2C335%5D%2Cnull%2Cnull%2Cnull%2C%5B%7B%2239387941%22%3A%5Btrue%2Cfalse%5D%7D%5D%2Cnull%2Cnull%2C%7B%2240655821%22%3A%5B%22https%3A%2F%2Fplus.google.com%2Fphotos%2F".$userID."%2Falbums%2F".$albumID."%2F".$photoid."%22%2C%22".$imgUrlX."%22%2C%22".$imgTitie."%22%2C%22%22%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22".$width."%22%2C%22".$height."%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22".$userID."%22%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22".$albumID."%22%2C%22".$photoid."%22%2C%22albumid%3D".$albumID."%26photoid%3D".$photoid."%22%2C1%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D%7D%5D%2Cnull%2C%5B".$proOrCommTxt."%5D%2Cnull%2Cnull%2C2%2Cnull%2Cnull%2Cnull%2C%22!".$bigCode."%22%2Cnull%2Cnull%2Cnull%2C%5B%22updates%22%5D%2C%5B%5Btrue%5D%5D%2Cnull%2C%5B%5D%5D&at=".$at."&";
 }
 //## Just Message    
 else $spar="f.req=%5B%22".$msg."%22%2C%22oz%3A".$pageID.".".$rnds.".6%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B".$proOrCommTxt."%5D%2Cnull%2Cnull%2C2%2Cnull%2Cnull%2Cnull%2C%22!".$bigCode."%22%2Cnull%2Cnull%2Cnull%2C%5B%5D%2C%5B%5Btrue%5D%5D%2Cnull%2C%5B%5D%5D&at=".$at."&";    
 //## POST  prr(urldecode($spar));
 $spar = str_ireplace('+','%20',$spar); $spar = str_ireplace(':','%3A',$spar);  $hdrsArr = $this->headers($refPage, 'https://plus.google.com', 'POST', true); $hdrsArr['X-Same-Domain']='1'; 
 //$ckt = $ck; $ck = array(); $no = array("LSID", "ACCOUNT_CHOOSER", "GoogleAccountsLocale_session", "GAPS", "GALX"); foreach ($ckt as $c) {if (!in_array($c->name, $no)) $ck[]=$c;}
 $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $spar, 'sslverify'=>$sslverify);
 $rep = nxs_remote_post($gpp, $advSet); if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR POST"; return $badOut; }  $contents = $rep['body']; // prr($advSet);    prr($rep);        
 if ($rep['response']['code']=='403') return "Error: You are not authorized to publish to this page. Are you sure this is even a page? (".$pageID.")";
 if ($rep['response']['code']=='404') return "Error: Page you are posting is not found.<br/><br/> If you have entered your page ID as 117008619877691455570/117008619877691455570, please remove the second copy. It should be one number only - 117008619877691455570";
 if ($rep['response']['code']=='400') return "Error (400): Something is wrong, please contact support";
 if ($rep['response']['code']=='500') return "Error (500): Something is wrong, please contact support";
 if ($rep['response']['code']=='200') { $ret = $rep['body']; $remTxt = CutFromTo($ret,'"{\"','}"'); $ret = str_replace($remTxt, '', $ret); $ret = prcGSON($ret);  $ret = json_decode($ret, true); 
   if (!empty($ret[0][1][1]) && is_array($ret[0][1][1]) && !empty($ret[0][1][1][0][0][21])) $ret = $ret[0][1][1][0][0][21]; 
     elseif (!empty($ret[0][0][1]) && is_array($ret[0][0][1]) && !empty($ret[0][0][1][0][0][21])) $ret = $ret[0][0][1][0][0][21]; 
   return array('isPosted'=>'1', 'postID'=>$ret, 'postURL'=>'https://plus.google.com/'.$ret, 'pDate'=>date('Y-m-d H:i:s'));
 }
 return print_r($contents, true);         
 }