Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2011-03-22 22:12:10

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: rah_function // Every PHP function is a tag

Hello,

Is there a way to add an attribute inside this snippet to count only articles that have an existing image. By existing, I mean an image that is recorded in the db…

<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" &&  status="4"' />

Tried this:

<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" &&  status="4" && Image="<txp:image />"' />

Unlucky :P

Thanks !

Last edited by hablablow (2011-03-22 22:33:30)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#32 2011-03-22 22:57:25

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,208

Re: rah_function // Every PHP function is a tag

Could this help:

where="image != ''" ?

I better paste my original: <txp:jmd_count table="textpattern" where="image != ''" />

Last edited by uli (2011-03-22 22:58:53)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#33 2011-03-22 23:10:30

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: rah_function // Every PHP function is a tag

Viel besser ! Danke Uli, neat I like it and very, very close… We have just one case missing:

<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" &&  status="4" && Image != ""' />

This snippet will not count articles with an empty image field, which is the first goal…

Aber (but)…

It will still count articles with a wrong image id defined in the article_image field… The id is wrong either because the user has entered a wrong number, more likely he has deleted an image from the image tab without removing first the article…

Any way we can check for the existence of a corresponding image recorded here ? In the txp_image table ?

Vielen dank ! (Thanks !)

Last edited by hablablow (2011-03-22 23:16:16)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#34 2011-07-08 15:16:59

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

Re: rah_function // Every PHP function is a tag

Rah_function v0.3 released. Changes:

  • Fixed: Now empty, nothing-at-all, string can be used as the container-mode’s wrapped statement.
  • Added: Now makes sure that the called function is really defined before executing anything.

More info and downloads

Offline

#35 2011-11-10 18:18:49

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: rah_function // Every PHP function is a tag

I’m trying to do a preg_match function but I think I’m doing it all wrong. This is the tag I’m using:

<txp:rah_function call="if" thing="preg_match" pattern="/^A/i" subject="AAA"> yes </txp:rah_function>

This doesn’t generate any errors or warnings but does nothing. Can anyone nudge me in the right direction?

Offline

#36 2011-11-10 18:33:52

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 583
Website

Re: rah_function // Every PHP function is a tag

Did you look at the second page of this thread? Some examples there.

Offline

#37 2011-11-10 18:35:54

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: rah_function // Every PHP function is a tag

Hey maruchan,

I did and those were pretty useful, however, they are all preg_replace examples. I’m trying to find a match only. I know it should probably be easier to figure out!

Offline

#38 2011-11-10 18:48:59

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: rah_function // Every PHP function is a tag

This worked:

<txp:rah_function call="preg_match" pattern="/^pdf/" subject="pdf" />

Wondering how one would use two functions (such as if and preg_match) in one rah tag. I’m a little confused over the attribute ‘thing’.

Offline

#39 2011-11-11 00:12:49

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

Re: rah_function // Every PHP function is a tag

lithium002 wrote:

This doesn’t generate any errors or warnings but does nothing.

The if you are calling isn’t a function, but a language construct. That’s the reason why it doesn’t return any errors or anything else either.

Wondering how one would use two functions (such as if and preg_match) in one rah tag.

Can’t. One tag can call one function. But you can use the tag to pass the results to other rah_function tag, or in the case of conditionals to variable and test the results with if_variable. Well, as long as the results can carry over to string land (you won’t be able to tell bool from integer for instance). As in:

<!--
	Create a variable called "math", and
	populate it with the results from rah_function
-->

<txp:variable name="match"><txp:rah_function call="preg_match" pattern="/^pdf/" subject="pdf" /></txp:variable>

<!--
	The variable should return either 1 or 0.
	Knowing that, one can do the conditional.
-->

<txp:if_variable name="match" value="1">
	Yes.
<txp:else />
	No.
</txp:if_variable>

I’m a little confused over the attribute ‘thing’.

That thing … thing sets to which parameter the wrapped content is passed to. The location thing attribute is placed in the parameter list, is where the wrapped content is passed. The attribute get’s it’s funky name, thing, from Textpattern. That’s what the parameter/functionality is called in Textpattern’s source code, and the name avoids collisions slightly better than potentially more commonly used names.

Last edited by Gocom (2011-11-11 00:17:06)

Offline

#40 2011-12-16 17:26:36

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

Re: rah_function // Every PHP function is a tag

Rah_function v0.4 released. Changes:

  • Improved: Do not use attributes’ real names in the function call, but use a temp array. Makes sure attributes get resolved as valid variables no matter what is passed to plugin tag by Textpattern’s parser.

More info and downloads

Last edited by Gocom (2011-12-16 17:27:21)

Offline

Board footer

Powered by FluxBB