Jump to content

Recommended Posts

I know this isn't the neatest code in the world, but I'm really trying my best to make the neatest code possible. If you have spare time, can you give me feedback & suggestions regarding making this code at least average when it comes to being neat? Thanks.

 

viewthread.php (for my forum)

<?php 
require('../includes/config.php');
require('../structure/base.php');
require('../structure/forum.php');
require('../structure/forum.thread.php');
require('../structure/forum.post.php');
require('../structure/database.php');
require('../structure/user.php');

$database = new database($db_host, $db_name, $db_user, $db_password);
$base = new base($database);
$user = new user($database);
$forum = new forum($database);
$thread = new thread($database);
$post = new post($database);

//set some variables that are used a lot throughout the page
$username = $user->getUsername($_COOKIE['user'], 2);
$rank = $user->getRank($username);
$f = $_GET['forum'];
$i = $_GET['id'];

//preform basic checks
if(!$thread->checkExistence($i)) $base->redirect('index.php');
if(!$thread->canView($i, $username, $rank)) $base->redirect('index.php');

//if the GOTO field is set, let's skip to the selected post
if(ctype_digit($_GET['goto']))
{
    $getPageNum = $thread->getPageNum($_GET['goto'], $i);
    
    if($getPageNum) $base->redirect('viewthread.php?forum='. $f.'&id='.$i.'&page='.$getPageNum.'&highlight='. $_GET['goto'] .'#'.$_GET['goto']);
}

//if a moderator chooses to hide, lets make it happen
if((isset($_GET['hide']) && !isset($_GET['pid'])) && $rank > 2) $thread->hideThread($i, $rank);
if((isset($_GET['hide']) && isset($_GET['pid'])) && $rank > 2) $post->hidePost($_GET['pid'], $rank);

//for administrators to delete posts
if(isset($_GET['delete'])) $post->deletePost($_GET['delete'], $rank);

//extract thread details
$detail_query = $database->processQuery("SELECT `id`,`lock`,`sticky`,`title`,`username`,`status`,`content`,`date`,`lastedit`,`qfc` FROM `threads` WHERE `id` = ? LIMIT 1", array($i), true);

//assign data to details[] array
$details[] = $detail_query[0]['lock'];
$details[] = $detail_query[0]['sticky'];
$details[] = htmlentities($detail_query[0]['title'], ENT_NOQUOTES);
$details[] = $detail_query[0]['username'];
$details[] = $detail_query[0]['status'];
$details[] = $detail_query[0]['content'];
$details[] = $detail_query[0]['date'];
$details[] = $detail_query[0]['lastedit'];
$details[] = $detail_query[0]['qfc'];

//get any extra icons
if($details[1] == 1) $extra .= '<img src="../img/forum/sticky.gif"> ';
if($details[0] == 1) $extra .= ' <img src="../img/forum/locked.gif">';

//check if the POST has been edited, then adjust the $date variable accordingly
if(empty($details[7]))
{
        $date = $details[6];
}
else
{
        //get USERNAME:DATE/TIME
        $edit_details = explode('@', $details[7]);
        $date = $details[6].'<br/>Last edit on '. $edit_details[1] .' by '. $edit_details[0];
}


//get forum details
$forum_details = $database->processQuery("SELECT `title` FROM `forums` WHERE `id` = ?", array($f), true);

//pagination
$per_page = 10;

//get # of pages
$database->processQuery("SELECT * FROM `posts` WHERE `thread` = ?", array($i), false);
$pages = ($database->getRowCount() == 0) ? 1 : ceil($database->getRowCount() / $per_page);

//get current page
(!ctype_digit($_GET['page']) || $_GET['page'] > $pages) ? $page = 1 : $page = $_GET['page'];

//get next link
($page < $pages) ? $next = $page+1 : $next = $page;

//get prev link
(($page-1) >= 1) ? $prev = ($page-1) : $prev = $page;

//start
$start = ($page == 1) ? 1 : ($page-1)*$per_page;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:IE>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<title><?php echo $data['wb_title']; ?></title>
<link href="../css/basic-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forum-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forummsg-1.css" rel="stylesheet" type="text/css" media="all" />
<style>

