Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-01-16 19:48:36

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

Help needed: rah_beacon collides with new textpattern tag registry

This immensely useful plugin of Jukka’s essentially allows you to turn a txp form into a txp tag of your own and pass variables to it that are valid just for that instance. Think smd_macro using normal txp forms. Like smd_macro, it makes it easy to build your own tags for your users, kind of like txp variants of WP shortcodes.

Jukka built it for 4.6 and thought ahead to register any self-built tags with the textpattern tag registry. It’s not been updated to match the late change to the class notation but that is easily rectified.

More recently, however, I discovered that the plugin collides with txp’s own tags if a form exists with the same name as a tag, for example, if you have a form called images the form gets called instead of txp’s own txp:images tag.

What I don’t know is where the remedy needs to be:

  • Does rah_beacon need to check if a tag first exists (e.g is already registered) before registering the form as a tag? If it does, I think it belongs somewhere here but have no idea how to implement it.
  • Does the \Textpattern\Tag\Registry class need adapting to prevent pre-registered tags from being usurped by another plugin?
  • If the Tag\Registry class already prevents double-registering of a tag (I’m not knowledgeable enough here), does some kind of plugin ordering need changing to prevent rah_beacon from getting in there first?

All tips or (even better) code remedies welcome…

Given that Jukka seems to be MIA, I’d be most grateful if anyone knowledgeable enough could offer their opinion


TXP Builders – finely-crafted code, design and txp

Offline

#2 2016-01-16 21:35:57

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Help needed: rah_beacon collides with new textpattern tag registry

With searches and replaces, would cbe_output_form be a workaround ?

Offline

#3 2016-01-17 11:15:35

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

Re: Help needed: rah_beacon collides with new textpattern tag registry

Claire, your plugin is great and addresses the same problem. Jukka’s is just that little bit more succinct in its execution and therefore simpler for users to add to body fields.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2016-01-17 12:01:50

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

Re: Help needed: rah_beacon collides with new textpattern tag registry

I think I’ve worked it out. The \Textpattern\Tag\Registry function includes a function called isRegistered, which can be added to rah_beacon.

Replace this function within src/Rah/Beacon.php

    public function light()
    {
        $forms = safe_column(
            'name',
            'txp_form',
            '1 = 1'
        );

        $beacon = new Rah_Beacon_Handler();

        foreach ($forms as $name) {
            if (!preg_match('/^[a-z][a-z0-9_]*$/', $name)) {
                trace_add('[rah_beacon: '.$name.' skipped]');
                continue;
            }

            Txp::get('\Textpattern\Tag\Registry')->register(array($beacon, $name), $name);
        }
    }

with this:

    public function light()
    {
        $forms = safe_column(
            'name',
            'txp_form',
            '1 = 1'
        );

        $beacon = new Rah_Beacon_Handler();

        foreach ($forms as $name) {
            if (!preg_match('/^[a-z][a-z0-9_]*$/', $name)) {
                trace_add('[rah_beacon: '.$name.' skipped]');
                continue;
            }

            if (Txp::get('\Textpattern\Tag\Registry')->isRegistered($name)) {
                trace_add('[rah_beacon: '.$name.' skipped – tag already exists]');
                continue;
            }

            Txp::get('\Textpattern\Tag\Registry')->register(array($beacon, $name), $name);
        }
    }

i.e. adding the ->isRegistered part in the middle after where rah_beacon checks that the form name is in lowercase a-z or 0-9 or underscore. In the tag trace, there will be a corresponding message: “rah_beacon: tag name skipped – tag already exists” if the form name collides with another txp:tag or one registered by another plugin.

If’ I’ve overlooked something, please let me know.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB