function viewcommentary($section, $message = "Interject your own commentary?", $limit = 25, $talkline = "says", $schema = false, $skipfooter = false, $customsql = false, $skiprecentupdate = false, $overridemod = false)
{
    global $session, $REQUEST_URI, $doublepost, $translation_namespace;
    global $emptypost;
    global $chatloc, $afk, $dni, $moderating;
    if (!array_key_exists('commentary_auto_update', $session['user']['prefs'])) {
        $session['user']['prefs']['commentary_auto_update'] = 1;
    }
    if (httpget("disable_auto_update")) {
        $session['user']['prefs']['commentary_auto_update'] = 0;
    }
    if (httpget("enable_auto_update")) {
        $session['user']['prefs']['commentary_auto_update'] = 1;
    }
    if (!$returnlink) {
        $returnlink = URLEncode($_SERVER['REQUEST_URI']);
    }
    if ($session['user']['superuser'] & SU_EDIT_COMMENTS || $overridemod) {
        $showmodlink = true;
    } else {
        $showmodlink = false;
    }
    if (!$skiprecentupdate) {
        $session['recentcomments'] = date("Y-m-d H:i:s");
    }
    rawoutput("<!--start of commentary area--><a name=\"commentarystart\"></a>");
    global $fiveminuteload;
    if ($session['user']['prefs']['commentary_auto_update'] && !httpget('comscroll') && $fiveminuteload < 8) {
        $jsec = strtolower($section);
        $jsec = str_replace("_", "", $jsec);
        $jsec = str_replace("-", "", $jsec);
        $jsec = str_replace(",", "0", $jsec);
        //this javascript code auto-updates the chat automatically, based on server load.
        //The current five-minute average as last reported to the game (reported once per minute) is stored in the global $fiveminuteload.
        // $refreshbase = ceil($fiveminuteload);
        // if ($refreshbase < 1) $refreshbase = 1;
        // $refreshrate = $refreshbase*1000;
        //or, just go with every six seconds
        $refreshrate = 6000;
        rawoutput("<script type=\"text/javascript\">\r\n\t\t\tvar limit" . $jsec . " = 0;\r\n\t\t\ttimer" . $jsec . "=setTimeout(\"loadnewchat" . $jsec . "()\"," . $refreshrate . ");\r\n\t\t\tfunction loadnewchat" . $jsec . "() {\r\n\t\t\t\tlimit" . $jsec . " ++;\r\n\t\t\t\tif (window.XMLHttpRequest){\r\n\t\t\t\t\t// code for IE7+, Firefox, Chrome, Opera, Safari\r\n\t\t\t\t\txmlhttp" . $jsec . "=new XMLHttpRequest();\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// code for IE6, IE5\r\n\t\t\t\t\txmlhttp" . $jsec . "=new ActiveXObject(\"Microsoft.XMLHTTP\");\r\n\t\t\t\t}\r\n\t\t\t\txmlhttp" . $jsec . ".onreadystatechange=function(){\r\n\t\t\t\t\tif (xmlhttp" . $jsec . ".readyState==4 && xmlhttp" . $jsec . ".status==200 && limit" . $jsec . " < 100){\r\n\t\t\t\t\t\tdocument.getElementById(\"ajaxcommentarydiv" . $jsec . "\").innerHTML = xmlhttp" . $jsec . ".responseText;\r\n\t\t\t\t\t\ttimer" . $jsec . "=setTimeout(\"loadnewchat" . $jsec . "()\"," . $refreshrate . ");\r\n\t\t\t\t\t} else if (limit" . $jsec . " >= 100){\r\n\t\t\t\t\t\tdocument.getElementById(\"ajaxcommentarynoticediv" . $jsec . "\").innerHTML = 'Auto-update has timed out.  Click any link to restart the clock.';\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\txmlhttp" . $jsec . ".open(\"GET\",\"ajaxcommentary.php?section=" . $section . "&message=" . $message . "&limit=" . $limit . "&talkline=" . $talkline . "&returnlink=" . $returnlink . "\",true);\r\n\t\t\t\txmlhttp" . $jsec . ".send();\r\n\t\t\t}\r\n\t\t</script>");
        rawoutput("<div id=\"ajaxcommentarydiv" . $jsec . "\">");
    }
    output_notl("`n");
    $out = preparecommentaryblock($section, $message, $limit, $talkline, $schema, $skipfooter, $customsql, $skiprecentupdate, $overridemod, $returnlink);
    $commentary = appoencode($out, true);
    rawoutput($commentary);
    //output_notl("%s",$commentary,true);
    if ($session['user']['prefs']['commentary_auto_update']) {
        rawoutput("</div>");
    }
    if ($showmodlink) {
        //moderation link mass delete button
        rawoutput("<input type=\"submit\" value=\"Mass Delete\"></form>");
    }
    if (!$skipfooter) {
        commentaryfooter($section, $message, $limit, $talkline, $schema);
    }
    rawoutput("<!--end of commentary area-->");
}
<?php

global $session;
define("ALLOW_ANONYMOUS", true);
define("OVERRIDE_FORCED_NAV", true);
require_once "common.php";
require_once "lib/commentary.php";
$section = $_REQUEST['section'];
//$section = "village";
sleep(5);
//todo: get return link properly, check the player's chatloc matches up with the commentary area
$commentary = preparecommentaryblock($section);
echo $section;
$commentary = appoencode($commentary, true);
echo $commentary;
saveuser();
$now = time();
$minute = round($now / 60) * 60;
$session['chatrequests'][$minute] += 1;
//echo("Chat requests: ".$session['chatrequests'][$minute]." this minute (minute number ".$minute.").<br />");
if ($session['chatrequests'][$minute] >= 50) {
    echo "Please don't run multiple Global Banter windows, it puts a tremendous strain on the server.  I've logged you out.  You'll be able to log back in again in a few minutes - please clear your cookies.";
    $session['user']['loggedin'] = false;
    saveuser();
    exit;
}
// if ($fiveminuteload>=8){
// echo ("Server load is too high for auto-update at the moment.  This will hopefully balance out in a few minutes.");
// exit();
// }
$expiresin = strtotime($session['user']['laston']) + 600;
$section = $_REQUEST['section'];
if ($now > $expiresin || $session['user']['chatloc'] != "global_banter" && $section != "global_banter" && $session['user']['chatloc'] != $section && $session['user']['chatloc'] . "_aux" != $section) {
    echo "Chat disabled due to inactivity";
} else {
    require_once "lib/commentary.php";
    $message = $_REQUEST['message'];
    $limit = $_REQUEST['limit'];
    $talkline = $_REQUEST['talkline'];
    $returnlink = urlencode($_REQUEST['returnlink']);
    $showmodlink = $_REQUEST['showmodlink'];
    $commentary = preparecommentaryblock($section, $message, $limit, $talkline, $schema = false, $skipfooter = false, $customsql = false, $skiprecentupdate = false, $showmodlink, $returnlink);
    $commentary = appoencode("`n" . $commentary . "`n", true);
    echo $commentary;
}
saveuser();
exit;