Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2013, 02:52 PM
laminedj laminedj is offline
 
Join Date: Oct 2013
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to show a module only to visitors?

Hello,

I want to show a "Sign up" image in a module on right sidebar only to visitors and a "Welcome" message if it's a registered user.

I know I have to ad a PHP module on right sidebar ad php code.

I found this, as base of work, but I am still blocked

PHP Code:
<?php

if (is_member_of(vB5_User::get('usergroupid'), 6)) {
echo 
"Hi Admin";
} else {
echo 
"Hello!!!!!!";
}

?>
I am limited on php, little help would be very appreciated.

Regards

Laminedj
Reply With Quote
  #2  
Old 11-03-2013, 04:08 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) { 
echo 
'<img src="image.png" alt="sign up" />';
} else {  
echo 
'<span style="color: red;">This is a welcome message</span>';

change to suit your needs
Reply With Quote
  #3  
Old 11-03-2013, 07:11 PM
laminedj laminedj is offline
 
Join Date: Oct 2013
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne, for your quick response.

If rgister user ID id "two" , I have to replace by '2' in your code?

For "else"

If I want to welcome a registred user with his name and pic, what syntax I have to use ?

Regards
Reply With Quote
  #4  
Old 11-04-2013, 03:40 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't understand the question about userid 2. My first line is regarding users with NO userid - they are unregistered.

As for the name, I believe that would be
vB5_User::get('username')

avatar is possibly:
$api->callApi('user', 'fetchAvatar', array('userid' => vB5_User::get('userid')))

(Never tried it, just grabbed it out of the code)
Reply With Quote
  #5  
Old 11-04-2013, 08:00 AM
laminedj laminedj is offline
 
Join Date: Oct 2013
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry for misunderstand about userid 2, now I get it.

I applied you code for pic and message and it works very well.

For the code for registered users (show name and avatar) I put this, but I doesn' work:



PHP Code:
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) { 
echo 
'<img src="/images/misc/signup.png" alt="sign up" />';
} else {  
echo 
'vB5_User::get('username') <span style="color: red;">This is a welcome message</span>' vB5_User::get('username'$api->callApi('user''fetchAvatar', array('userid' => vB5_User::get('userid');

Reply With Quote
  #6  
Old 11-04-2013, 10:52 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just played with it and got the avatar to work. You will need to format it (image size, change message, etc.) yourself:

PHP Code:
$avatar vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];

if (!
vB5_User::get('userid') OR vB5_User::get('userid')==0) {  
echo 
'<img src="http://fansfoot.com/forum/images/misc/signup.png" alt="sign up" />';
} else {   
echo 
'<img src="'$user['avatarpath'] .'" />';; 

Reply With Quote
Благодарность от:
ozzy47
  #7  
Old 11-05-2013, 02:58 PM
laminedj laminedj is offline
 
Join Date: Oct 2013
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

I got it, thanks :up: How can add also user name for register members ?

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

I tried to change the pic size to 50px by 50px , but id didn't work. any idea?

PHP Code:
$avatar vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];

if (!
vB5_User::get('userid') OR vB5_User::get('userid')==0) {  
echo 
'<img src="/images/misc/signup.png" alt="sign up" />';
} else {   

echo 
'<span style="color: red; height:50px; width:50px;">Welcome back!</span>';
echo 
'<img src="'$user['avatarpath'] .'width="50" height="50" " />';; 

Reply With Quote
  #8  
Old 11-05-2013, 08:45 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$avatar vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];

if (!
vB5_User::get('userid') OR vB5_User::get('userid')==0) {  
echo 
'<img src="/images/misc/signup.png" alt="sign up" />';
} else {   

echo 
'<span style="color: red; height:50px; width:50px;">Welcome back,'vB5_User::get('username')   .'!</span>';
echo 
'<img src="'$user['avatarpath'] .'" width="50" height="50" />';

Reply With Quote
  #9  
Old 11-07-2013, 09:48 AM
laminedj laminedj is offline
 
Join Date: Oct 2013
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, all is working now!
Reply With Quote
Reply


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:50 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.04428 seconds
  • Memory Usage 2,264KB
  • 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
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete