Malleable Musings

December 28, 2008

Cligs and the iPhone – Part II

Filed under:, iphone — Tags: — Brendan @ 8:42 pm

I posted previously about a better alternative to Twitterlink on the iPhone. A javascript function that calls directly. ( is a URL shortening service with analytics – great for measuring impact on a newsfeed from Twitter or elsewhere.)

Thanks to Pierre at, I’ve now improved this by creating several javascript functions as bookmarks that call a PHP script, passing specific variables. e.g. this function passes an action that I’m “Reading about ” the “document title” and the “URL” to the script which calls the API and returns the results as a parameter to the Twitter homepage (checking that it meets Twitter’s character limit).

N.B. I decided this was preferable rather than posting directly to Twitter as it allows a review before posting, however I might change this in the future.

javascript:(function(){'[location of php script]?url='+encodeURIComponent(location.href)%20+'&act=Reading%20about%20&title='+encodeURIComponent(document.title));%20})();

I’ve already completed the same bookmark for “Commenting on ” and making a “New post “. I’ll see what other actions I will find useful over the next few days.

If you are interested in implementing something like this for yourself. You’ll need a bit of webspace where you can run PHP.

The PHP script is simple enough (and most of it is courtesy of Thor Erik’s rater than me) however I’m sure it can probably be improved and suggestions will be gratefully recieved.

If you do want to use this you’ll need to alter [my api key] to your own API key and then upload the script.  Then all you need to do is change [location of php script] in the Javascript calls and work out what actions you want (remember to use %20 instead of spaces) when you’re setting your bookmarks.

$act = $_GET['act'];
$url = $_GET['url'];
$title = $_GET['title'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "[my api key]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($ch);
if (strlen($title) < (137 - strlen($act) - strlen($output))) {
$status = $act . $title . "%20-%20" . $output;
else {
$status = $act . substr($title, 0, (137 - strlen($act) - strlen($output))) . "%20-%20" . $output;
echo $status;

1 Comment »

  1. […] has caused me to rethink my “what I’m reading” behaviour.  Instead of doing this, now if I’ve picked something up via Twitter […]

    Pingback by Why do I follow, what do I seek, what should I say? « Malleable Musings — January 11, 2009 @ 10:13 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: