Untitled

Published January 14, 2007
Advertisement
lol, so I started moving the output of Rhubarb's PHP scripts from HTML (eww) to XML (*scream*). XML is, by nature, a bitch to work with. And my benchmarks show that there wasn't any performance gains from converting the forums, though the XML output is like 1/3 the size of the HTML output (which is really handy).

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
Previous Entry Untitled
0 likes 2 comments

Comments

Ravuya
Now to write me some SQL injections.
January 14, 2007 11:52 PM
mattd
January 15, 2007 01:08 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Untitled

5555 views

Untitled

1075 views

Untitled

1220 views

Untitled

1132 views

Untitled

1178 views

Untitled

1463 views

Untitled

1131 views

Untitled

1032 views

Untitled

1036 views

Untitled

1216 views
Advertisement