Location: PHPKode > projects > SiteX > forums_topic.php
<?PHP
ob_start();
session_start();

include("includes/globals.php.inc");
include("includes/functions.php");
include("lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("lang/".$sxSetup['Language'].".php");
include("themes/$THEME_FOLDER/config.php.inc");

protectComponentPage(6);

// Search forums only
if($search_text_forum)
{
	header("Location: search.php?type=forum&search=".urlencode($search_text_forum));
	die();
}

// Query for topic
$query = "SELECT * FROM $DB_Forums_Posts WHERE id='$topicid'";
$result = mysql_query($query, $Link) or queryError("71", mysql_error());
if (!mysql_num_rows($result))
{
	header("Location: forums.php");
	die();
}

// Clear notified flags for forum
$query2 = "UPDATE $DB_Forums_Notify SET notified='0' WHERE userid='$THIS_USER' AND id_num='$topicid' AND id_type='topic'";
$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());

// Set row pointer and vars
$ROW = mysql_fetch_object($result);
$topic_name = $ROW->topic;
$topic_locked = $ROW->locked;
$forumid = $ROW->forumid;
$views = $ROW->views + 1;

// Protect if private
protectPrivateForum($forumid);

if (!$reviewMode)
{
	// Subscribe to topic
	if($subscribe == 1)
	{
		$topicid = intval($topicid);
		$query = "INSERT INTO $DB_Forums_Notify (userid, notified, id_type, id_num) VALUES ('$THIS_USER', '0', 'topic', '$topicid')";
		$result = mysql_query($query, $Link) or queryError("69", mysql_error());
	}
	
	// Unsubscribe to topic
	if($unsubscribe == 1)
	{
		$topicid = intval($topicid);
		$query = "DELETE FROM $DB_Forums_Notify WHERE userid='$THIS_USER' AND id_type='topic' AND id_num='$topicid'";
		$result = mysql_query($query, $Link) or queryError("70", mysql_error());
	}
	
	if((userModerator())OR(userAdmin()))
	{
		if($delete)
		{
			$query = "DELETE FROM $DB_Forums_Posts WHERE id='$delete' OR replyto='$delete'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
			$query = "DELETE FROM $DB_Forums_Unread WHERE postid='$delete'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
		}
		
		if($censor)
		{
			$query = "UPDATE $DB_Forums_Posts SET censored='1' WHERE id='$censor'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
		}
		
		if($uncensor)
		{
			$query = "UPDATE $DB_Forums_Posts SET censored='0' WHERE id='$uncensor'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
		}
		
		if($lock)
		{
			$query = "UPDATE $DB_Forums_Posts SET locked='1' WHERE id='$lock'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
		}
		
		if($unlock)
		{
			$query = "UPDATE $DB_Forums_Posts SET locked='0' WHERE id='$unlock'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
		}
		
		if($move)
		{
			$query = "UPDATE $DB_Forums_Posts SET forumid='$new_forumid' WHERE replyto='$topicid' OR id='$topicid'";
			$result = mysql_query($query, $Link) or queryError("71", mysql_error());
			header("Location: forums_topic.php?topicid=$topicid");
			die();
		}
	}
}

// Form keyword array if search highlighting
$sxSearchKeywords = array();
if (strlen($sxSearchHighlight) > 0)
	$sxSearchKeywords = sxExtractKeywords(stripslashes(urldecode($sxSearchHighlight)));

// Normal page view - not being viewed from topic reviewer in forum post page
if(!$reviewMode)
{
	$query = "SELECT * FROM $DB_Forums_Posts WHERE id='$topicid'";
	$result = mysql_query($query, $Link) or queryError("71", mysql_error());
	if(!mysql_num_rows($result))
	{
		header("Location: forums.php");
		die();
	}
	$ROW = mysql_fetch_object($result);
	
	if($sxSearchHighlight)
		$topic_name = sxHighlightText($ROW->topic,$sxSearchKeywords);
	else
		$topic_name = $ROW->topic;

	$sticky = $ROW->sticky;
	$topic_locked = $ROW->locked;
	$forumid = $ROW->forumid;
	$views = $ROW->views + 1;
	
	$query = "UPDATE $DB_Forums_Posts SET views='$views' WHERE id='$topicid'";
	$result = mysql_query($query, $Link) or queryError("71", mysql_error());
	
	$query = "SELECT * FROM $DB_Forums WHERE id='$forumid'";
	$result = mysql_query($query, $Link) or queryError("71", mysql_error());
	$ROW = mysql_fetch_object($result);
	$forum_name = $ROW->name;
	
	$query0 = "SELECT * FROM $DB_Forums_Posts WHERE id='$topicid' OR replyto='$topicid'";
	$result0 = mysql_query($query0, $Link) or queryError("71", mysql_error());
	$totalPosts = mysql_num_rows($result0);
	
	if(!$page)
		$page = 1;
	$start = ($page - 1)*$sxSetup['ForumPostsPerPage'];
}

