As I couldn’t find any plugins that would shorten an URL I thought it would be a nice idea to make one myself and share it with the rest of the CI community.
The plugin uses the API’s of external services, such as TinyURL, to shorten the URL.
Services currently supported
* TinyURL
* Is.gd
* Tr.im
* U.nu
I am aware that there are some other known URL shorteners, such as Bit.ly, but those require you to log in and use an API key which I, for the sake of simplicity, am not going to support myself. However, feel free to add them yourself if needed, the plugin is licensed under the MIT license.
How to use
1. Unzip the archive and copy “shortify_pi.php” into either your system/plugins folder or your system/application/plugins folder.
2. Add the following line of code into your controller in one of your functions. It should also work in the view files but I haven’t tested that yet.
<?php
//Load the Shortify plugin
$this->load->plugin('shortifyurl');
?>
3. Use the plugin by adding the shortify() function. The function works as following:
<?php
shortify('long_url','service',html_hyperlink);
?>
A screenshot with an example can be seen here: http://i41.tinypic.com/8zqukw.jpg
Examples
<?php
function foo() {
echo shortify('http://www.yorickpeterse.com/','is.gd'); //This will output the following: http://is.gd/wbev
}
?>
Extra information
1. Each function will return the result, so don’t forget to use the echo statment.
2. By default the third parameter will be set to false, if set to true the shortify() function will return the URL as an HTML hyperlink using the following format:
<a href="[short-url]" title="Shorter URL using [service-name]">[short-url]</a>
For example:
<a href="http://is.gd/2" title="Shorter URL using is.gd">http://is.gd/2</a>
Download
Shortify can be downloaded at the following URL: http://www.yorickpeterse.com/downloads/CI_Plugins/Shortify/Shortify_v1.0.zip
