Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-11 11:32:24

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

[RFC] Import attributes into <txp:php />

Have you ever used this ugly construction to import a value into <txp:php />?

<txp:variable name="somevar" value='<txp:tag /> or something else' />

<txp:php>
global $variable;
$somevar = $variable['somevar'];
// use $somevar somehow
</txp:php>

Wouldn’t it be better to call simply

<txp:php somevar='<txp:tag /> or something else'>
// use $somevar somehow
</txp:php>

Internally, this would just require extract($atts) before eval(). Any drawbacks?

Offline

#2 2021-03-11 11:38:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,240
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Yes yes yes!

(I mean, yes to doing it. No drawbacks as far as I can see).

Last edited by Bloke (2021-03-11 11:39:24)


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

#3 2021-03-11 11:47:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,240
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Oooh, related: could I run a little request by you in 4.9 onwards? Can we rename the `php` function to tpt_php and alias it during tag registration, like we do with `tpt_link`? Any ramifications you can think of?

If we do this, we can remove this horrible hack in vendors/Textpattern/Mail/Adapter/SMTPMail.php:

$this->mailer::$validator = 'phpinternal';

which is there simply to bypass the fact that we expose ‘php’ as a global function and PHPMailer looks for a function in the global scpoe of that name and executes it as a callback to validate addresses, which causes all kinds of breakage in Txp.

Definitely for 4.9, not 4.8.5, but I forgot to mention it when I did the SMTP stuff.


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 2021-03-11 11:53:21

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Bloke wrote #329211:

Yes yes yes!

(I mean, yes to doing it. No drawbacks as far as I can see).

Already done, actually, just waiting for approval.

Bloke wrote #329212:

Oooh, related: could I run a little request by you in 4.9 onwards? Can we rename the `php` function to tpt_php and alias it during tag registration, like we do with `tpt_link`? Any ramifications you can think of?

Hmm, a number of plugins is using php() to check for user rights…

Offline

#5 2021-03-11 11:56:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,240
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Back on topic: I presume it would not be possible to share such variables between <txp:php> blocks? Currently, with the variable approach (ugly as it is) you can import $variable and use it across blocks. With this proposed syntax it would only be for creating local variables, right? Kinda like JavaScript’s let? It wouldn’t pollute the $variable global space at all would it?


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 2021-03-11 11:59:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,240
Website GitHub

Re: [RFC] Import attributes into <txp:php />

etc wrote #329213:

Hmm, a number of plugins is using php() to check for user rights…

Yeah. Good point. Annoying. Okay, no worries. Let’s stick with the PHPMailer hack.


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

#7 2021-03-11 12:01:54

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Bloke wrote #329214:

With this proposed syntax it would only be for creating local variables, right? Kinda like JavaScript’s let? It wouldn’t pollute the $variable global space at all would it?

As I get it, yes, it would be local to php() function and not use $variable at all:

<txp:php message="hello">
    echo $message;
</txp:php>
<!-- no $message defined, nor $variable['message'] ever created/altered -->

Offline

#8 2021-03-11 12:18:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,240
Website GitHub

Re: [RFC] Import attributes into <txp:php />

etc wrote #329216:

As I get it, yes, it would be local to php() function and not use $variable at all:

Sweeeet, thanks.

*awaits someone to ask if we can support both local and global variables somehow using this syntax*


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 2021-03-11 12:28:58

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [RFC] Import attributes into <txp:php />

Actually, <txp:php /> already can access its attributes/content, so nothing very much new here:

<txp:php one="1">
dmp($atts);
dmp($thing);
</txp:php>

Offline

Board footer

Powered by FluxBB