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
  #12  
Old 06-25-2006, 06:52 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know, it works for me. I used the steps described above to implement such thing in about 4 of my hacks by now...
Reply With Quote
  #13  
Old 08-22-2006, 05:58 PM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am trying to make a link in the thread tools.
What hooks would I use instead of "forumadmin_edit_form" and "forumadmin_update_save"?
Reply With Quote
  #14  
Old 12-03-2006, 01:32 AM
jerudc jerudc is offline
 
Join Date: Feb 2005
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have a question about the bitfield_myproductid.xml file.

When you release a product, can you include this information in the product.xml file? That is, can you put a new child

<bitfields ...></bitfields>
inside the <product ...></product> element of your installer? or must you have the user place the bitfields xml file in the mysite/includes/xml folder as part of product setup?
Reply With Quote
  #15  
Old 12-03-2006, 01:39 AM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The XML must be in /includes/xml.
Reply With Quote
  #16  
Old 03-18-2007, 10:07 AM
diades diades is offline
 
Join Date: Jul 2002
Location: Glasgow
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Psionic

Thanks for taking the time do publish this, very useful.
Reply With Quote
  #17  
Old 04-15-2007, 02:41 AM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So im trying to use a number input in my admincp, whenever i enter my numbers 10,5,.1and click go, it writes the number 8 to the database. ?? I have no clue how this is storing the information. I changed the int(10) to Varchar(250) by the way.
Reply With Quote
  #18  
Old 06-24-2007, 12:25 AM
Ted S Ted S is offline
 
Join Date: Dec 2003
Location: SoCal
Posts: 3,954
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great tutorial. Thanks a ton!
Reply With Quote
  #19  
Old 03-12-2013, 05:46 PM
liamwli liamwli is offline
 
Join Date: May 2012
Posts: 172
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works on vB4 :y:

How would I make a textbox appear in the forum manager, instead of a yesno row?
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:52 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.06889 seconds
  • Memory Usage 2,308KB
  • 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
  • (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
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (8)postbit
  • (9)postbit_onlinestatus
  • (9)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