[Plugin Help] Making available to certain usergroups

by Tropical - 18-05-2015, 03:19 AM
Fulltime Member
Posts:
1,134
Joined:
Apr 2015
Likes:
54
Credits:
117
Reputation:
37
3 Years of Service
#1
OP
Posted: 18-05-2015, 03:19 AM (This post was last modified: 18-05-2015, 03:30 AM by Tropical.)
I know on some forums, the usergroups have different features to access certain plugins
The only one I know of that allows this is Username Color Changer

The code for the "apparent" feature to allow this in that plugin is:

I am looking to add to plugins; a option like that to allow it's access to certain usergroups
I'd really appreciate it if anyone could help me with this

[AndresXZ09] - :noh: Told me to mention you huehue

http://community.mybb.com/thread-163996.html

:yus: I think this is what I am looking for but.....
may somebody tell me actually where those codes go in the plugin?
We are!
Posts:
1,044
Joined:
Jan 2015
Likes:
108
Credits:
1,962
Reputation:
25
3 Years of Service
#2
Posted: 18-05-2015, 06:45 AM
PHP Code:
function PLUGIN_install()
{
    global 
$db$lang;
    
    
$insertarray = array(
        
'name' => 'PLUGIN - SETTINGS'
        
'title' => 'IDK'
        
'description' => "IDK"
        
'disporder' => 100
        
'isdefault' => 0
    
);
    
$gid $db->insert_query("settinggroups"$insertarray);
    
    
$setting = array(
        
"sid"            => NULL,
        
"name"            => "PLUGIN_usergroups",
        
"title"            => "Allowed Usergroups",
        
"description"    => "Enter the IDs (GIDS) of the groups allowed to use this feature. (use \'all\' to allow everyone)",
        
"optionscode"    => "text",
        
"value"            => 'all',
        
"disporder"        => 1,
        
"gid"            => $gid
    
);
    
    
$db->insert_query("settings"$setting);
    
    
rebuild_settings();
}

function 
PLUGIN_uninstall()
{
    global 
$db$mybb;
    
    
// This deletes the setting group
    
$db->delete_query("settinggroups""name = 'PLUGIN'");

    
// And this removes the settings
    
$db->delete_query('settings''name IN (\'PLUGIN_usergroups\')');
    
    
rebuild_settings();
}

function 
PLUGIN_check_permissions($groups_comma)
{
    global 
$mybb;
    
    if (
$groups_comma == '')
        return 
false;
        
    if (
$groups_comma == 'all')
        return 
true;
        
    
$groups explode(","$groups_comma);
    
    
$ourgroups explode(","$mybb->user['additionalgroups']);
    
$ourgroups[] = $mybb->user['usergroup'];

    if(
count(array_intersect($ourgroups$groups)) == 0)
        return 
false;
    else
        return 
true;
}

function 
PLUGIN_page()
{
    global 
$mybb$lang$cache$db$templates$header$headerinclude$footer$theme$usercpnav;
    
    
$lang->load("PLUGIN");
    
    if(
$mybb->input['action'] != 'PLUGIN')
        return;
    
    if (!
$mybb->user['uid'])
        
error_no_permission();
        
    if (!
PLUGIN_check_permissions($mybb->settings['PLUGIN_usergroups']))
        
error_no_permission();
    
    if(
$mybb->request_method == "post")
    {
        
// Verify incoming POST request
        
verify_post_check($mybb->input['my_post_key']);
    
        
$errors = array();
        
        if(
count($errors) > 0)
        {
            
$errors inline_error($errors);
        }
    }
        
    

Tropical
18-05-2015, 08:47 AM
Nan Ihier Gelair Mordor
Divine
Posts:
2,635
Joined:
Jan 2015
Likes:
321
Credits:
8,642
Reputation:
92
3 Years of Service
#3
Posted: 18-05-2015, 08:36 AM
Algorithm:

1. Get users current groups
2. Check if user's group is in allowed usergroups

PHP Code:
$groups array_merge( (array)$GLOBALS['mybb']->user['usergroup'], (array)$GLOBALS['mybb']->user['displaygroup'], explode','$GLOBALS['mybb']->user['additionalgroups'] ) );

$allowedgroups = array( 1,); //Gids of allowed groups
$allowed FALSE//Not Allowed yet

foreach( $allowedgroups AS $group )
{
    if( 
in_array$group$allowedgroups ) )
    {
        
$allowed TRUE;
        break;
    } 
}

if( 
$allowed === FALSE )
{
    
error'You are not allowed to access this plugin/page.' );
}

/* Here you can leave the rest of your code :) */ 

Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.
Fulltime Member
Posts:
1,134
Joined:
Apr 2015
Likes:
54
Credits:
117
Reputation:
37
3 Years of Service
#4
OP
Posted: 18-05-2015, 08:45 AM (This post was last modified: 18-05-2015, 08:45 AM by Tropical.)
(18-05-2015, 08:36 AM)Sozin Wrote: Algorithm:

1. Get users current groups
2. Check if user's group is in allowed usergroups


PHP Code:
$groups array_merge( (array)$GLOBALS['mybb']->user['usergroup'], (array)$GLOBALS['mybb']->user['displaygroup'], explode','$GLOBALS['mybb']->user['additionalgroups'] ) );

$allowedgroups = array( 1,); //Gids of allowed groups
$allowed FALSE//Not Allowed yet

foreach( $allowedgroups AS $group )
{
 if( 
in_array$group$allowedgroups ) )
 {
 
$allowed TRUE;
 break;
 } 
}

if( 
$allowed === FALSE )
{
 
error'You are not allowed to access this plugin/page.' );
}

/* Here you can leave the rest of your code :) */ 


Thanks for this  :noh:
I wanna add this to "already-made" plugins, so:

Where would you insert that code at?
Nan Ihier Gelair Mordor
Divine
Posts:
2,635
Joined:
Jan 2015
Likes:
321
Credits:
8,642
Reputation:
92
3 Years of Service
#5
Posted: 18-05-2015, 09:20 AM
You need to add to the hook...

ah...

just post your plugin code here and I modify it.
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.
Fulltime Member
Posts:
1,134
Joined:
Apr 2015
Likes:
54
Credits:
117
Reputation:
37
3 Years of Service
#6
OP
Posted: 18-05-2015, 09:23 AM
(18-05-2015, 09:20 AM)Sozin Wrote: You need to add to the hook...

ah...

just post your plugin code here and I modify it.


Message me and we can talk there  :noh:
Nan Ihier Gelair Mordor
Divine
Posts:
2,635
Joined:
Jan 2015
Likes:
321
Credits:
8,642
Reputation:
92
3 Years of Service
#7
Posted: 18-05-2015, 09:25 AM
(18-05-2015, 09:23 AM)Tropical Wrote:
(18-05-2015, 09:20 AM)Sozin Wrote: You need to add to the hook...

ah...

just post your plugin code here and I modify it.


Message me and we can talk there  :noh:

I have got a lot of other stuff to do   :fp:
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.
The last reply on this thread is older than a month. Please do not unnecessarily bump it.
Register an account or login to reply
Create an account
Create a free account today and start posting right away. It only takes a few seconds.
Login
Log into an existing account.
1 Guest(s)