MyBB Community Forums

Full Version: Outputs, but not in table - member_profile_adminoptions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create a plugin which outputs a link on the member profile in the admin options table. I've got the following code so far:
<?php

$plugins->add_hook("member_profile_start", "reportuser");

function reportuser_info() {
	return array(
		"name" => "Report User",
		"description" => "Adds a link to every users profile and gives the ability to report them as a spammer.",
		"author" => "Shannon Rothe",
		"version" => "1.0",
		"website" => "http://jrpgclub.com/community",
		"authorsite" => "http://jrpgclub.com/community",
		"compatibility" => "*"
	);
}

function reportuser_activate() {
	global $db, $report_user;
	
	$db->write_query("CREATE TABLE " . TABLE_PREFIX . "reportuser (
						id INT AUTO_INCREMENT PRIMARY KEY,
						ruid INT,
						uid INT
					)");
					
	$template = array(
		"title" => $db->escape_string('reportuser_link'),
		"template" => "<li><a href=\"#\">Report this user</a></li>",
		"sid" => -1,
		"version" => 1608,
		"dateline" => TIME_NOW
	);
	
	$db->insert_query("templates", $template);
	
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("member_profile_adminoptions", "#".preg_quote('{$lang->admin_ban_in_acp}</a></li>')."#i", "{\$lang->admin_ban_in_acp}</a></li>\n{\$report_user}");
}

function reportuser_deactivate() {
	global $db;
	
	$db->query("DROP TABLE " . TABLE_PREFIX . "reportuser");
	
	$db->delete_query("templates", "title='reportuser_link'");
	
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile_adminoptions", '#'.preg_quote('{$report_user}').'#', '',0);
}

function reportuser() {
	global $db, $memprofile, $templates;
	
	eval("\$report_user = \"".$templates->get('reportuser_link')."\";"); 
	output_page($report_user);
}

?>

It outputs my link, but not in the table, it outputs it above the forums (logo, header etc). Any help is appreciated. Smile
output_page(); is meant for pages, not things like this.

Remove it and use {$report_user} in any member_profile* template.

I would advice you to use str_replace and hook at member_profile_end, but if this works for you, go ahead.
Alright. So I don't need eval? What do I use as the 3rd parameter for str_replace?

Also, using str_replace, do I need to deal with templates apart from inserting into an already existing template? I won't need to make a whole new template just for a link, correct?