最近公司网站 贵州都市网 准备升级.
在PHPWind8 和 Discuz!X 1.5之间纠结, 主要原因就是PHPWind8群组可以与论坛的板块关联而Discuz!X 1.5不能.
但纠结过后还是选择了Discuz!X 1.5, 群组与板块关联我们自己实现.
下面分享下我做的群组板块关联的实现.
打开/config/目录新建一个文件config_groupjoin.php
文件内容为
< ?php
$groupjoin = array(
36 => 2
// 群组id => 板块ID
);
打开/source/include/post/post_thread.php在大概520行左右找到
if($isgroup) {
DB::query("UPDATE ".DB::table('forum_groupuser')." SET threads=threads+1, lastupdate='".TIMESTAMP."' WHERE uid='$_G[uid]' AND fid='$_G[fid]'");
}
改为
if($isgroup) {
DB::query("UPDATE ".DB::table('forum_groupuser')." SET threads=threads+1, lastupdate='".TIMESTAMP."' WHERE uid='$_G[uid]' AND fid='$_G[fid]'");
include DISCUZ_ROOT . './config/config_groupjoin.php';
if (isset($groupjoin[$_G['fid']])) {
$moveto = $groupjoin[$_G['fid']];
DB::query("INSERT INTO ".DB::table('forum_thread')." (fid, posttableid, readperm, price, typeid, author, authorid, subject, dateline, lastpost, lastposter, displayorder, digest, special, attachment, moderated, replies, status, isgroup, closed)
VALUES ('$moveto', '$posttableid', '$readperm', '$price', '$typeid', '$author', '$_G[uid]', '$subject', '$_G[timestamp]', '$_G[timestamp]', '$author', '$displayorder', '$digest', '$special', '$attachment', '$moderated', '1', '$thread[status]', '1', '$tid')");
}
}
如果你的板块和群组能发表的主题类型一样, 则到此论坛与群组算是关联上了. 但人如果不同, 比如群组能发投票而板块不行, 那就请继续看下面.
打开/source/include/post/post_thread.php在大概520行左右找到
if($isgroup) {
DB::query("UPDATE ".DB::table('forum_groupuser')." SET threads=threads+1, lastupdate='".TIMESTAMP."' WHERE uid='$_G[uid]' AND fid='$_G[fid]'");
}
修改为
if($isgroup) {
DB::query("UPDATE ".DB::table('forum_groupuser')." SET threads=threads+1, lastupdate='".TIMESTAMP."' WHERE uid='$_G[uid]' AND fid='$_G[fid]'");
include DISCUZ_ROOT . './config/config_groupjoin.php';
if (isset($groupjoin[$_G['fid']])) {
$moveto = $groupjoin[$_G['fid']];
// 关联板块信息
$toforum = DB::fetch_first("SELECT f.fid, f.name, f.modnewposts, f.allowpostspecial, ff.threadplugin FROM ".DB::table('forum_forum')." f LEFT JOIN ".DB::table('forum_forumfield')." ff ON ff.fid=f.fid WHERE f.fid='$moveto' AND f.status='1' AND f.type<>'group'");
if(!$toforum || $_G['fid'] == $toforum['fid']) {
continue;
}
// 关联板块允许发表的特殊主题
$toforumallowspecial = array(
1 => $toforum['allowpostspecial'] & 1,
2 => $toforum['allowpostspecial'] & 2,
3 => isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($toforum['allowpostspecial'] & 4),
4 => $toforum['allowpostspecial'] & 8,
5 => $toforum['allowpostspecial'] & 16,
127 => $_G['setting']['threadplugins'] ? unserialize($toforum['threadplugin']) : array(),
);
// 系统自带的特殊主题
if($special != 127) {
$allowmove = $toforum['allowpostspecial'] ? $toforumallowspecial[$thread['special']] : 0;
} else {
// 特殊主题插件
if($toforumallowspecial['127']) {
$posttable = getposttablebytid($thread['tid']);
$message = DB::result_first("SELECT message FROM ".DB::table($posttable)." WHERE tid='$thread[tid]' AND first='1'");
$sppos = strrpos($message, chr(0).chr(0).chr(0));
$specialextra = substr($message, $sppos + 3);
$allowmove = in_array($specialextra, $toforumallowspecial[127]);
} else {
$allowmove = 0;
}
}
if($allowmove) {
DB::query("INSERT INTO ".DB::table('forum_thread')." (fid, posttableid, readperm, price, typeid, author, authorid, subject, dateline, lastpost, lastposter, displayorder, digest, special, attachment, moderated, replies, status, isgroup, closed)
VALUES ('$moveto', '$posttableid', '$readperm', '$price', '$typeid', '$author', '$_G[uid]', '$subject', '$_G[timestamp]', '$_G[timestamp]', '$author', '$displayorder', '$digest', '$special', '$attachment', '$moderated', '1', '$thread[status]', '1', '$tid')");
}
}
}
好了, 现在群组和板块关联已经搞定了.
Discuz!X 1.5其实已经自带了群组主题推送到板块这个功能, 只不过需要手动操作, 略显麻烦.
在查看其推送到板块的代码后发现其实就相当于将主题copy一份到forum_thread表, 不过fid变为推送到不板块的fid, tid自增, closed为原主题tid
根据这个思路, 建立一个配置文件, 在群组发表主题时判断该群组是否有关联, 之后copy一条数据就行了.
ok. 到此结束了, 我这正测试, 看看有没有啥不良反映, 大家如果发现了啥问题, 可以联系我.