</style>
<script language="JavaScript">
document.getElementById("smilytxt").style.display="";
function addsmiley(code) {
	var msgtext=document.getElementById("charlimit_text_a");
	msgtext.focus();
	if (document.selection && document.selection.createRange && !msgtext.setSelection) { 
		document.selection.createRange().text=code; 
	} else {
		var pretext = msgtext.value.substring(0,msgtext.selectionStart);
		var pos = msgtext.selectionStart;
		var posttext = msgtext.value.substring(msgtext.selectionEnd, msgtext.value.length);
		msgtext.value = pretext + code + posttext;
		msgtext.selectionEnd=pos+code.length;
	}
}
</script>
<script type="text/javascript">
var alerted=false;
function do_watch(msg, element, count, max, submit) {
try {
  var stri=element.value.replace(/\r/g, "");
  if(submit) if(stri.length>max) submit.disabled=true;
  if(stri.length>max) {
   if(msg==true && alerted==false) {
    alert('You have gone over your character limit for this message');
    alerted=true;
   }
   element.value=stri=stri.substring(0,max);
  }
  count.childNodes[0].nodeValue=max-stri.length;
}
catch(e) {}
}
function install_watch(msg, element, count, max, form, submit, reset) {
try {
  element.onkeyup=function() {
   do_watch(msg, element, count, max, submit);
  };
  element.onkeydown=function() {
   do_watch(msg, element, count, max, submit);
  };
  element.onkeypress=function() {
   do_watch(msg, element, count, max, submit);
  };
  element.onmousemove=function() {
   do_watch(msg, element, count, max, submit);
  };
  element.onchange=function() {
   do_watch(false, element, count, max, submit);
  };
  if(form) {
   form.onsubmit=function() {
    do_watch(msg, element, count, max, submit);
   }; 
  }
  if(reset && form) {
   reset.onclick=function() {
    form.reset();
    do_watch(msg, element, count, max, submit);
   }
  }
  do_watch(false, element, count, max, submit);
}
catch(e) {}
}
var charlimiter_run=false;
function install_charlimiters() {
if(charlimiter_run) return;
charlimiter_run=true;
try {
  var textboxes=document.getElementsByTagName("textarea");
  for(var i=0; i<textboxes.length; i++) install(textboxes[i]);
  var inputs=document.getElementsByTagName("input");
  for(var i=0; i<inputs.length; i++) install(inputs[i]);
}
catch(e) {}
}
function install(element) {
var textbox_id_len = new String("charlimit_text").length;
var text_id=element.id.toString();
if(text_id.match(/^charlimit_text/i) && text_id.length>=textbox_id_len) {
  var identifier=text_id.substr(textbox_id_len);
  var info=document.getElementById("charlimit_info" + identifier);
  var count=document.getElementById("charlimit_count" + identifier);
  var form=document.getElementById("charlimit_form" + identifier);
  var submit=document.getElementById("charlimit_submit" + identifier);
  var reset=document.getElementById("charlimit_reset" + identifier);
  if(info && count) {
   var msg=false;
   if(identifier.match(/^_msg/i)) msg=true;
   var max_val=parseInt(count.childNodes[0].nodeValue);
   install_watch(msg, element, count, max_val, form, submit, reset);
   info.style.display='inline';
  }
}
}
if(window.addEventListener) window.addEventListener('load', install_charlimiters, true);
else if(window.attachEvent) window.attachEvent('onload', install_charlimiters);
else window.onload=install_charlimiters;

