Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2008-01-06 14:45:58

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

2. With debug=“1” I get:

$out[] = ($thisarticle[“URL”] != “”) ? ‘true’ : ‘false’;

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”> -> Notice: Undefined index: URL on line 1

AND in the txp debug I get:

<txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”> [<txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”>: false] </txp:smd_if>

I am using textpattern 4.0.5

Thanks.

Offline

#22 2008-01-06 14:52:10

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

The diagnostic might help as well if you’re a bit stumped:

Textpattern version: 4.0.5 (r2466)
Last Update: 2007-12-29 08:44:50/2007-12-29 08:29:46

Permanent link mode: section_id_title

PHP version: 4.4.7
Register globals: 1
GD Image Library: 2.0 or higher; supported formats: GIF, JPG, PNG.
Server Local Time: 2008-01-07 01:48:28
MySQL: 4.1.21-standard-log
Locale: en_GB.UTF-8
Server: Apache
Apache version: Apache
PHP Server API: apache
RFC 2616 headers:
Server OS: Linux 2.6.21-1.3194.fc7
Active plugins: zem_ir-0.5, asy_wondertag-0.5, stm_image_uploader-0.3, glx_admin_image-2007.1, tru_tags-3.1, rss_admin_show_adv_opts-0.3, smd_if-0.4

.htaccess file contents:
————————————
#DirectoryIndex index.php index.html

#Options +FollowSymLinks
#Options -Indexes

<IfModule mod_rewrite.c> RewriteEngine On #RewriteBase /relative/web/path/

RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) – [PT,L]

RewriteRule ^(.*) index.php
</IfModule>

#php_value register_globals 0
————————————

I’d put the site address up but I don’t want google getting anywhere near it for a while.

Offline

#23 2008-01-06 15:02:33

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

I just spotted something else – here is a larger version of the debug above with an array message at the end, and an undefined offset error I hadn’t noticed:

$out[] = ($thisarticle[“URL”] != “”) ? ‘true’ : ‘false’;

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”> -> Notice: Undefined index: URL on line 1

textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code:1 unknown()
textpattern/lib/txplib_misc.php(534) : eval()’d code:138 eval()
textpattern/publish.php:963 smd_if()
processtags()
textpattern/publish.php:922 preg_replace_callback()
textpattern/lib/txplib_misc.php:1383 parse()
textpattern/publish.php:782 parse_form()
textpattern/publish.php:808 doarticle()
textpattern/publish.php:509 parsearticles()
textpattern/publish.php:963 article()

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”> -> Notice: Undefined offset: 1 on line 51

textpattern/lib/txplib_misc.php(534) : eval()’d code:51 smd_if()
textpattern/publish.php:963 smd_if()
processtags()
textpattern/publish.php:922 preg_replace_callback()
textpattern/lib/txplib_misc.php:1383 parse()
textpattern/publish.php:782 parse_form()
textpattern/publish.php:808 doarticle()
textpattern/publish.php:509 parsearticles()
textpattern/publish.php:963 article()
processtags()

$out[] = ($thisarticle[“URL_name”] != “”) ? ‘true’ : ‘false’;

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” logic=“and” debug=“1”> -> Notice: Undefined index: URL_name on line 1

textpattern/lib/txplib_misc.php(534) : eval()’d code(138) : eval()’d code:1 unknown()
textpattern/lib/txplib_misc.php(534) : eval()’d code:138 eval()
textpattern/publish.php:963 smd_if()
processtags()
textpattern/publish.php:922 preg_replace_callback()
textpattern/lib/txplib_misc.php:1383 parse()
textpattern/publish.php:782 parse_form()
textpattern/publish.php:808 doarticle()
textpattern/publish.php:509 parsearticles()
textpattern/publish.php:963 article()

array ( 0 => ‘false’, 1 => ‘false’,
)

Offline

#24 2008-01-06 15:36:20

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

Re: smd_if: Generic multiple if condition tests

Thanks for the debug and diagnostics. Your last one led me to it. I’m such a doughnut sometimes and contravened the immutable programming law: don’t code at 3:30am and expect it to be good :-)

Try v0.41 (compressed) which now treats field names as lower case and should fix the undefined index warning. I’m kinda flying blind because my version of PHP doesn’t ouput the warnings like yours does, but I’m pretty sure I nailed it.

See how you get on and let me know. And thanks for spotting the bug.

Last edited by Bloke (2008-01-06 15:37:27)


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

#25 2008-01-06 19:07:34

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: smd_if: Generic multiple if condition tests

Bloke wrote:

Try v0.4 (or the compressed version) with the official question-mark-in-value extension/patch mentioned above and more robust quote support. Shout if anything goes sideways, and thanks again for finding the bugs.

You’re a legend Stef! v0.4 seems to be working fine. Thanks so much…

Cheers

Last edited by NeilA (2008-01-06 19:58:19)


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#26 2008-01-06 21:10:40

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 28

Re: smd_if: Generic multiple if condition tests

Stef, v 0.4.1 is working perfectly, thank you.

Offline

#27 2008-01-13 13:29:23

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

Something is wrong.

For ex. i have the following category structure:

  1. metro
    1. metro1
    2. metro2
    3. metro3

My code:

<txp:smd_if field="parent" value="metro">
	the list of metro stations <txp:category title="1" />
</txp:smd_if>

