rah_bitly
Published under current TXP projects
Give articles tiny Bitly powered short links. The 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.
Image: rah_bitly
List of features
- Automatically generate shortened links for articles using Bitly service.
- Easy to set up, easy to use.
Requirements
Rah_bitly’s minimum requirements:
- Textpattern CMS v4.4.1 or newer.
- PHP: cURL library or allow_url_fopen set to true.
- Installed web server with 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 v4.4.1 or newer is installed.
Installation
The usual plugin installation method is used by rah_bitly.
- Download, and copy and paste the plugin code to the Install plugin field found in your Textpattern installation’s Plugins interface (TXP / Admin / Plugins).
- Start the automated setup process by clicking the Upload button next to the field.
- After the initial setup is done, active the plugin. Look for rah_bitly in the list of plugins and click the row’s Active column’s link to active.
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 (TXP/Admin/Preferences/Admin), neatly organized under Bitly integration section. Following three options will be present.
- Bitly login is where your login id to Bitly service would go.
- API key is your API key. You can find your API key from your Bitly account’s settings page.
- Store in 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 admin-side Write and Articles tabs.
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 />
No short link.
</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.3
- 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
- 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
- Initial release.