PDA

View Full Version : [vB4] Unfinished Settings - fix to work


Coroner
17 Jan 2010, 09:22
Since vB4 is out, there are 2 new unfinished settings. At this moment those settings aren't used by vB4. I've asked in the bugtracker, but get no answer 'bout this.
I wrote my own solution to finish up those 2 settings and hope that this will be implemented in one of the next versions. I've attached a image to, see what I mean.

Ok, let's start (remember: this is a beta solution).

1st extend the database
ALTER TABLE `vb4_setting` CHANGE `datatype` `datatype` ENUM( 'free', 'number', 'boolean', 'bitfield', 'username', 'integer', 'posint', 'arrayinteger', 'arrayfree' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'free'
2nd create two new GLOBAL phrases

title = datatype_arrayinteger
phrase = Array Integer
title = datatype_arrayfree
phrase = Array Free


The next parts is to change 3 files:
open admincp/options.php
search for:
case 'username':
$checked= array('username' => ' checked="checked"');
break;
add below:
case 'arrayinteger':
$checked= array('arrayinteger' => ' checked="checked"');
break;
case 'arrayfree':
$checked= array('arrayfree' => ' checked="checked"');
break;
search for:
<label for="rb_dt_username"><input type="radio" name="datatype" id="rb_dt_username" tabindex="1" value="username"' . $checked['username'] . ' />' . $vbphrase['datatype_username'] . '</label>
add below:
<label for="rb_dt_arrayinteger"><input type="radio" name="datatype" id="rb_dt_arrayinteger" tabindex="1" value="arrayinteger"' . $checked['arrayinteger'] . ' />' . $vbphrase['datatype_arrayinteger'] . '</label>
<label for="rb_dt_arrayfree"><input type="radio" name="datatype" id="rb_dt_arrayfree" tabindex="1" value="arrayfree"' . $checked['arrayfree'] . ' />' . $vbphrase['datatype_arrayfree'] . '</label>
search for:
if (is_demo_mode())
{
print_cp_message('This function is disabled within demo mode');
}

$db->query_write("
UPDATE " . TABLE_PREFIX . "setting SET
grouptitle = '" . $db->escape_string($vbulletin->GPC['grouptitle']) . "',
optioncode = '" . $db->escape_string($vbulletin->GPC['optioncode']) . "',
defaultvalue = '" . $db->escape_string($vbulletin->GPC['defaultvalue']) . "',
displayorder = " . $vbulletin->GPC['displayorder'] . ",

and change it into:
if (is_demo_mode())
{
print_cp_message('This function is disabled within demo mode');
}

if ($vbulletin->GPC['datatype'] == 'arrayinteger' OR $vbulletin->GPC['datatype'] == 'arrayfree')
{
$store = array ();
if (is_array (explode (',', $vbulletin->GPC['defaultvalue'])))
{
foreach (explode (',', $vbulletin->GPC['defaultvalue']) as $key => $val)
{
$store[] = $val;
}
}
$vbulletin->GPC['defaultvalue'] = serialize ($store);
$vbulletin->GPC['value'] = serialize ($store);
}

$db->query_write("
UPDATE " . TABLE_PREFIX . "setting SET
value = '" . $db->escape_string($vbulletin->GPC['value']) . "',
grouptitle = '" . $db->escape_string($vbulletin->GPC['grouptitle']) . "',
optioncode = '" . $db->escape_string($vbulletin->GPC['optioncode']) . "',
defaultvalue = '" . $db->escape_string($vbulletin->GPC['defaultvalue']) . "',
displayorder = " . $vbulletin->GPC['displayorder'] . ",

search for:
print_textarea_row($vbphrase['description'], 'description', $setting['description'], 4, '50" style="width:100%');
print_textarea_row($vbphrase['option_code'], 'optioncode', $setting['optioncode'], 4, '50" style="width:100%');
and add below:
if ($setting['datatype'] == 'arrayinteger' OR $setting['datatype'] == 'arrayfree')
{
$store = unserialize ($setting['defaultvalue']);
$setting['defaultvalue'] = (is_array ($store) ? implode (',', $store) : '');
}

next is to open includes/adminfunctions_options.php
search for:
// select:eval
case 'selectmulti:eval':
{
$options = null;

eval($setting['optiondata']);

if (is_array($options) AND !empty($options))
{
print_select_row($description, $name . '[]', $options, $setting['value'], false, 5, true);
}
else
{
print_input_row($description, $name, $setting['value']);
}
}
break;

and change it into:
// select:eval
case 'selectmulti:eval':
{
$options = null;

eval($setting['optiondata']);

if (is_array($options) AND !empty($options))
{
$setting['value'] = unserialize($setting['value']);
$setting['value'] = (is_array($setting['value']) ? $setting['value'] : array());
print_select_row($description, $name . '[]', $options, $setting['value'], false, 5, true);
}
else
{
print_input_row($description, $name, $setting['value']);
}
}
break;
search for:
case 'arrayinteger':
$key = array_keys($value);
$size = sizeOf($key);
for ($i = 0; $i < $size; $i++)
{
$value[$key[$i]] = intval($value[$key[$i]]);
}
break;

case 'arrayfree':
$key = array_keys($value);
$size = sizeOf($key);
for ($i = 0; $i < $size; $i++)
{
$value[$key[$i]] = trim($value[$key[$i]]);
}
break;
and change those lines into:
case 'arrayinteger':
if (!is_array ($value))
{
$value = unserialize($value);
$value = (is_array($value) ? $value : array());
}
$key = array_keys($value);
$size = sizeOf($key);
for ($i = 0; $i < $size; $i++)
{
$value[$key[$i]] = intval($value[$key[$i]]);
}
$value = serialize ($value);
break;

case 'arrayfree':
if (!is_array ($value))
{
$value = unserialize($value);
$value = (is_array($value) ? $value : array());
}
$key = array_keys($value);
$size = sizeOf($key);
for ($i = 0; $i < $size; $i++)
{
$value[$key[$i]] = trim($value[$key[$i]]);
}
$value = serialize ($value);
break;
next, open includes/adminfunctions_plugin.php
search for:
if (isset($vbulletin->options["$setting[varname]"]))
{
$newvalue = $vbulletin->options["$setting[varname]"];
}
else
{
$newvalue = $setting['defaultvalue'];
}

and add above:
if (trim ($setting['datatype']) == 'arrayinteger' OR trim ($setting['datatype']) == 'arrayfree')
{
$store = array ();
if (is_array (explode (',', trim ($setting['defaultvalue']))))
{
foreach (explode (',', trim ($setting['defaultvalue'])) AS $value)
{
$store[] = $value;
}
}
$setting['defaultvalue'] = serialize ($store);
}


Ok, with this changes you can have those settings working now.

How to use those options ?
In your product (under the settingsgroup) you can now have two more options:
This is example one:
<setting varname="multiinput_choose" displayorder="20">
<datatype>arrayfree</datatype>
<optioncode>multiinput</optioncode>
<defaultvalue>Hello up there,where on the air,it's hockey night tonight</defaultvalue>
</setting>

The optioncode is only multiinput and the datatype MUST be arrayfree or arrayinteger.

The next example is selectmulti:eval
<setting varname="multiselect_choose" displayorder="10">
<datatype>arrayinteger</datatype>
<optioncode>selectmulti:eval
$options = array (
'0' => 'you can choose what you want',
'1' => 'this is a multiselect field',
'2' => 'choose one or more',
'3' => 'option if you like',
'4' => 'this option wont work',
'5' => 'in a standard',
'6' => 'vBulletin 4.0.1',
); </optioncode>
<defaultvalue>1,3,4</defaultvalue>
</setting>
Here also you have to use arrayfree or arrayinteger. Others won't work !

I really hope, that those options are available in a further version of vB4.

Regards
Coroner

Coroner
18 Jan 2010, 06:29
I forgott to tell you, how to use those settings in you mod.

For both options, you will get back an array (serialized). First unserialized the value

// unserialized the value
$vbulletin->options['multiinput_choose'] = unserialized ($vbulletin-options['multiinput_choose']);
// unserialized the value

And next is to check the array.

if (in_array ('findme', $vbulletin->option['multiinput_choose']))
{
// I found "findme"
// ... let's do some code
}

wpeloquin
30 Jun 2010, 20:58
What exactly would this be for?

vbresults
30 Jul 2011, 19:03
This is to finish an incomplete implementation of the 'arrayinteger' and 'arrayfree' option data types. It's vB 4.1.5 now and this still is not finished in the core. Absolutely ridiculous.

Buray Savas ANI
31 Jul 2011, 17:02
Thank you for job, but i dont understand, if we have vbseo this is good or not good?

Badshah93
26 Sep 2011, 12:10
i was going to post this bug, but found ur thread..
its disappointing that it is not fix yet in main core files. have to create now a new admincp page for one setting.

grasshoper
17 Jan 2012, 18:24
Is it fixed by now in 4.10?