How to implement friends-only (meta)
It's actually pretty simple, though it requires that you're using phpBB as your MT comments engine. It also has a few subtle implementation details which will probably not go over so well for the faint of heart.
2/3, 8:10 AM Fixed a silly bug where users pending authorization were able to see the entry too. Also, made it so locked entries don't include the category list.
The first thing to do is to create a phpBB user group called "friends," and a forum set to "private (hidden)" which is set to only be visible/postable to users in that group. I have the group set to "open" (which still requires confirmation from me to allow users in) but you may want to set it even tighter, such as "closed" or "private" ("closed" means that you have to initiate adding them into the group, and "private" means that random strangers can't even see who's in it unless they're in the group already).
Next, edit your common page header (the one which includes the various thread display functions and so on), and add these lines just before the final ?>:
$query = $db->sql_query("SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE group_id=(GROUP_ID) AND user_pending=0 AND user_id=" . $display_userdata['user_id']);
$user_friend = $db->sql_fetchrow($query);
What this code does is gives every page a global PHP variable called $user_friend which indicates whether the currently logged-in user is a member of the friends group.
Create a new MT category called "friends" (or similar).
In your GetForum module, change the parameter for the forum ID to this:
At this point, you should post a test entry in the "friends" category and make sure that the thread is created in the friends-only forum, and post another test entry in some other category and make sure that its thread is created in the normal forum. Post a few comments. Notice how they don't show up on the weblog.
The reason they don't show up is because of one of the unfortunate hacks which was necessary to make the forum post bot work to begin with. (The integration layer actually has two sessions active, the real session for the user and then a fake "virtual" session for the forum bot.) In your thread display function, add the following lines of code, just after the line which starts with global:
$userdata = $display_userdata;
Now, the really important thing: making the entry itself only show up for friends. This bit is rather tricky.
I really, really hope you're using a template module for your entries' titles or headers or whatever. Here's a simplified version of mine, before this modification:
<h3 class="title">< href="<$MTEntryPermalink$>"><?
if ($restrict) { ?>
(private entry)</a>
<? } else { ?>
<$MTEntryTitle$></a> (<MTEntryCategories glue=", "><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a></MTEntryCategories>)
<? } ?>
</h3>
<? if ($restrict) { ?>
This is a private entry. If you would like to be allowed access, go to the forum and request to be added to the <a href="/forum/groupcp.php?g=364">friends group</a>.
<? } else { ?>
The other thing you should notice is that there's now an open { without a mate. This needs to be closed. What I did was created another template module called "End" which just contains
The reason I did it as a module was so that I could easily add more complicated entry-footer stuff later if I wanted. I probably won't, but you never know. (And anyway, it semantically matches better with the template module which starts each entry, even if it's more to type.)
Anyway. At this point, you should create a test user, browse your weblog to make sure everything works (and the test post doesn't show up), add the test user to the friends group, browse some more and make sure that your test post works, and then, well, that's it.
Some final notes: when setting an entry friends-only, you must set "friends" as the primary category. I could make the code detect if any category is "friends" (it's pretty simple, really) but it would be rather ugly, and anyway, this adds an extra layer of protection so that you won't have a few precious minutes where the entry is visible between you posting it and you adding the secondary categories.
Also, if you decide to make a non-friends entry friends-only later, remember to move the thread to the friends-only forum (and vice-versa).
One more useful thing which this can do that other weblogging software can't: you can make parts of individual entries friends-only, or display differently for friends vs. non-friends. It's actually pretty easy, and only requires a little tiny bit of PHP knowledge. Basically, to make a friends-only block you'd do something like:
(insert friends-only stuff here)
<? } ?>
(insert friends version here)
<? } else { ?>
(insert non-friends version here)
<? } ?>
Comments
Regards,
-lm
The WHAT group?!
It'd be nice if phpBB separated the 'visible to everyone' and the 'anyone can apply for membership' functionality. I don't want the group contents to be there for everyone to see, but I also would much rather have the 'join group' button which is great (I get a little email, I go to the groups page, and I can mass accept/deny everyone who asked to join).
+++ groupcp.php 2005-02-03 19:22:38.825052434 -0800
@@ -222,7 +222,8 @@
if ( $row = $db->sql_fetchrow($result) )
{
- if ( $row['group_type'] == GROUP_OPEN )
+ if ( $row['group_type'] == GROUP_OPEN
+ | $row['group_type'] == GROUP_HIDDEN )
{
do
{
@@ -858,7 +859,8 @@
}
else
{
- if ( $group_info['group_type'] == GROUP_OPEN )
+ if ( $group_info['group_type'] == GROUP_OPEN
+ | $group_info['group_type'] == GROUP_HIDDEN )
{
$template->assign_block_vars('switch_subscribe_group_input', array());