#11 2009-11-24 14:22:13

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

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

 

#12 2009-11-24 14:29:57

johnstephens
Plugin Author
mu
Real name: John Stephens
From: Harrisonburg, VA
Website

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

 

#13 2009-11-24 14:55:49

redbot
Plugin Author
rho

Re: rah_function // Every PHP function is a tag

johnstephens wrote:

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?

Yes, I understood what you are trying to achieve. You should use the tag in his self-enclosing form like this:

<txp:rah_function call="preg_replace" pattern="'\s|\t|\r|\n'" replacement="" subject="My source" />

You have to insert the text you want to change as the third argument.

Offline

 

#14 2009-11-24 15:02:51

johnstephens
Plugin Author
mu
Real name: John Stephens
From: Harrisonburg, VA
Website

Re: rah_function // Every PHP function is a tag

That worked, thanks again!

Offline

 

#15 2009-11-28 07:52:58

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

Re: rah_function // Every PHP function is a tag

Version 0.2 released. Changes:

  • Added attribute: thing. Thanks you ruud for suggestion.
  • More examples and helpful information in docs (lot of typos too).

More info and downloads @ rahforum.biz/plugins/rah_function


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

Offline

 

#16 2009-11-28 11:15:17

trenc
Plugin Author
lambda
Real name: Tommy
From: Cologne
Known languages: german, little bit english
Website

Re: rah_function // Every PHP function is a tag

Oh, whow!

That’s a neat thing. Thank you!

Offline

 

#17 2009-11-30 06:36:29

speeke
Member
êta
Real name: Sarah Peeke
From: Bruny Island, Australia
Website

Re: rah_function // Every PHP function is a tag

Hi Gocom,

I’m not sure if this is a bug, but when I use:

<txp:rah_function call="safe_count" table="textpattern" where='Section="<txp:section />"' />

I get one more article in the count than exists, for any section I specify. Could this be something to do with MySQL counts starting at 1 versus PHP starting at 0?

Great plugin, btw!


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

 

#18 2009-11-30 07:21:23

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

Re: rah_function // Every PHP function is a tag

speeke wrote:

Great plugin, btw!

Sarah, nice to see that you like the plugin.

Could this be something to do with MySQL counts starting at 1 versus PHP starting at 0?

Don’t know what PHP starting point you are meaning, but the count starts from one; The first found row is the number one.

safe_count() function you are calling with the tag, is part of Textpattern’s core library. It runs a standard count query:

select count(*) from textpattern where Section="name"

Remember that the count also counts draws and hidden articles. If the count is rendered wrong with plain query too, and you are certain that it is wrong, the table/index might be a bit broken. Running a repair helps with that. You can use repair with phpMyadmin, for example.

If you use specialchars in the value (", ', \ etc), you need to escape the chars by using doSlash. Something like:

<txp:rah_function table="textpattern" thing="here">
	foo='<txp:rah_function call="doSlash">bar</txp:rah_function>' and bar='foo'
</txp:rah_function>

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

Offline

 

#19 2009-11-30 07:27:21

speeke
Member
êta
Real name: Sarah Peeke
From: Bruny Island, Australia
Website

Re: rah_function // Every PHP function is a tag

Apologies, I forgot to add and status=4 – was also counting sticky articles. All good.


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

 

#20 2010-06-21 07:39:52

Darkliam
New Member
alpha

Re: rah_function // Every PHP function is a tag

Hello,

can we put this : <txp:rah_function call="safe_count" table="textpattern" where='Category="peintres"' /> for search the number of article in a category (I use rss_unlimited_categorie)

in a txp variable?

(I test that : <txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where='Category="peintres" ' />' /> but this not right.)

Added code formating -Gocom

Last edited by Gocom (2010-06-21 08:17:06)

Offline

 

Powered by PunBB
© Copyright 2002 – 2005 Rickard Andersson