PDA

View Full Version : Create new BB Code only viewable by Super Moderators and Administrators


Revenga
07-05-2013, 02:39 AM
Hi, I'm running a vBulletin 3.8.7 forum and basically what I'm looking for is how to go about creating a code such as:

this text here should only be viewable by Super Moderators and Administrators.

I want to be able to use that in posts to make comments to only my admins and super mods. I also want only the admin and super mod usergroups to have permission to use that BB Code - No one else. How do I accomplish this?

- Revenga

nerbert
07-05-2013, 03:49 AM
Conditionals just don't work inside bb codes; they don't execute at all. Maybe what you could do is have something like this

<div style="display:none" name="restricted">{param}</div>

Then up in the <head> have a script that changes the display to "block" for admins and supers for window.onload. The trouble is this will be visible in the source code to anyone who looks.

Actually I don't think there's any direct way to do it with the bbcode system, you would have to do it with php in a plugin in showthread.php and have regular expression matching chop the text out for registered members

--------------- Added 1373001216 at 1373001216 ---------------

I'm going to work on this. Check back in an hour or so.

--------------- Added 1373005186 at 1373005186 ---------------

Make a plugin for showhread_complete and an identical one for showpost-complete with this code:


$test = preg_match_all('#\[restricted\]([\s\S]*?)\[/restricted\]#i', $postbits, $matches);
$style = "
background:#ffffcc;
border:1px solid black;
padding:6px;
color:red;
";
$open_tag ='<div style="' . $style . '">';
$close_tag = '</div>';
if($test)
{
for($i = 0; $i < count($matches[0]); $i++)
{
if(is_member_of($vbulletin->userinfo, array(6,7)))
{
$postbits = preg_replace('#' . preg_quote($matches[0][$i], '#') . '#', $open_tag . $matches[1][$i] . $close_tag, $postbits);
}
else
{
$postbits = preg_replace('#' . preg_quote($matches[0][$i], '#') . '#', '', $postbits);
}
}
}


You can play with the styling if mine is too obnoxious. I haven't tested this much so give it a good testing.

Revenga
07-05-2013, 01:52 PM
Only problem is when someone quotes the post, they can see what's inside the restricted part.

- Revenga

nerbert
07-05-2013, 02:04 PM
You mean they can see it in the reply editor or it shows up in the finished post? Or both?

I'll try to figure this out. Will get back later

Revenga
07-05-2013, 02:27 PM
They can see it in the reply editor. Also when you go to advanced reply and scroll toward the bottom where it has some of the previous posts, it shows up for them there too. That's all I noticed atm.

- Revenga

nerbert
07-05-2013, 07:11 PM
I'm not finished yet, I still have to work on quick editing but for now I think I have this fixed for new replies .

make a new plugin for newreply_form_complete with this code;


$test = preg_match_all('#\[restricted\]([\s\S]*?)\[/restricted\]#i', $threadreviewbits, $matches);
$style = "
background:#ffffcc;
border:1px solid black;
padding:6px;
color:red;
";
$open_tag ='<div style="' . $style . '">';
$close_tag = '</div>';
if($test)
{
for($i = 0; $i < count($matches[0]); $i++)
{
if(is_member_of($vbulletin->userinfo, array(6,7)))
{
$threadreviewbits = preg_replace('#' . preg_quote($matches[0][$i]) . '#', $open_tag . $matches[1][$i] . $close_tag, $threadreviewbits);
}
else
{
$threadreviewbits = preg_replace('#' . preg_quote($matches[0][$i]) . '#', '', $threadreviewbits);
}
}
}


$test = preg_match_all('#\[restricted\]([\s\S]*?)\[/restricted\]#i', $postpreview, $matches);//was $postpreview
$style = "
background:#ffffcc;
border:1px solid black;
padding:6px;
color:red;
";
$open_tag ='<div style="' . $style . '">';
$close_tag = '</div>';
if($test)
{
for($i = 0; $i < count($matches[0]); $i++)
{
if(is_member_of($vbulletin->userinfo, array(6,7)))
{
$postpreview = preg_replace('#' . preg_quote($matches[0][$i]) . '#', $open_tag . $matches[1][$i] . $close_tag, $postpreview);
}
else
{
$postpreview = preg_replace('#' . preg_quote($matches[0][$i]) . '#', '', $postpreview);
}
}
}

