Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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: 993
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).

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

Offline

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

trenc
Plugin Author
From: Cologne
Registered: 2008-02-27
Posts: 569
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
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

#21 2010-06-21 08:16:11

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

Darkliam wrote:

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

Yep, it’s not. TXP.com weblog / Tag parser – par 1: new features

The parser stops because there are ' single quotes inside single quotes. Let me give some options.

Using variable as container:

<txp:variable name="test"><txp:rah_function call="safe_count" table="textpattern" where='Category="peintres"' /></txp:variable>

Escaping the single quotes by using double single quotes:

<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where=''Category="peintres"'' />' />

Or because the inner one doesn’t have tags used as values:

<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where="Category=''peintres''" />' />

Or:

<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where="Category=""peintres""" />' />

Hope it helps :-)

Offline

#22 2010-06-21 09:51:08

Darkliam
New Member
Registered: 2010-06-20
Posts: 9

Re: rah_function // Every PHP function is a tag

And that can be used with rss_unlimited_category? can we used the name of the other categories create ? This plugins use always category 1 and category 2 or it accept the other categories created by rss_unlimited_category?

Offline

#23 2010-06-21 10:25:05

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

Darkliam wrote:

And that can be used with rss_unlimited_category? can we used the name of the other categories create ? This plugins use always category 1 and category 2 or it accept the other categories created by rss_unlimited_category?

I can’t comment on that. I have no idea where or how rss_unlimited_categories stores the categories. I just basically corrected your markup, as that was what I thought you were asking.

What comes to the limits of rah_function, from the plugins pov there are none. The plugin just calls PHP functions, which means that it works as long as the returned output is a string. The actual limit comes from the function that is used.

The safe_count() you used in your example, runs a query that counts matching rows, and the limits of safe_count() are same as normal count query’s.

Offline

#24 2010-06-21 10:40:22

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

Darkliam, I took bit of look at rss_unlimited_categories and it stores the infomation about the categories in textpattern_category table.

<txp:rah_function call="safe_count" table="textpattern_category" where="category_id=13" />

Something like that should get the count. The category_id is what you want to macth. Instead the name of the category, it uses the ID number of the category.

You can dynamically fetch the category’s ID from txp_category table too, if you required:

<txp:rah_function call="fetch" what="id" table="txp_category" where="name" is="peintres" />

Which can then be feeded to the count. Best solution tho, would be use the ID without the extra step.

Offline

Board footer

Powered by FluxBB