vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Forum if condition not working (https://vborg.vbsupport.ru/showthread.php?t=232192)

Mythotical 01-05-2010 12:16 AM

Forum if condition not working
 
Not sure what is going on but my if condition is not working. Not sure why but it is getting annoying.

$foruminfo['forumid'] works for showing when you click on the category itself but not when your viewing threads inside a forum.

HTML Code:

<if condition="in_array($forum['forumid'], array($vboptions['pl9_qloc']))">
$vboptions['pl9_qloc'] is a line of forum id's that are inserted once selected from the settings.

Any help much appreciated.

Thanks
Steve

--------------- Added [DATE]1262664726[/DATE] at [TIME]1262664726[/TIME] ---------------

Well a response was here, got an email so here is my reply.

As I didn't give the template I'm trying to use this in, I have added this:
Code:

navbar
If anyone has a suggestion to pull all forum id's and match them in an if condition array for this to display on selected forums then please do post it.

Thanks

Lynne 01-05-2010 02:39 AM

If you look in the includes/functions.php file where the navbar is rendered, you'll see that $forum is not registered for use in that template. However, $foruminfo is registered for use, so try using that variable instead.

Mythotical 01-05-2010 02:47 AM

Yeah I have it in the conditional already, let me post the full conditional.

HTML Code:

<if condition="in_array($foruminfo['forumid'], array($vboptions['pl9_qloc'])) OR THIS_SCRIPT == 'index' OR in_array($forum['forumid'], array($vboptions['pl9_qloc']))">
<if condition="$vboptions['pl9_quote_display'] == 'table'">
$table
</if>
<if condition="$vboptions['pl9_quote_display'] == 'styled_table'">
$stable
</if>
<if condition="$vboptions['pl9_quote_display'] == 'normal_quote'">
$normal
</if>
<if condition="$vboptions['pl9_quote_display'] == 'styled_quote'">
$snormal
</if>
</if>

As you can see, the $foruminfo is there and works but only when viewing categories, here take a look at the link:
Category view with forums

Now click into one of those forums and it goes away.

EDIT: $vboptions[pl9_qloc] has all forums selected so all forum id's are in the settings row.

Lynne 01-05-2010 03:12 AM

Oh yikes, and I'm mixed up between vb4 and vb3, sorry about the stuff regarding registering!

You said that what I'm looking for is in the navbar, but I don't see anything different in the navbar when I click on one of the forums from the page you link to. What should I be looking for exactly?

Another thing..... when I've had a option field where I input a row of forumids... x,y,z and then I wanted to use them like you are (if in_array etc...), I've had to first explode it in a plugin...
ie. I have some forums set in option "verify_forums" (ie. 12,13,14)
In my plugin, I have
PHP Code:

$verifyforums explode(","$vbulletin->options[verify_forums]); 

Then in my template, I used:
HTML Code:

in_array($threadinfo[forumid], $verifyforums)

Mythotical 01-05-2010 03:16 AM

Oh yeah sorry, the quote box goes away. Its above the navbar but I forgot to allow guests to see it. Let me change that, just keep refreshing on that first link and you will see it appear.

Good point on the explode, I will give that a try.

--------------- Added [DATE]1262668603[/DATE] at [TIME]1262668603[/TIME] ---------------

Ok you as a guest can now see the quote box. I'm such an idiot for not remembering to give perms to guests.

--------------- Added [DATE]1262668880[/DATE] at [TIME]1262668880[/TIME] ---------------

Ok did the explode function and changed the $foruminfo to reflect $pl9_qloc in the array but with $foruminfo['forumid'] it didn't show on any forum page.

Lynne 01-05-2010 03:23 AM

I see it now. It seems the only forumid it is currently working in is forumid 1. I would try the explode thing cuz I'm pretty sure that is it. The text field is simply a string as an option, so you need to turn it into an array before you can do your in_array condition.

Mythotical 01-05-2010 03:27 AM

Did the explode, here is what I have in the global_start plugin:

PHP Code:

$pl9_quoteloc explode(","$vbulletin->options['pl9_qloc']);

$quote_sql $db->query_read("SELECT * FROM " TABLE_PREFIX "bfc_quotes WHERE unapproved = 0 ORDER BY RAND() LIMIT 1");
while(
$quotes $db->fetch_array($quote_sql))
{
$uname $quotes['username'];
$quote_text $quotes['quote'];
eval(
'$table = "' fetch_template('bfc_quote_table') . '";');
eval(
'$stable = "' fetch_template('bfc_quote_stable') . '";');
eval(
'$normal = "' fetch_template('bfc_quote_normal') . '";');
eval(
'$snormal = "' fetch_template('bfc_quote_snormal') . '";');
}
eval(
'$quote = "' fetch_template('bfc_quote') . '";'); 

EDIT: Even with the change nothing plus the forum with the id of 1 it goes away on as well.

Lynne 01-05-2010 03:44 AM

And your condition is now like this ?
HTML Code:

<if condition="in_array($foruminfo['forumid'], $pl9_quoteloc) OR THIS_SCRIPT == 'index' OR in_array($forum['forumid'], $pl9_quoteloc)">
If that isn't working, I'd start spitting stuff out in the template like $pl9_quoteloc and $vboptions['pl9_qloc'] to see exactly what it is getting.


Also, it looks like in your query, you are only pulling one row. You could just use query_first instead and then you don't have to do the fetch_array stuff:
PHP Code:

$quotes $db->query_first("SELECT * FROM " TABLE_PREFIX "bfc_quotes WHERE unapproved = 0 ORDER BY RAND() LIMIT 1");

$uname $quotes['username'];
$quote_text $quotes['quote'];
eval(
'$table = "' fetch_template('bfc_quote_table') . '";');
eval(
'$stable = "' fetch_template('bfc_quote_stable') . '";');
eval(
'$normal = "' fetch_template('bfc_quote_normal') . '";');
eval(
'$snormal = "' fetch_template('bfc_quote_snormal') . '";'); 

No biggie. What you wrote will work also, but query_first is also nice cuz it's easy.

Mythotical 01-05-2010 03:50 AM

Oh no, the forumid stuff has nothing to do with the quotes in the database, that is separate. Basically I am just trying to get the if condition to work so it will display the quote box on the forumdisplay page that I choose.

I just changed my if condition to what you suggested as I still had:
HTML Code:

<if condition="in_array($foruminfo['forumid'], array($pl9_quoteloc)) OR THIS_SCRIPT == 'index' OR in_array($forum['forumid'], $pl9_quoteloc)">
Notice the array() part. But when I remove that part, I get the following:

The following error occurred when attempting to evaluate this template:

Code:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in [path]/includes/adminfunctions_template.php(3950) : eval()'d code on line 1

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

If I continue anyway without going back to the template, the quote box displays flawlessly, any reason why that error would come up when the if condition the way you suggested works flawlessly?

Lynne 01-05-2010 01:48 PM

OK, this is odd because it really is almost exactly the type of condition I use in a mod of mine. (Sorry I took off, sleep was calling.)

Check your options for pl9_qloc - is the data validation type set to Free ?

This is exactly my code in my plugin:
PHP Code:

$verifyforums explode(","$vbulletin->options['verify_forums']);
eval(
'$template_hook[showthread_verify_thread] .= " ' fetch_template('added_verify_threads') . '";'); 

And in my template:
HTML Code:

<if condition="is_member_of($vbulletin->userinfo,array(5,6)) AND in_array($threadinfo['forumid'], $verifyforums)">
That looks very much like exactly what you have:
PHP Code:

$pl9_quoteloc explode(","$vbulletin->options['pl9_qloc']);
...
eval(
'$quote = "' fetch_template('bfc_quote') . '";'); 

and then
HTML Code:

<if condition="in_array($foruminfo['forumid'], $pl9_quoteloc) OR THIS_SCRIPT == 'index' OR in_array($forum['forumid'], $pl9_quoteloc)">
Only other thing I can think of is to add something before your explode statement to define the variable as an array:
PHP Code:

$pl9_quoteloc = array(); 


Mythotical 01-05-2010 02:56 PM

No worries, sleep was calling me too.

I am missing something here, I know I am. I just can't put my finger on it.

Maybe I should move the if condition to the plugin instead. I am searching all forums dealing with vB coding for that warning and I'm still reading threads.

Lynne 01-05-2010 03:06 PM

I am stumped. I mean, our code looks almost identical and yet mine works and I do not get that error. Try really shortening it just to see what happens...

HTML Code:

<if condition="in_array($foruminfo['forumid'], $pl9_quoteloc)">
And did you try spitting out those variables? And did you check you data type for the field?

Mythotical 01-05-2010 03:15 PM

Interesting, if I spit out $pl9_quoteloc it returns:
Code:

Array
And $vboptions[pl9_qloc] returns:
Code:

1,2,3,31,4,5,6,7,8,9,23,10,24,11,25,12,26,13,27,14,15,28,16,29,17,30,18,19,20,21,22
So this is very very interesting considering it works for you but not me.

Lynne 01-05-2010 04:58 PM

And $pl9_quoteloc *should* return an array and it *should* work in that condition. Did you try just using the one simple condition? If you get the error, have you tried just telling it to use it anyway and seeing what happens? (And yes, I get the same results you do - Array for the first variable and the string of forumids if I print out the other.)

Mythotical 01-05-2010 06:06 PM

Yep I tried the one simple condition. I have saved it and told it to use it anyway and it still works so I don't see the problem.

I have discovered something though. If I change it to include array() like so:
HTML Code:

in_array($foruminfo['forumid'], array($pl9_quoteloc))
It saves without that Warning but if I remove array() it gives the warning.

Lynne 01-05-2010 06:11 PM

But it doesn't work like that, right?

Try printing out $foruminfo['forumid'] also and see what prints out. Also, did you ever check the data type of the option and see if it is set to Free?

Mythotical 01-05-2010 06:23 PM

Right, it stops working as soon as I add array()

I tried printing $foruminfo['forumid'] and it caused my if condition to stop working so I had to move that inside the if condition and it prints out the forum id properly.

Lynne 01-05-2010 06:32 PM

Quote:

Originally Posted by Steve M (Post 1948094)
I tried printing $foruminfo['forumid'] and it caused my if condition to stop working so I had to move that inside the if condition and it prints out the forum id properly.

That is weird. It should print it out (as $foruminfo[forumid] <- no single quotes).

Quote:

Also, did you ever check the data type of the option and see if it is set to Free?
!!!!!

Seriously, please check that. I've said it a couple of times now.

Mythotical 01-05-2010 06:44 PM

Oh sorry, I keep forgetting to mention that, yeah I checked it and it is set to Free.

Also I am using $foruminfo[forumid] without single quotes as well. The warning is referring to $pl9_quoteloc portion.

--------------- Added [DATE]1262724383[/DATE] at [TIME]1262724383[/TIME] ---------------

You know what, let me try this on my fresh vb test site.

Lynne 01-05-2010 06:49 PM

When I set the option to Numeric on my site, I get the exact problem you get - it only works for the first forumid. That's why I emphasized you needing to verify that datatype.

Mythotical 01-05-2010 07:01 PM

I might know the problem then. I tried to install on my fresh test site but same problem so you saying that might help then.

--------------- Added [DATE]1262725405[/DATE] at [TIME]1262725405[/TIME] ---------------

EDIT: Fixed the database error. Seems when I went back and changed things then changed them again, it some how added multiple entries of the same setting to the database. So that is fixed but still I can't figure out why I keep getting that warning when saving the template.

--------------- Added [DATE]1262729717[/DATE] at [TIME]1262729717[/TIME] ---------------

I will just leave it as is for now and figure it out later. I need to get this released so I will make sure everyone knows about the warning but I doubt anyone will mess with that template.

Lynne 01-05-2010 08:41 PM

Once it's released, I can download it and try it out on my 3.8 test site and maybe I'll see something that we've missed.

Mythotical 01-05-2010 09:14 PM

Ok I will probably get it released tomorrow or Thursday. Got a few more features to finish up first.


All times are GMT. The time now is 03:55 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01294 seconds
  • Memory Usage 1,820KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (9)bbcode_html_printable
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (23)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete