Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-11-21 18:45:12
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- Website
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
#2 2009-11-21 18:49:36
- pieman
- Member
- From: Bristol, UK
- Registered: 2005-09-22
- Posts: 491
- Website
Re: rah_function // Every PHP function is a tag
Sir, I salute you.
Offline
#3 2009-11-21 18:56:21
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- Website
Offline
#4 2009-11-21 19:46:47
- ruud
- Developer emeritus
- From: a galaxy far far away
- Registered: 2006-06-04
- Posts: 5,068
- Website
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
#5 2009-11-21 20:45:25
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- Website
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
#6 2009-11-21 21:11:06
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- Website
Re: rah_function // Every PHP function is a tag
Released version 0.1.1. Changelog:
- Added
has_privs()
andallow_scripting
checks.
Offline
#7 2009-11-23 09:14:43
- Bloke
- Developer
- From: Leeds, UK
- Registered: 2006-01-29
- Posts: 9,978
- Website
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
#8 2009-11-23 10:19:47
- Destry
- Member
- From: Haut-Rhin
- Registered: 2004-08-04
- Posts: 4,662
- Website
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
#9 2009-11-24 13:26:17
- johnstephens
- Plugin Author
- From: Woodbridge, VA
- Registered: 2008-06-01
- Posts: 992
- Website
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