PDA

View Full Version : Create Multiple Options Per Forum (via Bitfields)


akanevsky
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.
<?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:

$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();

$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:

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

The following step is to add new options to AdminCP User Manager.
Create a plugin @ forumadmin_edit_form with the following 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:

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:

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