Skip to content

gocom/rah_bitly

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

rah_bitly

Download | Issues | Packagist

Bitly powered short links integration to Textpattern CMS. Automatically generates short link for an article when it is published, or its URL is updated.

Install

Using Composer:

$ composer require rah/rah_bitly

Or download an installer package.

Configuration

To start using rah_bitly, you will first need to configure your Bitly access token and a field you want to use to store the shortened links. You can find the options in Textpattern admin at the page Admin / Preferences and from there Bitly Integration section. Included options are:

Usage

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 and error message is shown in the editor.

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 admin page.

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 context. If article doesn’t have a short link, No short link. message is shown instead.

For developers

Customizing permlinks

The plugin offers rah_bitly.permlink callback event that can be used to customize the article permanent link that is sent to Bitly. An example observer registered to the event might look something like:

register_callback('abc_example', 'rah_bitly.permlink');

function abc_example($event, $step, &$data): void
{
    if ($data['articleData']['Section'] === 'example') {
        $data['permlink'] .= '#bitly';
    }
}

The above would add #bitly anchor to the sent URL, if the article is published to the section named example.

Changelog

Version 0.5.1 – 2022/04/25

  • Added rah_bitly.permlink callback event that can be used to customize the article permlink that is sent to Bitly.

Version 0.5.0 – 2022/04/18

  • Bitly API version 4 compatibility.
  • Textpattern >= 4.7.0 compatibility.
  • Now requires Textpattern >= 4.7.0 and PHP >= 7.2.0.

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.