Private text in posts

Started by Colonel Waffles, October 02, 2006, 12:21:21 AM

Previous topic - Next topic

Colonel Waffles

I am interested in a bbcode chunk that would allow me to mark part of a post as only viewable by certain members.  I have taken a look at this post, but I'm not sure how to put that code into the new bbc array in RC3.  I want to do exactly what is described in the first post of that thread, namely:


Public post text

[private=joebob]private text that only user joebob sees[/private]

more public text


Allowing multiple viewers with:

[private=joebob,marysue,etc,etc]text for all those users[/private]

would be ideal.

If anyone could help me plug in the code that KJToo posted in that other thread into RC3 that would be awesome.

codenaught

I admit I have even suggested such a feature in the past. But is this all that needed? There is a reason why there is a personal message system. I can't see this being something used all that often, and when it is, something that would be abused by certain members. If you want your messages to someone to be truly confidential, your are better off using the pm system in my opinion.

I am going to move this to mod requests as I think it is more suitable there.
Dev Consultant
Former SMF Doc Coordinator

Colonel Waffles

I managed to figure this out on my own anyway.  Perhaps I'll post the code later, but no one seems to care.

To answer your question akabugeyes, this isn't useful in a normal forum system, however I am running a Play-by-Post RPG, meaning that as I summarize a scene I often have text that is only applicable to one person.  Rather than having them look in two places I can now put it all in one post and only the people I want see it.  PM's are not useful for my situation, so I was left with either "spoiler" text, or private text.  To keep my players from seeing information not meant for them, private text was the best solution.  If you don't see the use, I guess that's your loss, it's very useful to me.

codenaught

Well I'm sure there are people who would like such a feature. You are welcome to post your code or even release a mod if you want to. I didn't know that your forum had a unique situation that needed it. ;)
Dev Consultant
Former SMF Doc Coordinator

JayBachatero

Ummm if I'm correct you can view the text when you quote the message ;).
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Colonel Waffles

Incorrect Juan, that has been taken in to account.

in Subs.php place this function somewhere, I put it after the forum_time function.  Note that this is just what I use, for a mod you would probably want to take into account disabled states and such.


function get_private($content, $boarduser = NULL) {
global $user_info;

if($boarduser == NULL && $user_info['name'] == "Name that always sees private text")
$retval = ('<div class="privateheader">Private text for Name that always sees private text:</div><div class="privateblock">'.$content.'</div>');
else if ($boarduser == NULL && $user_info['name'] != "Name that always sees private text")
$retval = ('');
// Is Current User in the $boarduser list?
else if(in_array(strtolower($user_info['name']),preg_split("/[\s]*,[\s]*/", strtolower($boarduser))) || $user_info['name'] == "Name that always sees private text")
$retval = ('<div class="privateheader">Private text for '.$boarduser.':</div><div class="privateblock">'.$content.'</div>');
else
$retval = ('');

return $retval;
}


Also in Subs.php, place this in the $codes array.

array(
'tag' => 'private',
'type' => 'unparsed_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', '$data = get_private(parse_bbc($data));'),
),
array(
'tag' => 'private',
'type' => 'unparsed_equals_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', '$data[0] = get_private(parse_bbc($data[0]),$data[1]);'),
),


in Post.php find:
$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
place this after that:
// Remove any private text.
$form_message = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $form_message);


find:
$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
place this after that:
// Remove any private text.
$row['body'] = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $row['body']);


If you want a button for users up on the bbc menu, find this in Post.template.php in your theme
'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
place this after:
'private' => array('private' => 'private', 'before' => '[private='. $user_info['name'] . ']', 'after' => '[/private]', 'description' => 'Private Text'),

you can then style
div.privateheader and div.privateblock however you would like. 

JayBachatero

Umm why use username instead of ID?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Colonel Waffles

Because this if for users.  Users might not know other users id's, in fact I hope they do not.

I'm not really going to stick around and be grilled on this, it is KJToo's code, I just fixed the functions and stuff. 

This code is not for everyone.  It has no use in a standard forum such as this one right here.  It does have use for me.  Maybe someone else will appreciate it.

JayBachatero

Oh true I forgot about that.  The only reason that I was asking is because people change their usernames.  But since it's users using the tag i guess it makes sense to use username instead.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

fiver

