Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: CapadY on June 03, 2011, 12:11:51 PM

Title: Integrate hookup functions
Post by: CapadY on June 03, 2011, 12:11:51 PM
When I am well informed since RC3 hookup functions are introduced.

When I look at the information that I can find about it till now it should be quit easy to add some functions to SMF but it isn't that clear how to use it.

At the moment I've add something shown in the forum but I want it to enable/disble in the administration to be shown.
Is it possible to use an hookup to make this extra option in the Admin part ? (Boardoption)

And if, can sombody explain how ?


Title: Re: Integrate hookup functions
Post by: All Colours Sam on June 05, 2011, 11:11:16 PM
Hi, yes there is an admin hook, I usually used like this:


// The admin hook
function ModAdmin(&$admin_areas){

global $txt;

$admin_areas['config']['areas']['mymod'] = array(
'label' => $txt['mod_description'],
'file' => 'MyFile.php',
'function' => 'ModifyModSettings',
'icon' => 'posts.gif',
);

}



on this particular case it will add a new button on the configuration menu in the admin panel, after that you will have to build your  ModifyModSettings();  function  inside your  MyMod.php  file  with something like this:


// The settings hook
function ModifyModSettings($return_config = false){

global $txt, $scripturl, $context, $sourcedir;

require_once($sourcedir . '/ManageServer.php');  // Important!

$config_vars = array(
// My arrays ie: array('check', 'something' ),
);

if ($return_config)
return $config_vars;

$context['post_url'] = $scripturl . '?action=admin;area=mymod;save';  // the url
$context['settings_title'] = $txt['somthing_admin_panel']; // the name
$context['page_title'] = $txt['somthing'];  // the page title
$context['sub_template'] = 'show_settings';

// Saving?
if (isset($_GET['save'])){

checkSession();
saveDBSettings($config_vars);
writeLog();
redirectexit('action=admin;area=mymod');
}

prepareDBSettingContext($config_vars);

}
Title: Re: Integrate hookup functions
Post by: live627 on June 06, 2011, 12:57:02 AM
integrate_admin_areas modifies the admin menu
integrate_admin_include calls a file to include only for the admin panel

I should look this up to verify this is correct :P

EDIT verified. My memory hasn't failed me yet! :P