2014-10-08, 06:00 AM
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?
$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
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')
);
(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. )
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.
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.
Anyway, it's 3AM, so forgive me if I made this confusing. Good luck with your plugin.