if(!is_member_of($vbulletin->userinfo, array(6,7)))
{

$messagearea = preg_replace('#\[restricted\][\s\S]*?\[/restricted\]#i', '', $messagearea);
}


See if the restricted text is completely cut out for regular members. I'll get back later with more for quick editing.

Revenga
07-05-2013, 07:44 PM
Nope, still the same problem: the [restricted] tags are still showing up for regular members in the reply editor and where it shows the previous posts on the newreply.php page.

- Revenga

nerbert
07-05-2013, 07:53 PM
I'll transfer this project over to my dev site and see what I can do. I'm working in vB 4.2.0, I doubt there would be any major differences in any vB 3 version.

--------------- Added 1373061935 at 1373061935 ---------------

When I moved the plugins over to my dev site I mistakenly put the last plugin in newthread_form_complete instead of newreply_form _complete. Is it possible you did the same?

And another correction: Move the plugin for showthread to showthread_complete.

Revenga
07-05-2013, 10:47 PM
Nope, everything looks correct. Same issues exist.

- Revenga

nerbert
07-06-2013, 12:56 AM
OK, I found one error in the last plugin. The preview and reviewed posts were working right but the editor text wasn't. Here's the corrected code:


//ini_set('display_errors', '1');

$test = preg_match_all('#\[restricted\]([\s\S]*?)\[/restricted\]#i', $threadreviewbits, $matches);
$style = "
background:#ffffcc;
border:1px solid black;
padding:6px;
color:red;
";
$open_tag ='<div style="' . $style . '">';
$close_tag = '</div>';
if($test)
{
for($i = 0; $i < count($matches[0]); $i++)
{
if(is_member_of($vbulletin->userinfo, array(6,7)))
{
$threadreviewbits = preg_replace('#' . preg_quote($matches[0][$i]) . '#', $open_tag . $matches[1][$i] . $close_tag, $threadreviewbits);
}
else
{
$threadreviewbits = preg_replace('#' . preg_quote($matches[0][$i]) . '#', '', $threadreviewbits);
}
}
}


$test = preg_match_all('#\[restricted\]([\s\S]*?)\[/restricted\]#i', $postpreview, $matches);//was $postpreview
$style = "
background:#ffffcc;
border:1px solid black;
padding:6px;
color:red;
";
$open_tag ='<div style="' . $style . '">';
$close_tag = '</div>';
if($test)
{
for($i = 0; $i < count($matches[0]); $i++)
{
if(is_member_of($vbulletin->userinfo, array(6,7)))
{
$postpreview = preg_replace('#' . preg_quote($matches[0][$i]) . '#', $open_tag . $matches[1][$i] . $close_tag, $postpreview);
}
else
{
$postpreview = preg_replace('#' . preg_quote($matches[0][$i]) . '#', '', $postpreview);
}
}
}

if(!is_member_of($vbulletin->userinfo, array(6,7)))
{

$messagearea = preg_replace('#\[restricted\]([\s\S]*?)\[/restricted\]#i', '', $messagearea);
}

Revenga
07-06-2013, 01:46 AM
Thanks for fixing that. I did find another little part though: When you click on a user's profile and find all posts made by that user, you can see what's in the [restricted] tags. Also when you go to Today's Posts and hover over the thread title, you can see what's in the [restricted] tags as well when that little bubble pops up. How do I fix this?

I'll look around some more to see if there's anything else I might be missing too, but if you could help me with that little bit too that would be very helpful.

Thank you for all you've done already. :)

- Revenga

