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

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

 

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

Create Multiple Options Per User (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 "user` ADD `mybitoptionsfield` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `options`");

    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 "user` 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 userinfo.
    Create a plugin @ fetch_userinfo with the following code:

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

  • The following step is to add new options to UserCP Option Page on Template Level.
    In template modifyoptions, add the following code whereever you want the options to appear:

    HTML Code:
    <fieldset class="fieldset">
    	<legend><label for="cb_option1">OPTION1_HEADING1</label></legend>
    	<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%">
    	<tr>
    		<td>
    			OPTION1_DESCRIPTION1
    		</td>
    	</tr>
    	<tr>
    		<td><label for="cb_option1"><input type="checkbox" name="mybitoptionsfield[option1]" value="1" id="cb_option1" $checked[option1] />OPTION1_HEADING1</label><input type="hidden" name="set_options[option1]" value="1" /></td>
    	</tr>
    	</table>
    </fieldset>
    
    <fieldset class="fieldset">
    	<legend><label for="cb_option2">OPTION2_HEADING2</label></legend>
    	<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%">
    	<tr>
    		<td>
    			OPTION2_DESCRIPTION2
    		</td>
    	</tr>
    	<tr>
    		<td><label for="cb_option2"><input type="checkbox" name="mybitoptionsfield[option2]" value="1" id="cb_option2" $checked[option2] />OPTION2_HEADING2</label><input type="hidden" name="set_options[option2]" value="2" /></td>
    	</tr>
    	</table>
    </fieldset>
  • The following step is to add new options to UserCP Option Page on Code Level.
    Create a plugin @ profile_updateoptions with the following code:

    PHP Code:
    if (isset($vbulletin->bf_misc['mybitoptionsfield']))
    {
        
    $vbulletin->input->clean_gpc('p''mybitoptionsfield'TYPE_ARRAY_BOOL);

        foreach (
    $vbulletin->bf_misc['mybitoptionsfield'] AS $key => $val)
        {
            if (isset(
    $vbulletin->GPC['mybitoptionsfield']["$key"]) OR isset($vbulletin->GPC['set_options']["$key"]))
            {
                
    $userdata->set_bitfield('mybitoptionsfield'$key$vbulletin->GPC['mybitoptionsfield']["$key"]);
            }
        }

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

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

        
    $mybitoptionsfield convert_bits_to_array($user['mybitoptionsfield'], $vbulletin->bf_misc['mybitoptionsfield']);
        
    $user array_merge($user$mybitoptionsfield);

        
    print_table_header('MYHEADING');
        
    print_yes_no_row('MYOPTION1''mybitoptionsfield[option1]'$user['option1']);
        
    print_yes_no_row('MYOPTION2''mybitoptionsfield[option2]'$user['option2']);

  • The following step is to have the new options saved when the button is clicked.
    Create a plugin @ useradmin_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"]))
            {
                
    $userdata->set_bitfield('mybitoptionsfield'$key$val);
            }
        }

  • The following step is to have the new bitfield added to the vBulletin_User_Dm.
    Create a plugin @ userdata_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 $userinfo['mybitoptiontitle'].

>> EOD
Reply With Quote
  #2  
Old 05-20-2006, 12:14 PM
-=Sniper=- -=Sniper=- is offline
 
Join Date: May 2002
Posts: 605
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bookmarked thanks dude
Reply With Quote
  #3  
Old 05-20-2006, 01:40 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You saved the day! Thank you very much Anthony!
Reply With Quote
  #4  
Old 05-28-2006, 03:31 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i just get

Invalid File Specified

when i try to import the xml product file containing:
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>
Reply With Quote
  #5  
Old 05-28-2006, 03:34 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Don't import that file, place it under ./includes/xml/ of your forum (filename should be: bitfield_myproductid.xml).
Reply With Quote
  #6  
Old 05-28-2006, 03:45 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ahh thanks for the quick response

btw myproductid is myproductid

lol
Reply With Quote
  #7  
Old 05-28-2006, 03:54 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should use a unique string as your product id, not keep the default one. Two product with the same product id cannot co-exist.
Reply With Quote
  #8  
Old 05-28-2006, 04:04 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah i am just testing i will change afterwards.

do you know how to get 2 radio buttons yes or no?
Reply With Quote
  #9  
Old 05-28-2006, 04:06 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please refer to the following text from the first post:

Quote:
Help on writing hacks will NOT be provided, and any such posts will be ignored.
Reply With Quote
  #10  
Old 05-28-2006, 04:07 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so how am i supposed to learn
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:25 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.04545 seconds
  • Memory Usage 2,335KB
  • 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
  • (1)bbcode_html
  • (9)bbcode_php
  • (1)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
  • (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
  • (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