Hi Colonel Waffles,

I find this very interesting. I shall give it a go on my forum too. Just to confirm with you - Is the code for smf1.1rc3?

Is it possible to allow a membergroup also? That will add a bit more flexibility. For example, if I have a group call Quiz Master posting questions, the members can post their answer but only the group Quiz Master can read the answers.

I also have birthchart reading for members by members. Sometime the birth person would like to reply some personal things about the birthchart but only wishes the Chart Readers can see it. I thought perhaps I can create a group call Chart Readers and use these codes.

:D

Colonel Waffles

RC3, yes.

You could pretty easily include a member group if you wanted by checking whatever the variable is for member group for a member.  I'm guessing it's something like $user_info['membergroup'], but I don't know.

fiver

Thanks Colonel Waffles

Quoteyou can then style
div.privateheader and div.privateblock however you would like.

What does this line mean?

QuoteYou could pretty easily include a member group if you wanted by checking whatever the variable is for member group for a member.  I'm guessing it's something like $user_info['membergroup'], but I don't know.

I can't do php  :'( ... I can only copy and paste the codes you posted and compile a package using SMF Mod Creator for easy install/uninstall.

Can anyone help with the codes to add membergroup please?

Thanks

Colonel Waffles

Go into style.css and add entries for the two div.'s so you can make the private text look however you want.

If you don't know how to do that then check KJToo's code in the thread I linked to in the first post.  If you still have trouble then this bit of code might just be a bit beyond you right now.  Grab a css tutorial off the web and you should be up and running in an hour or two. 

To check for member group you need to find out what the variable is for a users member group.  If you can find that out I will add the code for you, but it is incredibly simple. 

fiver

QuoteIf you don't know how to do that then check KJToo's code in the thread I linked to in the first post.  If you still have trouble then this bit of code might just be a bit beyond you right now.  Grab a css tutorial off the web and you should be up and running in an hour or two.

I see... fortunately, I have no problem with css.  :D

I have tested on a test-forum and realise that even I (as the one who use the private tag) cannot see the message after submiting the post.

Also as an admin I can't see it. Will you be able to help me with that please?

Many thanks.

QuoteTo check for member group you need to find out what the variable is for a users member group.  If you can find that out I will add the code for you, but it is incredibly simple.

Do I look in the smf files or the database? Is it something like this:
action=membergroups;group=18

Colonel Waffles

the variable for member group is likely to be something like $user_info['membergroup'], you might just have to ask in some other forum.

Also, the code has stuff in it about where to make a single person always able to view the private messages.  Just look for the text 'Name that always sees private text' and replace it with your user name (not your id).  I'm guessing that you have no programming experience at all because this code is extremely simple and shouldn't be too hard to tweak a little if needed.

From a basic standpoint, the function (that does the work) tests 4 cases:
1.  The poster didn't provide an =username in the tag and the current user is the one you want to always view private text.
2.  The poster didn't provide an =username in the tag and the current user is not the default viewer.
3.  The poster provided an =username in the tag and that user is the current viewer OR the default viewer.
4.  The current user is neither the username(s) provided in the tag nor the default viewer.

Technically I could have combined 2 and 4 but I figured I would split them out to make extending the function a little more clear. 

It really isn't hard though, just take a look at it and I think you'll see pretty quickly what's going on and probably even how you can make the changes you want.

fiver

#15
QuoteI'm guessing that you have no programming experience at all because this code is extremely simple and shouldn't be too hard to tweak a little if needed.

Trying to figure out these few lines of codes are turning my hair grey!!! :D

Quotethe variable for member group is likely to be something like $user_info['membergroup'], you might just have to ask in some other forum.

I searched the installation package of smf1.1rc3 and found these:

$user_info['groups']

if ($user_info['is_mod'])
$user_info['groups'][] = 3;

if ($user_info['is_admin'])

$message['member']


I have managed to squeeze in 'is admin' and now i can see the private message but the header I see as an admin is "Private text for Name that always sees private text:"

I still don't know
- how to allow a group
- how to make the poster see the private message he posted

Now the code looks like this

function get_private($content, $boarduser = NULL) {
global $user_info;

if($boarduser == NULL && $user_info['name'] || $user_info['is_admin'] == "Name that always sees private text")
$retval = ('<div class="privateheader">Private text for Name that always sees private text:</div><div class="privateblock">'.$content.'</div>');
else if ($boarduser == NULL && $user_info['name'] != "Name that always sees private text")
$retval = ('');
// Is Current User in the $boarduser list?
else if(in_array(strtolower($user_info['name']),preg_split("/[\s]*,[\s]*/", strtolower($boarduser))) || $user_info['name'] == "Name that always sees private text")
$retval = ('<div class="privateheader">Private text for '.$boarduser.':</div><div class="privateblock">'.$content.'</div>');
else
$retval = ('');

return $retval;
}


:-[

Colonel Waffles

This code should allow ANY admin to see all private text and eliminates some of the stuff you don't seem to want:


function get_private($content, $boarduser = NULL) {
global $user_info;

//User did not specify =username ([private][/private] and the current viewer is an admin.
if($boarduser == NULL && $user_info['is_admin'])
$retval = ('<div class="privateheader">Private text for Admins:</div><div class="privateblock">'.$content.'</div>');

// User did not specify =username ([private][/private] and the current viewer is not an admin.
else if ($boarduser == NULL && !$user_info['is_admin'])
$retval = ('');

//User did specify =username ([private=username(,username,etc)][/private]) and the current viewer is in the list of specified users or is an admin.
else if (in_array(strtolower($user_info['name']),preg_split("/[\s]*,[\s]*/", strtolower($boarduser))) || $user_info['is_admin'])
$retval = ('<div class="privateheader">Private text for '.$boarduser.':</div><div class="privateblock">'.$content.'</div>');

//Anything else, specifically, the User did specify =username ([private=username(,username,etc)][/private]) and the current viewer is not in the list of specified users and is not an admin.
else
$retval = ('');

return $retval;
}


To allow a user to see private text that they have posted, they will need to add themselves to the =list:  [private=myusername,usernametosee1,usernametosee2,usernametoseeN]Private text[/private].  You could do this in the code by automatically inserting the posters name into the list for them, but that would require some regular expression stuff and I'm not very good with those.  Just tell your users to add themselves to the list or edit their post to see their own private text.

Allowing a member group is going to be a bit harder.  As I see it, you have a couple choices:
1.  Create two different bbc chunks, [private] for usernames and [privategroup] for groups.  This is fine, but wouldn't allow you to specify both usernames and usergroups since I don't think these would work well nested.
2.  Try to extract "type" information from $boardusers, if it is a number then it's a usergroup, if it's a string it's a username.  While this seems like a great idea, in practice it seems like it would be somewhat hard to do and users would be confused. 

From what you've given me it also appears that a user would need to know the number corresponding to the usergroup, not the name of that group.  So the usergroup named "Chuckleheads" might correspond to the usergroup number 3. 

I will give it some thought, but I think you really need to decide whether you want private text to be per user or per user group and probably only pick one. 

I just want to state again what akabugeyes said:  This code is not useful for most situations.  Private Messages will work fine if you are trying to send private text to lots of users or groups of users.  If you could describe why you want to use this then I could probably help you come up with a good solution that would do what you need.  If you're putting it into a rather large general discussion forum then it's probably not too useful.  Functionality for functionality's sake is a waste, make sure you need this before you stress out over trying to get it to work.

fiver

#17
Thanks Colonel Waffles,

QuoteTo allow a user to see private text that they have posted, they will need to add themselves to the =list:  [private=myusername,usernametosee1,usernametosee2,usernametoseeN]Private text[/private].  You could do this in the code by automatically inserting the posters name into the list for them, but that would require some regular expression stuff and I'm not very good with those.  Just tell your users to add themselves to the list or edit their post to see their own private text.
That's a very simple and effective solution!!!

QuoteI will give it some thought, but I think you really need to decide whether you want private text to be per user or per user group and probably only pick one.
Weighing the choice between privatetext-to-user and privatetext-to-group, I'd choose the latter.

I can see the danger in the situation where the forum discussions fall into a place of 'whispering' if members start to use private tag with each other.

My main usage for private text is as posted earlier:

1. For a group called chartreader
This will help the person whose birthchart is being read to feel comfortable and confident enough to share personal feedback to the chartreader.

2. For a group called quizmaster
This will help allow members to post answers without turning it into a spoiler.

:)

Advertisement: