Author Topic: [CODE] - Show Badge/Icon if a user is a Paid Member  (Read 1331 times)

KHDev

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 501
  • Karma: +43/-2
  • Etano Contributor (Skins & Mods)
    • KH Web Development
[CODE] - Show Badge/Icon if a user is a Paid Member
« on: January 10, 2016, 12:02:57 PM »
Heres the full guide of adding "Badges/Icons" for users based on their membership. Typically used to indicate if a user is a paid member.

IMPORTANT
This guide is an example based on the default installation of etano! You will need to modify the code to your needs. You can find the membership numbers of custom memberships in your database under the memberships table (m_value) NOT (m_id).


PLEASE MAKE A BACK-UP OF ANY FILES YOU ARE GOING TO EDIT IN CASE SOMETHING GOES WRONG!



Remember to make sure the correct file name is given in the coding to match your badges/icons you are using.

I DO NOT PROVIDED ANY BADGE/ICON IMAGES SO YOU WILL NEED TO SOURCE THOSE YOURSELF.


Profile Page
NOTE! There are 3 options to choose from. DO NOT include all of them! Pick which one meets your needs!



Open ROOT > profile.php around line 47 add:


OPTION 1 - Show either a Free or Paid Badge
Code: [Select]
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$uid";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$u_status['has_badge']=true;
$u_status['badge']='freeuser.jpg';
} elseif ($status['membership']>='3') {
$u_status['has_badge']=true;
$u_status['badge']='paiduser.jpg';
}
}


OPTION 2 - Show Badge for ONLY PAID MEMBERS
Code: [Select]
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$uid";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$u_status['has_badge']=false;
} elseif ($status['membership']>='3') {
$u_status['has_badge']=true;
$u_status['badge']='paid_user.jpg';
}
}

OPTION 3 - Show DIFFERENT badges for PAID MEMBERSHIPS
Code: [Select]
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$uid";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$u_status['has_badge']=false;
} elseif ($status['membership']=='4') {
$u_status['has_badge']=true;
$u_status['badge']='paid_user.jpg';
} elseif ($status['membership']=='8') {
$u_status['has_badge']=true;
$u_status['badge']='silver_user.jpg';
} elseif ($status['membership']=='16') {
$u_status['has_badge']=true;
$u_status['badge']='gold_user.jpg';
} else {
$u_status['has_badge']=false;
}
}



Around line 134 add:

Code: [Select]
$tpl->set_var('u_status',$u_status);

SAVE.


Upload your badge images to ROOT > media > pics > here making sure the image names and format match what you use in the php code.


Now open ROOT > skins_site > def > profile.html and use something like below to load the badge then apply some css to get your desired look.

Code: [Select]
<!--opt name="u_status.has_badge"-->
<div class="badge">
<img id="users_badge" class="badge_icon" src="{tplvars.photourl}/{u_status.badge}" />
</div>
<!--/opt name="u_status.has_badge"-->


Let me know if you have any issues :)



Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1004
  • Karma: +56/-7
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #1 on: January 10, 2016, 07:46:55 PM »
Quote
Open ROOT  > includes > admin_functions.php around line 306 ( BEFORE $tpl->set_var('profile',$profile); ) add :

Did you mean the file named admin_functions.inc.php?
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1004
  • Karma: +56/-7
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #2 on: January 10, 2016, 08:01:01 PM »
When I create the global badge, I am unable to regenerate my skin. I click regenerate and only a handful of cache2 folders are created.
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

KHDev

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 501
  • Karma: +43/-2
  • Etano Contributor (Skins & Mods)
    • KH Web Development
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #3 on: January 10, 2016, 09:28:37 PM »
Quote
  Did you mean the file named admin_functions.inc.php? 

Yeah lol my mistake :)

When I create the global badge, I am unable to regenerate my skin. I click regenerate and only a handful of cache2 folders are created.

Can you post or pm the code you've put in admin functions file ( include about 3 lines before and after so I can check the placing)

