Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 07-04-2012, 03:23 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to make check-boxes for style selections in settings/options...

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:



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.
Attached Images
File Type: jpg disable-in-styles.jpg (26.2 KB, 0 views)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03558 seconds
  • Memory Usage 2,177KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_attachment
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete