BirdOPrey5
07-04-2012, 03:23 PM
This wasn't especially difficult and doesn't rise to the level of being an article but I did quite a bit of searching and never saw it posted before.
Below is some code that will let you put a "style chooser" in Admin CP -> Settings -> Options (options for any mod you may create.)
Previously I was asking users to manually enter styleids into a box if they wanted to enable or disable a style for a particular mod.
Now they can easily select the style via a checkbox just like a usergroup name.
In the Option Setup in the "Option Code" field enter this code:
" . eval('$options = "";
foreach($vbulletin->stylecache[-1] AS $sss)
{
$styleid = $sss[0][styleid];
$style = $sss[0];
$options .= "\\t\\t<label for=\\"setting[$setting[varname]]$styleid\\" title=\\"usergroupid: $styleid\\"><input type=\\"checkbox\\" tabindex=\\"1\\" name=\\"setting[$setting[varname]]"."[]\\" id=\\"setting[$setting[varname]]$styleid\\" value=\\"$styleid\\"" . iif(strpos(",$setting[value],", ",$styleid,") !== false, \' checked="checked"\') . iif($vbulletin->debug, " title=\\"name="setting[$setting[varname]]"\\"") . " />$style[title]</label><br />\\n";
}
return "<span class=\\"smallfont\\">\\n$options\\t</span>";') . "<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"-1\" />
That code always remains the same, it never needs to be edited in any way.
The second part is you need to make a plugin on the hook admin_options_processing.
In that plugin add the code:
//Style Setting
$tsett = 'setting-name-here';
if (is_array($settings[$tsett]))
{
$settings[$tsett] = implode(',', $settings[$tsett]);
}
$tsett = '';
The only thing that needs to be changed in the above code is setting-name-here with the varname you entered for the variable you created in options.
And that is it- it will now give you a functioning option that looks like this:
https://vborg.vbsupport.ru/attachment.php?attachmentid=139517&stc=1&d=1341418668
Oh in the back end calling the option like $vbulletin->options['varname'] will give you a comma separate string of styleids... so it might look like '1,2,3,5' if styleids 1, 2, 3, and 5 were selected. So if you need an array you will have to explode the data.
This will only show non-mobile styles in newer versions of vBulletin and in most cases you don't need to worry about the mobile style anyway.
If you did need to include the mobile styles you would have to edit this line in the option code:
foreach($vbulletin->stylecache[-1] AS $sss)
Mobile styles are stored in -2 I believe. So you would need to do the loop for both values, or just make a completely separate option to choose mobile styles.
Below is some code that will let you put a "style chooser" in Admin CP -> Settings -> Options (options for any mod you may create.)
Previously I was asking users to manually enter styleids into a box if they wanted to enable or disable a style for a particular mod.
Now they can easily select the style via a checkbox just like a usergroup name.
In the Option Setup in the "Option Code" field enter this code:
" . eval('$options = "";
foreach($vbulletin->stylecache[-1] AS $sss)
{
$styleid = $sss[0][styleid];
$style = $sss[0];
$options .= "\\t\\t<label for=\\"setting[$setting[varname]]$styleid\\" title=\\"usergroupid: $styleid\\"><input type=\\"checkbox\\" tabindex=\\"1\\" name=\\"setting[$setting[varname]]"."[]\\" id=\\"setting[$setting[varname]]$styleid\\" value=\\"$styleid\\"" . iif(strpos(",$setting[value],", ",$styleid,") !== false, \' checked="checked"\') . iif($vbulletin->debug, " title=\\"name="setting[$setting[varname]]"\\"") . " />$style[title]</label><br />\\n";
}
return "<span class=\\"smallfont\\">\\n$options\\t</span>";') . "<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"-1\" />
That code always remains the same, it never needs to be edited in any way.
The second part is you need to make a plugin on the hook admin_options_processing.
In that plugin add the code:
//Style Setting
$tsett = 'setting-name-here';
if (is_array($settings[$tsett]))
{
$settings[$tsett] = implode(',', $settings[$tsett]);
}
$tsett = '';
The only thing that needs to be changed in the above code is setting-name-here with the varname you entered for the variable you created in options.
And that is it- it will now give you a functioning option that looks like this:
https://vborg.vbsupport.ru/attachment.php?attachmentid=139517&stc=1&d=1341418668
Oh in the back end calling the option like $vbulletin->options['varname'] will give you a comma separate string of styleids... so it might look like '1,2,3,5' if styleids 1, 2, 3, and 5 were selected. So if you need an array you will have to explode the data.
This will only show non-mobile styles in newer versions of vBulletin and in most cases you don't need to worry about the mobile style anyway.
If you did need to include the mobile styles you would have to edit this line in the option code:
foreach($vbulletin->stylecache[-1] AS $sss)
Mobile styles are stored in -2 I believe. So you would need to do the loop for both values, or just make a completely separate option to choose mobile styles.