Also is there any errors showing up on screen or log?

Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1004
  • Karma: +56/-7
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #4 on: January 10, 2016, 11:44:31 PM »
Code: [Select]
if (empty($profile['_photo']) || !is_file(_PHOTOPATH_.'/t1/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/t2/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/'.$profile['_photo'])) {
$profile['_photo']='no_photo.gif';
} else {
$profile['has_photo']=true;
}
/*************Badge for PAID MEMBERS**********************/
$user_m=$profile['fk_user_id'];
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$user_m";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$profile['has_badge']=false;
} elseif ($status['membership']>='4') {
$profile['has_badge']=true;
$profile['badge']='paiduser.png';
}
}

$tpl->set_var('profile',$profile);

// generate the user details for result lists
$tpl->set_file('temp',$skins[$s].'/static/result_user.html');

I checked for errors and didn't see any. Especially when I regenerated the skin.
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

KHDev

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 501
  • Karma: +43/-2
  • Etano Contributor (Skins & Mods)
    • KH Web Development
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #5 on: January 13, 2016, 09:47:16 AM »



IMPORTANT NOTICE
Global Badge



If you applied the Global Badge (For searches ect..) please remove it.

To remove the global badge option please do the following:

1) Replace the includes > admin_functions.inc.php with a non-edited version or a back-up version from before you added  the global badge.

2) Replace the tools  > cron > jobs > 10 > gen_users.php with a non-edited version or a back-up version from before you added  the global badge.

3) Remove the badge from skins_site > def > static > result_user.html

4) Regenerate your sites skin via the admin panel and  things should be back to default.

Apologies for any inconvenience.

KHDev

AF

  • Prime Member
  • ****
  • Posts: 117
  • Karma: +3/-2
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #6 on: January 16, 2016, 08:12:55 PM »
Code: [Select]
if (empty($profile['_photo']) || !is_file(_PHOTOPATH_.'/t1/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/t2/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/'.$profile['_photo'])) {
$profile['_photo']='no_photo.gif';
} else {
$profile['has_photo']=true;
}
/*************Badge for PAID MEMBERS**********************/
$user_m=$profile['fk_user_id'];
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$user_m";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$profile['has_badge']=false;
} elseif ($status['membership']>='4') {
$profile['has_badge']=true;
$profile['badge']='paiduser.png';
}
}

$tpl->set_var('profile',$profile);

// generate the user details for result lists
$tpl->set_file('temp',$skins[$s].'/static/result_user.html');

I checked for errors and didn't see any. Especially when I regenerated the skin.


Did it end up working ok Marble? (Thanks KHDev for your contribution again!)

KHDev

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 501
  • Karma: +43/-2
  • Etano Contributor (Skins & Mods)
    • KH Web Development
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #7 on: January 16, 2016, 08:37:57 PM »
Code: [Select]
if (empty($profile['_photo']) || !is_file(_PHOTOPATH_.'/t1/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/t2/'.$profile['_photo']) || !is_file(_PHOTOPATH_.'/'.$profile['_photo'])) {
$profile['_photo']='no_photo.gif';
} else {
$profile['has_photo']=true;
}
/*************Badge for PAID MEMBERS**********************/
$user_m=$profile['fk_user_id'];
$query="SELECT `membership` FROM `{$dbtable_prefix}user_accounts` WHERE `user_id`=$user_m";
if (!($res=@mysql_query($query))) {trigger_error(mysql_error(),E_USER_ERROR);}
while ($status=mysql_fetch_assoc($res)) {
if ($status['membership']<='2') {
$profile['has_badge']=false;
} elseif ($status['membership']>='4') {
$profile['has_badge']=true;
$profile['badge']='paiduser.png';
}
}

$tpl->set_var('profile',$profile);

// generate the user details for result lists
$tpl->set_file('temp',$skins[$s].'/static/result_user.html');

I checked for errors and didn't see any. Especially when I regenerated the skin.


Did it end up working ok Marble? (Thanks KHDev for your contribution again!)

No the global badge didn't work out due to caching issues.

Hornyflings

  • Prime Member
  • ****
  • Posts: 194
  • Karma: +3/-0
    • AsiasHeart
Re: [CODE] - Show Badge/Icon if a user is a Paid Member
« Reply #8 on: June 08, 2016, 11:04:30 AM »
Just a short question:
Is the mod for ROOT > profile.php working
to show badge/icon with profile page ??