MyBB Support

[Plugin Help] Making available to certain usergroups

Submitted by Tropical, , Thread ID: 3944

Thread Closed
18-05-2015, 04:19 AM
This post was last modified: 18-05-2015, 04:30 AM by Tropical
#1
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:

PHP Code:
// add settings

$setting = array(

"sid"=> NULL,

"name"=> "userstyle_usergroups",

"title"=> "Allowed Usergroups",

"description"=> "Enter the IDs 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); 


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?

RE: [Plugin Help] Making available to certain usergroups

#2
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);
}
}



RE: [Plugin Help] Making available to certain usergroups

#3
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.

RE: [Plugin Help] Making available to certain usergroups

OP
This post was last modified: 18-05-2015, 09:45 AM by Tropical
#4
18-05-2015, 09: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?

RE: [Plugin Help] Making available to certain usergroups

#5
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.

RE: [Plugin Help] Making available to certain usergroups

OP
#6
18-05-2015, 10: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:

RE: [Plugin Help] Making available to certain usergroups

#7
18-05-2015, 10:23 AM
Tropical Wrote:
18-05-2015, 10: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.


Users browsing this thread: