MyBB Community Forums

Full Version: How to use the adminlog in plugins?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey there,

Currently I'm working on a view things and planning of useing the adminlog.
The function log_admin_action works fine and my things which I want to log are shown in the adminlogs.
But how can I format my log entries? Atm the information looks like: module/file - edit(1, 0, hey dude). If I would like to format it, do I have to edit the langfile of the adminlog?

I hope you guys could give me a little kick to find a solution. Big Grin

Greez Garlant
take a look at admin/modules/adminlog.php and this plugin hook:

$plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string);
$plugins->run_hooks_by_ref("admin_tools_get_admin_log_action", $plugin_array);

You'd call it like

$plugins->add_hook("admin_tools_get_admin_log_action", "myplugin_adminlog");

function myplugin_adminlog(&$logitem, &$lang_string)
{
    // do stuff here...
}

(Note I haven't tested it so it, but you get the idea - it should look something like that)
I'd look at this hook before I was posting here and I'm not shure. But wouldn't the following lines only try to load the lang strings out of the tools_adminlog.lang.php? (adminlog.php Line: 481 - 498, after the hook)
	if(isset($lang->$lang_string))
	{
		array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string
		$string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']);
		if(!$string)
		{
			$string = $lang->$lang_string; // Fall back to the one in the language pack
		}
	}
	else
	{
		// Build a default string
		$string = $logitem['module'].' - '.$logitem['action'];
		if(is_array($logitem['data']) && count($logitem['data']) > 0)
		{
			$string .= '('.implode(', ', $logitem['data']).')';
		}
	} 
Then do $lang->abc = "123"; in your plugin