$sxTitleAddendum = getComponentName("6").' - '.$forum_name.' - '.$topic_name;
include("themes/$THEME_FOLDER/header.php");

if(!$reviewMode)
{
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function confirmCensor(theID){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmCensor']; ?>")){
		window.location='<?PHP print $PHP_SELF."?topicid=$topicid&page=$page&censor="; ?>'+theID;
	}
}
function confirmUncensor(theID){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmUncensor']; ?>")){
		window.location='<?PHP print $PHP_SELF."?topicid=$topicid&page=$page&uncensor="; ?>'+theID;
	}
}
function confirmLock(theID){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmLock']; ?>")){
		window.location='<?PHP print $PHP_SELF."?topicid=$topicid&lock="; ?>'+theID;
	}
}
function confirmUnlock(theID){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmUnlock']; ?>")){
		window.location='<?PHP print $PHP_SELF."?topicid=$topicid&page=$page&unlock="; ?>'+theID;
	}
}
function confirmDelete(theID){
	if(confirm("<?PHP echo $sxLang['ForumJSConfirmDeletePost']; ?>")){
		window.location='<?PHP print $PHP_SELF."?topicid=$topicid&page=$page&delete="; ?>'+theID;
	}
}
//-->
</script> 
  <div class="bodyWrapper">
  <h1><?PHP echo getComponentName("6"); ?></h1>
  <table border="0" cellpadding="3" cellspacing="0" width="<?PHP echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td ><span class="sxSmallText"><a href="forums.php"><?PHP echo getComponentName("6"); ?></a> >
	  <a href="forums_view.php?forumid=<?PHP echo $forumid; ?>"><?PHP echo $forum_name; ?></a> >
	  <?PHP
	  if($topic_name)
	  	echo $topic_name;
	  else
	  	echo '[' . $sxLang['ForumUntitledTopic'] . ']';
		
	  if($topic_locked)
	  	echo ' (' . $sxLang['ForumLocked'] . ')';?></span></td>
	</tr>
	<tr>
	  <td><div style="float:left;" class="sxLargeText"><?PHP
	  
		if($sticky)
			echo '<img alt="' . $sxLang['ForumTopicSticky'] . '" title="' . $sxLang['ForumTopicSticky'] . '" src="images/sticky.gif" style="border: 0;" align="absmiddle" /> ';

		if($topic_name)
			echo $topic_name;
	  	else
			echo '[' . $sxLang['ForumUntitledTopic'] . ']';
			
	  	if($topic_locked)
			echo ' (' . $sxLang['ForumLocked'] . ')'; ?></div>
			<div style="float:right;"><a href="forums_post.php?replyid=<?PHP echo $topicid; ?>"><?PHP echo $sxLang['ForumLinkReplyTopic']; ?></a></div>
		</td>
	</tr>
	<tr>
	  <td><?PHP
		if($totalPosts > $sxSetup['ForumPostsPerPage']) echo '<div style="padding-top:8px;padding-bottom:8px;font-size:10px;">';
		pageTurns($PHP_SELF.'?topicid=' . $topicid . '&sxSearchHighlight=' . urlencode($sxSearchHighlight) . '&', $totalPosts, $page, $sxSetup['ForumPostsPerPage']);
		if($totalPosts > $sxSetup['ForumPostsPerPage']) echo '</div>';
	  ?></td>
	</tr>
  </table>
  <?PHP
  } // END IF REVIEW MODE
  ?>
  <table border="0" cellspacing="1" cellpadding="6" width="<?PHP if($reviewMode) echo $sxSetup['ForumWidth']-30; else echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td class="tableColumn sxForumPoster"><?PHP echo $sxLang['ForumItemAuthor']; ?></td>
	  <td class="tableColumn"><div style="float:left;"><?PHP echo $sxLang['ForumItemPost']; ?></div><div style="float:right;" ><?PHP echo '<a class="tableColumn" href="forums_topic.php?topicid=' . $topicid . '" title="' . $sxLang['ForumPostBookmark'] .'">#' . $topicid . '</a>'; ?></div></td>
	</tr>
	<?PHP
	if(!$reviewMode)
		$conditions = $sxThemeConfig['ForumOrder']." LIMIT $start, ".$sxSetup['ForumPostsPerPage'];
	else
		$conditions = "DESC";
	
	$query = "SELECT * FROM $DB_Forums_Posts WHERE id='$topicid' OR replyto='$topicid' ORDER BY timestamp $conditions";
	$result = mysql_query($query, $Link) or queryError("71", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		echo '<tr bgcolor="';
		if($odd)
		{
			echo $sxTheme['ColorTableRow'];
			$odd = false;
		}
		else
		{
			echo incrementHexNumber($sxTheme['ColorTableRow']);
			$odd = true;
		}
		echo '"><td width="120" class="sxForumPoster" valign="top" nowrap="nowrap">';
		
		if($ROW->userid != 0)
		{
			$query2 = "SELECT * FROM $DB_Users, $DB_Users_Assoc, $DB_Users_Types
					   WHERE $DB_Users.id='$ROW->userid' AND
							 $DB_Users.id=$DB_Users_Assoc.userid AND
							 $DB_Users_Assoc.typeid=$DB_Users_Types.id";
			$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());
			$ROW2 = mysql_fetch_object($result2);
			
			$this_signature = $ROW2->signature;
			
			// Username
			echo '<strong><a name="' . $ROW->id . '"></a><a href="admin/profile_view.php?user=' . $ROW2->username . '">' . $ROW2->username . '</a></strong><br />';
			
			// Avatar
			if(($sxSetup['UserAvatar'])AND($ROW2->avatar))
				echo '<img alt="' . $ROW2->avatar . '" src="' . $sxContentDir['Avatar'] . $ROW2->avatar . '" class="sxAvatar"/>';
			
			// User groups
			$query3 = "SELECT $DB_Users_Types.name FROM $DB_Users, $DB_Users_Assoc, $DB_Users_Types
					   WHERE $DB_Users.id='$ROW->userid' AND
							 $DB_Users.id=$DB_Users_Assoc.userid AND
							 $DB_Users_Assoc.typeid=$DB_Users_Types.id";
			$result3 = mysql_query($query3, $Link) or queryError("2050", mysql_error());
			echo '<br />';
			while($ROW3 = mysql_fetch_object($result3))
				echo '<span class="sxSmallText">' . $ROW3->name . '</span><hr size="1" noshade="noshade" />';
			
			// Location, posts
			echo '<span class="sxSmallText">';
			if($ROW2->location) echo $ROW2->location . '<br />';
		
			$query2 = "SELECT * FROM $DB_Forums_Posts WHERE userid='$ROW->userid'";
			$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());
			echo $sxLang['ForumItemPostsShort']. ': ' . number_format(mysql_num_rows($result2));
			echo '<hr size="1" noshade="noshade" />';
		}else echo $sxLang['Anonymous'].'<span class="sxSmallText">';
		if(!$reviewMode)
		{
			if((userModerator())OR(userAdmin()))
			{
				if($ROW->censored) echo '<a href="#" onclick="confirmUncensor(' . $ROW->id . ')">' . $sxLang['ForumUncensor'] . '</a><br />'."\n";
				else echo '<a href="#" onclick="confirmCensor(' . $ROW->id . ')">' . $sxLang['ForumCensor'] . '</a><br />'."\n";
				echo '<a href="forums_post.php?editid=' . $ROW->id . '">' . $sxLang['ForumButtonEditPost'] . '</a><br />'."\n";
				echo '<a href="#" onclick="confirmDelete(' . $ROW->id . ')">' . $sxLang['ForumButtonDeletePost'] . '</a></span>'."\n";
			}
			else
			{
				if($THIS_USER > 0)
				{
					// If user is the poster
					if($THIS_USER == $ROW->userid)
					{
						// If using timeouts on the edit
						if($sxSetup['ForumEditTimeout'])
						{
							// Check for timeout
							if($ROW->timestamp>($NOW-$sxSetup['ForumEditTimeoutSeconds']))
								echo '<br /><br /><a href="forums_post.php?editid=' . $ROW->id . '">' . $sxLang['ForumButtonEditPost'] . '</a><br />'."\n";
						}
						else
							echo '<br /><br /><a href="forums_post.php?editid=' . $ROW->id . '">' . $sxLang['ForumButtonEditPost'] . '</a><br />'."\n";
					}
				}
			}
		}
		
		echo '</td><td valign="top">'."\n";
		echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td>'."\n";
		echo '<table border="0" style="width:7px;height:8px;" bgcolor="';
			
		$query3 = "SELECT * FROM $DB_Forums_Unread, $DB_Forums_Posts
				   WHERE $DB_Forums_Posts.id=$DB_Forums_Unread.postid AND
						 $DB_Forums_Unread.userid='$THIS_USER' AND
						 $DB_Forums_Posts.id='$ROW->id'";
		$result3 = mysql_query($query3, $Link) or queryError("71", mysql_error());
		
		if(mysql_num_rows($result3))
			echo $sxTheme['ColorTextTable'];
		else
			echo $sxTheme['ColorTable'];
		
		echo '"><tr><td></td></tr></table></td><td width="5"></td><td>'."\n";
		echo '<a style="color:'. $sxTheme['ColorText'] .'; text-decoration:none;" href="forums_topic.php?topicid=' . $topicid . '#' . $ROW->id . '" title=" '. $sxLang['ForumPostBookmark'] .' "><span class="sxSmallText">' . $sxLang['ForumPostDate'] . ': '. fetchDate($ROW->timestamp, 1, 1) . ' ' . $sxLang['ForumItemTopic'] . ': ';
		
		if($ROW->topic)
			echo $ROW->topic . '</a>';
		else
			echo '[' . $sxLang['ForumUntitledTopic'] . ']</a>';
		
		echo '</span></td></tr></table>'."\n";
		echo '<hr size="1" noshade="noshade" />'."\n";
		echo '<table style="table-layout:fixed;word-wrap:break-word;" border="0" cellpadding="0" cellspacing="0"><tr><td>'."\n";

		// Output post content
		if($ROW->censored)
			echo '[' . $sxLang['ForumPostCensored'] . ']';
		else
		{
			/*$sxPostOutput = nl2br(strip_tags($ROW->content, str_replace("<a>","",$sxThemeConfig['ForumAllowedTags'])));
			$sxPostOutput = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" rel=\"nofollow\">\\0</a>", $sxPostOutput);
			$sxPostOutput = sxHighlightText($sxPostOutput, $sxSearchKeywords);
			echo $sxPostOutput;*/
			echo sxHighlightText(nl2br(strip_tags(preg_replace('/<a([^>]+)>/i', '<a\\1 rel="nofollow">', $ROW->content), $sxThemeConfig['ForumAllowedTags'])),$sxSearchKeywords);
		}
		
		// Apply edit message if necessary
		if (($ROW->lastedit != $ROW->timestamp) AND ($ROW->lastedit != 0))
			echo '<br /><br /><span class="sxSmallText">[' . $sxLang['ForumEditedOn'] . ' ' . fetchDate($ROW->lastedit, 1, 1) . ']</span>';
		
		// Apply signature
		if(($sxSetup['UserSignature'])AND($this_signature))
		{
			echo '<p><hr size="1" width="200" align="left" />';
			echo nl2br(strip_tags(preg_replace('/<a([^>]+)>/i', '<a\\1 rel="nofollow">', $this_signature), $sxThemeConfig['ForumAllowedTags']));
			echo '</p>'."\n";
		}
		echo '</td></tr></table>'."\n";
		echo '</td></tr>';
	}
	
	if(!$reviewMode)
	{
	  if((userModerator())OR(userAdmin()))
	  {
		  echo '<tr><td colspan="2"><form name="sxFormForumAdminOptions" action="' . $PHP_SELF . '" method="post">'."\n";
		  echo '<hr size="1" noshade="noshade" /><strong>' . $sxLang['ForumAdminOptions'] . ':</strong><br />'."\n";
		  
		  if($topic_locked)
		  	echo '<a href="#" onclick="confirmUnlock(' . $topicid . ')"><span class="sxSmallText">' . $sxLang['ForumUnlockTopic'] . '</span></a>'."\n";
		  else
		  	echo '<a href="#" onclick="confirmLock(' . $topicid . ')"><span class="sxSmallText">' . $sxLang['ForumLockTopic'] . '</span></a>'."\n";
		  
		  echo '<br />';
		  echo '<span class="sxSmallText">' . $sxLang['ForumMoveTopic'] . ': </span>'."\n";
		  
		  echo '<select name="new_forumid">'."\n";
		  
		  $query = "SELECT * FROM $DB_Forums ORDER BY name";
		  $result = mysql_query($query, $Link) or queryError("71", mysql_error());
		  while($ROW = mysql_fetch_object($result))
			echo '<option value="' . $ROW->id . '">' . $ROW->name . '</option>'."\n";
		  
		  echo '</select> '."\n";
		  echo '<input type="hidden" name="topicid" value="' . $topicid . '" />'."\n";
		  echo '<input type="submit" name="move" value="' . $sxLang['ButtonMove'] . '" class="sxButton" /><hr size="1" noshade="noshade" /></form>'."\n";
		  echo '</td></tr>'."\n";
	  }
  }
  ?>
  </table><?PHP if(!$reviewMode){ ?>
  <table border="0" cellpadding="3" cellspacing="0" width="<?PHP echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td><a href="forums_post.php?replyid=<?PHP echo $topicid; ?>"><?PHP echo $sxLang['ForumLinkReplyTopic']; ?></a></td>
	  <td align="right"><?PHP
	if($totalPosts > $sxSetup['ForumPostsPerPage']) echo '<div style="padding-top:8px;padding-bottom:8px;font-size:10px;">';
	pageTurns($PHP_SELF.'?topicid=' . $topicid . '&sxSearchHighlight=' . urlencode($sxSearchHighlight) . '&', $totalPosts, $page, $sxSetup['ForumPostsPerPage']);
	if($totalPosts > $sxSetup['ForumPostsPerPage']) echo '</div>';
  ?></td>
	</tr>
	<?PHP if(loggedIn()){ ?><tr>
	  <td colspan="2"><div style="text-align:right;font-size:10px;">
		  <?PHP 
		  if(sxForumSubscription('topic', $topicid))
			echo '<a href="' . $_SERVER['PHP_SELF'] . '?topicid=' . $topicid . '&unsubscribe=1">' . $sxLang['ForumTopicUnsubscribe'] . '</a>'; 
		  else
			echo '<a href="' . $_SERVER['PHP_SELF'] . '?topicid=' . $topicid . '&subscribe=1">' . $sxLang['ForumTopicSubscribe'] . '</a>'; 		  echo '<br />';
		  if(sxForumSubscription('forum', $forumid))
			echo '<a href="forums_view.php?forumid=' . $forumid . '&unsubscribe=1">' . $sxLang['ForumUnsubscribe'] . '</a>'; 
		  else
			echo '<a href="forums_view.php?forumid=' . $forumid . '&subscribe=1">' . $sxLang['ForumSubscribe'] . '</a>'; 
		  ?>
		  </div>
      </td>
	</tr><?PHP } ?>
	<tr>
	  <td colspan="4" align="right">
		  <form action="<?PHP echo $PHP_SELF; ?>" name="sxFormSearchForum" method="post">
		  <?PHP echo $sxLang['MessageForumSearch']; ?>: 
		  <input type="text" name="search_text_forum" style="width:150px;" /> 
		  <input type="submit" name="StartSearch" value="<?PHP echo $sxLang['ButtonFind']; ?>" style="width:50px;" class="sxButton" />
		  </form></td>
	</tr>
  </table>
  <?PHP } // End if(!$reviewMode) ?>
  </div>
<?PHP
include("themes/$THEME_FOLDER/footer.php");

if(!$reviewMode)
{
	$query = "SELECT * FROM $DB_Forums_Posts
			  WHERE id='$topicid' OR replyto='$topicid'
			  ORDER BY timestamp ASC
			  LIMIT $start, ".$sxSetup['ForumPostsPerPage'];
	$result = mysql_query($query, $Link) or queryError("71", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		$query2 = "SELECT * FROM $DB_Forums_Unread WHERE postid='$ROW->id' AND userid='$THIS_USER'";
		$result2 = mysql_query($query2, $Link) or queryError("71", mysql_error());
		if(mysql_num_rows($result2))
		{
			$query3 = "DELETE FROM $DB_Forums_Unread WHERE userid='$THIS_USER' AND postid='$ROW->id'";
			$result3 = mysql_query($query3, $Link) or queryError("71", mysql_error());
		}
	}
}

ob_end_flush();
?>
Return current item: SiteX