Too Cool for Internet Explorer

You know the dilemma, you want to write a simple tweeting PHP script and have to mess around with the Twitter API.
With the following small script you can tweet with a simple function call. It IS that simple (And SSL secured!!!).

Here’s the function:

function tweet($user, $pass, $text) {
	unset($GLOBALS['tweetError']);
	if(strlen($text) > 140) { $GLOBALS['tweetError'] = 'TEXT TOO LONG: '.$text; return false; }
	$tweet = curl_init();
	curl_setopt($tweet, CURLOPT_URL, 'https://www.twitter.com/statuses/update.xml');
	curl_setopt($tweet, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($tweet, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($tweet, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($user.':'.$pass)));
	curl_setopt($tweet, CURLOPT_POST, 1);
	curl_setopt($tweet, CURLOPT_POSTFIELDS, 'status='.utf8_encode($text));
	if(!$return = curl_exec($tweet)) $GLOBALS['tweetError'] = 'CURL ERROR: '.curl_error($tweet);
	else if($returnData = simplexml_load_string($return)) {
		if(!isSet($returnData->error)) $GLOBALS['tweetSuccess'] = 'Created at: '.$returnData->created_at.'Text: '.utf8_decode($returnData->text);
		else $GLOBALS['tweetError'] = 'TWITTER ERROR: '.$returnData->error;
	} else $GLOBALS['tweetError'] = 'RETURN IS NOT XML: '.$return;
	curl_close($tweet);
	return (isSet($GLOBALS['tweetError']))?false:true;
}

To make a tweet just call the function:

tweet("username", "password", "My cool tweet!");

The function returns “true” if successful or “false” if not.
To echo out the error or success messages, just use this code:

if(tweet("username", "password", "My cool tweet!")) {
	echo 'Tweet Successful!'.$GLOBALS['tweetSuccess'];
} else {
	echo 'Tweet Error!'.$GLOBALS['tweetError'];
}

If there was an error, the error description is saved in $GLOBALS['tweetError'], and if the tweet was successful, the time and the text itself is saved in $GLOBALS['tweetSuccess'].

Have fun and happy (automatic?) tweeting.

Bookmarks Plugin for Roundcube   September 27th, 2008

This is a simple Bookmarks “Plugin” for Roundcube. With it, you can administrate all your bookmarks (or favorites) within the web-mailer surface.

It is nether beautiful nor has it a browser bookmarks import capability, but it works. The installation is rather simple, but the included files are only valid for the current RoundCube version 0.2-beta. you should not install this plugin if the versions do not match.

Here you can find a sample preview image.

 

Before installing, please note:

  • IT WILL ONLY WORK WITH MYSQL AND ROUNDCUBE v0.2-BETA (For sure it will work with future versions, but i don’t guarantee this).
  • It is NOT multi-user capable (All users will see the same bookmarks).
  • It is not multi-language capable.
  • It will overwrite two files in the “default” skin (The menu and the .css).
  • It will not preserve sessions, so dont use it for a long time, otherwise your session will be lost.
  • It will create a new table in your database.
  • There will be no future support or development (It simply does what i want, so im fine with it as is).

Please don’t install this plugin if you don’t agree with this conditions.

 

Installation: (could not be easier)

  1. copy the .zip file to your /skins/ folder
  2. unzip it (with overwriting files option)
  3. reload your roundcube, click on the bookmarks link, add in the url field of your browser at the end of url: “&createTable=true” (without the brakets) and hit “enter”. if this fails (a message “could not create table” appears) you have to add the new table with your favorite sql tool (phpmyadmin for instance), for this, copy the sql statement from line 16 from the /default/bookmarks/index.php file in the zip file.

now youre all done.

 

Download:
RoundCube Bookmarks Plugin