Bit.ly integration for Textpattern CMS
PHP
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
textpacks
.gitignore
LICENSE
README.textile
composer.json
manifest.json
rah_bitly.php

README.textile

rah_bitly

Project page | Twitter | GitHub | Support forum | Donate

Gives Textpattern CMS’ articles tiny Bitly powered short links. These links are generated automatically when an article is published and stored in a custom field of your choosing. Easy to setup, just define your credentials via graphical user interface. Adds zero more steps to article publishing. Made by Jukka Svahn’s tiny hand, using and loving Bitly.

Requirements

Rah_bitly’s minimum requirements:

  • Textpattern 4.5.0 or newer.
  • PHP 5.2 or newer.
  • Installed on a web server with an internet connection and outgoing HTTP connections allowed.
  • Bitly account.
  • End user: a modern web browser with JavaScript support.

Most servers, including shared hosting spaces, should be able to run rah_bitly just fine as long as Textpattern 4.5.0 or newer is installed.

Installing

Rah_bitly’s installation follows the standard plugin installation steps.

  1. Download the plugin installation code.
  2. Copy and paste the installation code into the Install plugin box of your Textpattern Plugin pane.
  3. Run the automated setup.
  4. After the setup is done, activate the plugin. Done.

Configuring

To start using rah_bitly you will first need to define your Bitly login, API key and the custom field you want to use to store shortened links.

Setting the preferences is easy. You can find all you need in Textpattern’s Advanced Preferences panel, neatly organized under Bitly integration section. The following three options will be present.

  • Bitly login is where your Bitly username would go.
  • API key is your API key. Get your own API key here. You can also find and reset your API key from your Bitly account’s settings page.
  • Store in a custom field is the custom field that will be used to store shortened links.

Generating links

Bitly links are generated for an article when one of the three conditions is met.

  • When the article is published.
  • When already published article’s URL title is modified.
  • When the custom field used to store the link is emptied.

All three conditions only apply while the article is in, or is saved with, live or sticky status. Short links won’t be generated for unpublished articles.

All generated links will follow your Bitly account’s preferences, including your custom domain or preferred domain.

If requesting a short link from Bitly fails due to connection error, or because Bitly’s servers are temporarily unreachable, a new request is sent when the article is saved again. You will notice if the request has been successful when there is a shortened link in the custom field.

The link that the plugin will shorten is the article’s permanent link, the real location of the individual article page that Textpattern responds to. It’s the same location as where the View link points on the Write panel.

Displaying links

Displaying Bitly links on your page templates and articles is easy and customizable due to the fact that a custom field is used to store the shortened links.

<txp:if_custom_field name="short_url">
	<a href="<txp:custom_field name="short_url" />">
		<txp:custom_field name="short_url" />
	</a>
<txp:else />
	<p>No short link.</p>
</txp:if_custom_field>

The above snippet would display shortened Bitly link when placed to article form or context. When no link is available “No short link” message is shown. The short_url is the name of the custom field.

Changelog

Version 0.4.2 – 2012/12/21

  • Fixed: Undefined variable notices during article updates.
  • Added: Displays preferences group on Textpattern 4.6-dev’s Preferences panel.

Version 0.4.1 – 2012/09/20

  • Improved: Cleaned up the installer.

Version 0.4 – 2012/08/27

  • Added: Textpattern 4.5.0 compatibility. Thank you, Robert Wetzlmayr.
  • Added: Finnish translation.
  • Fixed: A potential issue with uninstaller SQL statement’s wildcards.
  • Changed: Textpacks aren’t embedded to the code, but uses installer.
  • Removed: Unnecessary HTML escaping in one of the preference controls.
  • Removed: Functionality added in v0.2 that allowed picking new custom fields from HTTP POST data. This is for future compatibility.
  • Removed: Dropped support to file_get_contents() and allow_url_fopen. cURL is now required in favor of future compliance and move to oAuth.

Version 0.3 – 2011/12/05

  • Changed: Now uses Textpattern’s script_js() to output JavaScript blocks.
  • Improved: Escape URLs returned by Bitly so that it can not break JavaScript string. This is to prevent potential JavaScript injections.

Version 0.2 – 2011/07/21

  • Changed: Preference section’s heading now uses title case, and option labels sentence case.
  • Changed: Now picks up new custom fields from POST data.
  • Stef, Markus, thank you for suggestions.

Version 0.1 – 2011/07/20

  • Initial release.