Malleable Musings

July 28, 2010

A digression

Filed under: PHP, RSS Feeds, simple hacks, Wordpress — Brendan @ 11:39 pm

I was invited in to a meeting at work a couple of weeks ago in which we were talking about blogging. After the meeting Stu threw a document up on Digress.It.

The document got a few mentions around the place and soon it started gathering a few comments (60 at the time of writing).

Digress.It is a really interesting platform however I think something went wrong with the comments.

I got a call of frustration from a member of the Marketing and Comms team earlier this week, who had been away on annual leave. She was amazed at how many really useful comments there had been. She’d seen some of them but wasn’t sure that she’d read them all of them and she certainly couldn’t do what she wanted which was to print off all of the comments alongside the original document.

I said I’d help and started by working out which RSS feeds were actually functioning (the comments by authors and the comments by numbered paragraph both seemed OK but the later certainly wasn’t displaying properly on Digress.It).

I realised early on that I was never going to manage to script a whole solution and it took a little while, until tonight, when I managed to clear enough time to complete this little digression. So I settled for a quick hack of an existing PHP script with some manual intervention.

What I did was to re-create the document in a Google Spreadsheet alongside the paragraph numbers (which are the keys for the RSS feeds of paragraph comments) and hacked the PHP script to include a request parameter. I also changed the end output slightly so it allowed me to pull down the comments and place them in to the cell next to the original text.

I know there must be a more elegant way of doing this but the document wasn’t that long whilst my time was short and my CSS and PHP skills and knowledge of ASCII/ANSI characters and regular expressions are all a little rusty.

From the spreadsheet it was a simple matter to copy and paste columns C&D in to a table in Word, run a couple of find and replaces, add some minor formatting and hey presto we have something more readable.

It was a nice little refresher for me as I’ve a feeling that I’m going to need to get reacquainted with regular expressions over the coming weeks.


April 25, 2009 and the iPhone – Part 3 (Twitterfon)

Filed under:, iphone, PHP, 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 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 (N.B. you’ll need to add your API key in the place indicated).

$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, "
              key=[API key goes here]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($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(){'[location of php script]?url='

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: iphone, PHP, 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="/', '', $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="">
      <title>Gold news</title>
      <link>URL where php script is</link>
      <description>An RSS enabled version of the Goldsmith News Page available at</description>
      <atom:link href="URL where php script is" rel="self" type="application/rss+xml" />


2) Upload it – and check it validates –

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.