#1 2009-11-21 18:45:12

Gocom
Moderator
omega
Real name: Jukka Svahn
From: Finland
Known languages: EN, FI
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>

More info and downloads at Rahforum.biz/rah_function


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

 

#2 2009-11-21 18:49:36

pieman
Member
lambda
Real name: Stuart Charlton
From: Bristol, UK
Website

Re: rah_function // Every PHP function is a tag

Sir, I salute you.

Offline

 

#3 2009-11-21 18:56:21

Gocom
Moderator
omega
Real name: Jukka Svahn
From: Finland
Known languages: EN, FI
Website

Re: rah_function // Every PHP function is a tag

Thank you Stuart :)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

 

#4 2009-11-21 19:46:47

ruud
Developer emeritus
omega
Real name: Ruud van Melick
From: a galaxy far far away
Known languages: li,nl,en,(de)
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
Moderator
omega
Real name: Jukka Svahn
From: Finland
Known languages: EN, FI
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.


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

 

#6 2009-11-21 21:11:06

Gocom
Moderator
omega
Real name: Jukka Svahn
From: Finland
Known languages: EN, FI
Website

Re: rah_function // Every PHP function is a tag

Released version 0.1.1. Changelog:

  • Added has_privs() and allow_scripting checks.

More info and downloads


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

 

#7 2009-11-23 09:14:43

Bloke
Developer
omega
Real name: Stef Dawson
From: Coventry, UK
Known languages: Engl(ish)
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 TXP.

TXP Builders – finely-crafted code, design and txp

Offline

 

#8 2009-11-23 10:19:47

Destry
Moderator
chi
From: Strasbourg, France
Known languages: en, fr
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)


EuroIA 2010 (Paris, Sept) | Paris Web 2010 (14-16 Oct) | Content Strategy Forum 2011 (London, 5-7 Sept), Official Announcement

Offline

 

#9 2009-11-24 13:26:17

johnstephens
Plugin Author
mu
Real name: John Stephens
From: Harrisonburg, VA
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
rho

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

 

Powered by PunBB
© Copyright 2002 – 2005 Rickard Andersson