• Welcome to PHPVIBE Forums. Please log in.

[ Video Sharing CMS v4 ] How to work with the PHPVibe groups (Subscriptions example included)

Started by PHPVibe A.,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PHPVibe A.Topic starter

Working with a logged in user's group is easy.

You have

user_group()


which returns the group of the user.

A basic example is the is_moderator function.

function is_moderator(){
global $db;
if (!is_user() || user_group() > 2 ) {
return false;
} else {
$check = $db->get_row("SELECT group_id from ".DB_PREFIX."users WHERE id='".user_id()."'");
if($check && ($check->group_id < 3)) {
return true;
} else {
return false;
}


This basically check if the user is in groups with ids 1 and 2, and can moderate stuff around.

But this can be easily coded for other use.

For example let's say we have a group Subscribers with the id 7 create from the admin panel, and we want all "Private" videos to be visible to this group and moderators only.

So, let's build a simple function:

function is_subscriber(){
return ((is_user() && user_group() == 7) || is_moderator());
}


Now you have a subscriber function to use (drop it at the end of the php files, before the closing php tag) and...use it!

if(is_subscriber()) {echo "Way to go man";} else {echo "You are free member";}


Now, let's apply it to our real life example : Making the "private" videos available only to subscribers!

Open com/com_video.php

find this line

//Check if it's private 
if(($video->private == 1) && !is_user()) {


and replace it with our new build condition:

//Check if it's private 
if(($video->private == 1) && !is_subscriber()) {


Now the system will check if the video is private and if the user is not subscribed, the new line is the actual hold:

//Video is not public
$embedvideo = '<div class="vprocessing"><div class="vpre">'._lang("This video is not public!").'</div> <div class="vex"><a href="'.site_url().'login/">'._lang("Please login or register to watch it").'</a></div></div>';



You can change this to the text and link to a payment gateway/processor, and build a comeback which upgrades the user to group 7 upon paying.
Make sure you refresh his session after the upgrade group id query.

RefreshUser(user_id())


Yes, it's that simple!

Happy coding!

Similar topics (7)