recoverFromErrors=true;
$this->hideSysErrors=true;
$this->logSystemErrors=NULL;
$this->imageSavePath=NULL;
$this->imageReturnPaths=false;
$this->debugging=true;
//end of settings vars
$this->myFriendsList=array();
$this->myToken=array();
$this->myHistory=array();
$this->myImages=array();
$this->myFriends=array();
$this->myHistoryPage=array();
if($this->imageSavePath==NULL){
global $HTTP_SERVER_VARS;
$imageBase=$HTTP_SERVER_VARS['PATH_TRANSLATED'];
$this->imageSavePath=str_replace(basename($imageBase),"",$imageBase);
}
ini_set("max_execution_time","60");
// 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);
}
//
//login functions
//
function myspaceCreds($user,$pass){
//set user
if(empty($user) || empty($pass)){
$this->makeError("blank login");
}else{
$this->myspace_email = $user;
$this->myspace_password = $pass;
$this->login();
}
}
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();
}
///
///system core
///
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,$autoToken=true){
//move to location via curl
//get previous urls index
$prevLoc=count($this->myHistory);
$prevLoc-=2;
// 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]);
}
if($autoToken){
curl_setopt($this->ch, CURLOPT_URL,$newLoc."".$this->token);
}else{
curl_setopt($this->ch, CURLOPT_URL,$newLoc);
}
$this->page = curl_exec($this->ch);
if($prevLoc>-2){
//check for errors
if($prevLoc>=0){
if($this->myHistoryPage[$prevLoc]==$this->page) $this->makeError('duplicate');
}
if($this->checkErrors()){
//if error try again - this only works if you set recover from errors
$this->page = curl_exec($this->ch);
//check onelast time for errors
$this->checkErrors();
}
//ok now if the page had errors it was handled by now
}
$this->myHistoryPage[]=$this->page;
$this->myHistory[]=$newLoc."".$this->token;
curl_setopt($this->ch, CURLOPT_POST, 0);
if($this->debugging) echo $newLoc."".$this->token."
";
}
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(){
$this->Hash="";
if(preg_match("/hash\" value=\"([^\"]+)\"/i",$this->page)){
preg_match("/hash\" value=\"([^\"]+)\"/i",$this->page,$hash);
$this->Hash = "hash=".$hash[1];
}elseif(preg_match("/value=\"([^\"]+)\" name=\"hash\"/i" ,$this->page)){
preg_match("/value=\"([^\"]+)\" name=\"hash\"/i",$this->page,$hash);
$this->Hash ="hash=".$hash[1];
}
if(preg_match("/hashcode\" value=\"([^\"]+)\"/i",$this->page)){
preg_match("/hashcode\" value=\"([^\"]+)\"/i",$this->page,$hash);
$this->Hash .= "&hashcode=".$hash[1];
}elseif(preg_match("/value=\"([^\"]+)\" name=\"hashcode\"/i" ,$this->page)){
preg_match("/value=\"([^\"]+)\" name=\"hashcode\"/i",$this->page,$hash);
$this->Hash .= "&hashcode=".$hash[1];
}
if(preg_match("/__VIEWSTATE\" value=\"([^\"]+)\"/i",$this->page)){
preg_match("/__VIEWSTATE\" value=\"([^\"]+)\"/i",$this->page,$hash);
$this->Hash .= "&__VIEWSTATE=".$hash[1];
}elseif(preg_match("/value=\"([^\"]+)\" name=\"__VIEWSTATE\"/i" ,$this->page)){
preg_match("/value=\"([^\"]+)\" name=\"__VIEWSTATE\"/i",$this->page,$hash);
$this->Hash .= "&__VIEWSTATE=".$hash[1];
}
$this->Hash=str_replace("__VIEWSTATE=__VIEWSTATE=","__VIEWSTATE=",$this->Hash);
$this->Hash=str_replace("hash=hash=","hash=",$this->Hash);
$this->Hash=str_replace("hashcode=hashcode=","hashcode=",$this->Hash);
}
function checkErrors(){
//this is only a placeholder
return true;
}
function getMyId(){
preg_match("/friendID=(.*?)\"/i",$this->page,$myid);
//print_r($myid);
$this->myId = $myid[1];
}
function close() {
//$this->newLocation("http://collect.myspace.com/index.cfm?fuseaction=signout");
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 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.=preg_replace("/\" id=\".*/i","",$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;
}
function getAllFields(){
$returnFields="";
preg_match_all("/type=\".*?\"[\s](name=\"(.*?)\").?(value=\"(.*?)\")/i",$this->page,$fields,PREG_PATTERN_ORDER);
$totalFields=count($fields[2]);
//print_r($fields);
for($iField=0;$iField<$totalFields;$iField++){
$returnFields.=urlencode(preg_replace("/\" id=\".*/i","",$fields[2][$iField]))."=".urlencode($fields[4][$iField])."&";
}
$fields=NULL;
$totalFields=NULL;
if(preg_match("/type=\".*?\"[\s](value=\"(.*?)\").?(name=\"(.*?)\")/i",$this->page)){
preg_match_all("/type=\".*?\"[\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;
}
function displayHistory(){
$totalUrls=count($this->myHistory);
for($urlI=0;$urlI<$totalUrls;$urlI++){
echo $urlI." : ".$this->myHistory[$urlI]."
";
}
}
///
///blogging
///
function blogPost($blogsubject=NULL, $blogpost=NULL,$blogId=-1) {
//int blog by going to blog page
$this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.create&editor=true");
// set the current date
$this->setDate();
//if($blogsubject) {
$this->Subject = urlencode("Myspace Access Class Demo");
//}
//if($blogpost) {
$this->Body = urlencode("Hi, This post was created via the Myspace access class demo.
Stop By Soon and see what brewing.");
//}
$postfields = "blogID={$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=";
//make form and go to url and post
$this->makeForm($postfields);
$this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.previewBlog");
$postfields = NULL;
//ok now we need to grab the hidden fields
$postfields =$this->getHiddenFields();
//makeform and post
$this->makeForm($postfields);
$this->newLocation("http://blog.myspace.com/index.cfm?fuseaction=blog.processCreate");
}
///
///friends
///
function getMyspaceFriends() {
$this->newLocation("http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID={$this->myId}");
preg_match_all("/viewprofile&friendid=(.*)\">(.*)<\/a>
(\s+)<\/a>/i",$this->page,$friends);
print_r($friends);
}
function populateFriendsList($limit=50,$start=0,$stop=0){
$currPage=1;
$recoveredFriends=array();
$recoveredFriends['ids']=$recoveredFriends['names']=$recoveredFriends['images']=array();
$perPage=40;
$this->newLocation("http://friends.myspace.com/index.cfm?fuseaction=user.viewfriends&friendID={$this->myId}");
if($start>0){
//$start=floor($start/$perPage);
$currPage=$start;
}
if($stop>0){
//$stop=ceil($stop/$perPage);
}else{
$stop=99999999;
}
echo $start." : ".$stop."
";
$found=0;
while(true!=$this->checkErrors() && $found<=$limit && $currPage<=$stop){
$postfields =$this->getHiddenFields();
$postfields=str_replace("__EVENTTARGET=&","__EVENTTARGET=".urlencode('ctl00$cpMain$pagerTop')."&",$postfields);
$postfields=str_replace("__EVENTARGUMENT=&","__EVENTARGUMENT=".urlencode("".$currPage."")."&",$postfields);
$postfields=str_replace("SearchBoxID=SplashHeader&fuseaction=advancedFind.hub&","",$postfields);
$postfields.="ctl00%24cpMain%24rptButton=btnFirstName&ctl00%24cpMain%24txtSearch=&ctl00%24cpMain%24hdnSearch=";
$this->makeForm($postfields);
$this->newLocation("http://friends.myspace.com/Modules/ViewFriends/FriendsView.aspx?%3ffuseaction=user.viewfriends&friendID={$this->myId}");
if(preg_match("/viewprofile&friendid=(.*)\">(.*)<\/a>
(\s+)<\/a>/i",$this->page)){
preg_match_all("/viewprofile&friendid=(.*)\">(.*)<\/a>
(\s+)<\/a>/i",$this->page,$friends);
$recoveredFriends['ids']=array_merge_recursive($recoveredFriends['ids'],$friends[1]);
$recoveredFriends['names']=array_merge_recursive($recoveredFriends['names'],$friends[2]);
$recoveredFriends['images']=array_merge_recursive($recoveredFriends['images'],$friends[5]);
}
//makeform and post
$found=count($recoveredFriends['ids']);
$currPage++;
}
$this->myFriendsList=$recoveredFriends;
return $found;
}
//show friends
function displayFriends($limit=50,$start=0,$stop=0,$imageSize="l"){
$friends=count($this->myFriendsList);
if(empty($this->myFriendsList) || $friends<1){
$friends=$this->populateFriendsList($limit,$start,$stop);
}
if($friends>$limit) $friends=$limit;
$display="";
for($i=0;$i<$friends;$i++){
$display.="
".$this->myFriendsList['names'][$i]." : ".$this->myFriendsList['ids'][$i]."
";
$display.="$i
"; $display.="An Error Has Occcured ---- Please View Detials Below
"; $display.="Error Type : {$this->errorType}
";
$display.="Error Page : {$this->errorPage}
";
$display.="Error Details : {$this->errorReport}
";
$display.="