nerbert
07-06-2013, 01:56 AM
Well, I don't think I have even this much working. I had tested it just before I posted that corrected plugin but apparently I had accidentally double clicked the reply button and had gone to the advanced page. It works for the advanced page but not for the quick reply that's put into the thread list under the post. So it's leaking out there. There's just no way to intercept the AJAX to fix that and if it leaks out once the whole purpose is defeated. This just doesn't seem to work at all. I'll tinker around a little and if I can find a better way of doing this I'll PM you. Thanks for helping test this.

Max Taxable
07-06-2013, 02:06 AM
There's a Mod that does what you're asking for, I've seen it.

nerbert
07-06-2013, 02:12 AM
There's a Mod that does what you're asking for, I've seen it.
I've been looking around for anything to do with conditionals in bbcodes and I found a thread where someone pointed out that posts are parsed and then cached. So everyone will see the last cached version. If it happens the last edit was by an admin the cached version is what admins see. This sounds impossible, but if you can find that mod I would be interested in looking it over.

Max Taxable
07-06-2013, 02:23 AM
I've been looking around for anything to do with conditionals in bbcodes and I found a thread where someone pointed out that posts are parsed and then cached. So everyone will see the last cached version. If it happens the last edit was by an admin the cached version is what admins see. This sounds impossible, but if you can find that mod I would be interested in looking it over.There IS a mod that allows staff comments on posts in threads, it works similar to the "thanks" system, they are messages under posts like the "thanks" bit. These are not quotable and visible only to those permissioned to view.

I have been looking for it, I KNOW it is there, if I find it I will post a link.

BUT, this also gives the coders here some idea of the real, actual way to do this.

EDIT: Granted this is not a BB code, but why do you need one to accomplish the task? Seems like a gross overcomplication of a simple deal.

nerbert
07-06-2013, 03:22 AM
There IS a mod that allows staff comments on posts in threads, it works similar to the "thanks" system, they are messages under posts like the "thanks" bit. These are not quotable and visible only to those permissioned to view.

I have been looking for it, I KNOW it is there, if I find it I will post a link.

BUT, this also gives the coders here some idea of the real, actual way to do this.

EDIT: Granted this is not a BB code, but why do you need one to accomplish the task? Seems like a gross overcomplication of a simple deal.
A mod like what you described sounds like a lot of work to build as it would surely require a new database table or at least a new field in the post table. But I think that's the only way to go for what Revenga wants.

Max Taxable
07-06-2013, 03:25 AM
A mod like what you described sounds like a lot of work to build as it would surely require a new database table or at least a new field in the post table. But I think that's the only way to go for what Revenga wants.I agree, I don't think it can be done with BB code so you're left with other alternatives and ideas.

I wonder though, what would you be writing that you can't just use User Notes for, and train your staff to be checking them regularly, or even start a thread in the admin/mod area with anything you want to say about a post you don't want reg. members to see? Shoot, the flag feature even, would start a thread in admin and you can comment there.

Having a hard time understanding why this is even necessary.

Revenga
07-06-2013, 03:00 PM
A mod like what you described sounds like a lot of work to build as it would surely require a new database table or at least a new field in the post table. But I think that's the only way to go for what Revenga wants.

So be it then, no big deal. I'll search around a little bit and see if I can find something. Thanks again for all your help.

I agree, I don't think it can be done with BB code so you're left with other alternatives and ideas.

I wonder though, what would you be writing that you can't just use User Notes for, and train your staff to be checking them regularly, or even start a thread in the admin/mod area with anything you want to say about a post you don't want reg. members to see? Shoot, the flag feature even, would start a thread in admin and you can comment there.

Having a hard time understanding why this is even necessary.

I help run a gaming community and when people get banned from our game servers, they are given a message telling them to appeal at our forum. They create an appeal thread in effort to get unbanned and tbh most of them get rejected. However there are times when it would be nice to make a comment to only our admins/super mods to help move things along quicker within a post that no one else can see rather than creating new topics in our admin section. That's why I was hoping I could do it using BB Code.

But it's no big deal, I'll look around for other mods that can accomplish a similar task. I'm sure I've seen them before, but it's been a while.

- Revenga