In the same way as most other users do, I find myself frequently posting links on twitter using one of the many URL shortening services. I’ll say at this point that I absolutely loathe these services, the recent demise of Tr.im and the debacle which has followed enforces the view that replicating something which already exists is bound to lead to issues (the thinking behind the popular programming acronym DRY).
It would be a serious step forwards (IMHO), if twitter allowed you to convert sections of a tweet to a link in much the same way as one does in HTML so we can avoid this, but anyway, I’ve digressed, people might complain it would make it too “complicated”, rant over, back on track.
As the subject of this post suggests this is just a random little code snippet I put together today to help me hold onto my links, make them a little more searchable and use the real link not a shortened version by posting them to delicious when I tweet them. It almost certainly exists elsewhere, but this is my take on it and doesn’t rely on me using a particular browser and having a plug-in installed on all the machines I use it on which the otherwise excellent tweecious would do.
Requirements
- PHP5 webserver
- SimplePie Rss parser (I’m using version 1.1.3 nothing has changed since which would break this, AFAIK)
- CRONtab or similar to make it automatic, you can always just load the page up in a browser window if you don’t have CRON on your server or use webcron.
What it does
- Any link you post on twitter is resolved to its original address, title grabbed off the original site and posted onto your delicious account with your tweet in the description and any tags you want.
- Links will only be posted once, so if a link is automatically posted and you then delete it from delicious then its not going to reappear the next time the script is run.
- You can optionally blacklist domains or sections of domains which you don’t want to be saved, for instance I tweeted a link to a programme on BBC iPlayer, there’s no point me saving it as iPlayer only stores stuff for a couple of weeks
- You can also prevent a tweet which has a specific hashtag from being posted, I use the tag “#ns” which will prompt the script to ignore the rest
To use it, just upload twittodel.php from the zip file below (or copy and paste the below source) to your webserver, add simplepie.inc and any other bits it needs, make a cache folder according to whatever you’ve set the CACHE_DIR option to (as a default it wants a folder called ‘cache’.
Download: twittodel.zip
As I say, it was put together fairly quickly so is not guaranteed to be perfect but anyway. Comments/improvements/criticism welcome. It might see the addition of Zemanta style automatic tagging like tweecious, I’ll update this post if it does.
// Author: Duncan Barnes (www.barnesdmd.co.uk)
// Updated: 16/08/09
// License: Creative Commons Attribution-Non-Commercial-Share Alike (http://creativecommons.org/licenses/by-nc-sa/2.0/)
//-----------------------------------------------------------------------------------------
//You'll need to enter your delicious credentials and a few other details here to make this work
//I've left in a few details as examples
//Delicious username
define('DELICIOUS_USERNAME','yourusernamehere');
//Delicious password
define('DELICIOUS_PASSWORD','yourpasswordhere');
//Tag/s to add to the delicious entry
define('DELICIOUS_TAGS','from_twitter');
//Your twitter account timeline rss feed
define('TWITTER_RSS','http://twitter.com/statuses/user_timeline/6752222.rss');
//You can put a hash tag here which you might want to use to prevent tweets being posted to delicious
define('TWITTER_OMIT','#ns');
//You can put bits of addresses in here which you don't want to be posted, separate with a comma, e.g 'bbc.co.uk/iplayer', no urls which have this in them would be posted
define('ADDRESS_OMIT','bbc.co.uk/iplayer,bbc.co.uk/programmes');
//Directory where this script can store cached data
define('CACHE_DIR','cache/');
//Max number of tweets to process each time the script is run, adjust based on how often you tweet and how often you run the cron controlling this script
define('MAX_TWEETS',6);
//-----------------------------------------------------------------------------------------
//Bit of quick error checking
if (!class_exists('SimplePie')){if(file_exists('simplepie.inc')){require_once 'simplepie.inc';}else{echo 'Simplepie not found, check simplepie.inc is in the same directory as this script!';exit();}}
$feed = new SimplePie(TWITTER_RSS,CACHE_DIR,3600) or die('Could not declare Simplepie, you might want to check your TWITTER_RSS and CACHE_DIR settings and also that you have any additional files which SimplePie wants.');
$curl_handle = curl_init() or die('Could not initiate curl, please check its enabled on your server!');
//Fetching our cache of previous things we've saved to delicious, means:
// a)we're not repeating a push to delicious
// b) If you delete an auto created entry from delicious it won't be recreated the next time this is run!
// The script will still continue if there's a problem here, we're not going to worry about it too much as this might be the first run
if(file_exists(CACHE_DIR.'delicious.data')){$deliciouscache = unserialize(file_get_contents(CACHE_DIR.'delicious.data'));}else{$deliciouscache = array();}
//For ease of use, the ADDRESS_OMIT option is a constant, however we want its contents as an array for ease of processing so we'll covert it now
$address_omit = explode(',',ADDRESS_OMIT);
@array_walk($address_omit, 'trim_value');
//Lets do it
$i=0;
foreach ($feed->get_items() as $item){
if($i==MAX_TWEETS){break;} //Stoppping if we've reached the limit
$tweet = $item->get_title();
//Checking the tweet isnt already in our cache or contains our omit string, we use an md5 of the tweet as it saves us doing any further lookups
if(in_array(md5($tweet),$deliciouscache) || strstr($tweet, TWITTER_OMIT)){$i++;continue;}
if(!$page = getUrl($tweet)){$i++;continue;} //We've failed to get the target url, on to the next...
if(!domain_check($page['url'])){$i++;continue;} //Checking the resolved url isn't in our list of urls we don't want to know about (ADDRESS_OMIT option)
// At this point we should have an array ($page) containing the title and the url provided by the getUrl function
// so lets go ahead and try and add to Delicious account
$url = urlencode($page['url']);
$title = urlencode($page['title']);
$tweetenc = urlencode($tweet);
$tag = urlencode(DELICIOUS_TAGS);
curl_setopt($curl_handle, CURLOPT_URL, 'https://'.DELICIOUS_USERNAME.':'.DELICIOUS_PASSWORD."@api.del.icio.us/v1/posts/add?url=$url&description=$title&extended=$tweetenc&tags=$tag");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 0);
if($result = curl_exec($curl_handle)){
array_unshift($deliciouscache, md5($tweet));
if(count($deliciouscache) > MAX_TWEETS){ //One in one out, stopping the cache file growing exponentially
array_pop($deliciouscache);
}
}
$i++;
}
//Writing our cache back to file ready for the next run
if($res = fopen(CACHE_DIR.'delicious.data','w')){fwrite($res,serialize($deliciouscache));}
curl_close($curl_handle);
//Done
//Helper functions
function domain_check($url){global $address_omit;if(is_array($address_omit)){foreach($address_omit as $address){if(!empty($address) && strstr($url, $address)){return false;}}}return true;}
function trim_value(&$value){$value = trim($value);} //Used to trim the $domain_omit array
function getUrl($tweet){
global $curl_handle;
if(!$tweet){return false;}
preg_match('/http:\/\/\S*?/U', $tweet, $result);
curl_setopt($curl_handle, CURLOPT_URL, $result[0]);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1); // follow redirects (in the case of shortened urls)
if(!$buffer = curl_exec($curl_handle)){return false;}
$info = curl_getinfo($curl_handle);
if($info['http_code'] !== 200){return false;} //If the page is gone then cancel
// match the title of the page at the url
preg_match( "/<title>(.*)<\/title>/s", $buffer, $match );
$title = preg_replace('/<\/?(title)[^>]*>/iU', '', $match[1]);
return array('title'=>$title,'url'=>$info['url']);
}
Just noticed this post on the Google Operating System blog.
The latest version of Google Maps for Mobile includes an option that was already available in Google Maps: directions for public transportation. Google’s coverage has been continuously expanded in the past months to many US states, Japan, Austria, Switzerland, important cities from Canada, Italy, France, UK and Australia. Google Maps is one of the applications that is very useful when you are on the go and this new feature is a good alternative to the existing driving directions.
Very cool, slightly frustrating bits at the moment include:
- Its not available for Windows Mobile devices like my HTC TyTnII (Kaiser) yet, I’ll try and be patient!
- I thought about writing an app to do this myself about the time I got my TyTnII using London transport data, unfortunatly TFL don’t make a lot of the required data publically obtainable to construct such a system, hence I gave up rather quickly. Frustrating at the time beacuse of TFL’s limited mobile device support.
Glad to see Google have been thinking this one through, looking forward to seeing how well it works…
One of the programs I use a lot is a little app called Maxivista, its got several features of particular merit, the ability to use another laptop/desktop as an extended display for your main computer and in another mode use the same mouse and keyboard to control several computers, with monitors using the network connection for them to talk to each other. This is accomplished simply by dragging the mouse off the side of the screen at which point it appears on the other computer, the keyboard follows the mouse. Its probably easiest to have a browse through the Desktop Extension and Remote Control sections of the Maxivista website to get a better idea what I’m talking about here. There’s also the obligatory open source offering called Synergy2 which sods law dictated that I would only discover after purchasing Maxivista!
Typically when I’m at my desk I have my main computer and my laptop next to it on a dock, with dual monitor on the desktop already I have a fair amount of real estate to work from (albeit not in quite the same league as Stefan Didak!). I might typically have two instances of Opera running, one on the laptop and one on the second desktop screen, using the primary screen as my working area and the other two as reference windows, the key point however is that I prefer to use the laptop in remote control mode so that I can take advantage of its processor and resources while the main computers working on other things.
Anyway, heres the point of the post (finally I know): in this sort of set-up I’ve found its useful at times to be able to “transfer” tabs, between the browser windows on the two machines and it took me a while to work out how, to be honest its really thanks to an Opera Watch post about opening tabs in firefox and ie that I got an idea for a slightly bodged but workable solution. I thought I’d share it below in case anyone else finds it useful, its nothing revolutionary but its useful all the same.
Requirements/how to:
- Two networked computers running Opera (obviously)
- For this to work both ways you will need the PsExec.exe file copied into the “c:\Windows\System32″ folder, you can the PsTools package from the sysinternals website, check against point 2 on this forum thread that everything is ready to go.
- Download this batch file (zipped), extract and open it and change all the parts marked <ike this> to the appropriate values, note that the remote computers username should be the same as the one you logon as otherwise it’ll open a fresh opera window instead of using the existing one. Save the batch file to “c:\Windows\System32″
- Drag the below Opera button to any opera panel, click and it should work!
Things to note, you will get a console window opening for a second on the source computer, without compiling everything into a binary there’s little way of totally hiding the action, also, the above button is set to also remove the tab from the source computer.
So I’ve just got around to having a play with PointUI which surfaced earlier this week. The iPhone crowd have come out and laid into it on other blogs, ignoring the fact that the 3rd party apps which have to be bodged into the iPhone are the lifeblood of a windows mobile device and the reason why many choose Windows Mobile over the iPhone. 
Anyway, rant over. I must say for a free and from nothing attempt, Pointui is pretty good, its slick for the most part, its let down at the moment on two (significant) counts (imo):
- a) when you want to do anything as it then opens that application in the standard windows mobile shell.
- b) Its not customizable and has no real settings which can be changed for user preference
I havn’t mentioned any of the bugs beacuse its in beta and this is to be expected and I’m sure the features and flexibility will be expanded in due time.
Of course these guys arent the only one creating nicer interfaces for Windows Mobile, HTC for one have for a while been supplying plugins and apps to extend Windows Mobiles functionality although it seems to be a bit of a lottery sometimes as to which ones are installed on your device (down to network whims most of the time it seems). They’re not as slick and iPhone like as Pointui for the most part but they provide added functionality with most of them being finger compatible. There’s a fairly comprehensive list of HTC apps on the XDA Developers site.
The one thing I keep wondering is when Microsoft will catch up, not to mention whether they are always going to be playing catch up with Apple, HTC and the mass of individual enterprising developers around the world.
Windows Mobile 6 was for the most part a let down and not much of a change over version 5, it still has the abomination that is Pocket IE (not a big deal thanks to Opera Mobile), still uses buttons which require a stylus and still looks like all they did was attempt to shrink down the desktop windows interface without any new thought put into it. 
Small changes are promised in the upcoming 6.1 and therafter but I for one am not holding out much hope of them making any significant advances. Dont get me wrong, in many ways Windows Mobile is fantastic, as I said before, the plethora of 3rd party applications mean you have a tool for any job and if not then Visual Basic isn’t hard to pick up and develop it yourself .
But they could do better and with 79,000 employees at Microsoft (Source: Wikipedia) its hard in some ways to see why all the interesting things are always coming from small players.
I’ve just taken the plunge and upgraded my HTC Wizard/O2 XDA MiniS to an HTC Kaiser/T-Mobile MDA Vario III. I changed to T-mobile mainly beacuse of the ‘web n walk’ deals with their overall offer a better option than the competition, plus the added bonus that they don’t mind if the phone is used as a laptop modem (not tested yet).
There are hundreds of reviews around the web so I won’t bother doing that but will note some of my own thoughts, I find bullet point lists for this sort of thing work well:
-  The phone itself is a bit smaller than the previous one, a testement if ever there was one to the fast moving world of modern technology, the new one packs in 3G, GPS, faster processor and a tilting screen to boot where as the old one managed GPRS at a push.
- The GPS is very fast to lock on, even inside buildings! It works very well with Google Maps although occasionally the software seems to forget to ask the GPS to update. I’m awaiting a memory card before testing TomTom.
- The keyboard is actually slightly smaller than the  old one which is odd beacuse there appears to be space for it to be bigger. Its still perfectly usable although symbols have been moved around quite a bit, having had the Wizard for 23 months I was able to touchtype on it (thumbs only of course!) so this is quite an annoyance although I’m sure I’ll get used to it.
- The phone feels more solidly built, the mechanism for the tilt is metal so should be pretty hard wearing.
- The comms manager button is gone, this is a little annoying, I’m going to consider re-mapping the voice dialling button to do this. I’ve never quite understood the point in these voice dialling buttons, if I want hands free then I’ll use the button on my bluetooth headset to activate it, or else I’ll just use the keypad and dial the number normally.
The XDA Developer forums are as ever a fountain of useful knowledge for Windows Mobile smartphones and very much recommended. One of the forum members has produced a program called TrackMe, this is now being contributed to by other forums members. Its essentially a GPS Logger, it can record to either a local file or send data to a web application as a KML file.
I’m thinking of using this when I go to Cape Town in December to record my track and then use this to geotag my photos when I return. Obviously I’ll use the local file option as otherwise I’ll end up with horrendous roaming data charges! Hopefully the version with support for GPX will be released soon otherwise I’ll write a little converter myself. Then I need to tie this in with the photo exif data from my camera by matching the most recent gps log entry to the exif time stamp.
I had a go at using Google Maps Mobile for the first time yesterday on my O2 XDA Mini S, I must say I was impressed, its interesting to see that this is the only application (that I am aware of) which Google have released as a proper Windows Mobile installer. There’s a java based application for Gmail but its pretty useless for the most part, if they had taken the time to make a full program for windows mobile perhaps it might have had useful features such as integration with the today screen on windows mobile and not such a dodgy connection with the gmail servers.
I digress, anyway, I ended up trying maps mobile on Oxford street in the end after failing to find a particular branch of Maplin, the fact that you can install from the phone without going through active sync is in itself a good thing. I’ve yet to try it out with the bluetooth GPS I use for satnav but I’m impressed so far.
Now the only bad part is standing there thinking of the data costs and cringing, my next phone is probably going to be the HTC Kaiser and with that I think one of the T-Mobile web n walk plans might go down quite well. I’ve been in contact with a couple of T-mobile people via email and have been assured that they will be carrying the phone, although they refuse to comment further on when, they won’t even narrow it down to a month which is quite frustrating. However when it does arrive, with GPS on board this should be quite a decent phone to use with the maps app.
Update (12/11/2007): I bought the Kaiser and yes google maps works very well, click here for the post…