MyBB Community Forums

Full Version: private tag
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been working on a bbcode but have no idea what to do next.

In "inc/functions_post.php" I put
$message = preg_replace("#\[pri={$mybb['username']\](.*?)\[/pri\]#si", "<font size='2'><i>Private: $1</i></font>", $message);

If a member would type [pri=harmor]Private message here[/pri]
I would see it as Private: Private message here
But all the other members would see "[pri=harmor]Private message here[/pri]"
How would I make it invisible to everyone except to the person that the private message is for?

I did make something similiar.
After the globals I made an array of the current admins
$mybb = array(s_admins => "harmor", s_admins => "Cory");

Then I made a conditional after the [hr ] bbcode
Here's the code
if (!$mybb['username'] == $mybb['s_admins']) {
	$message = preg_replace("#\[pri\](.*?)\[/pri\]#si", "<font size='2'><i>Private: $1</i></font>", $message);
    }
    if ($mybb['username'] == $mybb['s_admins']) {
	$message = preg_replace("#\[pri\](.*?)\[/pri\]#si", "", $message);
   }

I have no clue why putting ! worked because doesn't that mean if it doesn't match then diplay the following code?
I think it's happening because when you have made the admin user array, it's being redefined when mybb gets the user's information and puts it in the array of the same name. (You've called the admin array the same as what mybb uses, call it something different like "$my_admin_array" and make sure if you use it inside a function, you call "global $my_admin_array" first)
So you're getting something like
if(!$mybb['username'] == unset value)
since $mybb is not equal to an unset value, you get false, but negated with the ! you get true.

If you have made an array of the admins' names, then you shouldn't just be == it. You are comparing a string an array. You should use in_array

[b]global.php[/b]
$my_admin_array = array("harmor", "Cory");

[b]elsewhere[/b]
global $my_admin_array; //Use this if you are using it inside a function which I think you are doing.
if(in_array($mybb['username'], $my_admin_array))

Actually I could check if the person is admin and if so display the private text.
But I am new to mybb and I don't know the variable to check if the person is an admin.
Try:
$message = preg_replace("#\[pri={$privateusername\](.*?)\[/pri\]#si", "<font size='2'><i>Private: $1</i></font>", $message);



if ($mybbuser['usergroup'] == "4" && $mybbuser['username'] == $privateusername)
{
$message = preg_replace("#\[pri\](.*?)\[/pri\]#si", "<font size='2'><i>Private: $1</i></font>", $message);
}
else
{
$message = preg_replace("#\[pri\](.*?)\[/pri\]#si", "", $message);
}
Your code looks like it need some work though!
I like the idea. But even if the mod works, you'll have another problem. If someone (any user) presses the quote button at the bottom of the post with the private message, he/she'll be able to see the private message anyway.
Because the message that's being used with quoting is not yet transformed and you'll be able to see the tags.
If you're able to overcome this, then it'll be a very nice mod.
I got it an idea.

How about a dropdown menu and text box under the texarea.

In the drop down box would be all the members and you write the secret message in the text box.
Then have a "add new" button here another set appears.
Just place the variable above the signature.

When you quote a post it won't show the private text.
This sounds interesting, and I'm definately going to look forward to this once you finish it.

I like your latest idea (in the most previous post).
Thaks Yaggles.

I need help making a loop for the members for the the down box.
Kind of like this
$query = mysql_query("SELECT * FROM c_hosting WHERE bandwidth");
echo "<td bgcolor='#efefef'><b>Bandwidth:</b></td> <td bgcolor='#efefef' align='center'><select name='bandwidth' class='pink'>
      <option value='bandwidth'>&nbsp;&nbsp; -----Select----- &nbsp;&nbsp;</option>";
      while($row = mysql_fetch_row($query)) {
echo "<option value='{$row[0]}'>{$row['2']}</option>";
}
echo "</select>";
$query = mysql_query("SELECT uid, username FROM ".TABLE_PREFIX."users");
echo "<b>User:</b><select name='user'>
<option>&nbsp;&nbsp; -----Select----- &nbsp;&nbsp;</option>";
while($user = mysql_fetch_row($query)) {
echo "<option value='$user[uid]'>$user[username]</option>";
}
echo "</select>";
I guess this is what you mean.
one issue that you need to edit search.php

anyone can do search and see what private message is about.