PDA

View Full Version : [SOLVED] i need condition if user not moderator


omardealo
06-19-2014, 04:21 PM
Hello ,

i need php condition " if user is moderator "
In other words, I want Run Code only if is this user is a moderator

Like :

if (userid == can_moderate)
{
// my code
}

Simon Lloyd
06-19-2014, 04:53 PM
Just for certain moderators or the moderator group?

kh99
06-20-2014, 09:02 AM
Hello ,

i need php condition " if user is moderator "
In other words, I want Run Code only if is this user is a moderator

Like :

if (userid == can_moderate)
{
// my code
}

There is a function called can_moderate:
/**
* Returns whether or not the given user can perform a specific moderation action in the specified forum
*
* @param integer Forum ID
* @param string If you want to check a particular moderation permission, name it here
* @param integer User ID
* @param string Comma separated list of usergroups to which the user belongs
*
* @return boolean
*/
function can_moderate($forumid = 0, $do = '', $userid = -1, $usergroupids = '')
{

So for example if you wanted to know if userid has *any* moderator permissions, it would be
if (can_moderate(0, '', $userid))
{
// code
}

But just so you know, it does do database queries for the info it needs, depending on exactly what parameters you pass to it.

omardealo
06-22-2014, 03:03 PM
Just for certain moderators or the moderator group?

yeah i want show this code for any moderators without use moderator groupid



There is a function called can_moderate:
/**
* Returns whether or not the given user can perform a specific moderation action in the specified forum
*
* @param integer Forum ID
* @param string If you want to check a particular moderation permission, name it here
* @param integer User ID
* @param string Comma separated list of usergroups to which the user belongs
*
* @return boolean
*/
function can_moderate($forumid = 0, $do = '', $userid = -1, $usergroupids = '')
{

So for example if you wanted to know if userid has *any* moderator permissions, it would be
if (can_moderate(0, '', $userid))
{
// code
}

But just so you know, it does do database queries for the info it needs, depending on exactly what parameters you pass to it.


i think is working , but i have problem ... i want show this code for only moderators but it also Shows for admin :( No other solution if i don't want to use usegroupid

tbworld
06-22-2014, 03:20 PM
Nice call @Kh99, I would modify that routine. Seems like the way to go, at least I have not found anything better. :)

kh99
06-22-2014, 03:38 PM
[COLOR="red"]i think is working , but i have problem ... i want show this code for only moderators but it also Shows for admin :( No other solution if i don't want to use usegroupid

Could you maybe use can_moderate() but check the usergroupid to see if it's an admin? Or maybe you could use:
<if condition="can_moderate() AND !($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'])">


(assuming you're checking the "current" user and not a post author). That will make it so it doesn't show to anyone who has admincp permissions (I think).

Otherwise, you can write a plugin to do whatever checks you want and set a variable.

Simon Lloyd
06-22-2014, 04:43 PM
One question, is can_moderate available in all areas?

RichieBoy67
06-22-2014, 05:13 PM
One question, is can_moderate available in all areas?


Not sure what you mean.. This conditional goes around what ever you want to have those conditions. It is only going to work where ever that code is placed and surrounded with the conditional.

kh99
06-22-2014, 06:18 PM
One question, is can_moderate available in all areas?

I think what you're asking is if can_moderate() could be used in any template. I believe the answer is yes, it checks using the current user and/or the parameters you pass, so it should work anywhere. Of course if you want to check if the user can moderate the current forum, you need to pass the forumid.

omardealo
06-22-2014, 11:55 PM
THNX kh99, IT'S WORKING GOOD

if(can_moderate() AND !($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']))
{
// THE CODE WILL WORK TO ONLY ALL moderators
}

--------------- Added 1403485556 at 1403485556 ---------------

I think what you're asking is if can_moderate() could be used in any template. I believe the answer is yes, it checks using the current user and/or the parameters you pass, so it should work anywhere. Of course if you want to check if the user can moderate the current forum, you need to pass the forumid.

about template :
i try this Conditionals to be sure if user is " moderate the current forum" but not work on template [memberaction_dropdown] for vb4

<vb:if condition="can_moderate($forum['forumid'])">Show this to the moderator of the current forum</vb:if>

and
<vb:if condition="in_array($forumid, array(1)) AND can_moderate($foruminfo['forumid'] !== 1)"> xxx </vb:if>

kh99
06-23-2014, 08:42 AM
about template :
i try this Conditionals to be sure if user is " moderate the current forum" but not work on template [memberaction_dropdown] for vb4

I think that's probably because there is no $forum['forumid'] available there.

omardealo
06-24-2014, 07:30 PM
@tbworld adds this to the @kh99 toolbox of cool snippets. :)
sorry , i don't understand what you mean

I think that's probably because there is no $forum['forumid'] available there.

okay , i will try to Find a solution to this , thank you