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) ? 1 : 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
|