MyBB Community Forums

Full Version: Some questions on how to do things.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i'm new at making them plugins, and i find it very interesting. anyway, i'm making a plugin for the Member Profiles page, and i'm not exactly sure how to "officially" do things using the plugins.

1) how do i add a template element? i want to use $templates->get function, so i guess i need to insert some stuff into the database. right now, i'm doing a manual $db->query(insert into the template table duing the on_activate event... is there a smarter "forum way" to do this...some sort of function, or some generic template, so that i can use an appropriate template for different skin sets. (right now, i just added one that matches the default skin)

2) how do i add things to the language file? (other than manually editing it)

3) oh yea, can someone direct me to a plugin that includes an admin portion? my plugin needs one, and i need an example
*cough*
mike.cal Wrote:1) how do i add a template element? i want to use $templates->get function, so i guess i need to insert some stuff into the database. right now, i'm doing a manual $db->query(insert into the template table duing the on_activate event... is there a smarter "forum way" to do this...some sort of function, or some generic template, so that i can use an appropriate template for different skin sets. (right now, i just added one that matches the default skin)
I use this to insert templates in a plugin. The sid = -1 makes the template global, so it's used for all themes.
	$template_1 = array(
		"tid"			=> "NULL",
		"title"			=> 'templatename',
		"template"		=> 'template content',
		"sid"			=> "-1",
	);
	
	$db->insert_query(TABLE_PREFIX."templates", $template_1);
mike.cal Wrote:2) how do i add things to the language file? (other than manually editing it)
Make new language files and let those files be loaded using $lang->load("filename_without_.lang.php") and place those files in their correct folders.
I used this in my Alternative Reputation System to make sure that there is always a language loaded.
	$language = $mybb->settings['bblanguage'];
	if(!file_exists("./inc/languages/$language/nars.lang.php")){
		$lang->setLanguage("english");
	}
	$lang->load("nars");
I asked some people to translate the english nars.lang.php file to another language and included them in the download package. People can choose to upload them or not but the english language must be uploaded.
mike.cal Wrote:3) oh yea, can someone direct me to a plugin that includes an admin portion? my plugin needs one, and i need an example
If you want some settings to be created in the board settings group, you can do things like this:
$settingsgroup = array(
	"gid"			=> "NULL",
	"name"			=> "Group Name",
	"description"	=> "",
	"disporder"		=> "20",
	"isdefault"		=> "no",
);
$db->insert_query(TABLE_PREFIX."settinggroups", $settingsgroup);
$gid = $db->insert_id();

$setting_1 = array(
	"sid"			=> "NULL",
	"name"			=> "setting_name (no spaces allowed)",
	"title"			=> "the title",
	"description"	=> "",
	"optionscode"	=> "text",
	"value"			=> "default value",
	"disporder"		=> "1",
	"gid"			=> intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $setting_1);
The optionscode can be text, select, onoff, yesno, radio, checkbox, cpstyle, language, adminlanguage

If you want a totally new page in the admincp, I guess you could take a look at Nitemare's Ad Managment System
thanks a lot =)
The options for settings seem self-explanatory except for cpstyle. Also, how do you specify the possible options for select, radio, and checkbox?
laie_techie Wrote:The options for settings seem self-explanatory except for cpstyle. Also, how do you specify the possible options for select, radio, and checkbox?
Cpstyle is just the style that the admincp uses. It's a select box with all the current installed styles.
for select, radio and checkbox: you do something like this:
"radio
value1=some text
value2=some other text"
The users will see the text, and the value that corresponds with the text they choose will be used as the setting. In my example: If they choose "some other text", the value will be "value2".

As for the checkbox, there might be some dodgyness about it. The value that is used for the setting is always the one that is last selected.
I mean, if you tick off value1 and value3 in this example, only value 3 is set in the setting.
"checkbox
value1=some text
value2=some other text
value3=yeah whatever"