This can come in handy if you send out tweats, sms or other texts which should stay as short as possible and could contain urls.
But it can also be used for html emails to track visitor clicks (using the googl analytics overview for those urls).
There are many use cases where such a shortening service might be useful. The googl one is fast and reliable – and for now still without costs.
The source file can be found in my Tools plugin: GooglLib.php
If you have an API key (which is recommended for the use with analytics and high traffic pages which generate a lot of short urls) define it in your configs:
App::uses('GooglLib', 'Tools.Lib'); $this->Googl = new GooglLib(); $longUrl = 'http://www.spiegel.de'; $result = $this->Googl->getShort($longUrl); $shortUrl = $result['id'];
Since this is a lib you can use it anywhere in your application: In the view (inside a helper maybe) or in the model prior to saving or as a behavior for on demand replacing etc.
If you need to get the original url from a short url:
$result = $this->Googl->getLong($shortUrl); $longUrl = $result['longUrl'];
You can use the
statisticsUrl method to get an url to the analytics backend for this specific short url.
getHistory would need oAuth/oacurl to work and is not yet implemented. It would return the analytics data from the above link as an array.