URL Shortener Plugin for ExpressionEngine

July 7th, 2009 in Addon | ExpressionEngine | Plugin | 1 comments

About the Plug-in

URL Shortener Plugin creates short URL addresses using is.gd API for ExpressionEngine.

Installation

Download URL Shortener Plugin and unzip the package into your ExpressionEngine plug-ins folder.

Below is the actual code if you want to have a quick look.

<?php
/*
=========================================================
= Author: Cem Meric =
= http://webunder.com.au =
=========================================================
= File: pi.url_shortener.php =
=-------------------------------------------------------------------=
= Compatibility (tested): ExpressionEngine 1.6.7 =
=-------------------------------------------------------------------=
= Purpose: Creates short url addresses using =
= is.gd API =
=-------------------------------------------------------------------=
= Version History: =
= 1.0.0 - 07 July 2009 =
= plugin first built =
=========================================================
*/


$plugin_info = array(
'pi_name' => 'URL_Shortener',
'pi_version' => '1.0',
'pi_author' => 'Cem Meric',
'pi_author_url' => 'http://webunder.com.au',
'pi_description' => 'Creates short url addresses using is.gd API',
'pi_usage' => URL_Shortener::usage()
);


class URL_Shortener {

var $return_data = "";



/** ----------------------------------------
/** Constructor
/** ----------------------------------------*/

function URL_Shortener()
{
global $TMPL;

$url = $TMPL->tagdata;
$preview = $TMPL->fetch_param('preview');


$url = str_replace('&#47;', '/', $url);


$urlShort = "http://is.gd/api.php?longurl=" . $url;


$urlShort = file_get_contents($urlShort);


if ($preview == 'true')
{

$this->return_data = $urlShort . "-";

} else {

$this->return_data = $urlShort;

}

}

/* FUNCTION END */

// ----------------------------------------
// Plugin Usage
// ----------------------------------------

// This function describes how the plugin is used.
// Make sure and use output buffering

function usage()
{
ob_start();
?>

Examples:

{exp:url_shortener}http://expressionengine.com/{/exp:url_shortener}

Result: http://is.gd/1oTO5




{exp:url_shortener preview="true"}http://expressionengine.com/{/exp:url_shortener}

Result: http://is.gd/1oTO5-



<?php
$buffer = ob_get_contents();

ob_end_clean();

return $buffer;
}
/* END */


}
// END CLASS
?>

Examples

ExpressionEngine tag

{exp:url_shortener}http://expressionengine.com/{/exp:url_shortener}

Output

Result: http://is.gd/1oTO5

License

Dynamic Select Plugin is licensed under a Creative Commons Attribution 3.0 License.

Picture of Cem Meric

email | follow | peak

Cem Meric

Cem runs a creative web design and development studio called Webunder, specialising in ExpressionEngine CMS and he is an active member of the ExpressionEngine forums.

When he's not working, he enjoys being a hero with friends.

 
Picture of Clothing

Wow! Its imposible… I’m realy shocked :/

1 

said Clothing about 2 years, 8 months ago

 

Commenting is not available in this entry.