Malleable Musings

April 25, 2009

Cli.gs and the iPhone – Part 3 (Twitterfon)

Filed under: PHP, cli.gs, iphone, simple hacks — Tags: , , — Brendan @ 10:04 pm

Twitterfon is definitely my favourite Twitter client for the iPhone.  Although I still haven’t tried Tweetie but according to this post there really isn’t much in it.  So I was excited earlier this evening to discover the bookmarklet on the Naan Studio website (hadn’t realised that they also produced the excellent Twitterfox add-in for Firefox as well).

On using the bookmark I noticed whilst it posts shortish URL’s in full for long URL’s it uses the tinyurl.com shortener.  I’ve nothing against tinyurl, in fact many years ago I used to use them extensively when sending bulk email however today there are much better URL shortners to choose from.  So I hacked together a little PHP script to create private cli.gs (N.B. you’ll need to add your cli.gs API key in the place indicated).

<?php
$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, "http://cli.gs/api/v1/cligs/create?
              key=[API key goes here]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($ch);
curl_close($ch);
header("location: twitterfon:///post?".$output);
?>

You’d then need to call it in the usual way – i.e. via a bookmark of

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

I’m hoping that eventually I’ll figure out a better final line of the php script, i.e. something that can transfer more than just the URL over to Twitter, unfortunately there’s very little documentation for Twitterfon, the only thing I found other than on the Naan website was this piece from someone who had a similar idea of using a php script a couple of weeks ago.

March 25, 2009

Php files and the iphone

Filed under: PHP, iphone, simple hacks — Brendan @ 7:07 am

I’m beginning to think that php files offer an unrivalled way of doing things quickly with the iPhone.

Simply save the file and add the link to the file as a bookmark in Safari.

My most recent effort is a quickly hacked together page which updates my location on Twitter. I simply call the page and my location is updated, a process that otherwise I find quite convoluted (it’s the one missing feature from Twitterfon, although Twitterfon does allow lat/long coordinate updates).

Generally I am in one of three places, at home in Cov, in London at work or in between on the train. So I have four php files (all based on twitter.lib.php file from php classes) bookmarked in Safari, one for each of the three common locations and one for if I am elsewhere (this script has a text input box rather than the location value hard coded).

December 23, 2008

RSS feed from a static webpage

Filed under: PHP, Yahoo Pipes — Brendan @ 10:55 pm

I mentioned in an earlier post that I’d started playing around with twitterfeed having set up a newsfeed service on Twitter (not many followers at the mo but it’s not really been promoted yet and it’s main output may well not be on Twitter – I’ll probably look at aggregated RSS feeds elsewhere).

Where I work is fairly unique and one of the problems I’m facing is that I need to bring in news from a variety of sources that aren’t in RSS format. One example is the Goldsmiths College News Feed.

The purpose of this post is to remind myself what I did to include this as I’ll probably need to repeat this process on a whole range of other pages.  (N.B. this is one of those posts written for myself so I’ll not post the full file but rather some comments – the variable I used wasn’t called $str).

1) Create a php file which will use some of the following commands:

$strURL = "URL to be brought in";
$strHTML = file_get_contents($strURL);
$str = explode("<hr>",$strHTML);
// break the the html in to usable parts

$variable = strip_tags($itThree, '<a>');
// strip out the HTML apart from whatever tags are needed

Probably explode the text further so that individual elements are part
of an array, might need to use something like the following at this stage:
$str[2] = preg_replace('/\ \[ <a href="/', 'http://www.gold.ac.uk/news', $str[2]);
The publication date will need to be in a suitable format or needs to be changed
to a guid format, e.g.
$guid = strtotime($str[0])

Then echo it all out
echo '<?xml version="1.0" ?>
      <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
      <title>Gold news</title>
      <link>URL where php script is</link>
      <description>An RSS enabled version of the Goldsmith News Page available at http://www.gold.ac.uk/news</description>
      <atom:link href="URL where php script is" rel="self" type="application/rss+xml" />
      .......

      ......
      </channel>
      </rss>

2) Upload it – and check it validates – http://feedvalidator.org/

3) Add to feedburner – and sit back and watch the news roll out.

Postscript: after writing this and getting it working I remembered Yahoo Pipes for the conversion. Use this to remind self of regex options.

Blog at WordPress.com.