Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
65
scripts/game/beta5/forums/library.inc
Normal file
65
scripts/game/beta5/forums/library.inc
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_library {
|
||||
var $index = array(
|
||||
'deletePost',
|
||||
'deleteTopic',
|
||||
'edit',
|
||||
'getLatest',
|
||||
'getPost',
|
||||
'getPosts',
|
||||
'getStructure',
|
||||
'getTopic',
|
||||
'getTopics',
|
||||
'moveTopic',
|
||||
'newTopic',
|
||||
'reply',
|
||||
'searchPosts',
|
||||
'searchTopics',
|
||||
'updateLast'
|
||||
);
|
||||
|
||||
function beta5_forums_library($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Get the amount of read topics in an alliance forum
|
||||
function getRead($fid, $pid) {
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM af_read r,af_topic t WHERE t.id=r.topic AND t.forum=$fid AND r.reader=$pid");
|
||||
list($nr) = dbFetchArray($q);
|
||||
return $nr;
|
||||
}
|
||||
|
||||
function isRead($topic, $player) {
|
||||
$q = $this->db->query("SELECT * FROM af_read WHERE topic=$topic AND reader=$player");
|
||||
return $q && dbCount($q);
|
||||
}
|
||||
|
||||
function markRead($topic, $player) {
|
||||
if ($this->isRead($topic,$player)) {
|
||||
return false;
|
||||
}
|
||||
$this->db->query("DELETE FROM af_read WHERE topic=$topic AND reader=$player");
|
||||
$this->db->query("INSERT INTO af_read(topic,reader)VALUES($topic,$player)");
|
||||
return true;
|
||||
}
|
||||
|
||||
function markUnread($topic, $player) {
|
||||
$this->db->query("DELETE FROM af_read WHERE topic=$topic AND reader<>$player");
|
||||
}
|
||||
|
||||
function switchSticky($forum, $topic) {
|
||||
$this->db->query("UPDATE af_topic SET sticky=NOT sticky WHERE id=$topic AND forum=$forum");
|
||||
}
|
||||
|
||||
function markForumRead($fid, $pid) {
|
||||
$q = $this->db->query("SELECT id FROM af_topic WHERE forum=$fid");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$this->markRead($r[0], $pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
31
scripts/game/beta5/forums/library/deletePost.inc
Normal file
31
scripts/game/beta5/forums/library/deletePost.inc
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_deletePost {
|
||||
|
||||
function beta5_forums_deletePost($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($postId) {
|
||||
$q = $this->db->query(
|
||||
"SELECT f.id AS forum, t.id AS topic, reply_to FROM af_post p, af_forum f, af_topic t "
|
||||
. "WHERE p.id = $postId AND t.id = p.topic AND f.id = p.forum "
|
||||
. "FOR UPDATE OF p, f, t"
|
||||
);
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($fid,$tid,$rtid) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE af_post SET reply_to=$rtid WHERE reply_to=$postId");
|
||||
$this->db->query("UPDATE af_forum SET posts=posts-1 WHERE id=$fid");
|
||||
$this->db->query("DELETE FROM af_post WHERE id=$postId");
|
||||
$q = $this->db->query("SELECT id FROM af_post WHERE topic=$tid ORDER BY moment DESC LIMIT 1");
|
||||
list($lastid) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE af_topic SET last_post=$lastid WHERE id=$tid");
|
||||
$this->lib->call('updateLast', $fid);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
26
scripts/game/beta5/forums/library/deleteTopic.inc
Normal file
26
scripts/game/beta5/forums/library/deleteTopic.inc
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_deleteTopic {
|
||||
|
||||
function beta5_forums_deleteTopic($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($forum, $topic) {
|
||||
$q = $this->db->query(
|
||||
"SELECT t.id, f.id, p.id FROM af_post p, af_topic t, af_forum f "
|
||||
. "WHERE p.forum = $forum AND p.topic = $topic AND t.id = p.topic AND f.id = p.forum "
|
||||
. "FOR UPDATE OF p, t, f"
|
||||
);
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
$np = dbCount($q);
|
||||
$this->db->query("DELETE FROM af_post WHERE topic=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE af_forum SET posts=posts-$np,topics=topics-1 WHERE id=$forum");
|
||||
$this->lib->call('updateLast', $forum);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
23
scripts/game/beta5/forums/library/edit.inc
Normal file
23
scripts/game/beta5/forums/library/edit.inc
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_edit {
|
||||
|
||||
function beta5_forums_edit($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($a, $pid, $sub, $txt, $ec, $es) {
|
||||
$tm = time();
|
||||
$q = $this->db->query("SELECT topic FROM af_post WHERE id=$pid");
|
||||
list($tid) = dbFetchArray($q);
|
||||
$this->lib->call('markUnread', $tid,$a);
|
||||
$qs = "UPDATE af_post SET edited=$tm,edited_by=$a,title='".addslashes($sub)."',contents='"
|
||||
.addslashes($txt)."',enable_code=".dbBool($ec).",enable_smileys="
|
||||
. dbBool($es) . " WHERE id=$pid";
|
||||
return !is_null($this->db->query($qs));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
43
scripts/game/beta5/forums/library/getLatest.inc
Normal file
43
scripts/game/beta5/forums/library/getLatest.inc
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getLatest {
|
||||
|
||||
function beta5_forums_getLatest($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
|
||||
function run($aForums, $gForums, $nb, $first) {
|
||||
if (count($aForums) && count($gForums)) {
|
||||
$qs = "SELECT 'A',id,moment FROM af_post WHERE forum IN (".join(',',$aForums).")";
|
||||
$qs .= "UNION SELECT 'G',id,moment FROM f_post WHERE forum IN (".join(',',$gForums).") AND deleted IS NULL ";
|
||||
} elseif (count($aForums)) {
|
||||
$qs = "SELECT 'A',id,moment FROM af_post WHERE forum IN (".join(',',$aForums).") ";
|
||||
} elseif (count($gForums)) {
|
||||
$qs = "SELECT 'G',id,moment FROM f_post WHERE forum IN (".join(',',$gForums).") AND deleted IS NULL ";
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
$qs .= "ORDER BY moment DESC LIMIT $nb OFFSET $first";
|
||||
|
||||
$q = $this->db->query($qs);
|
||||
$posts = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
if ($r[0] == 'A') {
|
||||
$p = $this->lib->call('getPost', $r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
} else {
|
||||
$p = $this->mForums->call('getPost',$r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
}
|
||||
$p['ctype'] = $r[0];
|
||||
array_push($posts, $p);
|
||||
}
|
||||
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
46
scripts/game/beta5/forums/library/getPost.inc
Normal file
46
scripts/game/beta5/forums/library/getPost.inc
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getPost {
|
||||
|
||||
function beta5_forums_getPost($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
|
||||
function run($pid) {
|
||||
// Get post data
|
||||
$q = $this->db->query(
|
||||
"SELECT p.id AS id,p.title AS title,"
|
||||
. "t.id AS tid,p2.title AS tname,"
|
||||
. "f.id AS fid,f.title AS fname,"
|
||||
. "c.id AS cid,c.name AS cname,"
|
||||
. "p.author AS pid,p.reply_to as reply_to,"
|
||||
. "p.moment AS moment,p.title AS title,"
|
||||
. "p.contents AS contents,p.enable_code AS ec,"
|
||||
. "p.enable_smileys AS es,p.edited AS edited,"
|
||||
. "p.edited_by AS edit_id "
|
||||
. "FROM af_topic t,af_post p,af_post p2,af_forum f,alliance c "
|
||||
. "WHERE p.id=$pid AND t.id=p.topic AND p2.id=t.first_post "
|
||||
. "AND f.id=p.forum AND c.id=f.alliance"
|
||||
);
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return null;
|
||||
}
|
||||
$rv = dbFetchHash($q);
|
||||
$rv['html'] = $this->mForums->call('substitute',
|
||||
$rv['contents'], $rv['ec'], $rv['es']
|
||||
);
|
||||
$pinf = $this->players->call('get', $rv['pid'], true);
|
||||
$rv['html'] .= $this->mForums->call('signature', $pinf['uid']);
|
||||
$rv['author'] = $pinf['name'];
|
||||
if (!is_null($rv['edit_id'])) {
|
||||
$rv['edited_by'] = $this->players->call('getName', $rv['edit_id'], true);
|
||||
}
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
113
scripts/game/beta5/forums/library/getPosts.inc
Normal file
113
scripts/game/beta5/forums/library/getPosts.inc
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getPosts {
|
||||
|
||||
function beta5_forums_getPosts($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
|
||||
function run($tid, $thr, $o, $cnt, $fst) {
|
||||
$os = $o?"DESC":"ASC";
|
||||
$posts = array();
|
||||
|
||||
// FIXME: this is the wrong way to access player ID
|
||||
$myId = $_SESSION[game::sessName()]['player'];
|
||||
if ($thr) {
|
||||
// Read list of IDs
|
||||
$q = $this->db->query(
|
||||
"SELECT id,reply_to FROM af_post WHERE topic=$tid ORDER BY moment $os"
|
||||
);
|
||||
$ids = array();
|
||||
while ($qr = dbFetchArray($q)) {
|
||||
array_push($ids, $qr);
|
||||
}
|
||||
|
||||
// Get first post
|
||||
if ($o) {
|
||||
$mp = array_pop($ids);
|
||||
} else {
|
||||
$mp = array_shift($ids);
|
||||
}
|
||||
|
||||
// Initialize IDs and depths
|
||||
$sids = array($mp[0]);
|
||||
$dpth = array(0);
|
||||
|
||||
// Create lists
|
||||
$ist = array($mp[0]);
|
||||
$cd = 0;
|
||||
while (count($ids)) {
|
||||
$od = $cd;
|
||||
for ($i=0;$i<count($ids)&&$od==$cd;$i++) {
|
||||
if ($ids[$i][1] != $ist[$cd]) {
|
||||
continue;
|
||||
}
|
||||
array_push($ist, $ids[$i][0]);
|
||||
array_push($sids, $ids[$i][0]);
|
||||
array_splice($ids, $i, 1);
|
||||
array_push($dpth, $cd);
|
||||
$cd++;
|
||||
}
|
||||
if ($cd == $od) {
|
||||
$cd--;
|
||||
array_pop($ist);
|
||||
}
|
||||
}
|
||||
|
||||
$rsids = array_splice($sids, $fst, $cnt);
|
||||
$q = $this->db->query(
|
||||
"SELECT id,author AS pid,moment,title,contents,enable_code AS ec,"
|
||||
. "enable_smileys AS es,edited,edited_by AS edit_id "
|
||||
. "FROM af_post WHERE id IN (".join(',',$rsids).")"
|
||||
);
|
||||
while ($qr = dbFetchHash($q)) {
|
||||
$pinf = $this->players->call('get', $qr['pid'], true);
|
||||
$qr['author'] = $pinf['name'];
|
||||
$qr['mine'] = ($qr['pid'] == $myId);
|
||||
$qr['contents'] = $this->mForums->call('substitute',
|
||||
$qr['contents'], $qr['ec'], $qr['es']
|
||||
);
|
||||
$qr['contents'] .= $this->mForums->call('signature', $pinf['uid']);
|
||||
$i = array_search($qr['id'], $rsids);
|
||||
$qr['depth'] = $dpth[$i+$fst];
|
||||
if ($qr['depth'] > 9) {
|
||||
$qr['depth'] = 9;
|
||||
}
|
||||
if (!is_null($qr['edit_id'])) {
|
||||
$qr['edited_by'] = $this->players->call('getName', $qr['edit_id']);
|
||||
}
|
||||
$posts[$i] = $qr;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$q = $this->db->query(
|
||||
"SELECT id,author AS pid,moment,title,contents,enable_code AS ec,"
|
||||
. "enable_smileys AS es,edited,edited_by AS edit_id "
|
||||
. "FROM af_post WHERE topic=$tid "
|
||||
. "ORDER BY moment $os LIMIT $cnt OFFSET $fst"
|
||||
);
|
||||
while ($qr = dbFetchHash($q)) {
|
||||
$pinf = $this->players->call('get', $qr['pid'], true);
|
||||
$qr['mine'] = ($qr['pid'] == $myId);
|
||||
$qr['author'] = $pinf['name'];
|
||||
$qr['contents'] = $this->mForums->call('substitute',
|
||||
$qr['contents'], $qr['ec'], $qr['es']
|
||||
);
|
||||
$qr['contents'] .= $this->mForums->call('signature', $pinf['uid']);
|
||||
$qr['depth'] = 0;
|
||||
if (!is_null($qr['edit_id'])) {
|
||||
$qr['edited_by'] = $this->players->call('getName', $qr['edit_id']);
|
||||
}
|
||||
array_push($posts, $qr);
|
||||
}
|
||||
}
|
||||
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
98
scripts/game/beta5/forums/library/getStructure.inc
Normal file
98
scripts/game/beta5/forums/library/getStructure.inc
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getStructure {
|
||||
|
||||
function beta5_forums_getStructure($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->alliance = $this->lib->game->getLib('beta5/alliance');
|
||||
$this->account = $this->lib->game->getLib('main/account');
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
|
||||
function run($player) {
|
||||
$rv = array();
|
||||
$ord = 0;
|
||||
$pi = $this->players->call('get', $player);
|
||||
$isAdm = $this->account->call('isAdmin', $pi['uid']);
|
||||
$gAdm = $this->mForums->call('getAdministrator', $pi['uid']);
|
||||
$gMod = $this->mForums->call('getModerator', $pi['uid']);
|
||||
|
||||
// Get categories for general forums
|
||||
$gCats = $this->mForums->call('getCategories');
|
||||
foreach ($gCats as $gc) {
|
||||
$rv['G#'.$gc['id']] = array(
|
||||
"id" => $gc['id'],
|
||||
"type" => "G",
|
||||
"title" => $gc['title'],
|
||||
"desc" => $gc['description'],
|
||||
"order" => $ord ++,
|
||||
"forums" => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Get version-specific general category
|
||||
$vCat = $this->mForums->call('getVersionCategory', 'beta5');
|
||||
if ($vCat) {
|
||||
$rv['G#'.$vCat['id']] = array(
|
||||
"id" => $vCat['id'],
|
||||
"type" => "V",
|
||||
"title" => "Legacy Worlds - Beta 5",
|
||||
"desc" => $vCat['description'],
|
||||
"order" => $ord ++,
|
||||
"forums" => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Get general forums
|
||||
$gCats = array_keys($rv);
|
||||
foreach ($gCats as $cid) {
|
||||
$rcid = substr($cid,2);
|
||||
$rv[$cid]['forums'] = $this->mForums->call('getForums', $rcid);
|
||||
$foDiff = 0;
|
||||
for ($i=0;$i<count($rv[$cid]['forums']);$i++) {
|
||||
if (!$isAdm && $rv[$cid]['forums'][$i]['admin_only']) {
|
||||
array_splice($rv[$cid]['forums'], $i, 1);
|
||||
$i --;
|
||||
$foDiff ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = $rv[$cid]['forums'][$i]['id'];
|
||||
$rv[$cid]['forums'][$i]['unread'] = $rv[$cid]['forums'][$i]['topics'] - $this->mForums->call('getRead', $id, $pi['uid']);
|
||||
$rv[$cid]['forums'][$i]['mod'] = in_array($rv[$cid]['id'], $gAdm) || in_array($id, $gMod);
|
||||
$rv[$cid]['forums'][$i]['forder'] -= $foDiff;
|
||||
}
|
||||
}
|
||||
|
||||
// Get alliance forums
|
||||
$ap = $this->alliance->call('getPrivileges', $player);
|
||||
if (count($ap['f_read']) || count($ap['f_mod'])) {
|
||||
$rv['A#'.$pi['aid']] = array(
|
||||
"id" => $pi['aid'],
|
||||
"type" => "A",
|
||||
"title" => $pi['aname'],
|
||||
"order" => $ord ++,
|
||||
"forums" => array()
|
||||
);
|
||||
|
||||
$fl = $this->alliance->call('getForumsComplete', $pi['aid']);
|
||||
$rcid = 'A#'.$pi['aid'];
|
||||
foreach ($fl as $f) {
|
||||
if (!(in_array($f['id'],$ap['f_read']) || in_array($f['id'],$ap['f_mod']))) {
|
||||
continue;
|
||||
}
|
||||
$f['mod'] = in_array($f['id'],$ap['f_mod']);
|
||||
$f['unread'] = $f['topics'] - $this->lib->call('getRead', $f['id'], $player);
|
||||
$f['rcid'] = $rcid;
|
||||
array_push($rv[$rcid]['forums'],$f);
|
||||
}
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
32
scripts/game/beta5/forums/library/getTopic.inc
Normal file
32
scripts/game/beta5/forums/library/getTopic.inc
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getTopic {
|
||||
|
||||
function beta5_forums_getTopic($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($tid) {
|
||||
// Get main topic data
|
||||
$q = $this->db->query(
|
||||
"SELECT t.id AS id,p.title AS title,"
|
||||
. "f.id AS fid,f.title AS fname,"
|
||||
. "p.id AS fpid,t.last_post AS lpid "
|
||||
. "FROM af_topic t,af_post p,af_forum f "
|
||||
. "WHERE t.id=$tid AND p.id=t.first_post AND f.id=t.forum"
|
||||
);
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return null;
|
||||
}
|
||||
$rv = dbFetchHash($q);
|
||||
|
||||
// Get post count
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM af_post WHERE topic=$tid");
|
||||
list($rv["nitems"]) = dbFetchArray($q);
|
||||
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
37
scripts/game/beta5/forums/library/getTopics.inc
Normal file
37
scripts/game/beta5/forums/library/getTopics.inc
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_getTopics {
|
||||
|
||||
function beta5_forums_getTopics($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
}
|
||||
|
||||
|
||||
function run($f, $first, $count) {
|
||||
$q = $this->db->query(
|
||||
"SELECT t.id AS id,p.title AS title,p.moment AS moment,"
|
||||
. "p.author AS author_id,p2.moment AS last_moment,"
|
||||
. "p2.author AS last_author_id,t.sticky AS sticky "
|
||||
. "FROM af_topic t,af_post p,af_post p2 "
|
||||
. "WHERE t.forum=$f AND p.id=t.first_post AND p2.id=t.last_post "
|
||||
. "ORDER BY sticky DESC,last_moment DESC LIMIT $count OFFSET $first"
|
||||
);
|
||||
$a = array();
|
||||
if (!$q) {
|
||||
return $a;
|
||||
}
|
||||
while ($rs = dbFetchHash($q)) {
|
||||
$q2 = $this->db->query("SELECT COUNT(*)-1 FROM af_post WHERE topic=".$rs["id"]);
|
||||
list($rs['posts']) = dbFetchArray($q2);
|
||||
$rs['sticky'] = ($rs['sticky'] == 't');
|
||||
$rs['author'] = $this->players->call('getName', $rs['author_id']);
|
||||
$rs['last_author'] = $this->players->call('getName', $rs['last_author_id']);
|
||||
array_push($a, $rs);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
29
scripts/game/beta5/forums/library/moveTopic.inc
Normal file
29
scripts/game/beta5/forums/library/moveTopic.inc
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_moveTopic {
|
||||
|
||||
function beta5_forums_moveTopic($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($forum, $topic, $dest, $user) {
|
||||
$this->db->query("SELECT * FROM af_forum WHERE id IN ($forum,$dest) FOR UPDATE");
|
||||
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM af_post WHERE forum=$forum AND topic=$topic");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($np) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE af_post SET forum=$dest WHERE topic=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE af_topic SET forum=$dest WHERE id=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE af_forum SET posts=posts-$np,topics=topics-1 WHERE id=$forum");
|
||||
$this->db->query("UPDATE af_forum SET posts=posts+$np,topics=topics+1 WHERE id=$dest");
|
||||
$this->lib->call('markUnread', $topic, $user);
|
||||
$this->lib->call('updateLast', $forum);
|
||||
$this->lib->call('updateLast', $dest);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
39
scripts/game/beta5/forums/library/newTopic.inc
Normal file
39
scripts/game/beta5/forums/library/newTopic.inc
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_newTopic {
|
||||
|
||||
function beta5_forums_newTopic($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($a, $fid, $sub, $txt, $ec, $es, $st) {
|
||||
$tm = time();
|
||||
$qs = "INSERT INTO af_post(forum,author,moment,title,contents,enable_code,enable_smileys) VALUES ("
|
||||
. "$fid,$a,$tm,'".addslashes($sub)."','".addslashes($txt)."',"
|
||||
. dbBool($ec) . "," . dbBool($es) . ")";
|
||||
if (!$this->db->query($qs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT id FROM af_post WHERE forum=$fid AND topic IS NULL AND author=$a AND moment=$tm");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($pid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("INSERT INTO af_topic(forum,first_post,last_post,sticky) VALUES($fid,$pid,$pid," . ($st?"TRUE":"FALSE") . ")");
|
||||
$q = $this->db->query("SELECT id FROM af_topic WHERE forum=$fid AND first_post=$pid");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($tid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("UPDATE af_post SET topic=$tid WHERE id=$pid");
|
||||
$this->db->query("UPDATE af_forum SET topics=topics+1,posts=posts+1,last_post=$pid WHERE id=$fid");
|
||||
$this->lib->call('markRead', $tid, $a);
|
||||
return $pid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
34
scripts/game/beta5/forums/library/reply.inc
Normal file
34
scripts/game/beta5/forums/library/reply.inc
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_reply {
|
||||
|
||||
function beta5_forums_reply($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($a, $post, $sub, $txt, $ec, $es) {
|
||||
$tm = time();
|
||||
$fid = $post['fid']; $tid = $post['tid']; $pid = $post['id'];
|
||||
$qs = "INSERT INTO af_post(forum,topic,reply_to,author,moment,title,contents,enable_code,enable_smileys) VALUES ("
|
||||
. "$fid,$tid,$pid,$a,$tm,'".addslashes($sub)."','".addslashes($txt)."',"
|
||||
. dbBool($ec) . "," . dbBool($es) . ")";
|
||||
if (!$this->db->query($qs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$q = $this->db->query("SELECT id FROM af_post WHERE topic=$tid AND reply_to=$pid AND author=$a AND moment=$tm");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($pid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("UPDATE af_topic SET last_post=$pid WHERE id=$tid");
|
||||
$this->db->query("UPDATE af_forum SET posts=posts+1,last_post=$pid WHERE id=$fid");
|
||||
$this->lib->call('markUnread', $tid,$a);
|
||||
return $pid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
41
scripts/game/beta5/forums/library/searchPosts.inc
Normal file
41
scripts/game/beta5/forums/library/searchPosts.inc
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_searchPosts {
|
||||
|
||||
function beta5_forums_searchPosts($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
function run($aForums, $gForums, $nb, $first, $text, $complete, $sField, $sOrder) {
|
||||
$tQs = " AND (title ILIKE '$text'" . ($complete ? " OR contents ILIKE '$text'" : "") . ")";
|
||||
if (count($aForums) && count($gForums)) {
|
||||
$qs = "SELECT 'A',id,$sField FROM af_post WHERE forum IN (".join(',',$aForums).") $tQs ";
|
||||
$qs .= "UNION SELECT 'G',id,$sField FROM f_post WHERE forum IN (".join(',',$gForums).") AND deleted IS NULL $tQs ";
|
||||
} else if (count($aForums)) {
|
||||
$qs = "SELECT 'A',id,$sField FROM af_post WHERE forum IN (".join(',',$aForums).") $tQs ";
|
||||
} else {
|
||||
$qs = "SELECT 'G',id,$sField FROM f_post WHERE forum IN (".join(',',$gForums).") AND deleted IS NULL $tQs ";
|
||||
}
|
||||
$qs .= "ORDER BY $sField $sOrder LIMIT $nb OFFSET $first";
|
||||
|
||||
$q = $this->db->query($qs);
|
||||
$posts = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
if ($r[0] == 'A') {
|
||||
$p = $this->lib->call('getPost', $r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
} else {
|
||||
$p = $this->mForums->call('getPost',$r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
}
|
||||
$p['ctype'] = $r[0];
|
||||
array_push($posts, $p);
|
||||
}
|
||||
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
41
scripts/game/beta5/forums/library/searchTopics.inc
Normal file
41
scripts/game/beta5/forums/library/searchTopics.inc
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_searchTopics {
|
||||
|
||||
function beta5_forums_searchTopics($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->mForums = $this->lib->game->getLib('main/forums');
|
||||
}
|
||||
|
||||
function run($aForums, $gForums, $nb, $first, $text, $complete, $sField, $sOrder) {
|
||||
$tQs = "AND (title ILIKE '$text'" . ($complete ? " OR contents ILIKE '$text'" : "") . ")";
|
||||
if (count($aForums) && count($gForums)) {
|
||||
$qs = "SELECT 'A',topic,MAX($sField) AS $sField FROM af_post WHERE forum IN (".join(',',$aForums).") $tQs GROUP BY topic ";
|
||||
$qs .= "UNION SELECT 'G',topic,MAX($sField) AS $sField FROM f_post WHERE forum IN (".join(',',$gForums).") $tQs GROUP BY topic ";
|
||||
} else if (count($aForums)) {
|
||||
$qs = "SELECT 'A',topic,MAX($sField) AS $sField FROM af_post WHERE forum IN (".join(',',$aForums).") $tQs GROUP BY topic ";
|
||||
} else {
|
||||
$qs = "SELECT 'G',topic,MAX($sField) AS $sField FROM f_post WHERE forum IN (".join(',',$gForums).") $tQs GROUP BY topic ";
|
||||
}
|
||||
$qs .= " ORDER BY $sField $sOrder LIMIT $nb OFFSET $first";
|
||||
|
||||
$q = $this->db->query($qs);
|
||||
$topics = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
if ($r[0] == 'A') {
|
||||
$p = $this->lib->call('getTopic', $r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
} else {
|
||||
$p = $this->mForums->call('getTopic',$r[1]);
|
||||
$p['contents'] = $p['html'];
|
||||
}
|
||||
$p['ctype'] = $r[0];
|
||||
array_push($topics, $p);
|
||||
}
|
||||
|
||||
return $topics;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
21
scripts/game/beta5/forums/library/updateLast.inc
Normal file
21
scripts/game/beta5/forums/library/updateLast.inc
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class beta5_forums_updateLast {
|
||||
|
||||
function beta5_forums_updateLast($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($forum) {
|
||||
$q = $this->db->query("SELECT id FROM af_post WHERE forum=$forum ORDER BY moment DESC LIMIT 1");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($id) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE af_forum SET last_post=$id WHERE id=$forum");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue