Shorten urls and cache them in database

Sometimes you want to share your website pages with twitter. You can shorten the page urls with a JavaScript API, but it slows down terribly your website.
This plugin asks only once for the shorten url, then cache it in database for later access.

Installation

  • In a console, from your project root dir, run:
git clone git://github.com/ornicar/dmBitLyPlugin.git plugins/dmBitLyPlugin  
  • In config/ProjectConfiguration.class.php, add dmBitLyPlugin to the list of enabled plugins:
class ProjectConfiguration extends dmProjectConfiguration
{  
  public function setup()  
  {  
    parent::setup();  
 
    $this->enablePlugins(array(  
      // your enabled plugins  
      'dmBitLyPlugin'  
    ));  
  • In a console, from your project root dir, run:
php symfony doctrine:generate-migrations-diff  

php symfony doctrine:migrate  

php symfony dm:setup  

Configuration

Get a login and an api key at http://bit.ly/account/register?rd=/
And configure the service with them:
config/dm/services.yml

parameters:  
  bit_ly_api.login:       mylogin  
  bit_ly_api.api_key:     R_fd1ff8d93e3a646myapikey  

Usage

Shorten a url:

$shortUrl = $this->getService('bit_ly_api')->shorten($longUrl);

The first time, a request will be sent to bit.ly, to get the short url. Then it's stored in your database, and next time there will be no more external call.

    Add a comment

    Impossible to fetch issues for this plugin.
    Impossible to get this plugin changelog.

    dmBitLyPlugin, created on March 25, 2010 by Thibault D, used by 22 projects

    Fork Diem on GitHub