Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#11 2009-11-24 14:22:13
- 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
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
- From: Woodbridge, VA
- Registered: 2008-06-01
- Posts: 989
- 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
- Registered: 2006-02-14
- Posts: 1,410
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
- From: Woodbridge, VA
- Registered: 2008-06-01
- Posts: 989
- Website
Re: rah_function // Every PHP function is a tag
That worked, thanks again!
Offline
#15 2009-11-28 07:52:58
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- 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).
Offline
#16 2009-11-28 11:15:17
- trenc
- Plugin Author
- From: Cologne
- Registered: 2008-02-27
- Posts: 562
- Website
Offline
#17 2009-11-30 06:36:29
- speeke
- Member
- From: Bruny Island, Australia
- Registered: 2009-03-29
- Posts: 161
- 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
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- 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>
Offline
#19 2009-11-30 07:27:21
- speeke
- Member
- From: Bruny Island, Australia
- Registered: 2009-03-29
- Posts: 161
- 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
- Registered: 2010-06-20
- Posts: 9
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