Textpattern CMS support forum

You are not logged in. Register | Login | Help

#231 2009-04-05 17:31:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,566
Website

Re: smd_if: Generic multiple if condition tests

smd_if steps up a gear in terms of (long overdue) security. v0.8 | compressed adds filtering ability on all fields/values so you can clean up and remove unwanted input.

It’s similar to the system in smd_query and is pretty in-depth so has an entire section of the plugin help dedicated to it — including examples — and that should allow you to feel a little more comfortable about trusting user-submitted values. I think I’ve tested it to destruction but if there are any foibles that have crept in, please report them. Similarly, if you find any cool validation expressions that might help others grappling with the new feature, please post them also.

maniqui

I tried and tried to get a ‘default’ mechanism in the plugin but it wouldn’t have it. The sticking point was this:

  1. when a test is performed it compares field X against value Y
  2. the result of that test clocks up a little tally of true/false values (which are tested at the end to determine whether the true/else branch is taken)
  3. if a test fails and I apply a ‘default’ value I cannot repeat the test with the new value, because it would also fail: the default value would not match the user input and it would still add a ‘false’ to the tally
  4. if a test fails and I set the replacement variable to the default value, the ‘true’ branch of the container is never executed because the original test still failed, thus it nothces up a ‘false’ tally and usually drops into the ‘else’ part

So either way I’m damned if I do, damned if I don’t. The only way out of it is to force (read: hack) a ‘true’ result if the any given test fails and there’s a default value set up for that test. But even that might not be enough because if another test in the suite fails, you could still go the ‘else’ branch when using AND logic. And if that happens, the plugin appears to be “broken” because it’s not following the correct branch under certain conditions.

So after spending all morning trying to figure it out I gave up, sorry. You’ll have to just get a glowing feeling over the new security feature instead :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#232 2009-04-05 22:37:28

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Hi Bloke!
It’s all right!, you don’t even have to explain nor to sorry about it.

What do you think about this other idea?

<txp:smd_if field="urlvar:jquery" operator="defined">
  <script src="/js/jquery-{smd_if_jquery}.min.js" type="text/javascript"></script>
</txp:smd_if>

So, if the field is defined, make the variable value (in this case, the one passed along the jquery URL variable) available in {smd_if_jquery}.
(sorry if this already works and I’m just asking for something that all mighty smd_if can already do)

Of course, what about if var is empty (?jquery=), or if it’s not empty… etc.
Not sure… probably the answer is in Example 5 on help docs.

The above code can be refined to:

<txp:smd_if field="urlvar:jquery" operator="defined,isused">
  <script src="/js/jquery-{smd_if_jquery}.min.js" type="text/javascript"></script>
</txp:smd_if>

Would it test both conditions using AND logic?

(Again, sorry if I’m asking for things that are already possible with current plugin version)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#233 2009-04-06 00:08:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,566
Website

Re: smd_if: Generic multiple if condition tests

maniqui wrote:

<txp:smd_if field="urlvar:jquery" operator="defined">

That should work, yes. It’s supposed to work that way, at least! Any variable that smd_if encounters will become a replacement variable prefixed with {smd_if_. Should it not behave that way, let me know and I’ll see what I can do.

Regarding your 2nd example, again, it’s supposed to do that out of the box. It will test if the variable is defined AND used. But, by inference, if it is used it must be defined, so you can actually simplify it to:

<txp:smd_if field="urlvar:jquery" operator="isused">
  <script src="/js/jquery-{smd_if_jquery}.min.js" type="text/javascript"></script>
</txp:smd_if>

But that would also return true if someone entered ?jquery=squid. You don’t want that.

I’d like to say the new filter attribute comes in handy here but I can’t figure out how to write an expression to “remove anything that is not a digit or a dot”. I can get halfway there but my regex prowess is not much cop. Perhaps it would be easier if the plugin could optionally allow you to specify an expression for characters that you do want in your strings.

Sadly, I can’t figure out the appropriate code to do that right now either. I think my brain’s gone on holiday somewhere and hasn’t told me when it’s coming back. Hopefully tomorrow!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#234 2009-05-30 00:46:48

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: smd_if: Generic multiple if condition tests

Similar problem again—I am not really getting the hang of this:

<txp:variable name="page_number" value='<txp:rsx_page_number />' />
<txp:smd_if field="txpvar:page_number" operator="eq" value="1" >
blabla
</txp:smd_if>

At the moment this is never true, even if the variable is “1”. Is “eq” the right one to use here?

Offline

#235 2009-05-30 01:00:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,566
Website

Re: smd_if: Generic multiple if condition tests

dl33 wrote:

Is “eq” the right one to use here?

Yes. Providing <txp:rsx_page_number /> outputs a single number without any markup or spaces around it.

Test it like this:

<txp:variable name="page_number" value="1" />
<txp:smd_if field="txpvar:page_number" operator="eq" value="1">
blabla
</txp:smd_if>

Should see: blabla

<txp:variable name="page_number" value='<txp:custom_field name="custom1" />' />
<txp:smd_if field="txpvar:page_number" operator="eq" value="1">
blabla
</txp:smd_if>

Put 1 in custom1 and you shoud see blabla.

If both those work then my guess is that the rsx tag is outputting something in addition to the number.

Last edited by Bloke (2009-05-30 01:02:11)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#236 2009-05-30 08:51:13

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_if: Generic multiple if condition tests

It can output html markup with page number. So, new attr striptags can be useful in this case:

<txp:smd_if field="txpvar:page_number:striptags" operator="eq" value="1">
blabla
</txp:smd_if>

Last edited by the_ghost (2009-05-30 08:57:49)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#237 2009-07-09 06:14:17

cuda
Member
From: Georgia, USA
Registered: 2008-02-06
Posts: 70
Website

Re: smd_if: Generic multiple if condition tests

Ok trying to use this tag variation and not getting the desired result:

<txp:smd_if field="parent" value="music" > hi </txp:smd_if >

File categories

Music – Sub1 -Sub1-1 -Sub2

So if you go to url/section/?c=Sub1 you get nothing when I would expect “hi”
It always evaluates false, no matter the file category or sub category. When in any of the music file sub categories I want it to be true. Am I using the tag incorrectly? the tag is being used in a page template.

Thanks in advance

Offline

#238 2009-07-09 09:11:52

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: smd_if: Generic multiple if condition tests

cuda wrote:

Ok trying to use this tag variation and not getting the desired result:

Hi,
do you get the same result declaring the “operator” attribute explicitly like so
<txp:smd_if field="parent" operator="contains" value="music" > hi </txp:smd_if > ?

Offline

#239 2009-07-09 11:55:50

cuda
Member
From: Georgia, USA
Registered: 2008-02-06
Posts: 70
Website

Re: smd_if: Generic multiple if condition tests

Thanks redbot but I had tried that and it too does not work, with the operator…. Now this is a file category if that makes any difference. any other thoughts

Offline

#240 2009-07-09 11:58:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,566
Website

Re: smd_if: Generic multiple if condition tests

cuda wrote:

File categories

If you’re trying to compare file categories you won’t be able to do it this way. The ?c= syntax in the URL only works for articles. If you want to use smd_if to compare File parent cats you need to embed it in the form/container of a <txp:file_download_list> tag.

Last edited by Bloke (2009-07-09 11:59:16)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB