engine= new bbcode_engine;
$this->engine->cust_tag("/","<");
$this->engine->cust_tag("/>/",">");
//Since \n and
screw up preg, convert them out.
$this->engine->cust_tag("/\n/","&nbrlb;");
$this->engine->simple_bbcode_tag("b");
$this->engine->simple_bbcode_tag("i");
$this->engine->simple_bbcode_tag("u");
$this->engine->simple_bbcode_tag("s");
$this->engine->simple_bbcode_tag("sub");
$this->engine->simple_bbcode_tag("sup");
$this->engine->simple_bbcode_tag("big");
$this->engine->simple_bbcode_tag("small");
$this->engine->adv_bbcode_tag("list","ul");
$this->engine->adv_bbcode_tag("olist","ol");
$this->engine->adv_bbcode_tag("item","li");
$this->engine->adv_option_tag("font","font","family");
$this->engine->adv_option_tag("size","font","size");
$this->engine->adv_option_tag("url","a","href");
$this->engine->adv_option_tag("color","font","color");
$this->engine->adv_option_tag("style","span","style");
$this->engine->simp_option_notext("img","src");
$this->engine->simp_bbcode_att("img","src");
$this->engine->cust_tag("/\(c\)/","©");
$this->engine->cust_tag("/\(tm\)/","");
$this->engine->cust_tag("/\(r\)/","®");
$this->engine->adv_option_tag_em("email","a","href");
$this->engine->adv_bbcode_att_em("email","a","href");
$this->engine->cust_tag("/\[left\](.+?)\[\/left\]/","
\\1
");
$this->engine->cust_tag("/\[center\](.+?)\[\/center\]/","\\1
");
$this->engine->cust_tag("/\[right\](.+?)\[\/right\]/","\\1
");
$this->engine->cust_tag("/\[quote=(.+?)\](.+?)\[\/quote\]/","QUOTE(\\1)
\\2
");
$this->engine->cust_tag("/\[quote\](.+?)\[\/quote\]/","QUOTE
\\1
");
$this->engine->cust_tag("/\[code\](.+?)\[\/code\]/","CODE
\\1
");
$this->engine->cust_tag("/\[codebox\](.+?)\[\/codebox\]/","CODE
\\1
");
$this->engine->cust_tag("/&nbrlb;/","
\n");
}
function bbcode_parse($html)
{
return $this->engine->parse_bbcode($html);
}
}
function strip_html_tags($text)
{
return preg_replace("/<(.+?)>/is","", $text);
}
function forums_rank($tp)
{
if ( $tp < 3 ) { return "#1 Absolute Newbie"; }
else if ( $tp < 7 ) { return "#2 Newbie"; }
else if ( $tp < 12 ) { return "#3 Beginner"; }
else if ( $tp < 18 ) { return "#4 Not Experienced"; }
else if ( $tp < 25 ) { return "#5 Rookie"; }
else if ( $tp < 50 ) { return "#6 Average"; }
else if ( $tp < 100 ) { return "#7 Good"; }
else if ( $tp< 200 ) { return "#8 Very Good"; }
else if ( $tp < 350 ) { return "#9 Greater Than Average"; }
else if ( $tp < 500 ) { return "#10 Experienced"; }
else if ( $tp < 750 ) { return "#11 Highly Experienced"; }
else if ( $tp < 1200 ) { return "#12 Honoured"; }
else if ( $tp < 1800 ) { return "#13 Highly Hounoured"; }
else if ( $tp < 2500 ) { return "#14 Respect King"; }
else if ( $tp < 5000) { return "#15 True Champion"; }
}
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();
if($ir['hospital'] > 0)
{
die("You cannot access this page from hospital");
}
$bbc = new bbcode;
list($ir['ul_id'],$ir['ul_name'],$ir['ul_isstaff'],$ir['ul_isbold'],$ir['ul_color']) = mysql_fetch_array(mysql_query("SELECT * FROM users_levels WHERE ul_id={$ir['user_level']}", $c));
print "Forums
";
if($ir['forumban'])
{
die("! ERROR
You have been forum banned for {$ir['forumban']} days.
Reason: {$ir['fb_reason']}");
}
$_GET['viewforum']=(int) $_GET['viewforum'];
if($_GET['viewtopic'] and $_GET['act'] != 'quote') { $_GET['act']='viewtopic'; }
if($_GET['viewforum']) { $_GET['act']='viewforum'; }
if($_GET['reply']) { $_GET['act']='reply'; }
if($_GET['empty']==1 && $_GET['code']=='kill' && $_SESSION['owner'])
{
emptyallforums();
}
switch($_GET['act'])
{
case 'viewforum':
viewforum();
break;
case 'viewtopic':
viewtopic();
break;
case 'reply':
reply();
break;
case 'newtopicform':
newtopicform();
break;
case 'newtopic':
newtopic();
break;
case 'quote':
quote();
break;
case 'edit':
edit();
break;
case 'move':
move();
break;
case 'editsub':
editsub();
break;
case 'lock':
lock();
break;
case 'delepost':
delepost();
break;
case 'deletopic':
deletopic();
break;
case 'pin':
pin();
break;
case 'recache':
recache_forum($_GET['forum']);
break;
default:
idx();
break;
}
function idx() {
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_auth='public' ORDER BY ff_id ASC", $c) or die(mysql_error());
print "";
if($ir['user_level'] <> 1)
{
print "
Staff-Only Forums
";
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_auth='staff' ORDER BY ff_id ASC", $c) or die(mysql_error());
print "";
}
}
function viewforum()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$_GET['viewforum']}", $c);
$r=mysql_fetch_array($q);
if($r['ff_auth']=='gang' OR ($r['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.
> Back";
$h->endpage();
exit;
}
if($_GET['viewforum'] <> 1 OR $ir['user_level']==2)
{
$ntl=" [New Topic]";
}
else
{
$ntl="";
}
print "Forums Home >> {$r['ff_name']}$ntl
| Topic | Posts | Started | Last Post |
\n";
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_forum_id={$_GET['viewforum']} ORDER BY ft_pinned DESC, ft_last_time DESC", $c) or die(mysql_error());
while($r2=mysql_fetch_array($q))
{
$t1=date('F j Y, g:i:s a',$r2['ft_start_time']);
$t2=date('F j Y, g:i:s a',$r2['ft_last_time']);
if($r2['ft_pinned']) { $pt="Pinned: "; } else { $pt=""; }
if($r2['ft_locked']) { $lt=" (Locked)"; } else { $lt=""; }
print " $pt{$r2['ft_name']}$lt
{$r2['ft_desc']} | {$r2['ft_posts']} | $t1
By: {$r2['ft_owner_name']} | $t2
By: {$r2['ft_last_name']} |
\n";
}
print "
";
}
function viewtopic()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$_GET['viewtopic']}", $c);
$topic=mysql_fetch_array($q);
$q2=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$topic['ft_forum_id']}", $c);
$forum=mysql_fetch_array($q2);
if($forum['ff_auth']=='gang' OR ($forum['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.
> Back";
$h->endpage();
exit;
}
print "Forums Home >> {$forum['ff_name']} >> {$topic['ft_name']}
";
$posts_per_page=20;
$posts_topic=$topic['ft_posts'];
$pages=ceil($posts_topic/$posts_per_page);
$st= ($_GET['st']) ? $_GET['st'] : 0;
if($_GET['lastpost']) { $st=($pages-1)*20; }
$pst=-20;
print "Pages: ";
for($i=1;$i<=$pages;$i++)
{
$pst+=20;
print "";
if($pst == $st) { print ""; }
print $i;
if($pst == $st) { print ""; }
print " ";
}
print "
";
if($ir['user_level'] > 1)
{
print "
Toggle Sticky | Toggle Lock | Kill Topic
";
}
print "
\n";
$q3=mysql_query("SELECT * FROM forum_posts WHERE fp_topic_id={$topic['ft_id']} ORDER BY fp_time ASC LIMIT $st, 20", $c);
$no=$st;
while($r=mysql_fetch_array($q3))
{
$qlink="[Quote Post]";
if($ir['user_level'] > 1 || $ir['userid']==$r['fp_poster_id'])
{
$elink="[Edit Post]";
}
else { $elink=""; }
$no++;
if($no > 1 and $ir['user_level'] > 1) { $dlink="[Delete Post]"; }
else { $dlink=""; }
$t=date('F j Y, g:i:s a',$r['fp_time']);
if($r['fp_edit_count'] > 0) { $edittext="\n
Last edited by {$r['fp_editor_name']} at ".date('F j Y, g:i:s a',$r['fp_editor_time']).", edited {$r['fp_edit_count']} times in total."; } else { $edittext=""; }
$membq=mysql_query("SELECT * FROM users WHERE userid={$r['fp_poster_id']}", $c);
$memb=mysql_fetch_array($membq);
$rank=forums_rank($memb['posts']);
if($memb['forums_avatar']) { $av="
"; } else { $av="
"; }
if(!$memb['forums_signature']) { $memb['forums_signature']="No Signature"; } else {$memb['forums_signature']=$bbc->bbcode_parse($memb['forums_signature']); }
$r['fp_text']=$bbc->bbcode_parse($r['fp_text']);
print "
| Post #{$no} | Subject: {$r['fp_subject']}
Posted at: $t $qlink$elink$dlink |
{$r['fp_poster_name']} [{$r['fp_poster_id']}]
$av
Level: {$memb['level']} |
{$r['fp_text']}
{$edittext}
-------------------
{$memb['forums_signature']} |
";
}
print "
";
$pst=-20;
print "Pages: ";
for($i=1;$i<=$pages;$i++)
{
$pst+=20;
print "";
if($pst == $st) { print ""; }
print $i;
if($pst == $st) { print ""; }
print " ";
}
if(!$topic['ft_locked'])
{
print <<
Post a reply to this topic:
EOF;
}
else
{
print "
This topic has been locked, you cannot reply to it.";
}
}
function reply()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$_GET['reply']}", $c);
$topic=mysql_fetch_array($q);
$q2=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$topic['ft_forum_id']}", $c);
$forum=mysql_fetch_array($q2);
if($forum['ff_auth']=='gang' OR ($forum['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to reply to this topic.
> Back";
$h->endpage();
exit;
}
if(!$topic['ft_locked'])
{
$u=$ir['username'];
$u=mysql_escape($u);
mysql_query("INSERT INTO forum_posts VALUES('', {$_GET['reply']}, {$forum['ff_id']}, $userid, '$u', unix_timestamp(), '{$_POST['fp_subject']}', '{$_POST['fp_text']}', 0, '', 0, 0)", $c) or die(mysql_error());
mysql_query("UPDATE forum_topics SET ft_last_id=$userid, ft_last_name='$u', ft_last_time=unix_timestamp(), ft_posts=ft_posts+1 WHERE ft_id={$_GET['reply']}", $c);
mysql_query("UPDATE forum_forums SET ff_lp_time=unix_timestamp(), ff_posts=ff_posts+1, ff_lp_poster_id=$userid, ff_lp_poster_name='$u', ff_lp_t_id={$_GET['reply']}, ff_lp_t_name='{$topic['ft_name']}' WHERE ff_id={$forum['ff_id']}", $c);
mysql_query("UPDATE users SET posts=posts+1 WHERE userid=$userid", $c);
print "Reply Posted!
";
$_GET['lastpost']=1;
$_GET['viewtopic']=$_GET['reply'];
viewtopic();
}
else
{
print "
This topic has been locked, you cannot reply to it.
Back";
}
}
function newtopicform() {
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$_GET['forum']}", $c);
$r=mysql_fetch_array($q);
if($r['ff_auth']=='gang' OR ($r['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.
> Back";
$h->endpage();
exit;
}
if ($_GET['forum'] == 1 and $ir['user_level'] <> 2)
{
print "Only admins can start topics in Announcements.
> Back";
$h->endpage();
exit;
}
print <<Forums Home >> {$r['ff_name']} >> New Topic Form
EOF;
}
else
{
print "
This topic has been locked, you cannot reply to it.
Back";
}
}
function edit()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$_GET['topic']}", $c);
$topic=mysql_fetch_array($q);
$q2=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$topic['ft_forum_id']}", $c);
$forum=mysql_fetch_array($q2);
if($forum['ff_auth']=='gang' OR ($forum['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.
> Back";
$h->endpage();
exit;
}
$q3=mysql_query("SELECT * FROM forum_posts WHERE fp_id={$_GET['post']}", $c);
$post=mysql_fetch_array($q3);
if(!($ir['user_level'] > 1 || $ir['userid']==$post['fp_poster_id']))
{
print "You have no permission to edit this post.
> Back";
$h->endpage();
exit;
}
print "Forums Home >> {$forum['ff_name']} >> {$topic['ft_name']} >> Editing a Post
";
print <<
EOF;
}
function editsub()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$_GET['topic']}", $c);
$topic=mysql_fetch_array($q);
$q2=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$topic['ft_forum_id']}", $c);
$forum=mysql_fetch_array($q2);
if($forum['ff_auth']=='gang' OR ($forum['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.
> Back";
$h->endpage();
exit;
}
$q3=mysql_query("SELECT * FROM forum_posts WHERE fp_id={$_GET['post']}", $c);
$post=mysql_fetch_array($q3);
if(!($ir['user_level'] > 1 || $ir['userid']==$post['fp_poster_id']))
{
print "You have no permission to edit this post.
> Back";
$h->endpage();
exit;
}
mysql_query("UPDATE forum_posts SET fp_subject='{$_POST['fp_subject']}', fp_text='{$_POST['fp_text']}', fp_editor_id=$userid, fp_editor_name='{$ir['username']}', fp_editor_time=unix_timestamp(), fp_edit_count=fp_edit_count+1 WHERE fp_id={$_GET['post']}", $c);
print "Post Edited!
";
$_GET['viewtopic']=$_GET['topic'];
viewtopic();
}
function recache_forum($forum)
{
global $ir, $c, $userid, $h, $bbc;
print "Recaching forum ID $forum ... ";
$q=mysql_query("SELECT p.*,t.* FROM forum_posts p LEFT JOIN forum_topics t ON p.fp_topic_id=t.ft_id WHERE p.fp_forum_id=$forum ORDER BY p.fp_time DESC LIMIT 1", $c);
if(!mysql_num_rows($q))
{
mysql_query("update forum_forums set ff_lp_time=0, ff_lp_poster_id=0, ff_lp_poster_name='N/A', ff_lp_t_id=0, ff_lp_t_name='N/A',ff_posts=0, ff_topics=0 where ff_id={$forum}", $c);
print " ... Done";
}
else
{
$r=mysql_fetch_array($q);
$tn=mysql_escape($r['ft_name']);
$pn=mysql_escape($r['fp_poster_name']);
$posts=mysql_num_rows(mysql_query("SELECT fp_id FROM forum_posts WHERE fp_forum_id=$forum",$c));
$topics=mysql_num_rows(mysql_query("SELECT ft_id FROM forum_topics WHERE ft_forum_id=$forum",$c));
mysql_query("update forum_forums set ff_lp_time={$r['fp_time']}, ff_lp_poster_id={$r['fp_poster_id']}, ff_lp_poster_name='$pn', ff_lp_t_id={$r['ft_id']}, ff_lp_t_name='$tn',ff_posts=$posts, ff_topics=$topics where ff_id={$forum}", $c);
print " ... Done
";
}
}
function recache_topic($forum)
{
global $ir, $c, $userid, $h, $bbc;
print "Recaching topic ID $forum ... ";
$q=mysql_query("SELECT p.* FROM forum_posts p WHERE p.fp_topic_id=$forum ORDER BY p.fp_time DESC LIMIT 1", $c);
if(!mysql_num_rows($q))
{
mysql_query("update forum_topics set ft_last_id=0, ft_last_time=0, ft_last_name='N/A',ft_posts=0 where ft_id={$forum}", $c);
print " ... Done";
}
else
{
$r=mysql_fetch_array($q);
$pn=mysql_escape($r['fp_poster_name']);
$posts=mysql_num_rows(mysql_query("SELECT fp_id FROM forum_posts WHERE fp_topic_id=$forum",$c));
mysql_query("update forum_topics set ft_last_id={$r['fp_poster_id']}, ft_last_time={$r['fp_time']}, ft_last_name='$pn',ft_posts=$posts where ft_id={$forum}", $c);
print " ... Done
";
}
}
function move()
{
global $ir, $c, $userid, $h, $bbc;
if($ir['user_level'] < 2)
{
die("");
}
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$_GET['topic']}", $c);
$topic=mysql_fetch_array($q);
mysql_query("UPDATE forum_topics SET ft_forum_id={$_POST['forum']} WHERE ft_id={$_GET['topic']}", $c);
mysql_query("UPDATE forum_posts SET fp_forum_id={$_POST['forum']} WHERE fp_topic_id={$_GET['topic']}", $c);
print "Topic moved...
";
recache_forum($topic['ft_forum_id']);
recache_forum($_POST['forum']);
}
function lock()
{
global $ir, $c, $userid, $h, $bbc;
if($ir['user_level'] < 2)
{
die("");
}
mysql_query("UPDATE forum_topics SET ft_locked=-ft_locked+1 WHERE ft_id={$_GET['topic']}", $c);
print "Topic's lock status changed, if it was unlocked, it will now be locked, otherwise, it will be unlocked.";
}
function pin()
{
global $ir, $c, $userid, $h, $bbc;
if($ir['user_level'] < 2)
{
die("");
}
mysql_query("UPDATE forum_topics SET ft_pinned=-ft_pinned+1 WHERE ft_id={$_GET['topic']}", $c);
print "Topic's pin status changed, if it was unpinned, it will now be pinned, otherwise, it will be unpinned.";
}
function delepost()
{
global $ir, $c, $userid, $h, $bbc;
if($ir['user_level'] < 2)
{
die("");
}
$q3=mysql_query("SELECT * FROM forum_posts WHERE fp_id={$_GET['post']}", $c);
$post=mysql_fetch_array($q3);
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_id={$post['fp_topic_id']}", $c);
$topic=mysql_fetch_array($q);
$u=mysql_escape($post['fp_poster_name']);
mysql_query("INSERT INTO forum_topics VALUES('', 16, 'From: {$topic['ft_name']}', 'Post ID: {$post['fp_id']}, From Topic ID: {$post['fp_topic_id']}', 0, {$post['fp_poster_id']}, '$u', {$post['fp_time']}, 0, '', 0, 0, 0)", $c);
$i=mysql_insert_id();
mysql_query("UPDATE forum_posts SET fp_forum_id=16,fp_topic_id=$i WHERE fp_id={$post['fp_id']}", $c);
mysql_query("UPDATE forum_topics SET ft_last_id={$post['fp_poster_id']}, ft_last_name='$u', ft_last_time={$post['fp_time']}, ft_posts=ft_posts+1 WHERE ft_id={$i}", $c);
print "Post deleted...
";
recache_topic($post['fp_topic_id']);
recache_forum($post['fp_forum_id']);
recache_forum(16);
}
function deletopic()
{
$_POST['forum']=16;
print "Deleting topic (moving to Trash Can)...
";
move();
}
$h->endpage();
?>