Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Create Multiple Options Per Forum (via Bitfields)
akanevsky
Join Date: Apr 2005
Posts: 3,972

 

Show Printable Version Email this Page Subscription
akanevsky akanevsky is offline 05-21-2006, 10:00 PM

Create Multiple Options Per Forum (via Bitfields)

This How-To should serve as a reference to coders, who have a basic knowledge of PHP and who want to make their own mods.
Help on writing hacks will NOT be provided, and any such posts will be ignored.

Whereever it says mybitoptionsfield, you'll need to replace that with the actual fieldname that you are going to use.
  • The following step is to create bitfield xml for vBulletin.
    Create a file named bitfield_myproductid.xml, where myproductid is the id of your product, with the following content, in ./includes/xml/:
    Note: In the <bitfield> tag, name="" must contain the desired title of the option. You are going to use that title to access the options later on. The title must contain ALPHANUMBERIC characters only, and it should not contain spaces. The digit in between the opening and closing <bitfield> tags is the bit value. Each consecutive bit value must be 2 x (Previous Value). Sample valid sequence: 1, 2, 4, 8, 16, 32.
    PHP Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <bitfields product="myproductid">
        <bitfielddefs>
            <group name="misc">
                <group name="mybitoptionsfield">
                    <bitfield name="option1">1</bitfield>
                    <bitfield name="option2">2</bitfield>
                </group>
            </group>
        </bitfielddefs>
    </bitfields>
  • The following step is to define installation process of the bitfield in your product.
    Create a new product and add the following codes as install and uninstall, respectively:

    PHP Code:
    $db->hide_errors();

    $db->query_write("ALTER TABLE `" TABLE_PREFIX "forum` ADD `mybitoptionsfield` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'");

    require_once(
    DIR '/includes/class_bitfield_builder.php'); 
    $myobj =& vB_Bitfield_Builder::init();
    $myobj->save($db);
    build_forum_permissions(); 

    $db->show_errors(); 
    PHP Code:
    $db->hide_errors();

    $db->query_write("ALTER TABLE `" TABLE_PREFIX "forum` DROP `mybitoptionsfield`");

    require_once(
    DIR '/includes/class_bitfield_builder.php'); 
    $myobj =& vB_Bitfield_Builder::init();
    $myobj->save($db);
    build_forum_permissions(); 

    $db->show_errors(); 
  • The following step is to have the new options fetched together with foruminfo.
    Create a plugin @ fetch_foruminfo with the following code:

    PHP Code:
    if (isset($vbulletin->bf_misc['mybitoptionsfield']))
    {
        foreach (
    $vbulletin->bf_misc['mybitoptionsfield'] AS $optionname => $optionval)
        {
            
    $vbulletin->forumcache["$forumid"]["$optionname"] = (($vbulletin->forumcache["$forumid"]['mybitoptionsfield'] & $optionval) ? 0);
        }

  • The following step is to add new options to AdminCP User Manager.
    Create a plugin @ forumadmin_edit_form with the following code:

    PHP Code:
    if (isset($vbulletin->bf_misc['mybitoptionsfield']))
    {
        
    print_table_header('MYHEADING');

        
    print_yes_no_row('MYOPTION1''mybitoptionsfield[option1]'$forum['option1']);
        
    print_yes_no_row('MYOPTION2''mybitoptionsfield[option2]'$forum['option2']);

  • The following step is to have the new options saved when the button is clicked.
    Create a plugin @ forumadmin_update_save with the following code:

    PHP Code:
    if (isset($vbulletin->bf_misc['mybitoptionsfield']))
    {
        
    $vbulletin->input->clean_gpc('p''mybitoptionsfield'TYPE_ARRAY_BOOL);
        
        foreach (
    $vbulletin->GPC['mybitoptionsfield'] AS $key => $val)
        {
            if (isset(
    $vbulletin->GPC['mybitoptionsfield']["$key"]))
            {
                
    $forumdata->set_bitfield('mybitoptionsfield'$key$val);
            }
        }

  • The following step is to have the new bitfield added to the vBulletin_Forum_Dm.
    Create a plugin @ forumdata_start with the following code:

    PHP Code:
    if (isset($this->registry->bf_misc['mybitoptionsfield']))
    {
        
    $this->bitfields["mybitoptionsfield"] =& $this->registry->bf_misc['mybitoptionsfield'];


Once done, rebuild your btifields.
Now, you should be able to access the new options simply by using $foruminfo['mybitoptiontitle'].

>> EOD
Reply With Quote
  #2  
Old 05-22-2006, 01:16 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for taking the time to write this up
Reply With Quote
  #3  
Old 05-22-2006, 05:46 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks alot Anthony!

/me bookmarks!
Reply With Quote
  #4  
Old 05-22-2006, 08:24 PM
ronoxQ's Avatar
ronoxQ ronoxQ is offline
 
Join Date: Aug 2005
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What do you mean by Multiple Options?
Reply With Quote
  #5  
Old 05-22-2006, 08:31 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ronoxQ
What do you mean by Multiple Options?
I mean "two or more options held in a single database field".
Reply With Quote
  #6  
Old 05-22-2006, 10:47 PM
ronoxQ's Avatar
ronoxQ ronoxQ is offline
 
Join Date: Aug 2005
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Psionic Vision
I mean "two or more options held in a single database field".
Hmm... I'm still a tad confused. What options do forums have?
Reply With Quote
  #7  
Old 05-22-2006, 11:09 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This tutorial is about creating new options, therefore forums WILL have whatever options you add using this tutorial, given you do it correctly
Reply With Quote
  #8  
Old 06-25-2006, 06:22 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it's just giving me sql errors is this for 3.5.x or 3.0.x
Reply With Quote
  #9  
Old 06-25-2006, 06:47 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is for 3.5.x.
Reply With Quote
  #10  
Old 06-25-2006, 06:48 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i wonder why it doesn't work then.
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 08:06 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.04785 seconds
  • Memory Usage 2,316KB
  • Queries Executed 23 (?)
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
  • (7)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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
  • (9)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
  • 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
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete