Mod Title: Forum Search v1.0

Mod Author: Mark

Last Updated: 04/11/08

Mod Description:
This mod will add a search at the bottom of the thread list in the forum display which allows a user to search for a keyword in that forum.

Supported Version: XMB 1.9.5 Final

Installation Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License.

Author Note:
For security purposes, Please Check: http://www.xmbgarage.com for the latest version of this mod.
Downloading this mod from other sites could cause malicious code to enter into your XMB Forum software.
As such, XMBGarage.com will not offer support for mod's not offered in our mod forum.

=======================================================================================================================
=======
Step 1:
=======

===========================
Edit File: forumdisplay.php
===========================

===========================
Find Code:
===========================

loadtemplates(

=============
Replace with:
=============

loadtemplates('forumdisplay_search', 'forumdisplay_search_results', 'forumdisplay_search_noresult',

==========================================
Find Code:
==========================================

$notexist = false;
if (!isset($forum['type']) && $forum['type'] != 'forum' && $forum['type'] != 'sub' || $fid == 0) {
    $notexist = $lang['textnoforum'];
}

===============
Add Code Below:
===============

switch($action){
    case 'search':
        $forum['name'] = stripslashes($forum['name']);
        nav('<a href="./forumdisplay.php?fid='.$fid.'">'.$forum['name'].'</a>');
        nav($lang['textsearch']);
        eval('echo "'.template('header').'";');

        $keyword = isset($keyword) ? $keyword : '';
        $page = isset($page) && is_numeric($page) ? $page : 1;

        if (isset($page) && is_numeric($page)) {
            $startval = (($page * 10) - 1) - 9;
            $endval = $startval + 10;
        } else {
            $startval = 0;
            $endval = 10;
        }

        $query = $db->query("SELECT p.pid, p.message, t.subject, t.tid, p.author, p.dateline FROM $table_threads t LEFT JOIN $table_posts p ON (t.tid=p.tid) WHERE t.fid='$fid' AND (t.subject LIKE '%$keyword%' OR p.subject LIKE '%$keyword%' OR p.message LIKE '%$keyword%') LIMIT $startval, $endval");
        $result_num = $db->num_rows($query);

        $showresults = '';
        $nextpage = '&nbsp;';
        $previouspage = '&nbsp;';
        $npage = 0;
        $ppage = 0;

        if (isset($page) && $page != 1) {
            $npage = $page + 1;
            $ppage = $npage - 2;
            if ($result_num > 9) {
                $nextpage = "<a href=\"./forumdisplay.php?fid=".$fid."&amp;action=search&amp;keyword=".$keyword."&amp;page=".$npage."\">".$lang['nextsearch']."</a>";
            }
            $previouspage = "<a href=\"./forumdisplay.php?fid=".$fid."&amp;action=search&amp;keyword=".$keyword."&amp;page=".$ppage."\">".$lang['previoussearch']."</a>";
        } elseif ($page == 1) {
            if ($result_num > 9) {
                $nextpage = "<a href=\"./forumdisplay.php?fid=".$fid."&amp;action=search&amp;keyword=".$keyword."&amp;page=2\">".$lang['nextsearch']."</a>";
            }
        }

        if ($result_num == 0 || $keyword == ''){
            eval("echo (\"".template('forumdisplay_search_noresult')."\");");
        } else {
            while($result = $db->fetch_array($query)){
                $result['message'] = str_replace($keyword, "<strong>".$keyword."</strong>", $result['message']);
                $result['message'] = censor(nl2br(stripslashes($result['message'])));
                $result['subject'] = censor(stripslashes($result['subject']));
                $result['message'] = smile($result['message']);
                $date = gmdate($dateformat, $result['dateline'] + ($timeoffset * 3600) + ($addtime * 3600));
                $time = gmdate($timecode, $result['dateline'] + ($timeoffset * 3600) + ($addtime * 3600));
                $poston = "$date $lang[textat] $time";

                eval('$showresults .= "'.template('forumdisplay_search_results').'";');
            }
            eval('echo "'.template('forumdisplay_search').'";');
        }

        end_time();
        eval('echo "'.template('footer').'";');
        exit;
    break;
}

=======================================================================================================================
=======
Step 2:
=======

==================================================================
Go To Admin Panel --> Templates --> Edit Template --> forumdisplay
==================================================================

==============================
Find Code (2nd occasion only):
==============================

$multipage

=============
Add Below:
=============

<tr>
<td colspan="9" bgcolor="$THEME[altbg2]" class="ctrtablerow">
<form method="post" action="forumdisplay.php?fid=$fid&amp;action=search">
Enter a keyword to search this forum: <input type="text" name="keyword" value="" />&nbsp;<input type="submit" value="$lang[go]" />
</form>
</td>
</tr>

=======================================================================================================================
=======
Step 3:
=======

========================================================================
Go To Admin Panel --> Templates --> Edit Template --> forumdisplay_admin
========================================================================

==============================
Find Code (2nd occasion only):
==============================

$multipage

=============
Add Below:
=============

<tr>
<td colspan="10" bgcolor="$THEME[altbg2]" align="left" class="ctrtablerow">
<form method="post" action="forumdisplay.php?fid=$fid&amp;action=search">
Enter a keyword to search this forum: <input type="text" name="keyword" value="" />&nbsp;<input type="submit" value="$lang[go]" />
</form>
</td>
</tr>

=======================================================================================================================
=======
Step 4:
=======

===========================================================================
Go To Admin Panel --> Templates --> Create Template --> forumdisplay_search
===========================================================================

<table cellspacing="0" cellpadding="0" border="0" width="$THEME[tablewidth]" align="center">
<tr>
<td bgcolor="$THEME[bordercolor]">
<table border="0" cellspacing="$THEME[borderwidth]" cellpadding="$THEME[tablespace]" width="100%">

<tr>
<td class="category" colspan="2"><strong>$lang[cpsearch]</strong></td>
</tr>

$showresults

<tr class="tablerow" bgcolor="$THEME[altbg2]">
<td colspan="2">
<table cellspacing="0" border="0" cellpadding="0" width="100%">
<tr>
<td align="left" class="multi">$previouspage</td>
<td align="right" class="multi">$nextpage</td>
</tr>
</td>
</table>
</tr>
</table>
</td>
</tr>
</table>

=======================================================================================================================
=======
Step 5:
=======

===================================================================================
Go To Admin Panel --> Templates --> Create Template --> forumdisplay_search_results
===================================================================================

<tr>
<td width="75%" valign="top" bgcolor="$THEME[altbg1]" class="tablerow"><a href="viewthread.php?tid=$result[tid]#pid$result[pid]"><strong>$result[subject]</strong></a><br />$result[message]</td>
<td width="25%" align="center" bgcolor="$THEME[altbg2]" class="tablerow">$poston<br />$lang[textby]: $result[author]</td>
</tr>

=======================================================================================================================
=======
Step 6:
=======

====================================================================================
Go To Admin Panel --> Templates --> Create Template --> forumdisplay_search_noresult
====================================================================================

<table cellspacing="0" cellpadding="0" border="0" width="$THEME[tablewidth]" align="center">
<tr>
<td bgcolor="$THEME[bordercolor]">
<table border="0" cellspacing="$THEME[borderwidth]" cellpadding="$THEME[tablespace]" width="100%">

<tr>
<td class="category"><strong>$lang[cpsearch]</strong></td>
</tr>

<tr>
<td class="tablerow" bgcolor="$THEME[altbg1]">$lang[noresults]</td>
</tr>

</table>
</td>
</tr>
</table>

=======================================================================================================================
=======
Step 7:
=======

=================================
Edit File: /lang/English.lang.php
=================================

===============
Add Code Above ?> :
===============

// Forum Search Mod Begin
$lang['forumsearch'] = "Enter a keyword to search this forum:";
$lang['go'] = "Go!";
$lang['previoussearch'] = "[Previous Page]";
// Forum Search Mod End

=======================================================================================================================