Back to vBulletin 4 Articles

[vB4] Unfinished Settings - fix to work
by Coroner 17 Jan 2010

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:
PHP Code:
        case 'username':
            
$checked= array('username' => ' checked="checked"');
            break; 
add below:
PHP Code:
        case 'arrayinteger':
            
$checked= array('arrayinteger' => ' checked="checked"');
            break;
        case 
'arrayfree':
            
$checked= array('arrayfree' => ' checked="checked"');
            break; 
search for:
PHP Code:
<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:
PHP Code:
        <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:
PHP Code:
    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:
PHP Code:
    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:
PHP Code:
    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:
PHP Code:
    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:
PHP Code:
        // 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'], false5true);
            }
            else
            {
                
print_input_row($description$name$setting['value']);
            }
        }
        break; 
and change it into:
PHP Code:
        // 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'], false5true);
            }
            else
            {
                
print_input_row($description$name$setting['value']);
            }
        }
        break; 
search for:
PHP Code:
        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:
PHP Code:
        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:
PHP Code:
                if (isset($vbulletin->options["$setting[varname]"]))
                {
                    
$newvalue $vbulletin->options["$setting[varname]"];
                }
                else
                {
                    
$newvalue $setting['defaultvalue'];
                } 
and add above:
PHP Code:
                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
Attached Thumbnails
Click image for larger version
Name:	Bild 1.jpg
Views:	386
Size:	43.5 KB
ID:	110196  

Similar Mods

Hide Threads with unfinished Polls vBulletin 3.5 Add-ons

vblts.ru supports vBulletin®, 2022-2024