And if we are at global category metro1 (url looks like http://uromax.ru/category/metro1) plugin should return true, but:

<txp:smd_if field="parent" value="metro">
[SQL (0,000463): select lft as l, rgt as r from uro_txp_category as txp_category where name='avtozavodskaya' and type = 'article']
[SQL (0,000469): select * from uro_txp_category as txp_category where lft <= 21 and rgt >= 22 and type = 'article' order by lft asc]
[<txp:smd_if field="parent" value="metro">: false]
</txp:smd_if>

At the same time i have another plugin nfe_if_category:

<txp:nfe_if_category parent="METRO">
</txp:nfe_if_category>

And it works fine at the same page:

<txp:nfe_if_category parent="METRO">
[SQL (0,027634): select lft, rgt from uro_txp_category as txp_category where name = 'METRO']
[SQL (0,001715): select name, title from uro_txp_category as txp_category where (lft between 2 and 309) and type = 'article' and name != 'default'  order by lft asc]
[<txp:nfe_if_category parent="METRO">: true]

Some information:

  1. the whole tagtrace is here
  2. Diagnostic is here

Last edited by the_ghost (2008-01-13 13:38:47)


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

#28 2008-01-13 15:10:49

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

Re: smd_if: Generic multiple if condition tests

Thanks for the detailed diagnostics, the_ghost. I originally thought this had something to do with the URL structure (using /category/metro1 instead of ?c=metro1) but I tried a similar setup on my server and it worked fine. Out of curiosity, does it work if you use:

http://uromax.ru/?c=metro1

I don’t think it’ll make any difference, but I’d like to find out.

The next puzzling thing is that the plugin thinks the name you supplied in the value parameter is “avtozavodskaya” instead of “metro1”. Any idea where “avtozavodskaya” comes from? Is it the name of a section or an article or something? Do your categories have a different name and title? (the plugin uses the name)

Can you try a couple of things please and post the results:

  1. add debug="1" to the smd_if call. The plugin will output the whole category tree it tries to match, and a few other variables that might help me track the problem down
  2. add <txp:php>global $pretext; dmp($pretext);</txp:php> somewhere near the smd_if call and tell me what it outputs

If you’d rather not post these values publicly you can email them to me instead or use the forum e-mail system.

Sorry it’s not working: I can’t see what the problem is at the moment but clearly it should work so I’ll keep poking at the code and see if anything leaps out at me.

Last edited by Bloke (2008-01-13 15:11:17)


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

#29 2008-01-13 16:31:46

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

metro1 was provided like example to make my example clear. Аctually ш have the following tree of categories:

  • metro
    • http://uromax.ru/category/AVIAMOTORNAYA
    • http://uromax.ru/category/BRATISLAVSKAYA
    • and so on…

And i have glossary were childs are the letters:

  • slovar (russian translation of glossary)
    • http://uromax.ru/category/A/
    • http://uromax.ru/category/B/
    • http://uromax.ru/category/V/
    • and so on…

The result of debugging you can currently see:

  • Link to child of metrouromax.ru
  • Link to letter of glossary (parent is slovar) – uromax.ru


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

#30 2008-01-13 17:36:30

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

Re: smd_if: Generic multiple if condition tests

Aha, right, I think it might be a conceptual difficulty with the way I implemented the parent option. I will revisit the help to try and make it clearer, sorry!

First, a few observations:

  1. None of your examples contain an operator parameter, therefore they default to always compare exact equality (eq).
  2. The searches are always case sensitive (looking at this again, I will actually go back and add a parameter to allow you to turn this off in the next revision of the plugin)
  3. Usually with the parent option you would use operator="contains" or operator="begins" , and here is why:

Unlike nfe_if_category, the parent parameter does not directly compare just the “top level” parent with the value you supply. What it does is look at the entire tree from the current category all the way “up” to the root. Internally, the plugin concatenates that hierarchy into one long string and compares against that.

So if you had categories:

  • metro (level 1)
    • AVIAMOTORNAYA (level 2)
    • BRATISLAVSKAYA (level 2)
      • INFO (level3)
    • DUBROVKA (level2)

And you were currently browsing the ‘INFO’ category, its parents would be both “metro” and “BRATISLAVSKAYA”. By default, the plugin makes this into one string like this “metro BRATISLAVSKAYA and tests for a match against that.

Thus, to see if the current category is a descendent of metro you could use:

<txp:smd_if field="parent" operator="begins" value="metro">
  //something
</txp:smd_if>

Now, in your case, this is too general and you probably want to see if the current category is somewhere below the ‘level 1’ category called ‘metro’. The parent field can be told to only look at a particular tree level by adding the LVL modifier to the end. e.g.

<txp:smd_if field="parent:LVL1" value="metro">
  //something
</txp:smd_if>

Notice now you may omit the operator parameter because you are always directly comparing (eq) the value to a single category level which can of course only contain one element.

btw, in your second case you would have to use value="SLOVAR" because your category name is in capital letters. I will fix that in the next revision by adding a case_sensitive attribute.

Sorry if all that sounds confusing but I thought it was the most flexible solution. And sorry that the documentation neglects to mention this adequately! I will also fix the help with better examples and make it obvious that by default you should use contains or begins with the parent, but adding a :LVL allows you to use eq.

Does that (sort of) make sense? If you can think of a better way of implementing it without sacrificing the ability to search the whole tree, then please let me know :-)

Last edited by Bloke (2008-01-13 17:40:25)


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