MyBB Community Forums

Full Version: Where To Hook?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing a plugin that allows a custom message to be added to every page at the footer. So far I've successfully added the settings to the Administration panel, made a new template, and edited the footer template to hold my template.

However, I'm stuck as to where I should actually hook in to MyBB. I want this to be on every page.

Also, I added a setting to toggle on and off the message - how do I check this and appropriately exit if it is set to 0 (no)?

With all due respect,
Steven
$plugins->add_hook("global_end", "YOUR_FUNCTIONNAME");

function YOUR_FUNCTIONNAME()
{	
	global $mybb, $templates, $theme, $YOUR_DISPLAYVALUE;
	if($mybb->settings['YOUR_SETTINGNAME'] == 1)
	{
		eval("\$YOUR_DISPLAYVALUE = \"".$templates->get("YOUR_TEMPLATENAME")."\";");
	}
}
Thanks for the code. Unfortunately, I still cannot get it to display. Here is my full code:
<?php

/**
 * @author Steven | www.phreakyourgeek.com
 * @contact [email protected]
 * @copyright 2009
 * @software MyBB
 */

if(!defined("IN_MYBB"))
{
	die('You cannot directly access this file. To use, activate the "Custom Footer" plugin from the MyBB admin panel.');
}

$plugins->add_hook("global_end", "customfooter_execute");

function customfooter_info()
{
	return array(
		'name' => 'Custom Footer',
		'description' => 'Adds a custom footer to the forum.',
		'website' => 'http://www.phreakyourgeek.com/',
		'author' => 'Steven',
		'authorsite' => 'http://www.phreakyourgeek.com/info.php',
		'version' => '1.0.0',
		'compatibility' => '14*'
	);
}

function customfooter_activate()
{
	global $db;
	
	$settings_group = array(
		'gid' => null,
		'name' => 'customfooter',
		'title' => 'Custom Footer Settings',
		'description' => 'This section allows you to manage the settings for your custom footer',
		'disporder' => '1',
		'isdefault' => 'no'
	);
	$db->insert_query('settinggroups',$settings_group);
	$gid = $db->insert_id();
	
	$setting_1 = array(
		'sid' => null,
		'name' => 'customfooterenable',
		'title' => 'Enabled',
		'description' => 'Enable the custom footer?',
		'optionscode' => 'yesno',
		'value' => 'yes',
		'disporder' => '1',
		'gid' => intval($gid)
	);
	$db->insert_query('settings',$setting_1);
	
	$setting_2 = array(
		'sid' => null,
		'name' => 'customfootercode',
		'title' => 'Code',
		'description' => 'Enter the HTML code for the footer.',
		'optionscode' => 'textarea',
		'value' => '',
		'disporder' => '2',
		'gid' => intval($gid)
	);
	$db->insert_query('settings',$setting_2);
	
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets('footer', '#{\$auto_dst_detection}#', "{\$auto_dst_detection}\n{\$customfooter}");
	
	$template_1 = array(
		'tid' => null,
		'title' => 'custom_footer',
		'template' => "<div style=\"width:100%;text-align:center;\" class=\"smalltext\">{\$customfootercode}</div>",
		'sid' => '-1'
	);
	$db->insert_query('templates',$template_1);
	
	rebuildsettings();
}

function customfooter_deactivate()
{
	global $db;
	
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='customfooter'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='customfooterenable'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='customfootercode'");
	
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='custom_footer'");
	
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets('footer', '#(\n?){\$custom_footer}#', '', 0);
	
	rebuildsettings();
}

/** END CONFIGURATION FUNCTIONS **/

function customfooter_execute()
{
	global $mybb, $theme, $customfooter, $templates;
	
	$customfootercode = '';
	
	if($mybb->settings['customfooterenable'] == 1)
	{
		$customfootercode = $mybb->settings['customfootercode'];
		
		eval("\$customfooter = \"".$templates->get("custom_footer")."\";");
	}
}

?>
you've used
       'optionscode' => 'yesno',
        'value' => 'yes',

Set the value to '1' or change the check to
if($mybb->settings['customfooterenable'] == "yes")

Edit;
Try the attached file; deactivate yours, upload and activate
Is there any reason to use the file you provided over my original code?
cause your original code didn't work ?
i copied your code and changed everything so it would work.

Edit;
You don't have to use it; you can always figure it out yourself.