Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2008-01-05 19:24:48

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

Re: smd_if: Generic multiple if condition tests

Hi Stef,

The code is on a page template (called ‘fnc’). I tend to use separate page templates for each section.
I guess it’s sounding like a clash with something else or even a problem with another plugin?

No problem for a login… on it’s way.

Thanks for the help!

Cheers


Neil – Blue Mountains, Australia

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

Offline

#14 2008-01-05 20:52:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,433
Website GitHub

Re: smd_if: Generic multiple if condition tests

NeilA wrote:

I guess it’s sounding like a clash with something else or even a problem with another plugin?

Hehehe, I wish! Nope, it’s sloppy coding on my part; or at least a few unforeseen whatnots. Many thanks for the login: incredibly helpful.

First things first: your site now behaves. You might want to consider putting <txp:if_article_list> tags around the <h3>s inside each smd_if unless you want the “FNC Audio Media – by blah” to appear in the article itself.

Second things second: it’s a bug in the plugin that has 3 parts, all of which you found in one attempt! :-)

  1. I erroneously ran everything given in the ‘value’ argument through the “is this a field” check. In your case, you want to compare the urlvar “sort” with the word “title”. Unfortunately, “title” is the name of a TXP field so it was really looking at the title of the article and doing the comparison. D’oh!
  2. The “title” in your case is actually a custom field (custom_5). This confused the heck out of me (and probably TXP!) at first because the in-built “title” field gets overwritten by your custom field. If you experience odd behaviour (perhaps next/prev article titles not as you expect) you might want to rename that custom field to something else (e.g. “sermon”?)
  3. The contents of your ‘title’ and ‘series’ custom fields both have single quotes around them which threw my plugin into complete disarray, hence the pair of error messages.

To resolve 1) I’ve changed your local copy of smd_if so that it will only compare the in-built fields if you prefix the value attribute with a “?”. So <txp:smd_if field="urlvar:mythingy" operator="eq" value="?title"> will compare the url variable “mythingy” to the title of the article, but removing the ? will compare “mythingy” to the word “title” (as you originally intended).

I have no idea how to resolve #3 right now, I’ll work on a fix later. For now, that error will appear if any single quotes are lying around in any fields in the comparison. When I find a cure I’ll re-issue the plugin.

Many thanks for the use of your site to track this down, and apologies for the inconvenience. I’ll try and get a fix out tonight or tomorrow. In the meantime you’re good to go with the halfway-fixed plugin in your site.

Last edited by Bloke (2008-01-05 20:56: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

#15 2008-01-06 01:09:28

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

Re: smd_if: Generic multiple if condition tests

Hey Stef,

Glad to know my attempts at setting up TxP were useful to you! :-)
You programmers need twits like me to do things like use single quotes in names, and overwrite program variables! LOL.

Seriously, thanks for your prompt work on it, and for the education it’s been for me – it was no drama giving you a login as the site is not public yet and still very much under construction, and it certainly was no inconvenience…

I will change the name of custom_5 and will also drop the single quotes (I seem to recall them causing problems elsewhere too…).

Cheers


Neil – Blue Mountains, Australia

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

Offline

#16 2008-01-06 03:29:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,433
Website GitHub

Re: smd_if: Generic multiple if condition tests

NeilA wrote:

You programmers need twits like me to do things like use single quotes in names, and overwrite program variables!

Hehehe, we need normal people like you to make us see the blindingly obvious :-)

…will also drop the single quotes (I seem to recall them causing problems elsewhere too…).

Fine by me. The only reason I never spotted it is ‘cos I just don’t use them as a matter of course. Same with spaces. Old programming habit I guess. However, the latest version has better support for quotes insofar as I went the other way: single quotes are fine now to allow for apostrophes in words but double quotes will be converted to alleviate the errors you encountered.

So if you use double quotes in things and encounter stuff that fails to match any more, try not comparing against double quotes, or use a less restrictive comparison such as operator="contains" and search for a known bit within the string.

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.

Last edited by Bloke (2008-01-06 03:44:50)


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

#17 2008-01-06 13:40:42

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

Re: smd_if: Generic multiple if condition tests

Hi bloke,
I’ve had one instance where this nice plugin threw up errors that I couldn’t figure. I have very possibly done something silly but thought I’d post just in case.

I’m using the plugin in a form to check whether two custom fields are being used:

<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",,"> <p><a href='<txp:custom_field name="URL" />'><txp:custom_field name="URL_name" /></a></p> </txp:smd_if>

When a relevant article is accessed it returns one of these for each custom field queried (can’t seem to format it):

Tag error: <txp:smd_if field=“URL, URL_name” operator=“isused, isused” value=”,,” logic=“and”> -> 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()

the debug goes like this, despite both fields being used:
<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",," logic="and"> [<txp:smd_if field="URL, URL_name" operator="isused, isused" value=",," logic="and">: false] </txp:smd_if>

Any tips much appreciated.
(I have installed v0.4)
Thanks,
Peter

Offline

#18 2008-01-06 14:13:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,433
Website GitHub

Re: smd_if: Generic multiple if condition tests

peterj wrote:

I have very possibly done something silly

Hehe, unlikely, it’ll probably be the code!

I can immediately see one problem that I overlooked: custom field names are always stored in the database in lower case. I’ll fix the code in the next revision so that even if you give upper case names they will be converted to lower case before I ask TXP about them.

To get round it for now, just change to this: field="url, url_name".

But don’t do that just yet because it doesn’t explain the error message: I can’t replicate it here. I’ve named two custom fields the same as yours (same capitalisation too) and used the same tag — incidentally you now don’t need the two commas in the value field if you are wholly using operators that don’t require a value, you can either use value="" or miss it out altogether.

So before you change your field attribute to lower case, would you confirm a few things please:

  1. what sort of stuff is in each of your custom fields (I can guess(!) but want to be sure, post some examples if you can). It may be some odd characters are screwing up my code and I need to check for them
  2. add to your smd_if tag the attribute debug="1" and post the output. Just wanna check it’s comparing the right stuff.

Oh, and your version of TXP, thanks. I’m a bit stumped at the moment but I’ll carry on playing with it.


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

#19 2008-01-06 14:39:21

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

Re: smd_if: Generic multiple if condition tests

I’m working to late..
1. URL has no quotes, just something like http://www.theage.com.au/
2. The optional friendly name for the link ie The Age

Idea being if no friendly name is put in then LINK is shown.

Hope that helps.
The plugin is working fine on pages, although I’m having some problems there (I think) with the ‘isused’ operator – not 100% sure yet, will have to go to sleep before I break something,

Peter

Offline

#20 2008-01-06 14:40:17

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

Re: smd_if: Generic multiple if condition tests

Sorry misread the end of your post, will do as instructed.

Offline

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

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

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: 99

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: 99

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: 11,433
Website GitHub

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

Board footer

Powered by FluxBB