<?php

/*


	This will log the given activity to a Twitter Feed.
	Important things:
		-Set the username and password!

	The twitter rate limit is 100 requests per 60 minutes
	Twitter whitelisting can increase this to 20,000 per hour (http://twitter.com/help/request_whitelisting)

*/


class TwitterLog{
	private $twitter_username = "dbydtool";
	private $twitter_password = "twitterpass3A8";
	private $error;
	
	/*
	
	statuses/update
	Updates the authenticating user's status.  Requires the status parameter specified below.  Request must be a POST.  A status update with text identical to the authenticating user's current status will be ignored.
	URL: http://twitter.com/statuses/update.format
	Formats: xml, json.  Returns the posted status in requested format when successful.
	Method(s): POST
	Parameters:
		•	status.  Required.  The text of your status update.  Be sure to URL encode as necessary.  Should not be more than 140 characters.
		•	in_reply_to_status_id.  Optional.  The ID of an existing status that the status to be posted is in reply to.  This implicitly sets the in_reply_to_user_id attribute of the resulting status to the user ID of the message being replied to.  Invalid/missing status IDs will be ignored.
	Returns: status element	
	
	*/
	
	
	function updateStatus($status){

		$ch=curl_init();
		//Get data back, use POST
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch,CURLOPT_POST,true);
		
		//POST paramaters
		$post_array = array('status'=>$status);
		//Use POST + paramaters
		curl_setopt($ch,CURLOPT_POSTFIELDS,$post_array);
	
		//The Twitter API method to use (update)
		curl_setopt($ch,CURLOPT_URL,"http://twitter.com/statuses/update.json");
		
		//Set Twitter username/password
		curl_setopt($ch,CURLOPT_USERPWD,$this->twitter_username.":".$this->twitter_password);
		$return .= json_decode(curl_exec($ch));
		
		$http_status = (int)curl_getinfo($ch,CURLINFO_HTTP_CODE);
		
		if($http_status ==400)
			$this->error = "Rate limit encountered. Twitter stream not updated.";		
		elseif($http_status != 200)
			$this->error = "Some sort of other error occurred, probably the change was not published to the Twitter stream.";
		curl_close($ch);
		
		print_r($return);
	}
	
	
	

}

$TwitterLog = new TwitterLog();

$TwitterLog->updateStatus("First Post!");


?>