Not Solved deny a usergroup editing with specific text
#1
Not Solved
back story of this plugin resides here
https://community.mybb.com/thread-208382...pid1268303


What i am trying to do now is make a plugin that denies any other group besides admins and mods the ability to create a thread with the post content, create a post with post content, or edit an existing post with the post content of [mod] in it. Which is the custom MyCode i am trying to restrict to only team members. 

I know the code to determine if the user is an amdin/mod or not
function my_user_permissions_check($good_groups)
{
    // array-ify the list if necessary
    if (!is_array($good_groups)) {
        $good_groups = explode(',', $good_groups);
    }

    // no groups = all groups
    if (empty($good_groups)) {
        return true;
    }

    // get all the user's groups in one array
    global $mybb;
    $users_groups = array($mybb->user['usergroup']);
    $adtl_groups = explode(',', $mybb->user['additionalgroups']);
    array_merge($users_groups, $adtl_groups);

    // !empty = true for allow and false for disallow
    return !empty(array_intersect($users_groups, $good_groups));
} 

but what i dont know is how to deny a regular user the ability to post as well as scan the new content for forbidden content?

i tried this but the plugin is not registering at all the change to the MYCode [test]. In addition to that it doesnt even allow myself or a regular user to post a second post in the thread in which the thread already contains a [test]???
<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined. ");
}
 
 
$plugins->add_hook("parse_message", "team_mycode_run");
 
function customteamcodetags_info()
{
 return array(
 "name" => "Custom Team MyCodes",
 "description" => "Custom MyCodes for team members only",
 "website" => "",
 "author" => "metulburr",
 "authorsite" => "",
 "version" => "1.0",
 "guid" => "",
 "compatibility" => "18*"
 );
}
    



function my_user_permissions_check($good_groups)
{
    // array-ify the list if necessary
 if (!is_array($good_groups)) {
 $good_groups = explode(',', $good_groups);
 }
 
    // no groups = all groups
 if (empty($good_groups)) {
 return true;
 }
 
    // get all the user's groups in one array
 global $post;
 $users_groups = array($post['usergroup']);
 $adtl_groups = explode(',', $post['additionalgroups']);
 array_merge($users_groups, $adtl_groups);
 
    // !empty = true for allow and false for disallow
 return !empty(array_intersect($users_groups, $good_groups));
} 

 
 
function team_mycode_run($message){
    global $mybb, $post;
    
    $word = "[test]";
    
    if (my_user_permissions_check('3,4')){
        //NULL
    }   
    else{
        if(strpos($post['message'], $word) !== false){
            error("You do not have the required permissions to use " . $word);
        }
        //$message = preg_replace("#\[mod\](.*?)\[/mod\]#", '$1', $message);} 
    $message = preg_replace("#\[test\](.*?)\[/test\]#", '<code style="font-size: 1.0em; font-style:      normal; line-height: 1.3em; background: #FFF; padding: 0 3px; color: black; display: inline; background: lightgrey;">Moderator Test: $1</code>', $message);
    return $message;}
}

I tried modifying my code to use mybb->input['pid'] which works. It allows an admin to post the mycode, but not a regular user by not changing the HTML, not denying it. and by this it doestn matter if an admin edits another regular users post because it just doesnt show up modified in regular users posts. 

function team_mycode_run($message){
    global $mybb, $post;
 
    $word = "[test]";

    if (!my_user_permissions_check('3,4')){
        //NULL
    }
    else{
        if(strpos($mybb->input['pid'], $word) !== false){
            error("You do not have the required permissions to use " . $word);
        }
        //$message = preg_replace("#\[mod\](.*?)\[/mod\]#", '$1', $message);} 
    $message = preg_replace("#\[test\](.*?)\[/test\]#", '<code style="font-size: 1.0em; font-style:      normal; line-height: 1.3em; background: #FFF; padding: 0 3px; color: black; display: inline; background: lightgrey;">Moderator Test: $1</code>', $message);
    return $message;}
} 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)