Nice work @Burke Knight . Now let's see if we can make this Global Header And Footer (GHF) mod into a hook mod. We shall create files for it like GHF.subs.php, GHF.hooks.php etc.
First part is the header part. I think we can call that in $context['html_headers']. In GHF.subs.php (whatever you want to name it), create a function for that so it the file will look something like this:
<?php
/**
*
* @author Your name, email etc
* @license Your license
* @mod Your mod name
*
*/
if (!defined('ELK'))
die('No access...');
function GHF_Main()
{
// Globalize what you need
global $context, $modSettings;
// Load what you need
// eg. loadLanguage('GHF');
// Add things in header
if(!empty($modSettings['global_head'])) {
$context['html_headers'] .= ' . $modSettings['global_head'] . ';
}
}
?>
For footer, I think you can use $context['insert_after_template'] using the same principle as above. Just modify the above function like this:
// Add things in header
if(!empty($modSettings['global_head'])) {
$context['html_headers'] .= ' . $modSettings['global_head'] . ';
}
// Add things in footer
if(!empty($modSettings['global_foot'])) {
$context['insert_after_template'] .= ' . $modSettings['global_foot'] . ';
}
I am not so sure about the middle one after the linktree though I supposed you can use either addAfter or buffer. To use buffer, you can add another function like this:
function GHF_Mid(&$buffer)
{
// Globalize what you need
global $modSettings, $context;
if (isset($_REQUEST['xml']) || $context['current_action'] == 'printpage') return $buffer;
$ghf = array();
// Description
if(!empty($modSettings['global_mid'])) {
// Define the old and the new title
$title_old = '<div id="main_content_section"><a id="skipnav"></a>';
$title_new = '<br /><div>' . $modSettings['global_mid'] . '</div>
<div id="main_content_section"><a id="skipnav"></a>';
$gfh[$title_old] = $title_new;
}
// Now let's change the title, if we're allowed to
return str_replace(array_keys($gfh), array_values($gfh), $buffer);
}
Or if you wish to use layer addAfter you can create another function something like this:
function GHF_middle()
{
// Globalize what you need
// Load what you need
// Add things in middle
if(!empty($modSettings['global_mid'])) {
loadTemplate('GHF);
$template_layers->addAfter('template_body_above', 'GHF_middle');
}
}
That cover your changes in the template file. Your language file should be a simple GHF.english.php and put all the contents inside it.
<?php
/**
*
* @author Your name, email etc
* @license Your license
* @mod Your mod name
*
*/
$txt['global_head'] = 'Add content to the <head></head> tags:';
$txt['global_mid'] = 'Add content below linktree:';
$txt['global_foot'] = 'Add content to the footer:';
$txt['global_copy'] = 'Add custom copyright to the footer:';
?>
Your addon settings can be made inside the GHF.subs.php by adding another function:
function GHF_Settings(&$config_vars)
{
// Load the language
loadLanguage('GHF');
// Add the settings
$ghf = array(
array('large_text', 'global_head', '4'),
array('large_text', 'global_mid', '4'),
array('large_text', 'global_foot', '4'),
array('text', 'global_copy', '30'),
'',
);
// Insert after all available slice.
$first = array_slice($config_vars, 0);
$config_vars = array_merge($first, $ghf);
}
Then you hook file, GHF.hooks.php.
<?php
/**
*
* @author Your name, email etc
* @license Your license
* @mod Your mod name
*
*/
// If we have found SSI.php and we are outside of ELK, then we are running standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('ELK'))
require_once(dirname(__FILE__) . '/SSI.php');
// If we are outside ELK and can't find SSI.php, then throw an error
elseif (!defined('ELK'))
die('<b>Error:</b> Cannot install - please verify you put this file in the same place as Elkarte\'s SSI.php.');
if (ELK == 'SSI')
db_extend('packages');
// Define the hooks
$hook_functions = array(
'integrate_buffer' => 'GHF_Mid|SOURCEDIR/addons/GHF.subs.php',
'integrate_load_theme' => 'GHF_Main|SOURCEDIR/addons/GHF.subs.php',
'integrate_general_mod_settings' => 'GHF_Settings|SOURCEDIR/addons/GHF.subs.php',
);
// Adding or removing them?
if (!empty($context['uninstalling']))
$call = 'remove_integration_function';
else
$call = 'add_integration_function';
// Do the deed
foreach ($hook_functions as $hook => $function)
$call($hook, $function);
if (ELK == 'SSI')
echo 'Congratulations! You have successfully installed this mod!';
?>
Lastly, you should have something like this in your package-info.xml
<install for="1.0 - 1.0.99">
<readme type="file" parsebbc="true">GHF.readme.txt</readme>
<require-file name="GHF.english.php" destination="LANGUAGEDIR/english" />
<require-file name="GHF.subs.php" destination="SOURCEDIR/addons" />
<code>GHF.hooks.php</code>
<redirect url="?action=admin;area=addonsettings" timeout="499">Redirecting to Addons Settings...</redirect>
</install>
<uninstall for="1.0 - 1.0.99">
<readme parsebbc="true">GHF.readme.txt</readme>
<remove-file name="LANGUAGEDIR/english/GHF.english.php" />
<remove-file name="SOURCEDIR/addons/GHF.subs.php" />
<code>GHF.hooks.php</code>
<redirect url="?action=admin;area=packages" timeout="499">Redirecting to Package Manager...</redirect>
</uninstall>
That are the rough ideas on making it a hook mod. However, I haven't tested it yet.