Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
73
scripts/game/main/forums/library.inc
Normal file
73
scripts/game/main/forums/library.inc
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
class main_forums_library {
|
||||
var $index = array(
|
||||
'deletePost',
|
||||
'deleteTopic',
|
||||
'edit',
|
||||
'get',
|
||||
'getAdministrator',
|
||||
'getCategories',
|
||||
'getCategory',
|
||||
'getForums',
|
||||
'getModerator',
|
||||
'getPost',
|
||||
'getPosts',
|
||||
'getTopic',
|
||||
'getTopics',
|
||||
'move',
|
||||
'newTopic',
|
||||
'reply',
|
||||
'signature',
|
||||
'substitute',
|
||||
'updateLast',
|
||||
);
|
||||
|
||||
function main_forums_library($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function getVersionCategory($ver) {
|
||||
$q = $this->db->query("SELECT id,description FROM f_category WHERE title='!$ver!'");
|
||||
return dbFetchHash($q);
|
||||
}
|
||||
|
||||
function isRead($topic, $player) {
|
||||
$q = $this->db->query("SELECT * FROM f_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 f_read WHERE topic=$topic AND reader=$player");
|
||||
$this->db->query("INSERT INTO f_read(topic,reader)VALUES($topic,$player)");
|
||||
return true;
|
||||
}
|
||||
|
||||
function markUnread($topic, $player) {
|
||||
$this->db->query("DELETE FROM f_read WHERE topic=$topic AND reader<>$player");
|
||||
}
|
||||
|
||||
// Get the amount of unread topics in a forum
|
||||
function getRead($fid, $uid) {
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM f_read r,f_topic t WHERE t.id=r.topic AND t.forum=$fid AND r.reader=$uid AND t.deleted IS NULL");
|
||||
list($nr) = dbFetchArray($q);
|
||||
return $nr;
|
||||
}
|
||||
|
||||
function switchSticky($forum, $topic) {
|
||||
$this->db->query("UPDATE f_topic SET sticky=NOT sticky WHERE id=$topic AND forum=$forum AND deleted IS NULL");
|
||||
}
|
||||
|
||||
function markForumRead($fid, $uid) {
|
||||
$q = $this->db->query("SELECT id FROM f_topic WHERE forum=$fid AND deleted IS NULL");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$this->markRead($r[0], $uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
27
scripts/game/main/forums/library/deletePost.inc
Normal file
27
scripts/game/main/forums/library/deletePost.inc
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
class main_forums_deletePost {
|
||||
|
||||
function main_forums_deletePost($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($postId) {
|
||||
$q = $this->db->query("SELECT forum,topic,reply_to FROM f_post WHERE id=$postId AND deleted IS NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($fid,$tid,$rtid) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE f_post SET reply_to=$rtid WHERE reply_to=$postId");
|
||||
$this->db->query("UPDATE f_forum SET posts=posts-1 WHERE id=$fid");
|
||||
$this->db->query("UPDATE f_post SET deleted=" . time() . " WHERE id=$postId");
|
||||
$q = $this->db->query("SELECT id FROM f_post WHERE topic=$tid AND deleted IS NULL ORDER BY moment DESC LIMIT 1");
|
||||
list($lastid) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE f_topic SET last_post=$lastid WHERE id=$tid");
|
||||
$this->lib->call('updateLast', $fid);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
26
scripts/game/main/forums/library/deleteTopic.inc
Normal file
26
scripts/game/main/forums/library/deleteTopic.inc
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class main_forums_deleteTopic {
|
||||
|
||||
function main_forums_deleteTopic($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($forum, $topic) {
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM f_post WHERE forum=$forum AND topic=$topic AND deleted IS NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($np) = dbFetchArray($q);
|
||||
$tm = time();
|
||||
$this->db->query("UPDATE f_post SET deleted=$tm WHERE topic=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE f_topic SET deleted=$tm WHERE id=$topic");
|
||||
$this->db->query("UPDATE f_forum SET posts=posts-$np,topics=topics-1 WHERE id=$forum");
|
||||
$this->db->query("DELETE FROM f_read WHERE topic=$topic");
|
||||
$this->lib->call('updateLast', $forum);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
scripts/game/main/forums/library/edit.inc
Normal file
22
scripts/game/main/forums/library/edit.inc
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class main_forums_edit {
|
||||
|
||||
function main_forums_edit($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($a, $pid, $sub, $txt, $ec, $es) {
|
||||
$q = $this->db->query("SELECT topic FROM f_post WHERE id=$pid AND deleted IS NULL");
|
||||
list($tid) = dbFetchArray($q);
|
||||
$this->lib->call('markUnread', $tid,$a);
|
||||
$tm = time();
|
||||
$qs = "UPDATE f_post SET edited=$tm,edited_by=$a,title='".addslashes($sub)."',contents='"
|
||||
.addslashes($txt)."',enable_code=".dbBool($ec).",enable_smileys="
|
||||
. dbBool($es) . " WHERE id=$pid AND deleted IS NULL";
|
||||
return !is_null($this->db->query($qs));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
28
scripts/game/main/forums/library/get.inc
Normal file
28
scripts/game/main/forums/library/get.inc
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
class main_forums_get {
|
||||
|
||||
function main_forums_get($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($f) {
|
||||
$q = $this->db->query(
|
||||
"SELECT f.id AS id,f.title AS title,f.description AS description,"
|
||||
. "f.user_post AS user_post,f.topics AS ntopics,"
|
||||
. "c.id AS pid,c.title AS ptitle "
|
||||
. "FROM f_forum f,f_category c "
|
||||
. "WHERE f.id=$f AND c.id=f.category"
|
||||
);
|
||||
if (!$q||dbCount($q)!=1) {
|
||||
return null;
|
||||
}
|
||||
$a = dbFetchHash($q);
|
||||
$f['user_post'] = ($f['user_post'] == 't');
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
26
scripts/game/main/forums/library/getAdministrator.inc
Normal file
26
scripts/game/main/forums/library/getAdministrator.inc
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getAdministrator {
|
||||
|
||||
function main_forums_getAdministrator($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid) {
|
||||
$q = $this->db->query("SELECT category FROM f_admin WHERE \"user\"=$uid");
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
if (is_null($r[0])) {
|
||||
$q = $this->db->query("SELECT id FROM f_category");
|
||||
$a = array();
|
||||
} else {
|
||||
array_push($a, $r[0]);
|
||||
}
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
23
scripts/game/main/forums/library/getCategories.inc
Normal file
23
scripts/game/main/forums/library/getCategories.inc
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getCategories {
|
||||
|
||||
function main_forums_getCategories($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run() {
|
||||
$q = $this->db->query("SELECT id,title,description FROM f_category WHERE title NOT ILIKE '!%!' ORDER BY corder ASC");
|
||||
$a = array();
|
||||
if ($q) {
|
||||
while ($rs = dbFetchHash($q)) {
|
||||
array_push($a, $rs);
|
||||
}
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
20
scripts/game/main/forums/library/getCategory.inc
Normal file
20
scripts/game/main/forums/library/getCategory.inc
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getCategory {
|
||||
|
||||
function main_forums_getCategory($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($c) {
|
||||
$q = $this->db->query("SELECT id,title,description FROM f_category WHERE id=$c");
|
||||
if (!$q||dbCount($q)!=1) {
|
||||
return null;
|
||||
}
|
||||
return dbFetchHash($q);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
36
scripts/game/main/forums/library/getForums.inc
Normal file
36
scripts/game/main/forums/library/getForums.inc
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getForums {
|
||||
|
||||
function main_forums_getForums($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($c) {
|
||||
$q = $this->db->query("SELECT * FROM f_forum WHERE category=$c ORDER BY forder ASC");
|
||||
$a = array();
|
||||
if (!$q) {
|
||||
return $a;
|
||||
}
|
||||
while ($rs = dbFetchHash($q)) {
|
||||
if ($rs['last_post'] != "") {
|
||||
$q2 = $this->db->query(
|
||||
"SELECT u.name AS author,p.moment AS moment "
|
||||
. "FROM f_post p,account u "
|
||||
. "WHERE p.id=".$rs['last_post']." AND u.id=p.author"
|
||||
);
|
||||
$rs['last'] = dbFetchHash($q2);
|
||||
} else {
|
||||
$rs['last'] = null;
|
||||
}
|
||||
$rs['user_post'] = ($rs['user_post'] == 't');
|
||||
$rs['admin_only'] = ($rs['admin_only'] == 't');
|
||||
array_push($a, $rs);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
21
scripts/game/main/forums/library/getModerator.inc
Normal file
21
scripts/game/main/forums/library/getModerator.inc
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getModerator {
|
||||
|
||||
function main_forums_getModerator($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($uid) {
|
||||
$q = $this->db->query("SELECT forum FROM f_moderator WHERE \"user\"=$uid");
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
array_push($a, $r[0]);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
49
scripts/game/main/forums/library/getPost.inc
Normal file
49
scripts/game/main/forums/library/getPost.inc
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getPost {
|
||||
|
||||
function main_forums_getPost($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->accounts = $this->lib->game->getLib("main/account");
|
||||
}
|
||||
|
||||
|
||||
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.title AS cname,"
|
||||
. "p.author AS uid,u.name AS author,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 edited_by "
|
||||
. "FROM f_topic t,f_post p,f_post p2,f_forum f,f_category c,account u "
|
||||
. "WHERE p.id=$pid AND t.id=p.topic AND p2.id=t.first_post "
|
||||
. "AND f.id=p.forum AND c.id=f.category AND u.id=p.author "
|
||||
. "AND p.deleted IS NULL"
|
||||
);
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return null;
|
||||
}
|
||||
$rv = dbFetchHash($q);
|
||||
$rv['html'] = $this->lib->call('substitute',
|
||||
$rv['contents'], $rv['ec'], $rv['es']
|
||||
);
|
||||
$rv['html'] .= $this->lib->call('signature', $rv['uid']);
|
||||
|
||||
if (!is_null($rv['edited_by'])) {
|
||||
$rv['edited_by'] = $this->accounts->call('getUserName', $rv['edited_by']);
|
||||
}
|
||||
if (preg_match('/^!.*!$/', $rv['cname'])) {
|
||||
$game = config::getGame(preg_replace('/!/', '', $rv['cname']));
|
||||
$rv['cname'] = $all[$game->game['site_path']][1];
|
||||
}
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
117
scripts/game/main/forums/library/getPosts.inc
Normal file
117
scripts/game/main/forums/library/getPosts.inc
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getPosts {
|
||||
|
||||
function main_forums_getPosts($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->accounts = $this->lib->game->getLib("main/account");
|
||||
}
|
||||
|
||||
|
||||
function run($tid, $thr, $o, $cnt, $fst) {
|
||||
$os = $o?"DESC":"ASC";
|
||||
$posts = array();
|
||||
|
||||
if ($thr) {
|
||||
// Read list of IDs
|
||||
$q = $this->db->query(
|
||||
"SELECT id,reply_to FROM f_post WHERE topic=$tid AND deleted IS NULL 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 p.id AS id,p.author AS uid,u.name AS author,"
|
||||
. "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 "
|
||||
. "FROM f_post p,account u "
|
||||
. "WHERE p.id IN (".join(',',$rsids).") AND u.id=p.author "
|
||||
. "AND p.deleted IS NULL"
|
||||
);
|
||||
while ($qr = dbFetchHash($q)) {
|
||||
$qr['mine'] = ($qr['uid'] == $_SESSION['userid']);
|
||||
$qr['contents'] = $this->lib->call('substitute',
|
||||
$qr['contents'], $qr['ec'], $qr['es']
|
||||
);
|
||||
$qr['contents'] .= $this->lib->call('signature', $qr['uid']);
|
||||
$i = array_search($qr['id'], $rsids);
|
||||
$qr['depth'] = $dpth[$i+$fst];
|
||||
if ($qr['depth'] > 19) {
|
||||
$qr['depth'] = 19;
|
||||
}
|
||||
if (!is_null($qr['edited_by'])) {
|
||||
$qr['edited_by'] = $this->accounts->call('getUserName', $qr['edited_by']);
|
||||
}
|
||||
$posts[$i] = $qr;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$q = $this->db->query(
|
||||
"SELECT p.id AS id,p.author AS uid,u.name AS author,"
|
||||
. "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 edited_by "
|
||||
. "FROM f_post p,account u "
|
||||
. "WHERE p.topic=$tid AND u.id=p.author "
|
||||
. "AND p.deleted IS NULL "
|
||||
. "ORDER BY p.moment $os "
|
||||
. "LIMIT $cnt OFFSET $fst"
|
||||
);
|
||||
while ($qr = dbFetchHash($q)) {
|
||||
$qr['mine'] = ($qr['uid'] == $_SESSION['userid']);
|
||||
$qr['contents'] = $this->lib->call('substitute',
|
||||
$qr['contents'], $qr['ec'], $qr['es']
|
||||
);
|
||||
$qr['contents'] .= $this->lib->call('signature', $qr['uid']);
|
||||
$qr['depth'] = 0;
|
||||
if (!is_null($qr['edited_by'])) {
|
||||
$qr['edited_by'] = $this->accounts->call('getUserName', $qr['edited_by']);
|
||||
}
|
||||
array_push($posts, $qr);
|
||||
}
|
||||
}
|
||||
|
||||
return $posts;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
36
scripts/game/main/forums/library/getTopic.inc
Normal file
36
scripts/game/main/forums/library/getTopic.inc
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getTopic {
|
||||
|
||||
function main_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,"
|
||||
. "p.id AS fpid,t.last_post AS lpid,"
|
||||
. "f.id AS fid,f.title AS fname,"
|
||||
. "c.id AS cid,c.title AS cname "
|
||||
. "FROM f_topic t,f_post p,f_forum f,f_category c "
|
||||
. "WHERE t.id=$tid AND p.id=t.first_post "
|
||||
. "AND f.id=t.forum AND c.id=f.category "
|
||||
. "AND t.deleted IS NULL"
|
||||
);
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return null;
|
||||
}
|
||||
$rv = dbFetchHash($q);
|
||||
|
||||
// Get post count
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM f_post WHERE topic=$tid AND deleted IS NULL");
|
||||
list($rv["nitems"]) = dbFetchArray($q);
|
||||
|
||||
return $rv;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
33
scripts/game/main/forums/library/getTopics.inc
Normal file
33
scripts/game/main/forums/library/getTopics.inc
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class main_forums_getTopics {
|
||||
|
||||
function main_forums_getTopics($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($f, $first, $count) {
|
||||
$q = $this->db->query(
|
||||
"SELECT t.id AS id,p.title AS title,p.moment AS moment,"
|
||||
. "u.name AS author,p2.moment AS last_moment,"
|
||||
. "u2.name AS last_author,t.sticky AS sticky "
|
||||
. "FROM f_topic t,f_post p,account u,f_post p2,account u2 "
|
||||
. "WHERE t.forum=$f AND p.id=t.first_post AND u.id=p.author "
|
||||
. "AND p2.id=t.last_post AND u2.id=p2.author "
|
||||
. "AND t.deleted IS NULL "
|
||||
. "ORDER BY sticky DESC,last_moment DESC LIMIT $count OFFSET $first"
|
||||
);
|
||||
$a = array();
|
||||
while ($q && $rs = dbFetchHash($q)) {
|
||||
$q2 = $this->db->query("SELECT COUNT(*) - 1 FROM f_post WHERE topic={$rs["id"]} AND deleted IS NULL");
|
||||
list($rs['posts']) = dbFetchArray($q2);
|
||||
$rs['sticky'] = ($rs['sticky'] == 't');
|
||||
array_push($a, $rs);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
29
scripts/game/main/forums/library/move.inc
Normal file
29
scripts/game/main/forums/library/move.inc
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class main_forums_move {
|
||||
|
||||
function main_forums_move($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($forum, $topic, $dest, $user) {
|
||||
$this->db->query("SELECT * FROM f_forum WHERE id IN ($forum,$dest) FOR UPDATE");
|
||||
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM f_post WHERE forum=$forum AND topic=$topic AND deleted IS NULL");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($np) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE f_post SET forum=$dest WHERE topic=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE f_topic SET forum=$dest WHERE id=$topic AND forum=$forum");
|
||||
$this->db->query("UPDATE f_forum SET posts=posts-$np,topics=topics-1 WHERE id=$forum");
|
||||
$this->db->query("UPDATE f_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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
41
scripts/game/main/forums/library/newTopic.inc
Normal file
41
scripts/game/main/forums/library/newTopic.inc
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class main_forums_newTopic {
|
||||
|
||||
function main_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 f_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 f_post WHERE forum=$fid AND topic IS NULL AND author=$a AND moment=$tm ORDER BY id DESC LIMIT 1");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($pid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("INSERT INTO f_topic(forum,first_post,last_post,sticky) VALUES($fid,$pid,$pid,"
|
||||
. dbBool($st) . ")");
|
||||
$q = $this->db->query("SELECT id FROM f_topic WHERE forum=$fid AND first_post=$pid");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($tid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("UPDATE f_post SET topic=$tid WHERE id=$pid");
|
||||
$this->db->query("UPDATE f_forum SET topics=topics+1,posts=posts+1,last_post=$pid WHERE id=$fid");
|
||||
$this->lib->call('markRead', $tid, $a);
|
||||
return $pid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
33
scripts/game/main/forums/library/reply.inc
Normal file
33
scripts/game/main/forums/library/reply.inc
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class main_forums_reply {
|
||||
|
||||
function main_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 f_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 f_post WHERE topic=$tid AND reply_to=$pid AND author=$a AND moment=$tm ORDER BY id DESC LIMIT 1");
|
||||
if (!$q || dbCount($q) != 1) {
|
||||
return false;
|
||||
}
|
||||
list($pid) = dbFetchArray($q);
|
||||
|
||||
$this->db->query("UPDATE f_topic SET last_post=$pid WHERE id=$tid");
|
||||
$this->db->query("UPDATE f_forum SET posts=posts+1,last_post=$pid WHERE id=$fid");
|
||||
$this->lib->call('markUnread', $tid,$a);
|
||||
return $pid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
39
scripts/game/main/forums/library/signature.inc
Normal file
39
scripts/game/main/forums/library/signature.inc
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
class main_forums_signature {
|
||||
var $signatures = array();
|
||||
|
||||
function main_forums_signature($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($u) {
|
||||
if (is_array($this->signatures)) {
|
||||
if ($this->signatures[$u] != "")
|
||||
return $this->signatures[$u];
|
||||
} else {
|
||||
$this->signatures = array();
|
||||
}
|
||||
$q = $this->db->query(
|
||||
"SELECT id,value FROM user_preferences "
|
||||
. "WHERE account IN (0,$u) "
|
||||
. "AND id IN ('forums_sig','forum_code','smileys') "
|
||||
. "AND version='main' "
|
||||
. "ORDER BY account"
|
||||
);
|
||||
$p = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$p[$r[0]] = $r[1];
|
||||
}
|
||||
if ($p["forums_sig"] == "") {
|
||||
$s = "";
|
||||
} else {
|
||||
$s = "<div class='fsig'><hr/>" . $this->lib->call('substitute', $p['forums_sig'], $p['forum_code'] ? 't' : 'f', $p['smileys'] ? 't' : 'f') . "</div>";
|
||||
}
|
||||
return ($this->signatures[$u] = $s);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
60
scripts/game/main/forums/library/substitute.inc
Normal file
60
scripts/game/main/forums/library/substitute.inc
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
class main_forums_substitute {
|
||||
var $code = null;
|
||||
var $smiley = null;
|
||||
|
||||
function main_forums_substitute($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
function run($text, $ec, $es) {
|
||||
$src = array('/\\n/','/\\r/'); $dst = array("<br/>",'');
|
||||
$text = utf8entities($text, ENT_NOQUOTES);
|
||||
$ec = ($ec == 't');
|
||||
$es = ($es == 't');
|
||||
|
||||
if ($ec) {
|
||||
if (is_array($this->code)) {
|
||||
foreach ($this->code as $s => $d) {
|
||||
array_push($src, '/'.$s.'/i');
|
||||
array_push($dst, $d);
|
||||
}
|
||||
} else {
|
||||
$this->codes = array();
|
||||
$q = $this->db->query("SELECT * FROM f_code");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$this->code[$r[0]] = $r[1];
|
||||
array_push($src, '/'.$r[0].'/i');
|
||||
array_push($dst, $r[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($es) {
|
||||
if (is_array($this->smiley)) {
|
||||
foreach ($this->smiley as $s => $d) {
|
||||
array_push($src, '/'.$s.'/i');
|
||||
array_push($dst, $d);
|
||||
}
|
||||
} else {
|
||||
$this->smiley = array();
|
||||
$q = $this->db->query("SELECT * FROM f_smiley");
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$fn = getStatic("main/pics/smiles/icon_".$r[1].".gif");
|
||||
if (is_null($fn)) {
|
||||
continue;
|
||||
}
|
||||
$code = "<img src='$fn' alt='[S]' />";
|
||||
$this->smiley[$r[0]] = $code;
|
||||
array_push($src, '/'.$r[0].'/i');
|
||||
array_push($dst, $code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return preg_replace($src, $dst, $text);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
21
scripts/game/main/forums/library/updateLast.inc
Normal file
21
scripts/game/main/forums/library/updateLast.inc
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class main_forums_updateLast {
|
||||
|
||||
function main_forums_updateLast($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
function run($forum) {
|
||||
$q = $this->db->query("SELECT id FROM f_post WHERE forum=$forum AND deleted IS NULL ORDER BY moment DESC LIMIT 1");
|
||||
if (!($q && dbCount($q))) {
|
||||
return;
|
||||
}
|
||||
list($id) = dbFetchArray($q);
|
||||
$this->db->query("UPDATE f_forum SET last_post=$id WHERE id=$forum");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue