vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to make check-boxes for style selections in settings/options... (https://vborg.vbsupport.ru/showthread.php?t=285205)

BirdOPrey5 07-04-2012 02:23 PM

How to make check-boxes for style selections in settings/options...
 
1 Attachment(s)
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:

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=&quot;setting[$setting[varname]]&quot;\\"") . " />$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:

PHP 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/attachmen...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:
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.


All times are GMT. The time now is 10:30 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02490 seconds
  • Memory Usage 1,717KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete