Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2014, 04:21 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [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

Reply With Quote
  #2  
Old 06-19-2014, 04:53 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just for certain moderators or the moderator group?
Reply With Quote
  #3  
Old 06-20-2014, 09:02 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by omardealo View Post
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.
Reply With Quote
  #4  
Old 06-22-2014, 03:03 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Simon Lloyd View Post
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 View Post
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
Reply With Quote
  #5  
Old 06-22-2014, 03:20 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice call @Kh99, I would modify that routine. Seems like the way to go, at least I have not found anything better.
Reply With Quote
  #6  
Old 06-22-2014, 03:38 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by omardealo View Post
[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.
Reply With Quote
2 благодарности(ей) от:
RichieBoy67, tbworld
  #7  
Old 06-22-2014, 04:43 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One question, is can_moderate available in all areas?
Reply With Quote
  #8  
Old 06-22-2014, 05:13 PM
RichieBoy67's Avatar
RichieBoy67 RichieBoy67 is offline
 
Join Date: Apr 2004
Location: CT - Down in a hole..
Posts: 3,057
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Simon Lloyd View Post
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.
Reply With Quote
  #9  
Old 06-22-2014, 06:18 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Simon Lloyd View Post
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.
Reply With Quote
  #10  
Old 06-22-2014, 11:55 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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> 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:41 PM.


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.05514 seconds
  • Memory Usage 2,276KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (5)bbcode_php
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete