Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-06-16 20:58:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

smd_short_url: tiny/canonical URLs

Allow your visitors to use just the article ID in the URL. Optionally output a canonical <link> tag that uses said short URL too.

Written in response to Sam’s request, using wet’s code.

Download v0.21

Revision history
————————

All available versions and changes are listed here. Each entry indexes the relevant post(s) in the threads to learn about the features.

Last edited by Bloke (2009-10-19 10:25:34)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2009-06-18 08:46:54

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Killer idea Steph – another timely addition to the toolset.

The only problem I can see with it is that it doesn’t appear to play nicely with gbp_permanent_links (I’m using 1.3) – it just rewrites the URL according to the Txp prefs.

I’m not sure which plugin would need to be updated, but until they’re compatible, smd_short_url is a no go for me.

Offline

#3 2009-06-18 09:40:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: smd_short_url: tiny/canonical URLs

pieman wrote:

The only problem I can see with it is that it doesn’t appear to play nicely with gbp_permanent_links

No, you’re right it won’t. It just generates a stock TXP url and forwards the page to that. I guess gbp_permanent_links doesn’t get called again after a redirect. Have you tried putting smd_short_url at a higher priority (e.g 4) so it is called first, thus giving gbp_ a chance to rewrite the url a second time? Long shot, but it might work.

I’ll drop Graeme a line and see if he can tell me the best way to make the plugins play in the same sandpit without throwing sand in each others’ eyes.

Last edited by Bloke (2009-06-18 09:40:52)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2009-06-18 13:01:34

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: smd_short_url: tiny/canonical URLs

Sorry Stef,

@pieman :

Did you try robert’s solution within your error_default page ?


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#5 2009-06-18 15:28:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: smd_short_url: tiny/canonical URLs

pieman

I got a reply from Graeme. Give this a whirl: go into smd_short_url and change the first line to this:

register_callback('smd_short_url', 'textpattern');

Then see if it works with gbp_permanent_links. Also try adjusting the plugin priorities. It may be that gbp_permanent_links has to be first I don’t know. If any combination of change to plugin code and order of execution works, please let me know so I can supply the option to make it work with gbp_permanent_links.

Also give Pat64’s idea a go. If that works I can try and make the plugin optionally hook into the 404 page as well.

Thanks in advance.

Last edited by Bloke (2009-06-18 15:30:58)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2009-06-22 12:44:58

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Oops, I forgot to subscribe to this topic. How rude.

Thanks for the ideas – I’ll try them out.

Offline

#7 2009-06-23 15:09:31

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Stef, changing register_callback did the trick perfectly – no need to change plugin prios. Magic.

Offline

#8 2009-06-23 15:22:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: smd_short_url: tiny/canonical URLs

pieman wrote:

Stef, changing register_callback did the trick perfectly

Excellent, thanks for testing. In which case, consider the plugin updated to v0.11


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2009-06-26 07:31:54

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: smd_short_url: tiny/canonical URLs

Two things spring to mind:

  1. Trying to map a short to a canonical URL with every 'textpattern' event will result in approximately 99% energy waste as most requests will not go to any short URL. Thus, I’ve added a ‘txp_die’ event for TXP 4.2.0 which lets you easily intercept 404 (and some other) stati and redirect to the canonical URL then: register_callback('smd_short_url', 'txp_die', 404);
  2. I’m not quite sure if 302 is the proper HTTP status. Maybe 301 would fit better (I know who brought 302 onto the table in the first place)

Offline

#10 2009-06-26 08:28:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: smd_short_url: tiny/canonical URLs

wet wrote:

Two things spring to mind <snip>

Fabulous. Thank you very much, sir. I’ll fix the plugin ready for release alongside 4.2.0. In fact, that callback is going to come in very handy for a few other projects I’m working on.

And you’re right about the status code. I should have read up on the difference between 301 and 302 before blindly implementing it. Thanks for the correction.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2009-08-09 10:51:48

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: smd_short_url: tiny/canonical URLs

A brief call for help: please would anybody who is running Textpattern in either of the following environments consider testing smd_short_url:

  1. a sub-directory
  2. a multi-site setup under 4.2.0/SVN (use v0.2 of the plugin for this — see first post)

I have a suspicion the plugin needs some massaging to work properly in both the above circumstances, so any feedback on the success or otherwise, along with any diagnosticy output, would be much appreciated. Editing the first few lines of the plugin code to read:

$urlparts = parse_url(hu);
dmp($urlparts);

$re = '#^'.$urlparts['path'].'([0-9].*)#';
dmp($re);

$have_id = preg_match($re, $_SERVER['REQUEST_URI'], $m);
dmp($m);
exit;

and posting / mailing me any output would really help as well. Thanks in advance!

Last edited by Bloke (2009-09-15 07:30:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2009-08-12 11:23:11

dubh
Member
From: Wellington, New Zealand
Registered: 2004-02-27
Posts: 20
Website

Re: smd_short_url: tiny/canonical URLs

Stef: this plugin is just what I was looking for! Thanks!

Sadly though, I don’t have any Txp installs that fit your test criteria. :-)


Alan Macdougall — http://halfpie.net/

Offline

Board footer

Powered by FluxBB