'; $endstring = ''; //4 Open a text file to see what the last status was so that we don't double-tweet. $fname = "gtalkstatus.txt"; //5 Check to see if our new status is any of the default statuses that we don't want to send to Twitter. //Add other phrases as needed. //6 Send the status to twitter //Twitter Username/password $username = '********'; $password = '********'; //7 The final component is setting up a Cron Job to run this script periodically. //Dreamhost example: //Set the title, leave the email blank, status=enabled. //Set the command to run= /dh/cgi-system/php5.cgi /home/dhusername/example.com/gtalkstatus2twitter.php //When to run: Custom, Minutes= highlight every 5 minutes (dreamhost won't let you run it more often) //Pull the gtalk badge $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $gchatbadge); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL, and return output $output = curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); //Parse the string in the gtalk badge to find the status $beginposition = strlen($beginstring) + strpos($output, $beginstring)+1; $endposition = strpos( substr($output,$beginposition) , $endstring); $status = substr($output,$beginposition,$endposition); //Open our file to see what our last tweet was $fhandle = fopen($fname,"r"); $content = fread($fhandle,filesize($fname)); //Exclude Default statuses if (strtolower($content) == strtolower($status) || empty($status) || $status=="Offline" || $status=="Busy" || $status=="Available") { //Exclude certain phrases when updating } else { //Write our new status to our file. $fhandle = fopen($fname,"w"); fwrite($fhandle,$status); fclose($fhandle); //Send to Twitter $url = 'http://twitter.com/statuses/update.xml'; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=" . urlencode($status) ); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); $buffer = curl_exec($curl_handle); curl_close($curl_handle); } ?>