</script>
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="../css/forummsg-ie-1.css" />
<![endif]-->
</head>
<body>
	<div id="body">
	<div class="frame e">
		<span style="float: right;">
		<?php
			if($user->isLoggedIn())
			{
                                        if($rank > 3)
                                        {
                                            echo '<a href="../index.php">Main Page</a> | <a href="acp.php">Forum ACP</a> | <a href="../logout.php">Logout</a>';
                                        }
                                        else
                                        {
                                            echo '<a href="../index.php">Main Page</a> | <a href="../logout.php">Logout</a>';
                                        }
			}
			else
			{
				echo '<a href="../index.php">Main Page</a> | <a href="../login.php">Login</a>';
			}
		?>
		</span>
		<div>
		<?php 
			if($user->isLoggedIn()) 
			{ 
				echo 'You are logged in as <span style="color: rgb(255, 187, 34);">'. $username .'</span>'; 
			} 
			else 
			{ 
				echo 'You are not logged in.'; 
			} 
		?>
		</div>
	</div><br /><br />

	<div id="picker">
		<form method="post" action="jump.php">
			<ul class="flat">
				<!--<li><a href=""><img src="../img/forums/search_threads.gif"> Search threads</a></li>-->
				<li>Jump to Thread: <input size="8" name="qfc" maxlength="14" /></li>
				<li><input class="b" name="jump" value="Go" type="submit" /></li>

		</ul>
		</form>
	</div>
	<div id="infopane">
		<span class="title"><?php echo $extra.' '.$details[2]; ?></span>
		<div class="about">
			<ul class="flat">
				<!--<li><a href="#"><img src="../img/forum/code_of_conduct.gif" /> Code of Conduct</a></li>-->
			</ul>
		</div>
	</div>

	<!--<div id="nocontrols" class="phold"></div>-->

	<br>

	<div id="breadcrumb">
		<a href="../index.php">Home</a> > <a href="index.php"><?php echo $data['wb_name']; ?></a> > <a href="viewforum.php?forum=<?php echo $f; ?>"><?php echo $forum_details[0]['title']; ?></a> > <a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><?php echo $details[2]; ?></a>
	</div>
			<div class="actions" id="top">
		<table>
			<tbody>
				<tr>
					<td class="nav">
						<form action="viewthread.php" method="get" style="display: inline;">
							<input type="hidden" name="id" value="<?php echo $i; ?>" />
							<input type="hidden" name="forum" value="<?php echo $f; ?>" />
							<ul class="flat">
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><< first</a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $prev; ?>">< prev</a></li>
								<li>Page <input type="text" class="textinput" id="page" name="page" value="<?php echo $page; ?>" size="2" maxlength="3" /> of <?php echo $pages; ?></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $next; ?>">next ></a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $pages; ?>">last >></a></li>
							</ul>
						</form>
					</td>
					<td class="commands">
						<ul class="flat">
							<?php if($thread->canReply($i, $rank) && !$user->checkMute($username)) echo '<li><a href="reply.php?forum='. $f .'&id='. $i .'"><img src="../img/forum/new_thread.gif" alt="T" /> Reply</a></li>'; ?>
                                                                <li><a href=""><img src="../img/forum/refresh.gif" alt=""> Refresh</a></li>
                                                        </ul>
					</td>
				</tr>

			</tbody>
		</table>
	</div>
	<!--<form action="javascript://" method="post">-->
	<div id="contentmsg">
				<a name="188090"></a>
                                        <?php
                                        //set the action bar
                                        $action_bar = (($rank < 3 && $details[4] == 0 && $details[0] == 0) || $rank > 2) ? $thread->getActionBar($rank, $i, $f) : null;
                                        
                                        //only display thread on page 1
                                        if($page == 1)
                                        {
                                            if($details[4] == 1 && $rank < 3)
                                            {
                                                ?>
                                        
                                                <table class="<?php echo $thread->getPostType($details[4], $details[3], ($_GET['goto'] == 'start') ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"> </div>
                                                                                        <div class="modtype"> </div>
                                                                                        <div class="msgcommands"> </div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><br/></div>
                                                                                        <div class="msgcontents">
                                                                                                <i>The contents of this message is hidden</i>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php if($rank > 2) echo $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                            else
                                            {
                                                ?>
                                               
                                                <table class="<?php echo $thread->getPostType($details[4], $details[3], ($_GET['goto'] == 'start') ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"><?php echo $user->dName($details[3]); ?></div>
                                                                                        <div class="modtype"><?php echo $forum->getPostTitle($details[3]); ?>
                                                                                        <div class="msgcommands"></div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><?php echo $date; ?></div>
                                                                                        <div class="msgcontents">
                                                                                                <?php echo $base->br2nl($thread->formatPost($details[5], $details[3])); ?>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php echo ($details[3] == $username && $rank < 3 && $details[4] == 0 && $details[0] == 0) ? '<a href="edit.php?forum='. $f .'&id='. $i .'&type=2">Edit</a> | '.$action_bar : $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                        }
                                        
                                        //display posts
                                        $replies = $database->processQuery("SELECT `id`,`username`,`content`,`lastedit`,`date`,`status` FROM `posts` WHERE `thread` = ? ORDER BY `id` ASC LIMIT $start,$per_page", array($i), true);
                                        
                                        foreach($replies as $reply)
                                        {
                                            //set the user's action bar
                                            $action_bar = (($rank < 3 && $details[4] == 0 && $details[0] == 0) || $rank > 2) ? $post->getActionBar($rank, $reply['id'], $i, $f) : null;
                                            
                                            
                                            
                                            //check if the POST has been edited, then adjust the $date variable accordingly
                                            if(empty($reply['lastedit']))
                                            {
                                                    $date = $reply['date'];
                                            }
                                            else
                                            {
                                                    //get USERNAME:DATE/TIME
                                                    $edit_details = explode('@', $details[7]);
                                                    $date = $reply['date'].'<br/>Last edit on '. $edit_details[1] .' by '. $edit_details[0];
                                            }
                                            
                                            if($reply['status'] == 1 && $rank < 3)
                                            {
                                                ?>
                                                <a name="<?php echo $reply['id']; ?>"></a>
                                                <table class="<?php echo $thread->getPostType($reply['status'], $reply['username'], ($_GET['highlight'] == $reply['id']) ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"> </div>
                                                                                        <div class="modtype"> </div>
                                                                                        <div class="msgcommands"> </div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><br/></div>
                                                                                        <div class="msgcontents">
                                                                                                <i>The contents of this message is hidden</i>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php if($rank > 2) echo $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                            else
                                            {
                                               ?>
                                                <a name="<?php echo $reply['id']; ?>"></a>
                                                <table class="<?php echo $thread->getPostType($reply['status'], $reply['username'], ($_GET['highlight'] == $reply['id']) ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"><?php echo $user->dName($reply['username']).' ['. $reply['id'] .']'; ?></div>
                                                                                        <div class="modtype"><?php echo $forum->getPostTitle($reply['username']); ?></div>
                                                                                        <div class="msgcommands"></div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><?php echo $date; ?></div>
                                                                                        <div class="msgcontents">
                                                                                                <?php echo $base->br2nl($thread->formatPost($reply['content'], $reply['username'])); ?>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php echo ($reply['username'] == $username && $rank < 3 && $details[4] == 0 && $details[0] == 0) ? '<a href="edit.php?forum='. $f .'&id='. $i .'&type=1&pid='. $reply['id'] .'">Edit</a> | '.$action_bar : $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                                <?php
                                            }
                                        }
                                        ?>
                                        </div>
	<!--
			-->
	<div id="breadcrumb">
		<a href="../index.php">Home</a> > <a href="index.php"><?php echo $data['wb_name']; ?></a> > <a href="viewforum.php?forum=<?php echo $f; ?>"><?php echo $forum_details[0]['title']; ?></a> > <a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><?php echo $details[2]; ?></a>
	</div>

		<div class="actions" id="top">
			<table>
				<tbody>
					<tr>
						<td class="nav">
						<form action="viewthread.php" method="get" style="display: inline;">
							<input type="hidden" name="id" value="<?php echo $i; ?>" />
							<input type="hidden" name="forum" value="<?php echo $f; ?>" />
							<ul class="flat">
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><< first</a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $prev; ?>">< prev</a></li>
								<li>Page <input type="text" class="textinput" id="page" name="page" value="<?php echo $page; ?>" size="2" maxlength="3" /> of <?php echo $pages; ?></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $next; ?>">next ></a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $pages; ?>">last >></a></li>
							</ul>
						</form>
                                                        </td>
                                                        
						<td class="commands">
							<ul class="flat">
							<?php if($thread->canReply($i, $rank) && !$user->checkMute($username)) echo '<li><a href="reply.php?forum='. $f .'&id='. $i .'"><img src="../img/forum/new_thread.gif" alt="T" /> Reply</a></li>'; ?>
                                                                <li><a href=""><img src="../img/forum/refresh.gif" alt=""> Refresh</a></li>
                                                                </ul>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

		<div id="uid">Quick find code: <?php echo $details[8]; ?></div>

		<br>

		<div class="tandc"><?php echo $data['wb_foot']; ?></div>
</div>	
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/
Share on other sites

for example... this is "viewthread.php" which implies it should be used to "view a thread", right?

 

Why is this in there?

 

//for administrators to delete posts
if(isset($_GET['delete'])) $post->deletePost($_GET['delete'], $rank);

 

put that in "deletepost.php"

 

I suppose that's my only mixed-up functionality complaint.

 

Besides that, find a way to reuse your HTML.

 

And put your JS in an external .js file

 

That should be a good start....

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/#findComment-1355319
Share on other sites

Thanks for the reply.  :D

 

I put the large bit of JavaScript in an external file. Also, about the "deletepost.php" thing. I was thinking of doing something like that, but isn't one line with the required data already there better than creating a whole new file?

 

//for administrators to delete posts
if(isset($_GET['delete'])) $post->deletePost($_GET['delete'], $rank);

 

vs.

 

deletepost.php

<?php
require('../../includes/config.php');
require('../../structure/database.php');
require('../../structure/forum.post.php');
require('../../structure/base.php');
require('../../structure/user.php');

$database = new database($db_host, $db_name, $db_user, $db_password);
$post = new post($database);
$base = new base($database);
$user = new user($database);

$rank = $user->getRank($user->getUsername($_COOKIE['user'], 2));

if($rank > 2)
{
    $post->deletePost($_GET['id'], $rank);
}

$base->redirect('viewthread.php?forum='. $_GET['forum'] .'&id='. $_GET['id']);
?>

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/#findComment-1355329
Share on other sites

Thanks for the reply.  :D

Welcome, dude. :D

 

About the "deletepost.php" thing. I was thinking of doing something like that, but isn't one line with the required data already there better than creating a whole new file?

Nope.  Better to keep the separate functionality separate.

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/#findComment-1355330
Share on other sites

Thanks for the reply.  :D

Welcome, dude. :D

 

About the "deletepost.php" thing. I was thinking of doing something like that, but isn't one line with the required data already there better than creating a whole new file?

Nope.  Better to keep the separate functionality separate.

 

Alrighty, here's the updated version:

 

<?php 
require('../includes/config.php');
require('../structure/base.php');
require('../structure/forum.php');
require('../structure/forum.thread.php');
require('../structure/forum.post.php');
require('../structure/database.php');
require('../structure/user.php');

$database = new database($db_host, $db_name, $db_user, $db_password);
$base = new base($database);
$user = new user($database);
$forum = new forum($database);
$thread = new thread($database);
$post = new post($database);

//set some variables that are used a lot throughout the page
$username = $user->getUsername($_COOKIE['user'], 2);
$rank = $user->getRank($username);
$f = $_GET['forum'];
$i = $_GET['id'];

//preform basic checks
if(!$thread->checkExistence($i) || !$thread->canView($i, $username, $rank)) $base->redirect('index.php');

//if a moderator chooses to hide the thread, lets make it happen
if((isset($_GET['hide']) && !isset($_GET['pid'])) && $rank > 2) $thread->hideThread($i, $rank);

//if the GOTO field is set, let's skip to the selected post
if(ctype_digit($_GET['goto']))
{
    $getPageNum = $thread->getPageNum($_GET['goto'], $i);
    
    if($getPageNum) $base->redirect('viewthread.php?forum='. $f.'&id='.$i.'&page='.$getPageNum.'&highlight='. $_GET['goto'] .'#'.$_GET['goto']);
}

//extract thread details
$detail_query = $database->processQuery("SELECT `id`,`lock`,`sticky`,`title`,`username`,`status`,`content`,`date`,`lastedit`,`qfc` FROM `threads` WHERE `id` = ? LIMIT 1", array($i), true);

//assign data to details[] array
$details[] = $detail_query[0]['lock'];
$details[] = $detail_query[0]['sticky'];
$details[] = htmlentities($detail_query[0]['title'], ENT_NOQUOTES);
$details[] = $detail_query[0]['username'];
$details[] = $detail_query[0]['status'];
$details[] = $detail_query[0]['content'];
$details[] = $detail_query[0]['date'];
$details[] = $detail_query[0]['lastedit'];
$details[] = $detail_query[0]['qfc'];

//get any extra icons
if($details[1] == 1) $extra .= '<img src="../img/forum/sticky.gif"> ';
if($details[0] == 1) $extra .= ' <img src="../img/forum/locked.gif">';

//check if the POST has been edited, then adjust the $date variable accordingly
if(empty($details[7]))
{
        $date = $details[6];
}
else
{
        //get USERNAME:DATE/TIME
        $edit_details = explode('@', $details[7]);
        $date = $details[6].'<br/>Last edit on '. $edit_details[1] .' by '. $edit_details[0];
}


//get forum details
$forum_details = $database->processQuery("SELECT `title` FROM `forums` WHERE `id` = ?", array($f), true);

//pagination
$per_page = 10;

//get # of pages
$database->processQuery("SELECT * FROM `posts` WHERE `thread` = ?", array($i), false);
$pages = ($database->getRowCount() == 0) ? 1 : ceil($database->getRowCount() / $per_page);

//get current page
(!ctype_digit($_GET['page']) || $_GET['page'] > $pages) ? $page = 1 : $page = $_GET['page'];

//get next link
($page < $pages) ? $next = $page+1 : $next = $page;

//get prev link
(($page-1) >= 1) ? $prev = ($page-1) : $prev = $page;

//start
$start = ($page-1)*$per_page;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:IE>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<title><?php echo $data['wb_title']; ?></title>
<link href="../css/basic-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forum-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forummsg-1.css" rel="stylesheet" type="text/css" media="all" />
<script src="../js/v_thread_2.js"></script>
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="../css/forummsg-ie-1.css" />
<![endif]-->
</head>
<body>
	<div id="body">
	<?php $forum->getNavBar($username, $rank); ?>
                <br /><br />

	<div id="picker">
		<form method="post" action="jump.php">
			<ul class="flat">
				<!--<li><a href=""><img src="../img/forums/search_threads.gif"> Search threads</a></li>-->
				<li>Jump to Thread: <input size="8" name="qfc" maxlength="14" /></li>
				<li><input class="b" name="jump" value="Go" type="submit" /></li>

		</ul>
		</form>
	</div>
	<div id="infopane">
		<span class="title"><?php echo $extra.' '.$details[2]; ?></span>
		<div class="about">
			<ul class="flat">
				<!--<li><a href="#"><img src="../img/forum/code_of_conduct.gif" /> Code of Conduct</a></li>-->
			</ul>
		</div>
	</div>

	<!--<div id="nocontrols" class="phold"></div>-->

	<br>

	<div id="breadcrumb">
		<a href="../index.php">Home</a> > <a href="index.php"><?php echo $data['wb_name']; ?></a> > <a href="viewforum.php?forum=<?php echo $f; ?>"><?php echo $forum_details[0]['title']; ?></a> > <a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><?php echo $details[2]; ?></a>
	</div>
			<div class="actions" id="top">
		<table>
			<tbody>
				<tr>
					<td class="nav">
						<form action="viewthread.php" method="get" style="display: inline;">
							<input type="hidden" name="id" value="<?php echo $i; ?>" />
							<input type="hidden" name="forum" value="<?php echo $f; ?>" />
							<ul class="flat">
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><< first</a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $prev; ?>">< prev</a></li>
								<li>Page <input type="text" class="textinput" id="page" name="page" value="<?php echo $page; ?>" size="2" maxlength="3" /> of <?php echo $pages; ?></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $next; ?>">next ></a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $pages; ?>">last >></a></li>
							</ul>
						</form>
					</td>
					<td class="commands">
						<ul class="flat">
							<?php if($thread->canReply($i, $rank) && !$user->checkMute($username)) echo '<li><a href="reply.php?forum='. $f .'&id='. $i .'"><img src="../img/forum/new_thread.gif" alt="T" /> Reply</a></li>'; ?>
                                                                <li><a href=""><img src="../img/forum/refresh.gif" alt=""> Refresh</a></li>
                                                        </ul>
					</td>
				</tr>

			</tbody>
		</table>
	</div>
	<!--<form action="javascript://" method="post">-->
	<div id="contentmsg">
				<a name="188090"></a>
                                        <?php
                                        //set the action bar
                                        $action_bar = (($rank < 3 && $details[4] == 0 && $details[0] == 0) || $rank > 2) ? $thread->getActionBar($rank, $i, $f) : null;
                                        
                                        //only display thread on page 1
                                        if($page == 1)
                                        {
                                            if($details[4] == 1 && $rank < 3)
                                            {
                                                ?>
                                        
                                                <table class="<?php echo $thread->getPostType($details[4], $details[3]); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"> </div>
                                                                                        <div class="modtype"> </div>
                                                                                        <div class="msgcommands"> </div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><br/></div>
                                                                                        <div class="msgcontents">
                                                                                                <i>The contents of this message is hidden</i>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php if($rank > 2) echo $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                            else
                                            {
                                                ?>
                                               
                                                <table class="<?php echo $thread->getPostType($details[4], $details[3], ($_GET['goto'] == 'start') ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"><?php echo $user->dName($details[3]); ?></div>
                                                                                        <div class="modtype"><?php echo $forum->getPostTitle($details[3]); ?>
                                                                                        <div class="msgcommands"></div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><?php echo $date; ?></div>
                                                                                        <div class="msgcontents">
                                                                                                <?php echo $base->br2nl($thread->formatPost($details[5], $details[3])); ?>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php echo ($details[3] == $username && $rank < 3 && $details[4] == 0 && $details[0] == 0) ? '<a href="edit.php?forum='. $f .'&id='. $i .'&type=2">Edit</a> | '.$action_bar : $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                        }
                                        
                                        //display posts
                                        $replies = $database->processQuery("SELECT `id`,`username`,`content`,`lastedit`,`date`,`status` FROM `posts` WHERE `thread` = ? ORDER BY `id` ASC LIMIT $start,$per_page", array($i), true);
                                        
                                        foreach($replies as $reply)
                                        {
                                            //set the user's action bar
                                            $action_bar = (($rank < 3 && $details[4] == 0 && $details[0] == 0) || $rank > 2) ? $post->getActionBar($rank, $reply['id'], $i, $f) : null;
                                            
                                            
                                            
                                            //check if the POST has been edited, then adjust the $date variable accordingly
                                            if(empty($reply['lastedit']))
                                            {
                                                    $date = $reply['date'];
                                            }
                                            else
                                            {
                                                    //get USERNAME:DATE/TIME
                                                    $edit_details = explode('@', $details[7]);
                                                    $date = $reply['date'].'<br/>Last edit on '. $edit_details[1] .' by '. $edit_details[0];
                                            }
                                            
                                            if($reply['status'] == 1 && $rank < 3)
                                            {
                                                ?>
                                                <a name="<?php echo $reply['id']; ?>"></a>
                                                <table class="<?php echo $thread->getPostType($reply['status'], $reply['username']); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"> </div>
                                                                                        <div class="modtype"> </div>
                                                                                        <div class="msgcommands"> </div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><br/></div>
                                                                                        <div class="msgcontents">
                                                                                                <i>The contents of this message is hidden</i>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php if($rank > 2) echo $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                        
                                                <?php
                                            }
                                            else
                                            {
                                               ?>
                                                <a name="<?php echo $reply['id']; ?>"></a>
                                                <table class="<?php echo $thread->getPostType($reply['status'], $reply['username'], ($_GET['highlight'] == $reply['id']) ? true : false); ?>">
                                                <tbody>
                                                                        <tr>
                                                                                <td class="leftpanel">
                                                                                        <div class="msgcreator uname"><?php echo $user->dName($reply['username']).' ['. $reply['id'] .']'; ?></div>
                                                                                        <div class="modtype"><?php echo $forum->getPostTitle($reply['username']); ?></div>
                                                                                        <div class="msgcommands"></div>
                                                                                </td>
                                                                                <td class="rightpanel">
                                                                                        <div class="msgtime"><?php echo $date; ?></div>
                                                                                        <div class="msgcontents">
                                                                                                <?php echo $base->br2nl($thread->formatPost($reply['content'], $reply['username'])); ?>
                                                                                                </div>
                                                                                        <span style="float:right; margin-right: 5px; margin-bottom: 5px; margin-top: -20px;"><?php echo ($reply['username'] == $username && $rank < 3 && $details[4] == 0 && $details[0] == 0) ? '<a href="edit.php?forum='. $f .'&id='. $i .'&type=1&pid='. $reply['id'] .'">Edit</a> | '.$action_bar : $action_bar; ?></span>
                                                                                </td>
                                                                        </tr>
                                                </tbody>
                                                </table>
                                                <?php
                                            }
                                        }
                                        ?>
                                        </div>
	<!--
			-->
	<div id="breadcrumb">
		<a href="../index.php">Home</a> > <a href="index.php"><?php echo $data['wb_name']; ?></a> > <a href="viewforum.php?forum=<?php echo $f; ?>"><?php echo $forum_details[0]['title']; ?></a> > <a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><?php echo $details[2]; ?></a>
	</div>

		<div class="actions" id="top">
			<table>
				<tbody>
					<tr>
						<td class="nav">
						<form action="viewthread.php" method="get" style="display: inline;">
							<input type="hidden" name="id" value="<?php echo $i; ?>" />
							<input type="hidden" name="forum" value="<?php echo $f; ?>" />
							<ul class="flat">
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>"><< first</a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $prev; ?>">< prev</a></li>
								<li>Page <input type="text" class="textinput" id="page" name="page" value="<?php echo $page; ?>" size="2" maxlength="3" /> of <?php echo $pages; ?></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $next; ?>">next ></a></li>
								<li><a href="viewthread.php?forum=<?php echo $f.'&id='.$i; ?>&page=<?php echo $pages; ?>">last >></a></li>
							</ul>
						</form>
                                                        </td>
                                                        
						<td class="commands">
							<ul class="flat">
							<?php if($thread->canReply($i, $rank) && !$user->checkMute($username)) echo '<li><a href="reply.php?forum='. $f .'&id='. $i .'"><img src="../img/forum/new_thread.gif" alt="T" /> Reply</a></li>'; ?>
                                                                <li><a href=""><img src="../img/forum/refresh.gif" alt=""> Refresh</a></li>
                                                                </ul>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

		<div id="uid">Quick find code: <?php echo $details[8]; ?></div>

		<br>

		<div class="tandc"><?php echo $data['wb_foot']; ?></div>
</div>	
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/#findComment-1355339
Share on other sites

Put this junk into an include:

 

<html xmlns:IE>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<title><?php echo $data['wb_title']; ?></title>
<link href="../css/basic-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forum-3.css" rel="stylesheet" type="text/css" media="all" />
<link href="../css/forummsg-1.css" rel="stylesheet" type="text/css" media="all" />
<script src="../js/v_thread_2.js"></script>
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="../css/forummsg-ie-1.css" />
<![endif]-->
</head>

Link to comment
https://forums.phpfreaks.com/topic/264466-improving-this-code/#findComment-1355368
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.