예제 #1
0
	function doGetGoogleUrlInfo2($url) {
		$rnds = rndString ( 13 );
		$url = urlencode ( $url );
		$contents = getCurlPageX ( 'https://plus.google.com/', '', false );
		$at = CutFromTo ( $contents ['content'], 'csi.gstatic.com/csi","', '",' );
		$spar = "susp=false&at=" . $at . "&";
		$gurl = 'https://plus.google.com/u/1/_/sharebox/linkpreview/?c=' . $url . '&t=1&slpf=0&ml=1&_reqid=1064097&rt=j';
		$contents = getCurlPageX ( $gurl, '', false, $spar );
		$json = prcGSON ( $contents ['content'] );
		$arr = json_decode ( $json, true );
		$out ['link'] = $arr [0] [1] [4] [0] [1];
		$out ['fav'] = $arr [0] [1] [4] [0] [2];
		$out ['title'] = $arr [0] [1] [4] [0] [3];
		$out ['domain'] = $arr [0] [1] [4] [0] [4];
		$out ['txt'] = $arr [0] [1] [4] [0] [7];
		$out ['img'] = $arr [0] [1] [4] [0] [6] [0] [8];
		$out ['imgType'] = $arr [0] [1] [4] [0] [6] [0] [1];
		$out ['title'] = str_replace ( ''', "'", $out ['title'] );
		$out ['txt'] = str_replace ( ''', "'", $out ['txt'] );
		$out ['txt'] = html_entity_decode ( $out ['txt'] );
		$out ['title'] = html_entity_decode ( $out ['title'] ); // prr($out);
		return $out;
	}
 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);         
 }