2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
//TODO: Clean up this fucking mess
|
|
|
|
/*
|
|
|
|
Forums search result page
|
|
|
|
*/
|
2012-06-23 08:00:13 +00:00
|
|
|
include(SERVER_ROOT.'/classes/class_text.php');
|
|
|
|
$Text = new TEXT;
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
list($Page,$Limit) = page_limit(POSTS_PER_PAGE);
|
|
|
|
|
2011-10-27 08:00:15 +00:00
|
|
|
if($LoggedUser['CustomForums']) {
|
|
|
|
unset($LoggedUser['CustomForums']['']);
|
|
|
|
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
|
|
|
|
$PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1));
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
if((isset($_GET['type']) && $_GET['type'] == 'body')) {
|
|
|
|
$Type = 'body';
|
|
|
|
} else {
|
|
|
|
$Type='title';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// What are we looking for? Let's make sure it isn't dangerous.
|
|
|
|
if(isset($_GET['search'])) {
|
|
|
|
$Search = trim($_GET['search']);
|
2012-09-03 08:00:19 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
} else {
|
|
|
|
$Search = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Searching for posts by a specific user
|
|
|
|
if(!empty($_GET['user'])) {
|
|
|
|
$User = $_GET['user'];
|
|
|
|
$DB->query("SELECT ID FROM users_main WHERE Username='".db_string($User)."'");
|
|
|
|
list($AuthorID) = $DB->next_record();
|
|
|
|
} else {
|
|
|
|
$User = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we looking in individual forums?
|
|
|
|
if(isset($_GET['forums']) && is_array($_GET['forums'])) {
|
|
|
|
$ForumArray = array();
|
|
|
|
foreach($_GET['forums'] as $Forum) {
|
|
|
|
if(is_number($Forum)) {
|
|
|
|
$ForumArray[]=$Forum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count($ForumArray)>0) {
|
|
|
|
$SearchForums = implode(', ',$ForumArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 08:00:15 +00:00
|
|
|
// Searching for posts in a specific thread
|
|
|
|
if(!empty($_GET['threadid'])) {
|
|
|
|
$ThreadID = db_string($_GET['threadid']);
|
|
|
|
$Type='body';
|
|
|
|
$SQL = "SELECT Title FROM forums_topics AS t
|
|
|
|
JOIN forums AS f ON f.ID=t.ForumID
|
|
|
|
WHERE f.MinClassRead <= '$LoggedUser[Class]'
|
|
|
|
AND t.ID=$ThreadID";
|
|
|
|
if(!empty($RestrictedForums)) {
|
|
|
|
$SQL .= " AND f.ID NOT IN ('".$RestrictedForums."')";
|
|
|
|
}
|
|
|
|
$DB->query($SQL);
|
|
|
|
if (list($Title) = $DB->next_record()) {
|
2012-09-09 08:00:26 +00:00
|
|
|
$Title = " > <a href=\"forums.php?action=viewthread&threadid=$ThreadID\">$Title</a>";
|
2011-10-27 08:00:15 +00:00
|
|
|
} else {
|
|
|
|
$Title = '';
|
|
|
|
$ThreadID = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ThreadID = '';
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
// Let's hope we got some results - start printing out the content.
|
2012-07-08 08:00:09 +00:00
|
|
|
show_header('Forums'.' > '.'Search', 'bbcode');
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<div class="thin">
|
2011-10-27 08:00:15 +00:00
|
|
|
<h2><a href="forums.php">Forums</a> > Search<?=$Title?></h2>
|
2012-09-15 08:00:25 +00:00
|
|
|
<form class="search_form" name="forums" action="" method="get">
|
2011-03-28 14:21:28 +00:00
|
|
|
<input type="hidden" name="action" value="search" />
|
2012-09-01 08:00:24 +00:00
|
|
|
<table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr>
|
|
|
|
<td><strong>Search for:</strong></td>
|
|
|
|
<td>
|
|
|
|
<input type="text" name="search" size="70" value="<?=display_str($Search)?>" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
2011-10-27 08:00:15 +00:00
|
|
|
<?
|
|
|
|
if (empty($ThreadID)) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr>
|
|
|
|
<td><strong>Search in:</strong></td>
|
|
|
|
<td>
|
|
|
|
<input type="radio" name="type" id="type_title" value="title" <? if($Type == 'title') { echo 'checked="checked" '; }?>/>
|
|
|
|
<label for="type_title">Titles</label>
|
|
|
|
<input type="radio" name="type" id="type_body" value="body" <? if($Type == 'body') { echo 'checked="checked" '; }?>/>
|
|
|
|
<label for="type_body">Post bodies</label>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Forums:</strong></td>
|
|
|
|
<td>
|
2012-09-01 08:00:24 +00:00
|
|
|
<table class="cat_list layout">
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
|
2011-10-27 08:00:15 +00:00
|
|
|
<?// List of forums
|
|
|
|
$Open = false;
|
|
|
|
$LastCategoryID = -1;
|
|
|
|
$Columns = 0;
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2011-10-27 08:00:15 +00:00
|
|
|
foreach($Forums as $Forum) {
|
|
|
|
if (!check_forumperm($Forum['ID'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$Columns++;
|
|
|
|
|
|
|
|
if ($Forum['CategoryID'] != $LastCategoryID) {
|
|
|
|
$LastCategoryID = $Forum['CategoryID'];
|
|
|
|
if($Open) {
|
|
|
|
if ($Columns%5) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td colspan="<?=(5-($Columns%5))?>"></td>
|
|
|
|
<?
|
2011-10-27 08:00:15 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
</tr>
|
|
|
|
<?
|
2011-10-27 08:00:15 +00:00
|
|
|
}
|
|
|
|
$Columns = 0;
|
|
|
|
$Open = true;
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<tr>
|
|
|
|
<td colspan="5"><strong><?=$ForumCats[$Forum['CategoryID']]?></strong></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? } elseif ($Columns%5 == 0) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? } ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td>
|
|
|
|
<input type="checkbox" name="forums[]" value="<?=$Forum['ID']?>" id="forum_<?=$Forum['ID']?>"<? if(isset($_GET['forums']) && in_array($Forum['ID'], $_GET['forums'])) { echo ' checked="checked"';} ?> />
|
|
|
|
<label for="forum_<?=$Forum['ID']?>"><?=$Forum['Name']?></label>
|
|
|
|
</td>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? }
|
|
|
|
if ($Columns%5) { ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td colspan="<?=(5-($Columns%5))?>"></td>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? } ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? } else { ?>
|
|
|
|
<input type="hidden" name="threadid" value="<?=$ThreadID?>" />
|
|
|
|
<? } ?>
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr>
|
|
|
|
<td><strong>Username:</strong></td>
|
|
|
|
<td>
|
|
|
|
<input type="text" name="user" size="70" value="<?=display_str($User)?>" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colspan="2" class="center">
|
|
|
|
<input type="submit" value="Search" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
<div class="linkbox">
|
|
|
|
<?
|
|
|
|
|
|
|
|
// Break search string down into individual words
|
|
|
|
$Words = explode(' ', db_string($Search));
|
|
|
|
|
|
|
|
if($Type == 'body') {
|
2012-06-23 08:00:13 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$sql = "SELECT SQL_CALC_FOUND_ROWS
|
|
|
|
t.ID,
|
2011-10-27 08:00:15 +00:00
|
|
|
".(!empty($ThreadID) ? "SUBSTRING_INDEX(p.Body, ' ', 40)":"t.Title").",
|
2011-03-28 14:21:28 +00:00
|
|
|
t.ForumID,
|
|
|
|
f.Name,
|
|
|
|
p.AddedTime,
|
2012-06-23 08:00:13 +00:00
|
|
|
p.ID,
|
|
|
|
p.Body
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_posts AS p
|
|
|
|
JOIN forums_topics AS t ON t.ID=p.TopicID
|
|
|
|
JOIN forums AS f ON f.ID=t.ForumID
|
|
|
|
WHERE
|
2011-10-11 08:00:15 +00:00
|
|
|
((f.MinClassRead<='$LoggedUser[Class]'";
|
2011-05-15 12:06:04 +00:00
|
|
|
if(!empty($RestrictedForums)) {
|
2011-10-11 08:00:15 +00:00
|
|
|
$sql.=" AND f.ID NOT IN ('".$RestrictedForums."')";
|
2011-05-15 12:06:04 +00:00
|
|
|
}
|
2011-10-11 08:00:15 +00:00
|
|
|
$sql .= ')';
|
|
|
|
if(!empty($PermittedForums)) {
|
|
|
|
$sql.=' OR f.ID IN (\''.$PermittedForums.'\')';
|
|
|
|
}
|
|
|
|
$sql .= ') AND ';
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
//In tests, this is significantly faster than LOCATE
|
|
|
|
$sql .= "p.Body LIKE '%";
|
|
|
|
$sql .= implode("%' AND p.Body LIKE '%", $Words);
|
|
|
|
$sql .= "%' ";
|
|
|
|
|
|
|
|
//$sql .= "LOCATE('";
|
|
|
|
//$sql .= implode("', p.Body) AND LOCATE('", $Words);
|
|
|
|
//$sql .= "', p.Body) ";
|
|
|
|
|
|
|
|
if(isset($SearchForums)) {
|
|
|
|
$sql.=" AND f.ID IN ($SearchForums)";
|
|
|
|
}
|
|
|
|
if(isset($AuthorID)) {
|
|
|
|
$sql.=" AND p.AuthorID='$AuthorID' ";
|
|
|
|
}
|
2011-10-27 08:00:15 +00:00
|
|
|
if(!empty($ThreadID)) {
|
|
|
|
$sql.=" AND t.ID='$ThreadID' ";
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
$sql .= "ORDER BY p.AddedTime DESC LIMIT $Limit";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$sql = "SELECT SQL_CALC_FOUND_ROWS
|
|
|
|
t.ID,
|
|
|
|
t.Title,
|
|
|
|
t.ForumID,
|
|
|
|
f.Name,
|
|
|
|
t.LastPostTime,
|
|
|
|
'',
|
|
|
|
''
|
|
|
|
FROM forums_topics AS t
|
|
|
|
JOIN forums AS f ON f.ID=t.ForumID
|
|
|
|
WHERE
|
2011-10-11 08:00:15 +00:00
|
|
|
((f.MinClassRead<='$LoggedUser[Class]'";
|
2011-05-15 12:06:04 +00:00
|
|
|
if(!empty($RestrictedForums)) {
|
2011-10-11 08:00:15 +00:00
|
|
|
$sql.=" AND f.ID NOT IN ('".$RestrictedForums."')";
|
|
|
|
}
|
|
|
|
$sql .= ')';
|
|
|
|
if(!empty($PermittedForums)) {
|
|
|
|
$sql.=' OR f.ID IN (\''.$PermittedForums.'\')';
|
2011-05-15 12:06:04 +00:00
|
|
|
}
|
2011-10-11 08:00:15 +00:00
|
|
|
$sql .= ') AND ';
|
2011-03-28 14:21:28 +00:00
|
|
|
$sql .= "t.Title LIKE '%";
|
|
|
|
$sql .= implode("%' AND t.Title LIKE '%", $Words);
|
|
|
|
$sql .= "%' ";
|
|
|
|
if(isset($SearchForums)) {
|
|
|
|
$sql.=" AND f.ID IN ($SearchForums)";
|
|
|
|
}
|
|
|
|
if(isset($AuthorID)) {
|
|
|
|
$sql.=" AND t.AuthorID='$AuthorID' ";
|
|
|
|
}
|
|
|
|
$sql .= "ORDER BY t.LastPostTime DESC LIMIT $Limit";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform the query
|
|
|
|
$Records = $DB->query($sql);
|
|
|
|
$DB->query('SELECT FOUND_ROWS()');
|
|
|
|
list($Results) = $DB->next_record();
|
|
|
|
$DB->set_query_id($Records);
|
|
|
|
|
|
|
|
$Pages=get_pages($Page,$Results,POSTS_PER_PAGE,9);
|
|
|
|
echo $Pages;
|
|
|
|
?>
|
|
|
|
</div>
|
2012-09-01 08:00:24 +00:00
|
|
|
<table cellpadding="6" cellspacing="1" border="0" class="forum_list border" width="100%">
|
2011-03-28 14:21:28 +00:00
|
|
|
<tr class="colhead">
|
|
|
|
<td>Forum</td>
|
2011-10-27 08:00:15 +00:00
|
|
|
<td><?=(!empty($ThreadID))?'Post Begins':'Topic'?></td>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td>Time</td>
|
|
|
|
</tr>
|
|
|
|
<? if($DB->record_count() == 0) { ?>
|
|
|
|
<tr><td colspan="3">Nothing found!</td></tr>
|
|
|
|
<? }
|
|
|
|
|
|
|
|
$Row = 'a'; // For the pretty colours
|
2012-06-23 08:00:13 +00:00
|
|
|
while(list($ID, $Title, $ForumID, $ForumName, $LastTime, $PostID, $Body) = $DB->next_record()) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$Row = ($Row == 'a') ? 'b' : 'a';
|
|
|
|
// Print results
|
|
|
|
?>
|
|
|
|
<tr class="row<?=$Row?>">
|
|
|
|
<td>
|
|
|
|
<a href="forums.php?action=viewforum&forumid=<?=$ForumID?>"><?=$ForumName?></a>
|
|
|
|
</td>
|
|
|
|
<td>
|
2011-10-27 08:00:15 +00:00
|
|
|
<? if(empty($ThreadID)) { ?>
|
|
|
|
<a href="forums.php?action=viewthread&threadid=<?=$ID?>"><?=cut_string($Title, 80); ?></a>
|
|
|
|
<? } else { ?>
|
|
|
|
<?=cut_string($Title, 80); ?>
|
|
|
|
<? }
|
|
|
|
if ($Type == 'body') { ?>
|
2012-09-09 08:00:26 +00:00
|
|
|
<a href="#" onclick="$('#post_<?=$PostID?>_text').toggle(); return false;">(show)</a> <span style="float: right;" class="last_read" title="Jump to post"><a href="forums.php?action=viewthread&threadid=<?=$ID?><? if(!empty($PostID)) { echo '&postid='.$PostID.'#post'.$PostID; } ?>"></a></span>
|
2011-03-28 14:21:28 +00:00
|
|
|
<? } ?>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<?=time_diff($LastTime)?>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?
|
2012-06-23 08:00:13 +00:00
|
|
|
if($Type == 'body') { ?>
|
|
|
|
<tr class="row<?=$Row?> hidden" id="post_<?=$PostID?>_text">
|
|
|
|
<td colspan="3"><?=$Text->full_format($Body)?></td>
|
|
|
|
</tr>
|
|
|
|
<? }
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<div class="linkbox">
|
|
|
|
<?=$Pages?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<? show_footer(); ?>
|