vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Create Multiple Options Per Forum (via Bitfields) (https://vborg.vbsupport.ru/showthread.php?t=116370)

akanevsky 05-21-2006 10:00 PM

Create Multiple Options Per Forum (via Bitfields)
 
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

amykhar 05-22-2006 01:16 PM

Thanks for taking the time to write this up :)

Logikos 05-22-2006 05:46 PM

Thanks alot Anthony!

/me bookmarks!

ronoxQ 05-22-2006 08:24 PM

What do you mean by Multiple Options?

akanevsky 05-22-2006 08:31 PM

Quote:

Originally Posted by ronoxQ
What do you mean by Multiple Options?

I mean "two or more options held in a single database field".

ronoxQ 05-22-2006 10:47 PM

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?

akanevsky 05-22-2006 11:09 PM

This tutorial is about creating new options, therefore forums WILL have whatever options you add using this tutorial, given you do it correctly :)

rogersnm 06-25-2006 06:22 PM

it's just giving me sql errors is this for 3.5.x or 3.0.x

akanevsky 06-25-2006 06:47 PM

This is for 3.5.x.

rogersnm 06-25-2006 06:48 PM

i wonder why it doesn't work then.

akanevsky 06-25-2006 06:52 PM

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...

harmor19 08-22-2006 05:58 PM

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"?

jerudc 12-03-2006 01:32 AM

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?

akanevsky 12-03-2006 01:39 AM

The XML must be in /includes/xml.

diades 03-18-2007 10:07 AM

Hi Psionic

Thanks for taking the time do publish this, very useful.

Blaine0002 04-15-2007 02:41 AM

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.

Ted S 06-24-2007 12:25 AM

Great tutorial. Thanks a ton!

liamwli 03-12-2013 05:46 PM

Works on vB4 :y:

How would I make a textbox appear in the forum manager, instead of a yesno row?


All times are GMT. The time now is 06:11 PM.

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.01411 seconds
  • Memory Usage 1,778KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete