Lesson Three - What to do when Mod's FailThis will also work for getting mods to work on custom themes.
When a mod fails chances are that you have a conficting mod installed. So the only way around it is to install manually. This lesson will show you how to do just that. For this example, I'll be using JayBachatero's Global Announcement's Mod and for a custom theme, I'll be using the Babylon theme packaged with SMF 1.1.
First off, even though you get failures, complete the installation of the mod anyway. You'll be finishing the rest off the hard way.
Look in the [List Files] section of the mod to list all the files listed inside the package. The package manager can read .zip, .tar.gz and .tar.bz2 files easily.
Look for something such as install.xml, modification.xml or similar. Sometimes though this may be a .mod file instead and some have version numbers such as "RC3" or "109" to tell which file is for which version of SMF. .mod is actually easier than .xml but it's not recommended though.
To make life easier for the coder, the package manager has some special paths, they should be fairly obvious.
$boarddir = This is the forum root. eg. public_html/forum
$sourcedir = This is the sources folder.
$themedir = This is the default theme's folder.
$languagedir = This is the language folder in the default theme.
$avatardir = This is the avatar folder.
$smileysdir = This is the Smiley folder.
I'll be using those names here on out.
And look for the area for the file that failed. Lets say that
MessageIndex.php failed in $sourcedir. It has this code.
<file name="$sourcedir/MessageIndex.php">
<operation>
<search position="before"><![CDATA[
$context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new'];
]]></search>
<add><![CDATA[
//Check to see if Global Announcements are enabled.
if (isset($modSettings['global_announcements_enable']) && $modSettings['global_announcements_enable'] == 1)
{
//Load the Global Announcements.
$selectGA = db_query("
SELECT
ga.ID_GA, ga.ID_MEMBER, ga.time, ga.icon, ga.subject, ga.numViews, ga.enabled,
gab.ID_BOARD, m.realName
FROM {$db_prefix}global_announcements AS ga
LEFT JOIN {$db_prefix}global_announcements_boards AS gab ON (ga.ID_GA = gab.ID_GA)
LEFT JOIN {$db_prefix}members AS m ON (ga.ID_MEMBER = m.ID_MEMBER)
WHERE gab.ID_BOARD = '$board' OR gab.ID_board = '0'
" .(!$context['user']['is_admin'] ? "AND enabled = '1'" : ""). "
ORDER BY gaOrder ASC,
" . (isset($modSettings['global_announcements_sort_by'], $modSettings['global_announcements_sort_direction'])
? $modSettings['global_announcements_sort_by'] . ' ' . $modSettings['global_announcements_sort_direction']
: "time DESC"), __FILE__, __LINE__);
//Set $globalAnnouncements array.
$globalAnnouncements = array();
//Loop through the results.
while ($row = mysql_fetch_array($selectGA))
{
// Cencor the text Hope this fixes UTF-8 issues
censorText($row['subject']);
$globalAnnouncements[] = array(
'member' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'link' => '<a href="' .$scripturl. '?action=profile;u=' .$row['ID_MEMBER']. '">' .$row['realName']. '</a>',
),
'ga' => array(
'id' => $row['ID_GA'],
'time' => timeformat($row['time']),
'icon' => empty($row['icon']) ? 'xx' : $row['icon'],
'subject' => censorText($row['subject']),
'views' => $row['numViews'],
'href' => $scripturl . '?action=globalAnnouncements;id=' .$row['ID_GA'],
'enabled' => $row['enabled'],
),
);
}
mysql_free_result($selectGA);
// Set $context['globalAnnouncements'].
$context['globalAnnouncements'] = $globalAnnouncements;
}
]]></add>
</operation>
</file>
Quite a bit huh? Dont worry, what the actual code is isnt important. This is just a copy and paste job.
First, lets look at the XML tags around the code.
<file name="$sourcedir/MessageIndex.php">
This tells us what file to look at. In our case, we're looking to download MessageIndex.php from $sourcedir onto our local computer and open it in any text editor.
<search position="before">
This tells us that the code we are about to add must go before the code we are looking for.
Okay, listen up, this important, ignore the "<![CDATA[" "]]>" code, we're not going to be using it. Thats just there so that you can use <, >,&, " etc without it turning into HTML entities. (&, " etc...).
Now that we know that we have to be looking to add the code before what we're searching for, we can add the second batch of code which is stated after <add>.
There are some other search possitions they are
<search position="after">
This one places the second batch of code after what we're after.
<search position="replace">
This replaces the first batch of code with the second.
<search position="end" />
This adds the code to the end of the file before the closing "?>" ideal for stuff going in $languagedir files.
Once you've manually inputted all the code the mod requires, you can just upload it over your current one.
To install on custom themes, such as our Babylon theme, you need to look out for the $themedir filenames. Such as
ManagePermissions.template.php, and basically do the same thing. But if your theme does not have the file it's looking for then it'll be in the default theme, because if your theme does not have its own, then SMF automatically falls back on the default theme's, and chances are that the mod will be installed on that file anyway. (unless it failed.

)