Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-03-04 14:23:20

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Summary

ais_url_alias is a very simple “URL alias” plugin, allowing the configuration of short “friendly” paths, or facilitating the migration of a legacy URL structure when moving from another CMS to Textpattern.

Download

Features

  • Use any custom field as a URL alias
  • Allow for multiple aliases, using multiple custom fields
  • View and manage aliases in bulk, saving administration time
  • Diagnostics and debugging available
  • Ideal for migrating articles to Textpattern with existing permalinks

Complete help is included with the plugin, of course!

History

Version 0.2

New functionality:

  • URL query strings are now passed through the redirection from alias to permalink #7
  • Added URL aliases list panel to view and search configured aliases #8
  • Added ability to bulk remove URL aliases via the URL aliases list panel #9
  • Improved validation #10
  • Added French translation (cara-tm) #1
  • Added German translation (jools-r, uli) #2
  • Added Dutch translation #3

Fixes:

  • Code quality fixes
  • Fix for permanent redirection not triggering
  • Fix for empty URL aliases showing as duplicates in diagnostics #6
Version 0.1:

Initial release.

Last edited by abutcher (2025-03-07 12:12:14)

Offline

#2 2025-03-04 14:32:40

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

A little bit of backstory:

I bashed this together quickly to facilitate a migration to Textpattern from another CMS, which actually had multiple permalinks to articles because it itself was an installation migrated to from another CMS. What a mess.

I also wanted something where I could easily debug duplicate permalinks (or badly formatted invalid permalinks), to help with cleaning up junk permalink URLs after data migration, so this plugin includes output in the diagnostics and some very rudimentary browser-side validation on the article edit panel.

I would prefer to do server-side validation, but I didn’t see a hook for intercepting saving an object like an article and intercepting the validation phase. Likewise, I wanted to add diagnostics to ensure the permalinks weren’t clobbering an official Textpattern permlink, but I saw it’s mostly done in preText() so it’s not easy to test with an API call, and I gave up. :)

I know this is a “wheel reinvention” in a way – I need this to work quickly, and was disappointed that modules like jra_alias_urls were no longer available. I only saw rah_pathway recently by accident (didn’t see a forum post about it), but it also doesn’t do everything I needed it to do. I am struggling a little to find quality information about plugins that are being maintained, work with version 4.8.8 and modern PHP, and have enough help text to explain how they work before installing them.

Last edited by abutcher (2025-03-04 14:59:47)

Offline

#3 2025-03-04 16:18:47

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,851
Website GitHub

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Great that you’ve done this. I’m sure it could come in handy, and it seems to offer more than other plugins ever have. Thanks too for posting a notification in the other thread.

I posted a proposal for the German textpack in the relevant issue. Maybe someone else (@uli?) can improve on it / give it the once over.

abutcher wrote #339188:

I would prefer to do server-side validation, but I didn’t see a hook for intercepting saving an object like an article and intercepting the validation phase.

There are callbacks for article_posted and article_saved which you can use to process / check the article data on publish/save. Maybe that helps?

FWIW: I found jra_alias_urls via archive.org – no idea if it still works or would have been of use.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2025-03-04 20:15:14

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Hey jakob,

Thanks for your comment, and your help with the German :) It’s already committed in preparation for the next version. It seems a small change to add functionality may be needed to fit the customer’s use case anyway, so v0.2 might be just around the corner.

I’ve seen article_posted and article_saved but unfortunately they just fire blindly. There’s no way to interrupt the process cleanly. It would be nice if there were a set of callbacks for validating saves (like article saving) where you can return a go/no-go validation style response. A simple example would be a boolean (true to save, false to abort) or even better, a structure with a true/false response and a validation message.

Ideally I’d like to intercept the save and be able to post a message explaining what is wrong before bad data hits the database, but for now the quick and dirty client side validation works, I think.

I did actually see jra_alias_urls and also found information about it on the waybackmachine, but I didn’t install it. I’m reticent to use an abandoned plugin on a fresh website, so I didn’t dig deeper. Since it was so small I figured the functionality would be easy to duplicate and modernise.

I’ve now sat down and taken a look at jra_alias_urls, and it does work a little differently. It allows you to put multiple URLs in a single custom field, which is interesting but less user-friendly because it requires you to wrap the URLs in commas. This is because it cheats and uses a LIKE when querying the database (i.e. @custom_1 = ‘,$path,’). It could be an alternative for other people if ais_url_alias isn’t a good fit.

