The only real good thing was that it really helped refactor the code, since the PHP only handles the raw data processing, and all the formatting is left to the XSL scripts on the client. Let's take a look at before-and-after (at the cost of breaking the margins of my journal):
BEFORE:
/* processing section culled, since its basically the same */
"login.php">Main Page | "discuss.php">Forum Index
"post">
class
="forum_reply">"hidden" name="post" value="">
"hidden" name="spam" value="pls">
"0" cellpadding="0" cellspacing="0">
Subject:"text" name="sub" size="18" class="txt">
Name:"text" name="nam" size="18" class="txt">
Email:"text" name="lnk" size="18" class="txt">
"msg" cols="40" rows="5">
"submit" value="Post" class="btn">
"0" width="75%">
function output_post( $reply, $post_id, $post_time, $post_sub, $post_nam, $post_lnk, $post_msg ) {
?>
"0" cellspacing="0" width="100%" class="forum_post">
echo( "$post_sub " );
if( $post_lnk != "" ) {
if ( substr($post_lnk,0,7) != "http://" ) $prefix="mailto:";
echo( "by $post_nam" );
}
else echo( " by $post_nam " ); ?>
"right">if( $reply ) { ?>"discuss.php?post=">Reply
"r", $post_time ); ?>
"3">
}
function output_topic_head( $post_id, $post_last, $post_sub, $post_nam, $post_cnt, $post_msg ) {
if ( $post_sub == "" ) $post_sub = "(No Subject)";
?>
class="forum_topic">
"discuss.php?post="> by
replies
}
if ( $post_id == 0 ) {
// output thread table or something
$query = "SELECT * FROM forum WHERE thread=0 ORDER BY lastpost DESC LIMIT $FRONT_PAGE_POST_VIEW";
$result = mysql_query( $query, $link )
or $error .= "MySQL query failed - couldn't fetch page content. ($query)
";
while ( $line = mysql_fetch_array( $result ) ) {
output_topic_head( $line['id'], $line['lastpost'], $line['subject'], $line['name'],
$line['replycount'], $line['body'] );
}
mysql_free_result( $result );
} else {
mysql_free_result( $result );
$query = "SELECT * FROM forum WHERE thread=$post_id OR id=$post_id ORDER BY id";
$result = mysql_query( $query, $link )
or $error .= "MySQL error - couldn't fetch thread contents. ($query)
";
while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
output_post( $reply, $line['id'], $line['time'], $line['subject'], $line['name'],
$line['link'], $line['body'] );
}
mysql_free_result( $result );
}
?>
"FF0000">
"0000FF">
AFTER:
$FRONT_PAGE_POST_VIEW = 25; $MAX_POST_LENGTH = 1024; $link = get_connection(); $post_id = (int) $_GET['post']; echo( '' ); if ( $post_id == 0 ) { echo( "" ); // display topic list $query = "SELECT * FROM forum WHERE thread=0 ORDER BY lastpost DESC LIMIT $FRONT_PAGE_POST_VIEW"; $result = mysql_query( $query, $link ) or die( "Query failed: $query: " . mysql_error() ); while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { echo( "" ); echo( "" . $line['id'] . "
echo( "" . $line['name'] . "" );
echo( "" . $line['subject'] . "" );
echo( "" . $line['replycount'] . "" );
echo( "" );
}
mysql_free_result( $result );
echo( "" );
}
else {
// display thread.
echo( "" );
echo( "$post_id" );
$query = "SELECT * FROM forum WHERE thread=$post_id OR id=$post_id ORDER BY id";
$result = mysql_query( $query, $link )
or die( "Query failed: $query: " . mysql_error() );
while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
echo( "" );
echo( "" . $line['id'] . "" );
echo( "" . $line['name'] . "" );
echo( "" . $line['subject'] . "" );
echo( "" . $line['time'] . "" );
echo( "" . date( "r", $line['time'] ) . "" );
if ( $line['link'] ) {
if ( substr( $line['link'],0,7 ) != "http://" ) $prefix="mailto:";
else $prefix = "";
echo( "$prefix" . $line['link'] . "" );
} // don't output this node if there isn't a link.
echo( " . $line['body'] . "]]>" );
echo( "" );
}
mysql_free_result( $result );
echo( "" );
}
echo( '' );
mysql_close( $link );
?>
Hurr. Time to figure out the XML layout for the rest of the stuff :3