Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2013, 05:55 AM
Peter Walker Peter Walker is offline
 
Join Date: Oct 2005
Location: Germany
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default BB Code - Need help restricting to specific usergroups

I am trying to resolve the following problem, but my coding skills are obviously not sufficient to get this working. What I am trying to do is have a BB code that displays a video to users in the premium usergroup and shows all others an image and a comment that they have to buy a subscription to view this video.

I have got a working BB code to display the video, my problem is restricting this to members of the specified usergroup.

Here is the code I put together (i shortened the video part as that is not the issue):

Code:
if(is_member_of($user,30)==TRUE)
{
// Premium member, can watch video
//

<a href="premium/{param}" style="display:block;width:720px;height:405px;" id="player"></a>

<script language="JavaScript">
flowplayer("player", "flash/flowplayer-3.2.5.swf", 
	{

[ **** VIDEO CODE REMOVED FROM THIS EXAMPLE ****]
});
</script>

}
else
{
//  Not Premium Member

<img src="premium/thumbs/{option}" border="0" alt="" />

Note: Premium membership required to watch this video.
}



// #############################################################################
/**
* Works out if a user is a member of the specified usergroup(s)
*
* This function can be overloaded to test multiple usergroups: is_member_of($user, 1, 3, 4, 6...)
*
* @param	array	User info array - must contain userid, usergroupid and membergroupids fields
* @param	integer	Usergroup ID to test
* @param	boolean	Pull result from cache
*
* @return	boolean
*/
function is_member_of($userinfo, $usergroupid, $cache = true)
{
	static $user_memberships;

	switch (func_num_args())
	{
		// 1 can't happen

		case 2: // note: func_num_args doesn't count args with default values unless they're overridden
			$groups = is_array($usergroupid) ? $usergroupid : array($usergroupid);
		break;

		case 3:
			if (is_array($usergroupid))
			{
				$groups = $usergroupid;
				$cache = (bool)$cache;
			}
			else if (is_bool($cache))
			{
				// passed in 1 group and a cache state
				$groups = array($usergroupid);
			}
			else
			{
				// passed in 2 groups
				$groups = array($usergroupid, $cache);
				$cache = true;
			}
		break;

		default:
			// passed in 4+ args, which means it has to be in the 1,2,3 method
			$groups = func_get_args();
			unset($groups[0]);

			$cache = true;
	}

	if (!is_array($user_memberships["$userinfo[userid]"]) OR !$cache)
	{
		// fetch membergroup ids for this user
		$user_memberships["$userinfo[userid]"] = fetch_membergroupids_array($userinfo);
	}

	foreach ($groups AS $usergroupid)
	{
		// is current group user's primary usergroup, or one of their membergroups?
		if ($userinfo['usergroupid'] == $usergroupid OR in_array($usergroupid, $user_memberships["$userinfo[userid]"]))
		{
			// yes - return true
			return true;
		}
	}

	// if we get here then the user doesn't belong to any of the groups.
	return false;
}
This code is stored in a custom BB Code: [premiumvideo=imagefile.jpg]videofile.f4v[/premiumvideo]

Can someone here help me to get this working, please?
Reply With Quote
  #2  
Old 08-19-2013, 12:09 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, no , no, your your code will never work. You're putting php code in a bb code tag and it simply won't work.

It's possible to do this but the question is how important is this feature? You're posting in the vB3 forum, what version are you using? You'll probably have to upgrade sooner or later to vB4. vB3 won't be supported forever and older versions require PHP 4, which is obsolete. My hosting service made PHP 4 available for a while after upgrading to PHP 5 but eventually quit.

The reason I ask about this is vB4 has a built in video bb code and it wouldn't be very difficult to modify it and then add some JavaScript to the showthread page to switch from a default image to the video for premium members. But this would affect all videos, there wouldn't be a distinction between some videos for everyone and special videos only for premium members. Trying to do this for vB3 would also be possible but when you eventually upgrade to vB4 I'm not sure how to fix all your old threads. But I can't test anything in vB3 now that my hosting service no longer uses PHP4.

Now, on the technical side, the reason this is so messy is that whenever you post a new reply, the bb codes are parsed (i.e., translated) into html and the parsed version is stored in the database and that's what is used whenever the thread is displayed. Once it's parsed it's too late to check what usergroup the viewer belongs to, everyone sees the same thing. So to make this work you would have to have both the image and the video in place but the video is inside a <div style="display:none;">. Once the page is loaded JavaScript can run through all the posts, find the undisplayed videos and switch them to display block for premium members and then hide the images.
Reply With Quote
Благодарность от:
TheLastSuperman
  #3  
Old 08-20-2013, 02:26 PM
Peter Walker Peter Walker is offline
 
Join Date: Oct 2005
Location: Germany
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi nerbert,
I am open for ways of making this work. This feature is important for me as I release a lot of videos on my forum that only paying "premium" members should be able to see.