I know I’m guilty of reinventing the wheel :(

Offline

#5 2025-03-04 21:49:33

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

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

There’s a validation step during article save that has a callback for adding your own validation checks.

See article_validate() and the Validator class for more info.

Edit: …

abutcher wrote #339191:

or even better, a structure with a true/false response and a validation message.

The Validator does exactly this 😃

Last edited by Bloke (2025-03-04 23:13:19)


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 2025-03-04 21:57:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,851
Website GitHub

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

No worries. Each plugin is a little different. I gave it a whirl on txp 4.9 and php 8.4 and get a few minor errors:

  • Various warnings about Undefined $redirectPermament on line 438. It’s a typo (m instead of n) in the name [ EDIT: you’ve already corrected that ].
  • Warning "Undefined variable $oldRedirectPermanent". when saving a preference. [ EDIT: Found it: line 667 has the same typo with m instead of n. ]
  • I don’t see the pref group on the regular Admin › Preferences panel, only by using the “Options” link in the plugin panel.

The validation of the custom field works nicely, and a quick test worked too.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2025-03-05 06:22:26

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,313

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

jakob wrote #339190:

Maybe someone else (@uli?) can improve on it

No, impossible, perfect German! Just 1 small typo (in line 27) there’s a deviant “Aliase” instead of “Aliasse”.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2025-03-05 09:44:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,851
Website GitHub

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Thanks uli!


TXP Builders – finely-crafted code, design and txp

Offline

#9 2025-03-06 16:07:27

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Thanks everyone for your help :) This plugin was a part of customisations for a last minute rush project (and a moving target), and I appreciate the input from everyone. I have a new version coming soon with a couple of additional features needed for the project.

@Bloke I did see that but it wasn’t immediately apparent how it worked without reverse engineering. Being in a rush, I didn’t really dig into it, so the fault is mine. If I can find some time, I’ll look into incorporating something, but I assume it’ll need to be done with a custom constraint class… leave it with me :)

@jakob I did see that typo and had already squished it, and I was sure it was dealt with before the v0.1 release was packaged, but apparently I didn’t – woops. I really need to get new glasses :( Thanks for the heads-up.

@uli Danke! Ich habe in der Schule etwas Deutsch gelernt, aber nicht viel mehr als “der Bahnhof ist neben dem Rathaus” :) :) It helps me enormously, the contribution from Jakob and yourself. Can I ask, is it correct as “Aliasse” or “Aliase” ? Since it’s a loanword from Latin, should it be Aliase for a masculine plural, like der Atlas -> die Atlase?

Offline

#10 2025-03-06 17:44:29

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

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

abutcher wrote #339196:

I did see that but it wasn’t immediately apparent how it worked without reverse engineering.

Yeah. It’s not very well documented, apologies. On my to-do list is to write a blog post about it. Constraints are going to be a bigger part of core in Txp 5 because custom fields will be wired up to handle them.

I assume it’ll need to be done with a custom constraint class

You assume correctly, if one of the core constraints doesn’t match your use case. Essentially you can instantiate one of ours, or your own (perhaps extended from one of core’s classes) and add it to a constraints array with each entry being a constraint you want to operate on a piece of data in the $rs record set. Pass as the second parameter an array of limits that match the constraint type and/or a gTxt() message string from your plugin pack that is shown if the constraint fails. Check the individual constraint class you’re using/extending to see what it accepts in its constructor.

At the appropriate callback point (in this case article_ui > validate_save (or validate_publish) just pass your constraints array back by reference merged with the one you get given in the callback’s 4th(?? I forget which one, might be 3rd) argument, and the system will handle the rest.


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 2025-03-06 18:10:20

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

@Bloke Perfect, this saves me even more time, and fills in some blanks I had when skimming through the code and comments. You guys are brilliant. :)

I’ll try and give it a bash tonight.

Offline

#12 2025-03-07 12:18:47

abutcher
Plugin Author
Registered: 2023-06-29
Posts: 14

Re: ais_url_alias - URL aliases (aka friendly paths, legacy paths, ...)

Version 0.2 is now available for download.

New functionality:

  • URL query strings are now passed through the redirection from alias to permalink #7
  • Added URL aliases list panel to view and search configured aliases #8
  • Added ability to bulk remove URL aliases via the URL aliases list panel #9
  • Improved validation #10
  • Added French translation (cara-tm) #1
  • Added German translation (jools-r, uli) #2
  • Added Dutch translation #3

Fixes:

  • Code quality fixes
  • Fix for permanent redirection not triggering
  • Fix for empty URL aliases showing as duplicates in diagnostics #6

Offline

Board footer

Powered by FluxBB