Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions

Reply
 
Thread Tools Display Modes
  #11  
Old 02-25-2013, 04:46 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

create new plugin

Hook Location: threadbit_display
Title: usergroup check for threadstarter in threadbit
Plugin PHP Code:
PHP Code:
$current_thread $thread['threadid'];

$query $vbulletin->db->query_first_slave("
    SELECT user.usergroupid, user.membergroupids
    FROM " 
TABLE_PREFIX "thread AS thread
    LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = thread.firstpostid)
    WHERE thread.threadid = " 
$current_thread "
    "
);
    
$primary_group $query['usergroupid'];
$secondary_groups $query['membergroupids'];

if(!empty(
$secondary_groups)) {
    
$groups $primary_group "," $secondary_groups;
} else {
    
$groups $primary_group;
}    
$groups_all explode(","$groups);

vB_Template::preRegister('threadbit',array('group' => $groups_all)); 
then in template threadbit

You could do
Code:
<vb:if condition="in_array(6, $group)">This thread starter is in admin group</vb:if>
The 6 being the group you want to check, and this example 6 is the Administrator group.

This checks the primary and additional groups of a thread starter.
Reply With Quote
  #12  
Old 02-25-2013, 02:43 PM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks!

Like Lynne said about the additional queries, I really only want to do this one or two sections of the forum. Is there anyway to have the plug-in only run that query for specific forums?
Reply With Quote
  #13  
Old 02-25-2013, 02:48 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if (in_array($thread['forumid'], array(1,2,3)))

{

    
$current_thread $thread['threadid'];

    
$query $vbulletin->db->query_first_slave("
        SELECT user.usergroupid, user.membergroupids
        FROM " 
TABLE_PREFIX "thread AS thread
        LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = thread.firstpostid)
        WHERE thread.threadid = " 
$current_thread "
        "
);
        
    
$primary_group $query['usergroupid'];
    
$secondary_groups $query['membergroupids'];

    if(!empty(
$secondary_groups)) {
        
$groups $primary_group "," $secondary_groups;
    } else {
        
$groups $primary_group;
    }    
    
$groups_all explode(","$groups);

    
vB_Template::preRegister('threadbit',array('group' => $groups_all));


change 1,2,3 to forums you want it to run in.
Reply With Quote
Благодарность от:
kh99
  #14  
Old 02-25-2013, 03:01 PM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

When I go to save the threadbit template after inserting your if conditional, I get the following error message:

"Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3568

Forum Message
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish."
Reply With Quote
  #15  
Old 02-25-2013, 03:47 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Kudos to LifesGreatestGift for writing the plugin. But I think there may be one small problem: on this line:

Code:
    LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
I think you want thread.postuserid instead of thread.firstpostid.
As is, if you do a var_dump on $groups it shows the proper primary and secondary groups of the threadstarter.
The code works, I just messed up the "Specific forums" conditional.

if (in_array($thread['forumid'], array(1,2,3)))

please review other mods and vB code for proper usage. But other than that, the code is sound, and taken directly from forumdisplay.php

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

Quote:
Originally Posted by addamroy View Post
When I go to save the threadbit template after inserting your if conditional, I get the following error message:

"Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3568

Forum Message
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish."
you must be doing something wrong because the code is tested as working 100% on vanilla vbulletin 4.2 pl3

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

i didnt even mess up the conditional it all works 100%

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

It was throwing an error, try this code

PHP Code:
if (in_array($thread['forumid'], array(3,4,5))) 



    
$current_thread $thread['threadid']; 

    
$query $vbulletin->db->query_first_slave(
        SELECT user.usergroupid, user.membergroupids 
        FROM " 
TABLE_PREFIX "thread AS thread 
        LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = thread.firstpostid) 
        WHERE thread.threadid = " 
$current_thread 
        "
); 
         
    
$primary_group $query['usergroupid']; 
    
$secondary_groups $query['membergroupids']; 

    if(!empty(
$secondary_groups)) { 
        
$groups $primary_group "," $secondary_groups
    } else { 
        
$groups $primary_group
    }     
    
$groups_all explode(","$groups); 

} else { 

$groups_all = array(); 


    
vB_Template::preRegister('threadbit',array('group' => $groups_all)); 
Reply With Quote
  #16  
Old 02-25-2013, 04:00 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

change 3,4,5 to forums you want it ran in.

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

PHP Code:
if (in_array($thread['forumid'], array(3,4,5))) 



    
$current_thread $thread['threadid']; 

    
$query $vbulletin->db->query_first_slave(
        SELECT user.usergroupid, user.membergroupids 
        FROM " 
TABLE_PREFIX "thread AS thread 
        LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = thread.firstpostid) 
        WHERE thread.threadid = " 
$current_thread 
        "
); 
         
    
$primary_group $query['usergroupid']; 
    
$secondary_groups $query['membergroupids']; 

    if(!empty(
$secondary_groups)) { 
        
$groups $primary_group "," $secondary_groups
    } else { 
        
$groups $primary_group
    }     
    
$groups_all explode(","$groups); 

} else { 

$groups_all = array(); 


    
vB_Template::preRegister('threadbit',array('group' => $groups_all)); 
This is the proper working code. The reason the first conditional threw an error was because when you visit a forum not listed in the 3,4,5 the template threadbit was still looking for the $group array and it wasn't defined. New code puts null array in place so there isn't an error.
Reply With Quote
  #17  
Old 02-25-2013, 05:54 PM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still getting the same error.

I'm using vb 4.1.12 if that makes any difference (since you said you tested on 4.2)? I don't believe I have any mods doing anything in the threaddisplay hook or threadbit template at all so I can't think of what might be conflicting
Reply With Quote
  #18  
Old 02-25-2013, 06:16 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

post me the conditional you are using exactly as is. or just post the contents of threadbit template in code tags.
Reply With Quote
  #19  
Old 02-25-2013, 08:15 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Isn't there some vb code somewhere that's depending on the last poster information being there?
I dont know
Reply With Quote
  #20  
Old 02-25-2013, 08:31 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol, ridiculous.

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

then when you upgrade its something else to remember to change.

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

also, my code accounts not only a users primary usergroup, but additional usergroups as well.
Reply With Quote
Reply

Thread Tools
Display Modes

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 12:37 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04443 seconds
  • Memory Usage 2,303KB
  • 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
  • (2)bbcode_code
  • (4)bbcode_php
  • (3)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
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (1)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_postinfo_query
  • fetch_postinfo
  • 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