Discuz 完美集成進(jìn)現(xiàn)有系統(tǒng)(整合用戶和版面增刪)
發(fā)布時間:2011-07-13 00:46:08 作者:佚名
我要評論

之前寫過《【Discuz】自動同步登陸的完美解決辦法》,主要是解決Discuz的同步登陸問題,用戶系統(tǒng)是采用UCenter進(jìn)行管理的。
最近的一次應(yīng)用是基本完成了業(yè)務(wù)系統(tǒng),需要整合Discuz進(jìn)去作為交流版塊使用。于是,涉及到用戶系統(tǒng)的整合和版面的增刪操作。UCenter提供了API進(jìn)行用戶的增刪管理,自然可以用,但為了保證用戶id的統(tǒng)一性,暴力地繞過了UCenter API,而采用直接操作數(shù)據(jù)庫的方式來完成用戶增刪,當(dāng)然版面的增刪也是操作數(shù)據(jù)庫來完成。
1、增加用戶到Discuz和UCenter的代碼
$uid = 100; // 用戶編號
$username = "maple"; // 用戶名
$password = "mypassword"; // 用戶密碼
$salt = md5((string)rand()); // 隨機(jī)字符用于加密
$password = md5(md5($pwd) . $salt); // 加密后的密碼
$groupid = 10; // 用戶組編號
$timestamp = time(); // 時間戳
$bbsemail = "i@witmax.cn"; // 注冊郵箱,不能重復(fù)
execute_sql("INSERT INTO cdb_members (uid, username, password, secques, gender, adminid, groupid, regip, regdate, lastvisit, lastactivity, posts, credits, email, bday, sigstatus, tpp, ppp, styleid, dateformat, timeformat, showemail, newsletter, invisible, timeoffset) VALUES ('$uid', '$username', '$salt', '$password', '0', '0', '$groupid', 'Manual Acting', '$timestamp', '$timestamp', '$timestamp', '0', '0', '$bbsemail', '0000-00-00', '0', '0', '0', '0', '0', 'H:i', '1', '1', '0', '8')");
execute_sql("INSERT INTO cdb_memberfields (uid) VALUES ('$uid')");
execute_sql("INSERT INTO `cdb_uc_members` SET uid='$uid', username='$username', password='$password', email='$bbsemail', regip='Manual Acting', regdate='$timestamp', salt='$salt'");
2、在Discuz和UCenter中刪除用戶的代碼
$uid = 100; // 要刪除的用戶編號
execute_sql("DELETE FROM `cdb_members` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_memberfields` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_uc_members` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_uc_memberfields` WHERE uid=$uid");
3、在Discuz中增加版面并設(shè)置版主的代碼
$uid = 100; // 版主用戶編號
$fid = 100; // 版面編號,需要保證不與現(xiàn)有版面編號重復(fù)
$forum_name = "Test Forum"; // 版面名稱
execute_sql("INSERT INTO `cdb_forums` (`fid`, `fup`, `type`, `name`, `status`, `displayorder`, `styleid`, `threads`, `posts`, `todayposts`, `lastpost`, `allowsmilies`, `allowhtml`, `allowbbcode`, `allowimgcode`, `allowmediacode`, `allowanonymous`, `allowshare`, `allowpostspecial`, `allowspecialonly`, `alloweditrules`, `allowfeed`, `recyclebin`, `modnewposts`, `jammer`, `disablewatermark`, `inheritedmod`, `autoclose`, `forumcolumns`, `threadcaches`, `alloweditpost`, `simple`, `modworks`, `allowtag`, `allowglobalstick`) VALUES
('$fid', 3, 'forum', '$forum_name', 1, 0, 0, 0, 0, 0, '', 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);");
execute_sql("INSERT INTO `cdb_forumfields` (`fid`, `description`, `password`, `icon`, `postcredits`, `replycredits`, `getattachcredits`, `postattachcredits`, `digestcredits`, `redirect`, `attachextensions`, `formulaperm`, `moderators`, `rules`, `threadtypes`, `threadsorts`, `viewperm`, `postperm`, `replyperm`, `getattachperm`, `postattachperm`, `keywords`, `supe_pushsetting`, `modrecommend`, `tradetypes`, `typemodels`, `threadplugin`, `extra`) VALUES ('$fid', '', '', '', '', '', '', '', '', '', '', 'a:5:{i:0;s:0:\"\";i:1;s:0:\"\";s:5:\"medal\";N;s:7:\"message\";s:0:\"\";s:5:\"users\";s:0:\"\";}', '', '', '', '', ' 9 10 11 12 13 14 15 20 21 16 17 18 19 1 2 3 4 5 6 7 8 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', '', '', 'a:8:{s:4:\"open\";s:1:\"0\";s:3:\"num\";i:10;s:8:\"imagenum\";i:5;s:10:\"imagewidth\";i:200;s:11:\"imageheight\";i:150;s:9:\"maxlength\";i:0;s:9:\"cachelife\";i:900;s:8:\"dateline\";i:0;}', '', '', 'N;', 'a:1:{s:9:\"namecolor\";s:0:\"\";}');");
execute_sql("UPDATE cdb_members SET adminid='3' WHERE uid='$uid'");
execute_sql("INSERT INTO cdb_moderators (uid, fid, inherited) VALUES ('$uid', '$fid', '1')");
4、在Discuz中刪除版面并取消版主管理權(quán)限的代碼
$uid = 100; // 要刪除版面的版主用戶編號
$fid = 100; // 要刪除的版面編號
execute_sql("DELETE FROM cdb_forums WHERE fid='$fid'");
execute_sql("DELETE FROM cdb_forumfields WHERE fid='$fid'");
execute_sql("DELETE FROM cdb_moderators WHERE fid='$fid'");
execute_sql("UPDATE cdb_members SET adminid='0' WHERE uid='$uid'");
直接操作數(shù)據(jù)庫的好處是業(yè)務(wù)邏輯簡單,操作方便,與現(xiàn)有系統(tǒng)整合容易;缺點就是很流氓很暴力,需要保證操作數(shù)據(jù)的有效性,如增加的版面的fid要保證唯一。
1、增加用戶到Discuz和UCenter的代碼
復(fù)制代碼
代碼如下:$uid = 100; // 用戶編號
$username = "maple"; // 用戶名
$password = "mypassword"; // 用戶密碼
$salt = md5((string)rand()); // 隨機(jī)字符用于加密
$password = md5(md5($pwd) . $salt); // 加密后的密碼
$groupid = 10; // 用戶組編號
$timestamp = time(); // 時間戳
$bbsemail = "i@witmax.cn"; // 注冊郵箱,不能重復(fù)
execute_sql("INSERT INTO cdb_members (uid, username, password, secques, gender, adminid, groupid, regip, regdate, lastvisit, lastactivity, posts, credits, email, bday, sigstatus, tpp, ppp, styleid, dateformat, timeformat, showemail, newsletter, invisible, timeoffset) VALUES ('$uid', '$username', '$salt', '$password', '0', '0', '$groupid', 'Manual Acting', '$timestamp', '$timestamp', '$timestamp', '0', '0', '$bbsemail', '0000-00-00', '0', '0', '0', '0', '0', 'H:i', '1', '1', '0', '8')");
execute_sql("INSERT INTO cdb_memberfields (uid) VALUES ('$uid')");
execute_sql("INSERT INTO `cdb_uc_members` SET uid='$uid', username='$username', password='$password', email='$bbsemail', regip='Manual Acting', regdate='$timestamp', salt='$salt'");
2、在Discuz和UCenter中刪除用戶的代碼
復(fù)制代碼
代碼如下:$uid = 100; // 要刪除的用戶編號
execute_sql("DELETE FROM `cdb_members` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_memberfields` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_uc_members` WHERE uid=$uid");
execute_sql("DELETE FROM `cdb_uc_memberfields` WHERE uid=$uid");
3、在Discuz中增加版面并設(shè)置版主的代碼
復(fù)制代碼
代碼如下:$uid = 100; // 版主用戶編號
$fid = 100; // 版面編號,需要保證不與現(xiàn)有版面編號重復(fù)
$forum_name = "Test Forum"; // 版面名稱
execute_sql("INSERT INTO `cdb_forums` (`fid`, `fup`, `type`, `name`, `status`, `displayorder`, `styleid`, `threads`, `posts`, `todayposts`, `lastpost`, `allowsmilies`, `allowhtml`, `allowbbcode`, `allowimgcode`, `allowmediacode`, `allowanonymous`, `allowshare`, `allowpostspecial`, `allowspecialonly`, `alloweditrules`, `allowfeed`, `recyclebin`, `modnewposts`, `jammer`, `disablewatermark`, `inheritedmod`, `autoclose`, `forumcolumns`, `threadcaches`, `alloweditpost`, `simple`, `modworks`, `allowtag`, `allowglobalstick`) VALUES
('$fid', 3, 'forum', '$forum_name', 1, 0, 0, 0, 0, 0, '', 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);");
execute_sql("INSERT INTO `cdb_forumfields` (`fid`, `description`, `password`, `icon`, `postcredits`, `replycredits`, `getattachcredits`, `postattachcredits`, `digestcredits`, `redirect`, `attachextensions`, `formulaperm`, `moderators`, `rules`, `threadtypes`, `threadsorts`, `viewperm`, `postperm`, `replyperm`, `getattachperm`, `postattachperm`, `keywords`, `supe_pushsetting`, `modrecommend`, `tradetypes`, `typemodels`, `threadplugin`, `extra`) VALUES ('$fid', '', '', '', '', '', '', '', '', '', '', 'a:5:{i:0;s:0:\"\";i:1;s:0:\"\";s:5:\"medal\";N;s:7:\"message\";s:0:\"\";s:5:\"users\";s:0:\"\";}', '', '', '', '', ' 9 10 11 12 13 14 15 20 21 16 17 18 19 1 2 3 4 5 6 7 8 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', ' 20 21 1 2 3 ', '', '', 'a:8:{s:4:\"open\";s:1:\"0\";s:3:\"num\";i:10;s:8:\"imagenum\";i:5;s:10:\"imagewidth\";i:200;s:11:\"imageheight\";i:150;s:9:\"maxlength\";i:0;s:9:\"cachelife\";i:900;s:8:\"dateline\";i:0;}', '', '', 'N;', 'a:1:{s:9:\"namecolor\";s:0:\"\";}');");
execute_sql("UPDATE cdb_members SET adminid='3' WHERE uid='$uid'");
execute_sql("INSERT INTO cdb_moderators (uid, fid, inherited) VALUES ('$uid', '$fid', '1')");
4、在Discuz中刪除版面并取消版主管理權(quán)限的代碼
復(fù)制代碼
代碼如下:$uid = 100; // 要刪除版面的版主用戶編號
$fid = 100; // 要刪除的版面編號
execute_sql("DELETE FROM cdb_forums WHERE fid='$fid'");
execute_sql("DELETE FROM cdb_forumfields WHERE fid='$fid'");
execute_sql("DELETE FROM cdb_moderators WHERE fid='$fid'");
execute_sql("UPDATE cdb_members SET adminid='0' WHERE uid='$uid'");
直接操作數(shù)據(jù)庫的好處是業(yè)務(wù)邏輯簡單,操作方便,與現(xiàn)有系統(tǒng)整合容易;缺點就是很流氓很暴力,需要保證操作數(shù)據(jù)的有效性,如增加的版面的fid要保證唯一。
相關(guān)文章
Discuz! X3.4默認(rèn)模板自適應(yīng)手機(jī)與pc的方法
這是我去年自己花了一個下午一點點研究出來的,現(xiàn)在免費貢獻(xiàn)給大家試用,代碼放入后臺統(tǒng)計即可,效果如下2020-11-16- 如果想要404頁面跟網(wǎng)站其他頁面一樣帶有頂部和底部導(dǎo)航,能顯示用戶信息怎么辦呢?今天小編就為大家介紹discuz設(shè)置嵌入式404頁面教程,來看看吧2016-05-10
Discuz X3/3.1 門戶中的Keyword和Description顯示不正確的解決方法
這篇文章主要介紹了Discuz X3/3.1 門戶中的Keyword和Description顯示不正確的解決方法,默認(rèn)顯示的是游客能看到的,而Discuz 對游客屏蔽了關(guān)鍵詞與描述,為了SEO,還是讓它正常2015-03-25Discuz提示您安裝的不是正版應(yīng)用問題解決辦法
這篇文章主要介紹了Discuz提示您安裝的不是正版應(yīng)用問題解決辦法,完整提示“對不起,您安裝的不是正版應(yīng)用,安裝程序無法繼續(xù)執(zhí)行”,本文使用修改PHP文件的方法解決了這個2015-03-25- 這篇文章主要介紹了Discuz和jQuery變量名沖突的3種解決方法,在開發(fā)模板或者插件時經(jīng)常遇到這個問題,本文列出的3種方法都可以解決這個問題,需要的朋友可以參考下2015-03-25
Discuz提示“密碼錯誤次數(shù)過多,請15分鐘后重新登陸”問題解決方法
這篇文章主要介紹了Discuz提示“密碼錯誤次數(shù)過多,請15分鐘后重新登陸”問題解決方法,本文方法適合網(wǎng)站管理員操作,不是普通網(wǎng)友可以使用的解決方法,需要的朋友可以參考下2015-03-25Discuz X2通過數(shù)據(jù)庫批量替換修改帖子內(nèi)容
帖子數(shù)量上萬,一開始是通過設(shè)置詞語過濾,發(fā)現(xiàn)無效果,只能通過數(shù)據(jù)庫批量替換了,具體方法請接著往下看2014-09-04Discuz!X3.2版設(shè)置論壇QQ在線客服號碼無法發(fā)起聊天的問題解決辦法
這篇文章主要介紹了Discuz!X3.2版設(shè)置論壇QQ在線客服號碼無法發(fā)起聊天的問題解決辦法,需要的朋友可以參考下2014-08-03- 這篇文章主要為大家介紹了Discuz論壇發(fā)帖技巧,需要的朋友可以參考下2014-06-21
- 這篇文章主要為大家介紹了Discuz論壇宣傳與優(yōu)化技巧,需要的朋友可以參考下2014-06-21