<?xjs
// User editable settings...

// Number of posts to show per page.
var max_posts=16;

// Minimum number of characters in an exerpt
var min_chars=400;

// Number of pixels per level to indent comments
var indent_pixels=20;

var bloginfo=new Object();
bloginfo.html_type='text/html';
bloginfo.charset='utf-8';
bloginfo.version='$Revision: 1.9 $';

//
// Don't change stuff down here.
//

load("sbbsdefs.js");

// User name of the blogger
var parameters=http_request.path_info.substr(1).split("/");
var msg_code=parameters[0];
if(msg_code==null || msg_code=='') {
	xjs_load("msg_index.xjs");
	do_exit(0);
}
bloginfo.name=msg_area.sub[msg_code].description;
var poster=parameters[1];
var year=parseInt(parameters[2],10);
var month=parseInt(parameters[3],10);
var day=parseInt(parameters[4],10);
var msgid=parseInt(parameters[5],10);
var subject=parameters[6];

//var pnum=system.matchuser(poster);
//if(pnum==0) {
//	write("Error getting UserID for "+poster+"!");
//	do_exit(1);
//}

if(!msg_area.sub[msg_code].can_read) {
	write("Error opening "+msg_code+"!");
	do_exit(1);
}

var msgbase = new MsgBase(msg_code);
if(!msgbase.open()) {
	write("Error opening "+msg_code+"!");
	do_exit(1);
}

if(!isNaN(msgid)) {
	if(subject==undefined || subject=="") {
		var hdr=msgbase.get_msg_header(parseInt(msgid));
		http_reply.status="301 Moved Permanently";
		http_reply.header["Location"]="http://"+http_request.host+http_request.virtual_path+msg_code+"/"+hdr.from+"/"+format("%04d",year)+"/"+format("%02d",month)+"/"+format("%02d",day)+"/"+msgid+"/"+clean_subject(hdr.subject);
		do_exit(0);
	}
}

function clean_subject(sub)
{
	sub=sub.replace(/[^a-zA-Z0-9]/g,"_");
	return(sub);
}

if(!isNaN(msgid)) {
	xjs_load("blog_item.xjs");
	do_exit(0);
}
xjs_load("entry_list.xjs");
do_exit(0);

function page_start(title,extra_head_content,extra_body_attribs)
{
	if(title==undefined || title==null)
		title='The Blogifier!';
	if(extra_head_content==undefined)
		extra_head_content='';
	if(extra_body_attribs==undefined)
		extra_body_attribs='';
?>
<html>
<head>
<title><?xjs write(title) ?></title>
<?xjs write(extra_head_content) ?>
</head>
<body <?xjs write(extra_body_attribs) ?>>

<p>
Welcome to the <?xjs if(msgbase != undefined) write(msgbase.cfg.name); ?> Blogifier <?xjs if(poster != undefined && poster != null && poster != '') write("for "+poster); ?>
</p>
<?xjs
}

function page_end()
{
?>

</body>
</html>

<?xjs
}

function do_exit(exitval)
{
	page_end();
	exit(exitval);
}

// WordPress compatability things
function blog_title()
{
	// Extra stuff for the title
	return('');
}

?>
