vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=263)
-   -   How to show a module only to visitors? (https://vborg.vbsupport.ru/showthread.php?t=304124)

laminedj 11-03-2013 02:52 PM

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

Lynne 11-03-2013 04:08 PM

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

laminedj 11-03-2013 07:11 PM

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

Lynne 11-04-2013 03:40 AM

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)

laminedj 11-04-2013 08:00 AM

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');



Lynne 11-04-2013 10:52 PM

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'] .'" />';; 



laminedj 11-05-2013 02:58 PM

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" " />';; 



Lynne 11-05-2013 08:45 PM

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" />';



laminedj 11-07-2013 09:48 AM

Thanks, all is working now!


All times are GMT. The time now is 01:48 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.01097 seconds
  • Memory Usage 1,749KB
  • 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
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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