Discuz 完美集成進(jìn)現(xiàn)有系統(tǒng)(整合用戶(hù)和版面增刪)
來(lái)源:易賢網(wǎng) 閱讀:1700 次 日期:2014-08-15 11:23:01
溫馨提示:易賢網(wǎng)小編為您整理了“Discuz 完美集成進(jìn)現(xiàn)有系統(tǒng)(整合用戶(hù)和版面增刪)”,方便廣大網(wǎng)友查閱!

最近的一次應(yīng)用是基本完成了業(yè)務(wù)系統(tǒng),需要整合Discuz進(jìn)去作為交流版塊使用。于是,涉及到用戶(hù)系統(tǒng)的整合和版面的增刪操作。UCenter提供了API進(jìn)行用戶(hù)的增刪管理,自然可以用,但為了保證用戶(hù)id的統(tǒng)一性,暴力地繞過(guò)了UCenter API,而采用直接操作數(shù)據(jù)庫(kù)的方式來(lái)完成用戶(hù)增刪,當(dāng)然版面的增刪也是操作數(shù)據(jù)庫(kù)來(lái)完成。

1、增加用戶(hù)到Discuz和UCenter的代碼

代碼如下:

$uid = 100; // 用戶(hù)編號(hào)

$username = "maple"; // 用戶(hù)名

$password = "mypassword"; // 用戶(hù)密碼

$salt = md5((string)rand()); // 隨機(jī)字符用于加密

$password = md5(md5($pwd) . $salt); // 加密后的密碼

$groupid = 10; // 用戶(hù)組編號(hào)

$timestamp = time(); // 時(shí)間戳

$bbsemail = "i@witmax.cn"; // 注冊(cè)郵箱,不能重復(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中刪除用戶(hù)的代碼

代碼如下:

$uid = 100; // 要?jiǎng)h除的用戶(hù)編號(hào)

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; // 版主用戶(hù)編號(hào)

$fid = 100; // 版面編號(hào),需要保證不與現(xiàn)有版面編號(hào)重復(fù)

$forum_name = "Test Forum"; // 版面名稱(chēng)

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; // 要?jiǎng)h除版面的版主用戶(hù)編號(hào)

$fid = 100; // 要?jiǎng)h除的版面編號(hào)

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ù)庫(kù)的好處是業(yè)務(wù)邏輯簡(jiǎn)單,操作方便,與現(xiàn)有系統(tǒng)整合容易;缺點(diǎn)就是很流氓很暴力,需要保證操作數(shù)據(jù)的有效性,如增加的版面的fid要保證唯一。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看CMS教程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!
相關(guān)閱讀CMS教程

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)