MyBB Community Forums

Full Version: Forum Dropdown in Plugin Settings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Okay, I'm writing a plugin that will require me to specify which forums the plugin will have an effect on. I know that I could make a text field and have the user input all the values of the forums, but I was hoping to be able to use the forum select list which appears in other places (such as selecting which forums a thread prefix will be used, for example). Is there a setting already built to allow this?

I know that another option would be to make it a part of the individual forum's settings, but I'd like to see if this would be possible first.
you can trace the code from this plugin --> ignored forums
Just to clarify, this is where I'm trying to get the forum select:

$setting[0] = array(
	    "name" => "userpages_html_active",
	    "title" => $lang->userpages_html_active,
	    "description" => $lang->userpages_html_active_desc,
	    "optionscode" => "yesno",
	    "value" => "0",
	    "disporder" => "1",
	    "gid" => $gid,
	);

Not specifically for this plugin, but can you use the forum_select function as a value for the optionscode?
You can use its output as the value, like this:

$form = new Form();
$forum_select = "php
{$form->generate_forum_select('forum_select_name', '')}";

$setting[0] = array
(
    "name" => "userpages_html_active",
    "title" => $lang->userpages_html_active,
    "description" => $lang->userpages_html_active_desc,
    "optionscode" => $db->escape_string($forum_select),
    "value" => "0",
    "disporder" => "1",
    "gid" => $gid,
);

I just typed that out of my head and haven't tested at all but something like that is what I mean.
Yeah, sort of. I guess you should require admin/inc/class_form.php to initialize the Form() class.
Shouldn't it already be available? module config-plugins uses the DefaultForm class to produce settings already . . . I'd have to look at the code, but he might even be able to globalize an existing instance.

I'll look.

EDIT: Yeah, class_form is required in the beginning of admin/index.php
I'm a woman, by the way. Not a he. =)

I think you're on to it, but I've tried playing with it, and this is the error that I'm getting:
Parse error: syntax error, unexpected T_STRING in admin\modules\config\settings.php(1119) : eval()'d code on line 2

$form = new Form();
$forum_select = "php
{$form->generate_forum_select('foo_test', '', array('multiple' => true, 'size' => 5))}";

$setting[0] = array
(
    "name" => "foo_test",
    "title" => $lang->userpages_html_active,
    "description" => $lang->userpages_html_active_desc,
    "optionscode" => $db->escape_string($forum_select),
    "value" => "0",
    "disporder" => "1",
    "gid" => $gid,
); 

The settings.php line is:
eval("\$setting_code = \"".$setting['optionscode']."\";");

I tried removing the {} to see if that might be the issue, which left me with 'foo_test', '', array('multiple' => true, 'size' => 5)), but no form.
(2013-09-24, 09:21 PM)jshort Wrote: [ -> ]I'm a woman, by the way. Not a he. =)

Its the Internet, how can I know? :p

(2013-09-24, 09:21 PM)jshort Wrote: [ -> ]I tried removing the {} to see if that might be the issue

I know it looks a little odd, but that is correct syntax.



I just tried scratched this out quickly and it worked fine:

global $db;

	$settinggroup = array
	(
		"name" 				=> 'test_settings',
		"title" 					=> "test title",
		"description" 		=> 'test description',
		"disporder" 			=> "101",
		"isdefault" 			=> "no"
	);
	$gid = (int) $db->insert_query('settinggroups', $settinggroup);

	$form = new Form('', '', '', '', '', true);
	$forum_select = "php
{$form->generate_forum_select('foo_test', '', array('multiple' => true, 'size' => 5))}";

	$setting = array
	(
		"name" => "foo_test",
		"title" => 'test title',
		"description" => 'test description',
		"optionscode" => addcslashes($db->escape_string($forum_select), '"'),
		"value" => "",
		"disporder" => "1",
		"gid" => $gid,
	);
	$db->insert_query('settings', $setting);

Note: Think before you include this as a setting in ACP-- when the admin adds or removes forums your select box will not be updated.

If nothing else, you might need to add a link in the settings page to refresh the forum list. jmo
There is a field in the profile for it. Wink But no worries, it's happened before and will happen again.

Thanks for throwing that together for me, worked like a charm. Unfortunately, I didn't realize that it wouldn't stay up to date if you add a forum, so that's probably not the best solution.

What I might do instead, though, is make a core file edit to make a forum drop down one of the options you can use for settings. It seems a bit silly that it isn't by default, but that would be pretty straight forward - easier than having to refresh my settings every time I add or remove a forum.

Thanks a lot for your help. I appreciate it!
Pages: 1 2