I solved this in the past by using realplayer .ram files in attachments, which contain a link to the actual video. This required the user to have real player installed - I want to use flash player or html5 video to do this now as I need to support subtitles. As this is what finances my forum costs, and I have 9 new videos waiting to be released, it is essential that I solve this somehow.

If we can somehow process the contents of an attachment, if access is denied then the user is not a premium member - that would work.

I am currently using vBulletin 3.8.7 Patch Level 3 (PHP5 is no problem with this version) and due to a lot of mods I am using, I have not upgraded so far, particularly as everything is working smoothly. I am considering upgrading directly to vBulletin 5 once that is stable enough and I can find replacements for the mods I need.

I run my own root server, so it is in my hands what software runs on it.

I could just place these videos in a forum that only premium members can access, but I want normal members to be able to see that a video is available and read the description, just not be able to play the video (this encourages more subscriptions).

I have all the other items in place, I just need to be able to restrict the showing of the video to premium members and preferably show everyone else an image instead.

If you need to test anything, I can setup a vbtest forum on my server for example. Again, my forum is using php5 without problems.

I see what you are saying about the parsing. maybe an option is needed to simply open up a new window and that is then capable of determining if premium or not?

I am open to any suggestions on how to resolve this. My members are eagerly waiting for the new videos...
Reply With Quote
  #4  
Old 08-20-2013, 03:23 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There is a modification for VB 3.x- Automatic Media Embedder (AME) 2.5.

This mod automatically turns youtube (and other video sites) links into embedded videos.

It also uses a template to embed the code in the page.

This means you could EDIT the video template created by the AME mod and use template conditionals to display the video to premium usergroups and your message to those who aren't supposed to see video.

It does rely on a 3rd party mod, and it will be difficult to upgrade in the future and keep the functionality, but it should work.

You need to use template conditionals (not PHP) in templates, there is an Article in the VB3 Articles section here on how template conditionals work.
Reply With Quote
  #5  
Old 08-20-2013, 05:36 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have other things to attend to at the moment but I'll get back on this later today. I'm pretty sure I can make this work. One question I need to have answered :
What do vb3.8.7 look like,
this -- <if condition=".....">,
or this -- <vb:if condtion=".....">
Reply With Quote
  #6  
Old 08-20-2013, 07:16 PM
Peter Walker Peter Walker is offline
 
Join Date: Oct 2005
Location: Germany
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

From what I can see, <if condition="....."> is used.
Reply With Quote
  #7  
Old 08-20-2013, 07:20 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, vb 3.x is <if condition=""></if>

VB 4.x and 5.x is <vb:if condition=""></vb:if>
Reply With Quote
  #8  
Old 08-21-2013, 08:31 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@ BOP5: That looks like too nice a product to chop up. Can you add extra tags so you could have premium tags available only for admins and still have video tags for members?

@ Peter Walker: If you want to go with AME and it can be suitably modified maybe BOP5 can give some guidance. An alternative I have in mind would be a direct edit of the file includes/class_bbcode.php to insert some code from vB4. No point using plugins here, the next upgrade will be to at least vB4 and it won't require a plugin (and besides, I'm not sure I can write the plugin code). A problem I foresee is regular members will see the [premium] tags when they quote your post and try using them just to see what happens. I don't know how to make them usable only for admins.

I haven't found all the little pieces that go into parsing a video tags so I would have to write some of it myself. If you plan on using only youtube that wouldn't be much trouble. Do you need this for other types of videos?
Reply With Quote
  #9  
Old 08-21-2013, 10:50 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
@ BOP5: That looks like too nice a product to chop up. Can you add extra tags so you could have premium tags available only for admins and still have video tags for members?
It doesn't use tags at all... yes you can add more sites, hundreds of video sites even, but not by usergroup. Like I said the way to limit it by usergroup would be to use template conditionals. That would be far simpler then manually editing code.
Reply With Quote
  #10  
Old 08-21-2013, 12:28 PM
Peter Walker Peter Walker is offline
 
Join Date: Oct 2005
Location: Germany
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I already use flowplayer video code to show this. The reason being I need to be able to support subtitles and splash pages and most other video programs do not support this. I also host the video files on my own server, to give me better control.

The problem with YouTube is that once people see the youtube link, they can potentially just give the address to others for free and that is against the whole point of restricting access to non-paying members. Otherwise, Youtube would be suitable as that does support subtitles, etc.

The interim solution I am working on is to put the videos into a subforum that only premium members can see. The links to this forum being in the normal premium directory which others can at least view. It is clumsy, so I hope you guys can come up with a better solution.

I had a brief look at the AME system, but from what I saw the video component would not support subtitles.

Thanks to all those trying to help.

Regards

Peter
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 04:05 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.07752 seconds
  • Memory Usage 2,277KB
  • Queries Executed 13 (?)
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
  • (1)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
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete