插件: 用户精华帖数统计 1.51
User's Digest Counting 1.51
作者: Polo!
适用: Discuz! 2.5 SP1
难度: 中
修改: digest.php, viewthread.php, topicadmin.php, admin/members.php
admin/counter.php, admin/tpl/counter.php
模版: digest, viewthread, viewpro
语言包: admincp, templates
数据: 一句数据库升级 *反升级
统计用户的精华帖数
第一步
以管理员身份,进入后台系统设置,进入 数据库 -> 数据库升级
粘贴以下文字 (若数据表前前缀不是默认,请修改 cdb_members 为你数据表的名称)
- ALTER TABLE `cdb_members` ADD `userdigests` SMALLINT( 6 ) UNSIGNED DEFAULT '0' NOT NULL AFTER `postnum` ;
复制代码
第二步
开启 viewthread.php,找到以下语法
- $post_user_info_sql = 'm.username, m.gender, m.groupid, m.adminid, m.regdate, m.lastactivity, m.postnum, m.credit, m.email, m.site, m.icq, m.oicq, m.yahoo, m.msn, m.location, m.avatar, m.avatarwidth, m.avatarheight, m.signature, m.customstatus, m.showemail';
复制代码
用以下语法替换
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: m.userdigests,
- // ----------------------------------------------------------------
- $post_user_info_sql = 'm.username, m.gender, m.groupid, m.adminid, m.regdate, m.lastactivity, m.postnum, m.credit, m.userdigests, m.email, m.site, m.icq, m.oicq, m.yahoo, m.msn, m.location, m.avatar, m.avatarwidth, m.avatarheight, m.signature, m.customstatus, m.showemail';
- // ----------------------------------------------------------------
复制代码
继续找到以下语法
- $post['regdate'] = gmdate($dateformat, $post['regdate'] + $timeoffset * 3600);
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: Next Line
- // ----------------------------------------------------------------
- $post['userdigests'] = $post['userdigests'] ? "<a href="digest.php?authorid=".$post['authorid']."">".$post['userdigests']."</a>" : NULL;
- // ----------------------------------------------------------------
复制代码
第三步
用以下语法覆盖 digest.php
- <?php
- /*
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: [DISCUZ!] Crossday Discuz! Board ::
- :: (c) 2001-2005 Comsenz Technology Ltd ([url]www.discuz.com)[/url] ::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: Author: Crossday ([email]tech@discuz.com[/email]) Cnteacher ([email]cnteacher@discuz.com[/email]) ::
- :: Version: 2.5F 2004/10/01 05:15 ::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- */
- require './include/common.php';
- require DISCUZ_ROOT.'./include/misc.php';
- require DISCUZ_ROOT.'./forumdata/cache/cache_forums.php';
- $page = intval($page) ? intval($page) : 1;
- $start_limit = ($page - 1) * $tpp;
- $forumsarray = array();
- foreach((is_array($forums) ? $forums : explode('_', $forums)) as $forum) {
- $forum = intval(trim($forum));
- if($forum) {
- $forumsarray[] = $forum;
- }
- }
- $fids = '0';
- $forumlist = $forumcheck = array();
- foreach($_DCACHE['forums'] as $fid => $forum) {
- if($forum['type'] != 'group' && (!$forum['viewperm'] && $allowview) || ($forum['viewperm'] && strstr($forum['viewperm'], "\t$groupid\t"))) {
- $forumlist[] = array('fid' => $fid, 'name' => $forum['name']);
- if(!$forumsarray || in_array($fid, $forumsarray)) {
- $fids .= ','.$fid;
- $forumcheck[$fid] = 'checked';
- }
- }
- }
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next 5 Lines
- // ----------------------------------------------------------------
- if($author) {
- $query = $db->query("SELECT uid FROM {$tablepre}members WHERE username='$author'");
- $authorid = ($member = $db->fetch_array($query)) ? $member['uid'] : 0;
- }
- $authoradd = $authorid ? "AND authorid='$authorid'" : NULL;
- // ----------------------------------------------------------------
- $keywordadd = $keyword ? "AND subject LIKE '%$keyword%'" : '';
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: $authoradd
- // ----------------------------------------------------------------
- $query = $db->query("SELECT COUNT(*) FROM {$tablepre}threads WHERE digest>'0' AND fid IN ($fids) AND displayorder>='0' $authoradd $keywordadd");
- // ----------------------------------------------------------------
- $threadcount = $db->result($query, 0);
- if(!$threadcount) {
- showmessage('digest_nonexistence');
- }
- if(!$order || !in_array($order, array('dateline', 'lastpost', 'replies', 'views'))) {
- $order = 'digest';
- }
- $ordercheck = array($order => 'selected="selected"');
- $forumsarray = $threadlist = array();
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: $authoradd
- // ----------------------------------------------------------------
- $query = $db->query("SELECT * FROM {$tablepre}threads WHERE digest>'0' AND fid IN ($fids) AND displayorder>='0' $authoradd $keywordadd ORDER BY $order DESC LIMIT $start_limit, $tpp");
- // ----------------------------------------------------------------
- while($thread = $db->fetch_array($query)) {
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- $threadauthor = $thread['author'];
- // ----------------------------------------------------------------
- $threadlist[] = procthread($thread);
- }
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: &authorid=$authorid
- // ----------------------------------------------------------------
- $multipage = multi($threadcount, $tpp, $page, "digest.php?order=$order&keyword=".rawurlencode($keyword)."&authorid=$authorid&forums=".str_replace(',', '_', $fids), $threadmaxpages);
- // ----------------------------------------------------------------
- $keyword = dhtmlspecialchars($keyword);
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- $author = $authorid ? dhtmlspecialchars($threadauthor) : NULL;
- // ----------------------------------------------------------------
- include template('digest');
- ?>
复制代码
第四步
开启 topicadmin.php,找到以下语法
- }elseif($operation == 'digest' && $allowdigest){
- if($level < 0 || $level > 3) {
- showmessage('undefined_action', NULL, 'HALTED');
- }
- while($thread = $db->fetch_array($query)) {
- if ($thread['fid'] == $fid && $thread['digest']<>$level){
- $digest_mark=($level-intval($thread['digest']))*$digestcredits;
- $db->query("UPDATE $table_threads SET digest='$level' WHERE tid='$thread[tid]'");
- if($digest_mark && $discuz_uid != $thread[authorid]) {
- $db->query("UPDATE $table_members SET credit=credit".($digest_mark > 0 ? '+' : '')."$digest_mark WHERE uid='$thread[authorid]'");
- }
- }
- }
- modlog();
- showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$page");
- }
复制代码
用以下语法替换
- }elseif($operation == 'digest' && $allowdigest){
- if($level < 0 || $level > 3) {
- showmessage('undefined_action', NULL, 'HALTED');
- }
- while($thread = $db->fetch_array($query)) {
- if ($thread['fid'] == $fid && $thread['digest']<>$level){
- $digest_mark=($level-intval($thread['digest']))*$digestcredits;
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next 2 Lines
- // ----------------------------------------------------------------
- $creditadd = $digest_mark && $discuz_uid != $thread[authorid] ? "credit=credit".($digest_mark > 0 ? '+' : '').$digest_mark : NULL;
- $userdigestsadd = $thread['digest'] == 0 || $level == 0 ? ($creditadd ? "," : NULL)."userdigests=userdigests".($level == 0 ? "-" : "+")."1" : NULL;
- // ----------------------------------------------------------------
- $db->query("UPDATE $table_threads SET digest='$level' WHERE tid='$thread[tid]'");
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Replaced
- // ----------------------------------------------------------------
- // if($digest_mark && $discuz_uid != $thread[authorid]) {
- // $db->query("UPDATE $table_members SET credit=credit".($digest_mark > 0 ? '+' : '')."$digest_mark WHERE uid='$thread[authorid]'");
- // }
- // ----------------------------------------------------------------
- if($creditadd || $userdigestsadd) {
- $db->query("UPDATE $table_members SET $creditadd $userdigestsadd WHERE uid='$thread[authorid]'");
- }
- // ----------------------------------------------------------------
- }
- }
- modlog();
- showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$page");
- }
复制代码
继续找到以下语法
- } elseif($action == 'digest' && $allowdigest) {
- if(!submitcheck('digestsubmit')) {
- include template('topicadmin_digest');
- } else {
- if($level < 0 || $level > 3) {
- showmessage('undefined_action', NULL, 'HALTED');
- }
- $digest_mark=($level-intval($thread['digest']))*$digestcredits;
- $db->query("UPDATE $table_threads SET digest='$level' WHERE tid='$tid'");
- if($digest_mark && $discuz_uid != $thread['authorid'] ) {
- $db->query("UPDATE $table_members SET credit=credit".($digest_mark > 0 ? '+' : '')."$digest_mark WHERE uid='$thread[authorid]'");
- }
- modlog();
- showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$fpage");
- }
- }
复制代码
用以下语法替换
- } elseif($action == 'digest' && $allowdigest) {
- if(!submitcheck('digestsubmit')) {
- include template('topicadmin_digest');
- } else {
- if($level < 0 || $level > 3) {
- showmessage('undefined_action', NULL, 'HALTED');
- }
- $digest_mark=($level-intval($thread['digest']))*$digestcredits;
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next 2 Lines
- // ----------------------------------------------------------------
- $creditadd = $digest_mark && $discuz_uid != $thread[authorid] ? "credit=credit".($digest_mark > 0 ? '+' : '').$digest_mark : NULL;
- $userdigestsadd = $thread['digest'] == 0 || $level == 0 ? ($creditadd ? "," : NULL)."userdigests=userdigests".($level == 0 ? "-" : "+")."1" : NULL;
- // ----------------------------------------------------------------
- $db->query("UPDATE $table_threads SET digest='$level' WHERE tid='$tid'");
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Replaced
- // ----------------------------------------------------------------
- // if($digest_mark && $discuz_uid != $thread['authorid'] ) {
- // $db->query("UPDATE $table_members SET credit=credit".($digest_mark > 0 ? '+' : '')."$digest_mark WHERE uid='$thread[authorid]'");
- // }
- // ----------------------------------------------------------------
- if($creditadd || $userdigestsadd) {
- $db->query("UPDATE $table_members SET $creditadd $userdigestsadd WHERE uid='$thread[authorid]'");
- }
- // ----------------------------------------------------------------
- modlog();
- showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$fpage");
- }
- }
复制代码
第五步
开启 admin/members.php,找到以下语法
- showsetting('members_edit_postnum', 'postnumnew', $member['postnum'], 'text');
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- showsetting('members_edit_userdigests', 'userdigestsnew', $member['userdigests'], 'text');
- // ----------------------------------------------------------------
复制代码
继续找到以下语法
- $db->query("UPDATE $table_members SET email='$emailnew', credit='$creditnew', postnum='$postnumnew', regip='$regipnew',
- regdate='$regdatenew', lastvisit='$lastvisitnew', site='$sitenew', oicq='$oicqnew', icq='$icqnew',
- yahoo='$yahoonew', msn='$msnnew', location='$locationnew', bday='$bdaynew', bio='$bionew',
- styleid='$styleidnew', tpp='$tppnew', ppp='$pppnew', timeformat='$timeformatnew',
- customstatus='$cstatusnew', ignorepm='$ignorepmnew', showemail='$showemailnew', newsletter='$newsletternew',
- invisible='$invisiblenew', timeoffset='$timeoffsetnew', avatar='$avatarnew', signature='$signaturenew'
- $passwordadd $secquesadd $groupidadd WHERE uid='$uid'");
复制代码
用以下语法替换
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: userdigests='$userdigestsnew',
- // ----------------------------------------------------------------
- $db->query("UPDATE $table_members SET email='$emailnew', credit='$creditnew', postnum='$postnumnew', userdigests='$userdigestsnew', regip='$regipnew',
- regdate='$regdatenew', lastvisit='$lastvisitnew', site='$sitenew', oicq='$oicqnew', icq='$icqnew',
- yahoo='$yahoonew', msn='$msnnew', location='$locationnew', bday='$bdaynew', bio='$bionew',
- styleid='$styleidnew', tpp='$tppnew', ppp='$pppnew', timeformat='$timeformatnew',
- customstatus='$cstatusnew', ignorepm='$ignorepmnew', showemail='$showemailnew', newsletter='$newsletternew',
- invisible='$invisiblenew', timeoffset='$timeoffsetnew', avatar='$avatarnew', signature='$signaturenew'
- $passwordadd $secquesadd $groupidadd WHERE uid='$uid'");
- // ----------------------------------------------------------------
复制代码
第六步
开启 admin/counter.php,找到以下语法
- if(!submitcheck('forumsubmit', 1) && !submitcheck('membersubmit', 1) && !submitcheck('threadsubmit', 1)) {
复制代码
用以下语法替换
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added: && !submitcheck('digestsubmit', 1)
- // ----------------------------------------------------------------
- if(!submitcheck('forumsubmit', 1) && !submitcheck('membersubmit', 1) && !submitcheck('threadsubmit', 1) && !submitcheck('digestsubmit', 1)) {
- // ----------------------------------------------------------------
复制代码
继续找到以下语法
在其之上加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Belows
- // ----------------------------------------------------------------
- elseif(submitcheck('digestsubmit', 1)) {
- if(!$current) {
- $current = 0;
- }
- $pertask = intval($pertask);
- $current = intval($current);
- $next = $current + $pertask;
- $nextlink = "admincp.php?action=counter¤t=$next&pertask=$pertask&digestsubmit=yes";
- $processed = 0;
- $queryt = $db->query("SELECT uid FROM $table_members LIMIT $current, $pertask");
- while($mem = $db->fetch_array($queryt)) {
- $processed = 1;
- $query = $db->query("SELECT COUNT(*) FROM $table_threads WHERE authorid='$mem[uid]' AND digest <> 0");
- $db->query("UPDATE $table_members SET userdigests='".$db->result($query, 0)."' WHERE uid='$mem[uid]'");
- }
- if($processed) {
- cpmsg("$lang[counter_digest]: $lang[counter_processing]", $nextlink);
- } else {
- cpmsg('counter_digest_succeed');
- }
- }
- // ----------------------------------------------------------------
复制代码
第七步
开启 admin/tpl/counter.php,找到以下语法
- <form method="post" action="admincp.php?action=counter">
- <input type="hidden" name="formhash" value="<?=FORMHASH?>">
- <table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
- <tr><td bgcolor="<?=BORDERCOLOR?>">
- <table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
- <tr class="header"><td colspan="2"><?=$lang['counter_member']?></td></tr>
- <tr bgcolor="<?=ALTBG2?>">
- <td align="center"><?=$lang['counter_amount']?> <input type="text" name="pertask" value="1000"></td>
- </tr></table></td></tr></table><br><center>
- <input type="submit" name="membersubmit" value="<?=$lang['submit']?>">
- <input type="reset" value="<?=$lang['reset']?>"></center></form><br>
复制代码
在其之下加入以下语法
- <!----------------------------------------------------------------
- User's Digest Counting 1.51 By Polo!
- Added Belows
- ---------------------------------------------------------------->
- <form method="post" action="admincp.php?action=counter">
- <input type="hidden" name="formhash" value="<?=FORMHASH?>">
- <table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
- <tr><td bgcolor="<?=BORDERCOLOR?>">
- <table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
- <tr class="header"><td colspan="2"><?=$lang['counter_digest']?></td></tr>
- <tr bgcolor="<?=ALTBG2?>">
- <td align="center"><?=$lang['counter_amount']?> <input type="text" name="pertask" value="1000"></td>
- </tr></table></td></tr></table><br><center>
- <input type="submit" name="digestsubmit" value="<?=$lang['submit']?>">
- <input type="reset" value="<?=$lang['reset']?>"></center></form><br>
- <!---------------------------------------------------------------->
复制代码
第八步
到后台模版编辑,编辑 admincp 语言包
- 'counter_member' => '重建用户发帖数',
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- 'counter_digest' => '重建用户精华帖数',
- // ----------------------------------------------------------------
复制代码
继续找到以下语法
- 'counter_member_succeed' => '用户发帖数重建完成。',
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- 'counter_digest_succeed' => '用户精华帖数重建完成。',
- // ----------------------------------------------------------------
复制代码
继续找到以下语法
- 'members_edit_postnum' => '发帖数:',
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- 'members_edit_userdigests' => '精华帖数:',
- // ----------------------------------------------------------------
复制代码
第九步
到后台模版编辑,编辑 templates 语言包
- 'posts_per_day' => '平均每日发帖',
复制代码
在其之下加入以下语法
- // ----------------------------------------------------------------
- // User's Digest Counting 1.51 By Polo!
- // Added Next Line
- // ----------------------------------------------------------------
- 'digestscount' => '精华帖',
- // ----------------------------------------------------------------
复制代码
第十步
到后台模版编辑,编辑 viewthread 模版
- {lang credit_title} $post[credit]<br>
复制代码
在其之上加入以下语法
- <!----------------------------------------------------------------
- User's Digest Counting 1.51 By Polo!
- Added Next Line
- ---------------------------------------------------------------->
- <!--{if $post[userdigests]}-->{lang thread_digest} $post[userdigests]<br><!--{/if}-->
- <!---------------------------------------------------------------->
复制代码
第十一步
到后台模版编辑,编辑 viewpro 模版
- <tr><td width="45%" class="bold">{lang posts_per_day}:</td><td width="55%">$postperday {lang posts}</td></tr>
复制代码
在其之上加入以下语法
- <!----------------------------------------------------------------
- User's Digest Counting 1.51 By Polo!
- Added Next Line
- ---------------------------------------------------------------->
- <tr><td width="45%" class="bold">{lang digestscount}:</td><td width="55%">$member[userdigests] {lang posts}</td></tr>
- <!---------------------------------------------------------------->
复制代码
第十二步
到后台模版编辑,编辑 digest 模版
- {lang keyword}: <input type="text" size="15" name="keyword" value="$keyword">
复制代码
在其之下加入以下语法
- <!----------------------------------------------------------------
- User's Digest Counting 1.51 By Polo!
- Added Next Line
- ---------------------------------------------------------------->
- {lang author}: <input type="text" size="15" name="author" value="$author">
- <!---------------------------------------------------------------->
复制代码
完成
到后台重建用户精华帖数及更新缓存,完成!!
反安装数据库升级
以管理员身份,进入后台系统设置,进入 数据库 -> 数据库升级
粘贴以下文字 (若数据表前前缀不是默认,请修改 cdb_members 为你数据表的名称)
- ALTER TABLE `cdb_members` DROP `userdigests`
复制代码 |