Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2013, 07:55 AM
ExcelFox ExcelFox is offline
 
Join Date: Apr 2011
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default <vb:if condition="$bbuserinfo[userid]"> Not Working

I am trying to have my BBCODE contents not viewable unless the user is logged in. I found a hack from this forum that will allow conditionals in BBCODE. I've installed that too.

What I'm trying to do is use
Code:
<vb:if condition="$bbuserinfo[userid]">
'Something here
<vb:else />
'Something else here
</vb:if>
When I try to do it as below, it gives me an error when the page is loaded
Code:
<div class="bbcode_container">
	<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
	<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>>
		<code>
			<vb:if condition="$bbuserinfo[userid]">
				{vb:raw code}
			<vb:else />
				<b><font color="green">Hello Guest!</font></b>
				<font color="black"><p>To post questions, download files, to provide solutions to queries and <b>especially to view this code</b>, <a href="register.php"><u>register for free!</u></a></p>
			</vb:if>
		</code>
	</pre>
</div>
The original code that works is below

Code:
<div class="bbcode_container">
	<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
	<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>><code>{vb:raw code}</code></pre>
</div>
Any idea what's going wrong?

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

This isn't throwing any error. However, I am not getting the message for a guest. Instead, I am getting the actual contents of the BBCode even if a user is logged in or not

Code:
<div class="bbcode_container">
	<div class="bbcode_description">{vb:rawphrase code}:&nbsp;<input type="button" value="Click To Select" onclick="selectAll(this); return false;"></div>
	<pre class="bbcode_code"<vb:if condition="$vboptions['codemaxlines']">style="height:<vb:if condition="$blockheight<$vboptions['codemaxlines']">{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}*2}<vb:else />{vb:math {vb:raw blockheight}*{vb:stylevar mid_fontSize}+{vb:stylevar mid_fontSize}}</vb:if>;"</vb:if>>
		<code>

<vb:if condition="$bbuserinfo[userid]">
<b><font color="green">Hello Guest!</font></b>
				<font color="black"><p>To post questions, download files, to provide solutions to queries and <b>especially to view this code</b>, <a href="register.php"><u>register for free!</u></a></p>
<vb:else />

				{vb:raw code}
</vb:if>
		</code>
	</pre>
</div>
Reply With Quote
  #2  
Old 04-13-2013, 11:44 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know what mod you installed to allow conditions, but normally the contents of posts are cached to avoid processing them over and over every time anyone views a thread. But the result is that conditons like yours don't work correctly unless something was done to avoid caching.
Reply With Quote
  #3  
Old 04-13-2013, 12:26 PM
ExcelFox ExcelFox is offline
 
Join Date: Apr 2011
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your inputs. The mod that I installed is https://vborg.vbsupport.ru/showthread.php?t=149107

My objective is to mask the contents within the code wrap unless the user is logged in (not a guest). I have seen countless forums doing similar things (even this forum has something that does that). I just want to know how to do that.
Reply With Quote
  #4  
Old 04-13-2013, 03:32 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you read all of the modification thread? You need to have post caching disabled, as Kevin stated.
Reply With Quote
  #5  
Old 04-13-2013, 06:51 PM
ExcelFox ExcelFox is offline
 
Join Date: Apr 2011
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could you please let me know how to disable caching?
Reply With Quote
  #6  
Old 04-13-2013, 07:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In the admincp setting, under Server Settings and Optimization Options, set Cached Posts Lifespan to 0.
Reply With Quote
  #7  
Old 04-13-2013, 08:41 PM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm reading it 00:30am so maybe I'm not reading well but I believe that you have the condition just the opposite:
Code:
<vb:if condition="!$bbuserinfo[userid]">
 ............Hello Guest!........... 
<vb:else /> 
{vb:raw code}
 </vb:if>
Also sometimes try different syntax with the same result. eg
Instead of:
Code:
$bbuserinfo[userid]
Try
Code:
$vbulletin->userinfo['userid']
And finally, is good to close all tags.... You have the <font color="black"> unclosed.

Edited: In my opinion is better to use:
Code:
<vb:if condition="$bbuserinfo[userid] > 0">
instead of:
Code:
<vb:if condition="!$bbuserinfo[userid]">
because (if I remember well such hour), even the guest are getting userid=0

Chris
Reply With Quote
  #8  
Old 04-13-2013, 11:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ChrisTERiS View Post
Edited: In my opinion is better to use:
Code:
<vb:if condition="$bbuserinfo[userid] > 0">
instead of:
Code:
<vb:if condition="!$bbuserinfo[userid]">
because (if I remember well such hour), even the guest are getting userid=0
!$bbuserinfo[userid] is true if the userid is 0, so you're right about it being the reverse but it can be used to do the same check.
Reply With Quote
  #9  
Old 04-14-2013, 04:30 AM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Reply removed as it will leads in an endless discussion........

Chris
Reply With Quote
  #10  
Old 04-14-2013, 07:28 AM
ExcelFox ExcelFox is offline
 
Join Date: Apr 2011
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a lot everybody. It seems to be working in my forum now. I will try out the suggestions given above too. And ChrisTERis, you were right about my wrongly sequencing the conditional statement. Other than that, I am not sure about the conversion between you and Kevin (I'm sure both of you know), but I'll go with
Code:
<vb:if condition="$bbuserinfo[userid] > 0">
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:01 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06644 seconds
  • Memory Usage 2,256KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (12)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete