MyBB Community Forums

Full Version: Create admin module?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Recently added a database that i'd like to be able to manage through an admin module on the administrator page. Upon googling it I was surprised there was not an answer for 1.6... Has anyone found a way to do this?
can you elaborate your requirement - added database for what ? what type of database management you need ?

for MyBB forum database there were a couple of plugins (for MyBB 1.6.x/1.4.x) to execute simple queries .. (eg. MySquirrel , EZsql)
I'm not entirely sure what you're talking about, but I'm assuming you're referring to modules that add the tabs at the top of the admin panel? (Home, Configuration, Tools & Maintenance, etc. )

If so, adding new modules is a bit on the tricky side. I'm going to go ahead and assume you know PHP pretty well, and if that's the case, the best approach is just to copy/paste a small module (the home module being a good module to use) and to change what you need. (That's what I'm doing on my upcoming project, at least. Toungue)

Each module goes into a separate directory in the /admin/modules folder. This directory name must obviously be unique, and the modulename_meta and modulename_action_handler functions inside of the module_meta.php must correspond to this directory name. (In the home module, these functions are respectively named "home_meta" and "home_action_handler." If you were creating a new module called "database", you'd create your "database" directory inside of /admin/modules, and in module_meta.php, you'd rename these functions database_meta () and database_action_handler(), respectively. Do not rename the module_meta.php file. )

	$sub_menu = array();
	$sub_menu['10'] = array("id" => "dashboard", "title" => $lang->dashboard, "link" => "index.php?module=home-dashboard");
	$sub_menu['20'] = array("id" => "preferences", "title" => $lang->preferences, "link" => "index.php?module=home-preferences");
	$sub_menu['30'] = array("id" => "docs", "title" => $lang->mybb_documentation, "link" => "http://docs.mybb.com");
	$sub_menu['40'] = array("id" => "credits", "title" => $lang->mybb_credits, "link" => "index.php?module=home-credits");
	$sub_menu = $plugins->run_hooks("admin_home_menu", $sub_menu);

	$page->add_menu_item($lang->home, "home", "index.php", 1, $sub_menu); // change "home" to your module name

That adds links that will show up on the sidebar, and should be pretty self explanatory. Edit as you wish. Note that you will need to change these link URLs to be relative to your new module. index.php?module=home-dashboard would become index.php?module=database-dashboard, for example. Toungue

	global $page, $db, $lang, $plugins;

	$page->active_module = "home"; // change this to your module name

	$actions = array(
		'preferences' => array('active' => 'preferences', 'file' => 'preferences.php'),
		'credits' => array('active' => 'credits', 'file' => 'credits.php'),
		'version_check' => array('active' => 'version_check', 'file' => 'version_check.php'),
		'dashboard' => array('active' => 'dashboard', 'file' => 'index.php')
	);

This essentially just links URLs within the module to the files that will process them. For example, index.php?module=database-credits will direct to the credits.php file inside of your module directory. Just create new files in your module directory and add the appropriate element to this array in order to "route" requests within this module to the correct file.

As far as the rest is concerned, you should be able to get an idea of how it works by looking at the default core modules. I will go ahead and say that this is one of the more complicated elements to designing advanced plugins because none of this is really documented. It's not difficult at all once you get all of your module_meta stuff set up though. Toungue

Anyway, it's 3AM, so forgive me if I made this confusing. Good luck with your plugin. Big Grin
(2014-10-08, 07:10 AM)Darth Apple Wrote: [ -> ]I'm not entirely sure what you're talking about, but I'm assuming you're referring to modules that add the tabs at the top of the admin panel? (Home, Configuration, Tools & Maintenance, etc. )

If so, adding new modules is a bit on the tricky side. I'm going to go ahead and assume you know PHP pretty well, and if that's the case, the best approach is just to copy/paste a small module (the home module being a good module to use) and to change what you need. (That's what I'm doing on my upcoming project, at least. Toungue)

Each module goes into a separate directory in the /admin/modules folder. This directory name must obviously be unique, and the modulename_meta and modulename_action_handler functions inside of the module_meta.php must correspond to this directory name. (In the home module, these functions are respectively named "home_meta" and "home_action_handler." If you were creating a new module called "database", you'd create your "database" directory inside of /admin/modules, and in module_meta.php, you'd rename these functions database_meta () and database_action_handler(), respectively. Do not rename the module_meta.php file. )


 $sub_menu = array();
 $sub_menu['10'] = array("id" => "dashboard", "title" => $lang->dashboard, "link" => "index.php?module=home-dashboard");
 $sub_menu['20'] = array("id" => "preferences", "title" => $lang->preferences, "link" => "index.php?module=home-preferences");
 $sub_menu['30'] = array("id" => "docs", "title" => $lang->mybb_documentation, "link" => "http://docs.mybb.com");
 $sub_menu['40'] = array("id" => "credits", "title" => $lang->mybb_credits, "link" => "index.php?module=home-credits");
 $sub_menu = $plugins->run_hooks("admin_home_menu", $sub_menu);

 $page->add_menu_item($lang->home, "home", "index.php", 1, $sub_menu);

That adds links that will show up on the sidebar, and should be pretty self explanatory. Edit as you wish. Note that you will need to change these link URLs to be relative to your new module. index.php?module=home-dashboard would become index.php?module=database-dashboard, for example.  Toungue


 global $page, $db, $lang, $plugins;

 $page->active_module = "home"; // change this to your module name

 $actions = array(
 'preferences' => array('active' => 'preferences', 'file' => 'preferences.php'),
 'credits' => array('active' => 'credits', 'file' => 'credits.php'),
 'version_check' => array('active' => 'version_check', 'file' => 'version_check.php'),
 'dashboard' => array('active' => 'dashboard', 'file' => 'index.php')
 );

That adds the action handlers for module links. Actions will be handled by files in your module directory, such as config.php, home.php, etc. Just add new files and add a new element to this array to allow it to be used when you visit /admin/index.php?module=modulename-action. (For example, index.php?module=database-credits will direct to the credits.php file inside of the database module directory. )

As far as the rest is concerned, you should be able to get an idea of how it works by looking at the default core modules. I will go ahead and say that this is one of the more complicated elements to designing advanced plugins because none of this is really documented. It's not difficult at all once you get all of your module_meta stuff set up though. Toungue

Anyway, it's 3AM, so forgive me if I made this confusing. Good luck with your plugin. Big Grin

Damn! Lol yeah I know PHP pretty well, I actually found out how to do the little module just in time before you sent me this. But this would've saved me a bunch of time. I basically did the same thing through modifying another plugin called "Page Manager".
[Image: fc03cc7df98eb7fb33de49badf162280.png]

And now I am onto the next part of my plugin where I incorporate a tournament bracket editor. I'm trying to make rankings for different games.
http://gyazo.com/5a9e007a0b4348bee42059daef220430

Shouldn't take too long, but I just started editing with MyBB but have known PHP for a while now. Loving the way it works but the admin panel sure is tricky. This is my first plugin attempt so wish me luck!
I'm moving this to Plugin Development because if you do need more help, you'll get better responses here.