vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   [SOLVED] i need condition if user not moderator (https://vborg.vbsupport.ru/showthread.php?t=312276)

omardealo 06-19-2014 04:21 PM

[SOLVED] i need condition if user not moderator
 
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 :

PHP Code:

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

Quote:

Originally Posted by omardealo (Post 2502631)
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 :

PHP Code:

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



There is a function called can_moderate:
Code:

/**
* 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
Code:

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

Quote:

Originally Posted by Simon Lloyd (Post 2502638)
Just for certain moderators or the moderator group?

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



Quote:

Originally Posted by kh99 (Post 2502724)
There is a function called can_moderate:
Code:

/**
* 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
Code:

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

Quote:

Originally Posted by omardealo (Post 2503096)
[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:
Code:

<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

Quote:

Originally Posted by Simon Lloyd (Post 2503113)
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

Quote:

Originally Posted by Simon Lloyd (Post 2503113)
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

PHP Code:

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


--------------- Added [DATE]1403485556[/DATE] at [TIME]1403485556[/TIME] ---------------

Quote:

Originally Posted by kh99 (Post 2503126)
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
PHP Code:

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

and
PHP Code:

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



All times are GMT. The time now is 01:04 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01513 seconds
  • Memory Usage 1,756KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (5)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete