myToken=array(); $this->myHistory=array(); $this->myImages=array(); $this->errorMsgs=array("You Must Be Logged-In to do That!","Server Error","Sorry! an unexpected error has occurred.") ; // constructor $this->ch = curl_init(); // // setup and configure // $this->randnum = rand(1,9999999); curl_setopt($this->ch, CURLOPT_COOKIEJAR, "/tmp/cookiejar-{$this->randnum}"); curl_setopt($this->ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-{$this->randnum}"); curl_setopt($this->ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_POST, 0); } //set user function myspaceCreds($user,$pass){ if(empty($user) || empty($pass)){ echo "please enter your myspace login information"; }else{ $this->myspace_email = $user; $this->myspace_password = $pass; } } //login functions function login() { // // get homepage for login page token // $this->newLocation("http://www.myspace.com"); // // do login // $postfields = "email=" . urlencode($this->myspace_email); $postfields .= "&password=" . urlencode($this->myspace_password); $postfields .= '&ctl00%24Main%24SplashDisplay%24login%24loginbutton.x=38&ctl00%24Main%24SplashDisplay%24login%24loginbutton.y=15'; $this->makeForm($postfields); $this->newLocation("http://login.myspace.com/index.cfm?fuseaction=login.process"); // // go to home // $this->newLocation("http://home.myspace.com/index.cfm?fuseaction=user"); //get users id $this->getMyId(); // // check login error // } function findToken(){ //find token string - case insensitive //this must be case insensitive as myspace likes to change cases if(preg_match("/&Mytoken=(.*?)\"/i",$this->page,$token)){ $token=substr($token[0],0,strlen($token[0])-1); $this->myTokens[]=$token; }else{ $token=""; } return $token; } function newLocation($newLoc){ //move to location via curl //get previous urls index $prevLoc=count($this->myHistory); $prevLoc-=2; //grab new token // find new token $this->token = $this->findToken(); //set refer and go to url curl_setopt($this->ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); if($prevLoc>=0){ curl_setopt($this->ch, CURLOPT_REFERER,$this->myHistory[$prevLoc]); } curl_setopt($this->ch, CURLOPT_URL,$newLoc."".$this->token); $this->page = curl_exec($this->ch); //check for errors if($this->checkErrors()){ //if error try again $this->page = curl_exec($this->ch); } //check onelast time for errors before displaying error msg $this->checkErrors(); if($this->errors){ echo $this->stdError; $this->myHistory=NULL; curl_setopt($this->ch, CURLOPT_POST, 0); }else{ $this->myHistory[]=$newLoc."".$this->token; curl_setopt($this->ch, CURLOPT_POST, 0); } } function makeForm($formData){ //setup curl so that the next url jump is a post curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded")); curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_POSTFIELDS,$formData); } function getHash(){ preg_match("/hash\" value=\"([^\"]+)\"/i",$this->page,$hash); $this->Hash = $hash[1]; } function checkErrors(){ $errorPage=str_replace($this->errorMsgs,"ERRORERRORERROR",$this->page); if(false===strpos($errorPage,"ERRORERRORERROR")){ $this->errors=false; }else{ $this->errors=true; } // login error return $this->errors; } function getMyId(){ preg_match("/friendID=(.*?)\"/i",$this->page,$myid); //print_r($myid); $this->myId = $myid[1]; } function close() { curl_close($this->ch); @unlink("/tmp/cookiejar-{$this->randnum}"); } function setDate() { $time = time(); $this->PostMonth = date("n", $time); $this->PostDay = date("j", $time); $this->PostYear = date("Y", $time); $this->PostHour = date("g", $time); $this->PostMinute = date("i", $time); $this->PostTimeMarker = date("a", $time); } function blogPost($blogsubject=NULL, $postUrl=NULL, $blogContent) { //blogsubject and postUrl are now redundant because of the added blogContent //int blog by going to blog page $this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.create&editor=true"); $this->setDate(); $this->Subject = urlencode($blogsubject); $this->Body = urlencode($blogContent); $postfields = "blogID={$this->BlogID}&postMonth={$this->PostMonth}&postMinute={$this->PostMinute}&postDay={$this->PostDay}&postYear={$this->PostYear}&postHour={$this->PostHour}&postTimeMarker={$this->PostTimeMarker}&subject={$this->Subject}&BlogCategoryID=0&editor=true&body={$this->Body}&CurrentlyASIN=&CurrentlyProductName=&CurrentlyProductBy=&CurrentlyImageURL=&CurrentlyProductURL=&CurrentlyProductReleaseDate=&CurrentlyProductType=&Mode=music&MoodID={$this->MoodID}&MoodOther=&ProhibitComments={$this->ProhibitComments}&BlogViewingPrivacyID={$this->BlogViewingPrivacyID}&Enclosure="; //$this->showLocation(); //make form and go to url and post $this->makeForm($postfields); $this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.previewBlog"); //$this->showLocation(); $postfields = NULL; // grab the hash $this->getHash(); // previewed; // we're previewed, we have the hash, time to post $postfields =$this->getHiddenFields(); //"BlogID={$this->BlogID}&PostMonth={$this->PostMonth}&PostDay={$this->PostDay}&PostYear={$this->PostYear}&PostHour={$this->PostHour}&PostMinute={$this->PostMinute}&PostTimeMarker={$this->PostTimeMarker}&Subject={$this->Subject}&Body={$this->Body}&CurrentlyASIN=&CurrentlyProductName=&CurrentlyProductBy=&CurrentlyImageURL=&CurrentlyProductURL=&CurrentlyProductReleaseDate=&CurrentlyProductType=&MoodID={$this->MoodID}&MoodOther=&BlogViewingPrivacyID={$this->BlogViewingPrivacyID}&ProhibitComments={$this->ProhibitComments}&Editor=true&isPreviewed=true&BlogCategoryID=0&hash={$this->Hash}&Enclosure="; //makeform and post $this->makeForm($postfields); $this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.processCreate"); $this->showLocation(); } function showLocation(){ //print($this->page); } function getHiddenFields(){ $returnFields=""; preg_match_all("/type=\"hidden\"[\s](name=\"(.*?)\").?(value=\"(.*?)\")/i",$this->page,$fields,PREG_PATTERN_ORDER); $totalFields=count($fields[2]); for($iField=0;$iField<$totalFields;$iField++){ $returnFields.=$fields[2][$iField]."=".urlencode($fields[4][$iField])."&"; } $fields=NULL; $totalFields=NULL; if(preg_match("/type=\"hidden\"[\s](value=\"(.*?)\").?(name=\"(.*?)\")/i",$this->page)){ preg_match_all("/type=\"hidden\"[\s](value=\"(.*?)\").?(name=\"(.*?)\")/i",$this->page,$fields,PREG_PATTERN_ORDER); $totalFields=count($fields[2]); if($totalFields>0 && $totalFields!=NULL){ for($iField=0;$iField<$totalFields;$iField++){ $returnFields.=$fields[2][$iField]."=".urlencode($fields[4][$iField])."&"; } } } return $returnFields; } //close class } ?>