$clanrankcolors=array("`!","`#","`^","`&","`\$"); // Needs to be here because scrolling through the commentary pages, entering a bio, then scrolling again forward // then re-entering another bio will lead to $com being smaller than 0 and this will lead to an SQL error later on. $com=(int)httpget("comscroll"); if ($com < 0) $com = 0; $cc = false; if (httpget("comscroll") !==false && (int)$session['lastcom']==$com+1) $cid = (int)$session['lastcommentid']; else $cid = 0; $session['lastcom'] = $com; if ($com > 0 || $cid > 0) { // Find newly added comments. $sql = "SELECT COUNT(commentid) AS newadded FROM " . db_prefix("commentary") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid = " . db_prefix("commentary"). ".author WHERE section='$section' AND " . "(".db_prefix("accounts").".locked=0 or ".db_prefix('accounts').".locked is null) AND commentid > '$cid'"; $result = db_query($sql); $row = db_fetch_assoc($result); $newadded = $row['newadded']; } else { $newadded = 0; } $commentbuffer = array(); if ($cid == 0) { $sql = "SELECT ". db_prefix("commentary") . ".*, " . db_prefix("accounts").".name, " . db_prefix("accounts").".acctid, " . db_prefix("accounts").".clanrank, " . db_prefix("clans") . ".clanshort FROM " . db_prefix("commentary") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid = " . db_prefix("commentary"). ".author LEFT JOIN " . db_prefix("clans") . " ON " . db_prefix("clans") . ".clanid=" . db_prefix("accounts") . ".clanid WHERE section = '$section' AND " . "( ".db_prefix("accounts") . ".locked=0 OR ".db_prefix("accounts") .".locked is null ) ". "ORDER BY commentid DESC LIMIT " . ($com*$limit).",$limit"; if ($com==0 && strstr( $_SERVER['REQUEST_URI'], "/moderate.php" ) !== $_SERVER['REQUEST_URI'] ) $result = db_query_cached($sql,"comments-{$section}"); else $result = db_query($sql); while($row = db_fetch_assoc($result)) $commentbuffer[] = $row; } else { $sql = "SELECT " . db_prefix("commentary") . ".*, " . db_prefix("accounts").".name, " . db_prefix("accounts").".acctid, " . db_prefix("accounts").".clanrank, " . db_prefix("clans").".clanshort FROM " . db_prefix("commentary") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid = " . db_prefix("commentary"). ".author LEFT JOIN " . db_prefix("clans") . " ON " . db_prefix("clans") . ".clanid=" . db_prefix("accounts") . ".clanid WHERE section = '$section' AND " . "( ".db_prefix("accounts") . ".locked=0 OR ".db_prefix("accounts") .".locked is null ) ". "AND commentid > '$cid' " . "ORDER BY commentid ASC LIMIT $limit"; $result = db_query($sql); while ($row = db_fetch_assoc($result)) $commentbuffer[] = $row; $commentbuffer = array_reverse($commentbuffer); } $rowcount = count($commentbuffer); if ($rowcount > 0) $session['lastcommentid'] = $commentbuffer[0]['commentid']; $counttoday=0; for ($i=0; $i < $rowcount; $i++){ $row = $commentbuffer[$i]; $row['comment'] = comment_sanitize($row['comment']); $commentids[$i] = $row['commentid']; if (date("Y-m-d",strtotime($row['postdate']))==date("Y-m-d")){ if ($row['name']==$session['user']['name']) $counttoday++; } $x=0; $ft=""; for ($x=0;strlen($ft)<5 && $x""?"{$clanrankcolors[ceil($row['clanrank']/10)]}<`2{$row['clanshort']}{$clanrankcolors[ceil($row['clanrank']/10)]}> `&":"").$row['name']; } if ($ft=="::" || $ft=="/me" || $ft==":"){ $x = strpos($row['comment'],$ft); if ($x!==false){ if ($linkbios) $op[$i] = str_replace("&","&",HTMLEntities(substr($row['comment'],0,$x), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0\n`&{$row['name']}`0\n`& ".str_replace("&","&",HTMLEntities(substr($row['comment'],$x+strlen($ft)), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`n"; else $op[$i] = str_replace("&","&",HTMLEntities(substr($row['comment'],0,$x), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`&{$row['name']}`0`& ".str_replace("&","&",HTMLEntities(substr($row['comment'],$x+strlen($ft)), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`n"; $rawc[$i] = str_replace("&","&",HTMLEntities(substr($row['comment'],0,$x), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`&{$row['name']}`0`& ".str_replace("&","&",HTMLEntities(substr($row['comment'],$x+strlen($ft)), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`n"; } } if ($ft=="/game" && !$row['name']) { $x = strpos($row['comment'],$ft); if ($x!==false){ $op[$i] = str_replace("&","&",HTMLEntities(substr($row['comment'],0,$x), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`&".str_replace("&","&",HTMLEntities(substr($row['comment'],$x+strlen($ft)), ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`0`n"; } } if (!isset($op) || !is_array($op)) $op = array(); if (!array_key_exists($i,$op) || $op[$i] == "") { if ($linkbios) $op[$i] = "`0`&{$row['name']}`0`3 says, \"`#".str_replace("&","&",HTMLEntities($row['comment'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`3\"`0`n"; elseif (substr($ft,0,5)=='/game' && !$row['name']) $op[$i] = str_replace("&","&",HTMLEntities($row['comment'], ENT_COMPAT, getsetting("charset", "ISO-8859-1"))); else $op[$i] = "`&{$row['name']}`3 says, \"`#".str_replace("&","&",HTMLEntities($row['comment'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`3\"`0`n"; $rawc[$i] = "`&{$row['name']}`3 says, \"`#".str_replace("&","&",HTMLEntities($row['comment'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")))."`3\"`0`n"; } $session['user']['prefs']['timeoffset'] = round($session['user']['prefs']['timeoffset'],1); if (!array_key_exists('timestamp', $session['user']['prefs'])) $session['user']['prefs']['timestamp'] = 0; if ($session['user']['prefs']['timestamp']==1) { if (!isset($session['user']['prefs']['timeformat'])) $session['user']['prefs']['timeformat'] = "[m/d h:ia]"; $time = strtotime($row['postdate']) + ($session['user']['prefs']['timeoffset'] * 60 * 60); $s=date("`7" . $session['user']['prefs']['timeformat'] . "`0 ",$time); $op[$i] = $s.$op[$i]; }elseif ($session['user']['prefs']['timestamp']==2) { $s=reltime(strtotime($row['postdate'])); $op[$i] = "`7($s)`0 ".$op[$i]; } if ($message=="X") $op[$i]="`0({$row['section']}) ".$op[$i]; if ($row['postdate']>=$session['user']['recentcomments']) $op[$i]="> ".$op[$i]; addnav("",$link); $auth[$i] = $row['author']; if (isset($rawc[$i])) { $rawc[$i] = full_sanitize($rawc[$i]); $rawc[$i] = htmlentities($rawc[$i], ENT_QUOTES, getsetting("charset", "ISO-8859-1")); } } $i--; $outputcomments=array(); $sect="x"; $del=translate_inline("Del"); $scriptname=substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['SCRIPT_NAME'],"/")+1); $pos=strpos($_SERVER['REQUEST_URI'],"?"); $return=$scriptname.($pos==false?"":substr($_SERVER['REQUEST_URI'],$pos)); $one=(strstr($return,"?")==false?"?":"&"); $editrights=($session['user']['superuser'] & SU_EDIT_COMMENTS?1:0); for (;$i>=0;$i--){ $out=""; if ($editrights) { $out.="`2[$del`2]`0 "; addnav("",$return.$one."removecomment={$commentids[$i]}§ion=$section&returnpath=/".URLEncode($return).""); } $out.=$op[$i]; if (!array_key_exists($sect,$outputcomments) || !is_array($outputcomments[$sect])) $outputcomments[$sect]=array(); array_push($outputcomments[$sect],$out); } //output the comments ksort($outputcomments); reset($outputcomments); $sections = commentarylocs(); $needclose = 0; foreach ($outputcomments as $sec=>$v) { if ($sec!="x") { if($needclose) modulehook("}collapse"); output_notl("`n
`b`^%s`0`b`n", $sec, isset($sections[$sec]) ? $sections[$sec] : "($sec)", true); addnav("", "moderate.php?area=$sec"); modulehook("collapse{",array("name"=>"com-".$sec)); $needclose = 1; } else { modulehook("collapse{",array("name"=>"com-".$section)); $needclose = 1; } reset($v); foreach ($v as $key=>$val) { $args = array('commentline'=>$val); $args = modulehook("viewcommentary", $args); $val = $args['commentline']; output_notl($val, true); } } if ($session['user']['loggedin']) { $args = modulehook("insertcomment", array("section"=>$section)); if (array_key_exists("mute",$args) && $args['mute'] && !($session['user']['superuser'] & SU_EDIT_COMMENTS)) { output_notl("%s", $args['mutemsg']); } elseif ($counttoday<($limit/2) || ($session['user']['superuser']&~SU_DOESNT_GIVE_GROTTO) || ($session['user']['superuser']&SU_IS_GAMEMASTER) == SU_IS_GAMEMASTER || !getsetting('postinglimit',1)){ if ($message!="X"){ $message="`n`@$message`n"; output($message); talkform($section,$talkline,$limit,$schema); } }else{ $message="`n`@$message`n"; output($message); output("Sorry, you've exhausted your posts in this section for now.`0`n"); } } $jump = false; if (!isset($session['user']['prefs']['nojump']) || $session['user']['prefs']['nojump'] == false) { $jump = true; } $firstu = translate_inline("<< First Unseen"); $prev = translate_inline("< Previous"); $ref = translate_inline("Refresh"); $next = translate_inline("Next >"); $lastu = translate_inline("Last Page >>"); if ($rowcount>=$limit || $cid>0){ $sql = "SELECT count(commentid) AS c FROM " . db_prefix("commentary") . " WHERE section='$section' AND postdate > '{$session['user']['recentcomments']}'"; $r = db_query($sql); $val = db_fetch_assoc($r); $val = round($val['c'] / $limit + 0.5,0) - 1; if ($val>0){ $first = comscroll_sanitize($REQUEST_URI)."&comscroll=".($val); $first = str_replace("?&","?",$first); if (!strpos($first,"?")) $first = str_replace("&","?",$first); $first .= "&refresh=1"; if ($jump) { $first .= "#$section"; } output_notl("$firstu",true); addnav("",$first); }else{ output_notl($firstu,true); } $req = comscroll_sanitize($REQUEST_URI)."&comscroll=".($com+1); $req = str_replace("?&","?",$req); if (!strpos($req,"?")) $req = str_replace("&","?",$req); $req .= "&refresh=1"; if ($jump) { $req .= "#$section"; } output_notl("$prev",true); addnav("",$req); }else{ output_notl("$firstu $prev",true); } $last = appendlink(comscroll_sanitize($REQUEST_URI),"refresh=1"); // Okay.. we have some smart-ass (or stupidass, you guess) players // who think that the auto-reload firefox plugin is a good way to // avoid our timeouts. Won't they be surprised when I take that little // hack away. $last = appendcount($last); $last = str_replace("?&","?",$last); if ($jump) { $last .= "#$section"; } //if (!strpos($last,"?")) $last = str_replace("&","?",$last); //debug($last); output_notl(" $ref ",true); addnav("",$last); if ($com>0 || ($cid > 0 && $newadded > $limit)){ $req = comscroll_sanitize($REQUEST_URI)."&comscroll=".($com-1); $req = str_replace("?&","?",$req); if (!strpos($req,"?")) $req = str_replace("&","?",$req); $req .= "&refresh=1"; if ($jump) { $req .= "#$section"; } output_notl(" $next",true); addnav("",$req); output_notl(" $lastu",true); }else{ output_notl("$next $lastu",true); } if (!$cc) db_free_result($result); tlschema(); if ($needclose) modulehook("}collapse"); } function talkform($section,$talkline,$limit=10,$schema=false){ require_once("lib/forms.php"); global $REQUEST_URI,$session,$translation_namespace; if ($schema===false) $schema=$translation_namespace; tlschema("commentary"); $jump = false; if (isset($session['user']['prefs']['nojump']) && $session['user']['prefs']['nojump'] == true) { $jump = true; } $counttoday=0; if (substr($section,0,5)!="clan-"){ $sql = "SELECT author FROM " . db_prefix("commentary") . " WHERE section='$section' AND postdate>'".date("Y-m-d 00:00:00")."' ORDER BY commentid DESC LIMIT $limit"; $result = db_query($sql); while ($row=db_fetch_assoc($result)){ if ($row['author']==$session['user']['acctid']) $counttoday++; } if (round($limit/2,0)-$counttoday <= 0 && getsetting('postinglimit',1)){ if ($session['user']['superuser']&~SU_DOESNT_GIVE_GROTTO){ output("`n`)(You'd be out of posts if you weren't a superuser or moderator.)`n"); }else{ output("`n`)(You are out of posts for the time being. Once some of your existing posts have moved out of the comment area, you'll be allowed to post again.)`n"); return false; } } } if (translate_inline($talkline,$schema)!="says") $tll = strlen(translate_inline($talkline,$schema))+11; else $tll=0; $req = comscroll_sanitize($REQUEST_URI)."&comment=1"; $req = str_replace("?&","?",$req); if (!strpos($req,"?")) $req = str_replace("&","?",$req); if ($jump) { $req .= "#$section"; } addnav("",$req); output_notl("
",true); previewfield("insertcommentary", $session['user']['name'], $talkline, true, array("size"=>"40", "maxlength"=>getsetting('maxchars',200)-$tll)); rawoutput(""); rawoutput(""); rawoutput(""); $session['commentcounter'] = $session['counter']; if ($section=="X"){ $vname = getsetting("villagename", LOCATION_FIELDS); $iname = getsetting("innname", LOCATION_INN); $sections = commentarylocs(); reset ($sections); output_notl("",true); }else{ output_notl("",true); } $add = translate_inline("Add"); output_notl("`n",true); if (round($limit/2,0)-$counttoday < 3 && getsetting('postinglimit',1)){ output("`)(You have %s posts left today)`n`0",(round($limit/2,0)-$counttoday)); } rawoutput("
"); // modulehook("commentarytrail",array()); tlschema(); } ?>