Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
rah_function // Every PHP function is a tag
Ever felt that there isn’t enough <txp:tags/>
? Now there is — kinda. Call any PHP function with a TXP tag.
<txp:rah_function call="base64_encode">
Hello world!
</txp:rah_function>
<txp:rah_function call="str_replace" search="Hello" replace="Hi" subject="Hello world!" />
<txp:rah_function call="trim" charlist="H">
Hello world!
</txp:rah_function>
<txp:rah_function call="safe_strftime">
%Y
</txp:rah_function>
Offline
Re: rah_function // Every PHP function is a tag
Sir, I salute you.
Offline
Offline
Re: rah_function // Every PHP function is a tag
Jukka, you may want to have a look at how the tag handler for <txp:php>
uses the ‘allow_article_php_scripting’ preference and the has_privs() function call, because as it is now, your plugin can be used to circumvent several security related preferences:
Offline
Re: rah_function // Every PHP function is a tag
ruud wrote:
Jukka, you may want to have a look at how the tag handler for
<txp:php>
uses the ‘allow_article_php_scripting’ preference and the has_privs() function call, because as it is now, your plugin can be used to circumvent several security related preferences:
Yes, if the site has an author that really is a crack user. Will add those options. Thx.
Offline
Re: rah_function // Every PHP function is a tag
Released version 0.1.1. Changelog:
- Added
has_privs()
andallow_scripting
checks.
Offline
Re: rah_function // Every PHP function is a tag
Fab-u-lous. Why didn’t I think of that? ;-)
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
Re: rah_function // Every PHP function is a tag
Wow. This seems pretty powerful. As I’m not a PHP dev, thus lacking the ability to visualize how to take advantage of this, I’m looking forward to seeing what others might come up with.
Post your examples!
Does this deserve it’s own sub-category in the Tag Reference? Something different than “Programmer Tags”? Or would it be better to keep core and plugin tags separate? Ah, maybe that’s the sub-category: “Plugin Tags” ? Mmmm. No, kind of misleading, I think.
Last edited by Destry (2009-11-23 10:22:32)
Offline
Re: rah_function // Every PHP function is a tag
This is awesome! I have a use-case, if I can figure out how to do it. I could probably use this plugin to replace pax_grep, and gain some additional flexibility, but I’m not sure how to set up the tag. Here’s an example:
<txp:pax_grep from="'\s|\t|\r|\n'" to=""/>
My
source
</txp:pax_grep>
I’ve tried some variations of this:
<txp:rah_function call="preg_replace" pattern="'\s|\t|\r|\n'" replacement="">
But I keep getting a Textpattern “Empty regular expression on line 1” error. Any hints?
Offline
#10 2009-11-24 14:17:54
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: rah_function // Every PHP function is a tag
johnstephens wrote:
…But I keep getting a Textpattern “Empty regular expression on line 1” error. Any hints?
Hi,
I think preg_replace requires a third parameter (subject) which is missing here.
Or are you wrapping the subject with the rah_function tag? In this case consider that the wrapped text becomes the first argument of the called function while it should be the last.
(from the instructions: “…If used as a container, contained code is used as the first attribute for the function”)
Last edited by redbot (2009-11-24 14:23:31)
Offline
Re: rah_function // Every PHP function is a tag
John, if you’re using rah_function as a container tag, whatever is in the container tag is fed to the called function as the first argument. In this case you want it to be the 3rd argument, because the first and second argument for the preg_replace call is the regex and replacement respectively.
Gocom, perhaps you can add a magic attribute that indicates where the $thing should be used, so John (and others) could do something like this:
<txp:rah_function call="preg_replace" pattern="'\s|\t|\r|\n'" replacement="" thing="here">
some thing
</txp:rah_function>
Offline
Re: rah_function // Every PHP function is a tag
Thank you Redbot! I’m using the tag to wrap the text that I want to find and replace patterns in, just like in the pax_grep example above. The purpose of this example is to strip out whitespace characters from the wrapped text. Does that make sense?
Offline