PDA

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


akanevsky
22 May 2006, 15:04
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
22 May 2006, 15:16
Thanks for taking the time to write this up :)

Logikos
22 May 2006, 19:46
Thanks alot Anthony!

/me bookmarks!

ronoxQ
22 May 2006, 22:24
What do you mean by Multiple Options?

akanevsky
22 May 2006, 22:31
What do you mean by Multiple Options?

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

ronoxQ
23 May 2006, 00:47
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
23 May 2006, 01:09
This tutorial is about creating new options, therefore forums WILL have whatever options you add using this tutorial, given you do it correctly :)

rogersnm
25 Jun 2006, 20:22
it's just giving me sql errors is this for 3.5.x or 3.0.x

akanevsky
25 Jun 2006, 20:47
This is for 3.5.x.

rogersnm
25 Jun 2006, 20:48
i wonder why it doesn't work then.

akanevsky
25 Jun 2006, 20:52
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
22 Aug 2006, 19:58
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
03 Dec 2006, 03:32
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
03 Dec 2006, 03:39
The XML must be in /includes/xml.

diades
18 Mar 2007, 12:07
Hi Psionic

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

Blaine0002
15 Apr 2007, 04:41
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
24 Jun 2007, 02:25
Great tutorial. Thanks a ton!

liamwli
12 Mar 2013, 18:46
Works on vB4 :y:

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