[MOD]Edit User's Postcount(修改用户帖子数)

PHPBB2.0.X资源收集专用版,提问和建议请发到主版面
Locked
newerby
论坛管理员
论坛管理员
Posts: 1293
Joined: 2006-11-10 2:20

[MOD]Edit User's Postcount(修改用户帖子数)

Post by newerby » 2007-10-19 11:50

说明:phpbbchina 推出的 phpbbxs 已经有按帖子数自动划分用户组的 MOD,但有个缺陷,对灌水用户不好控制,删帖当然是个好方法,但不好留下作为“证据”,看这个 MOD 的功能不错——直接修改用户的帖子数。

题外话:phpbb 3 在这方面很强大,把计入帖子数作为一个权限,官方也已经有 auto-group MOD 发布,直接修改用户帖子数的 MOD 也有了。

官方链接: http://www.phpbb.com/community/viewtopi ... 5&t=217133

##############################################################
## MOD Title: Edit User's Postcount
## MOD Author: tomlevens < tom@tomlevens.co.uk > (Tom Levens) N/A
## MOD Description: This MOD enables you to change a user's postcount through the admin panel.
## MOD Version: 1.0.3
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit: admin/admin_users.php
## templates/subSilver/admin/user_edit_body.tpl
## language/lang_english/lang_admin.php
## includes/functions.php (Optional)
## Included Files: N/A
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
#############################################################
## Author Notes:
##
## This MOD adds a field to the user management section of the admin panel
## which enables you to change a user's postcount to any value.
##
## Optional Edit (includes/functions.php):
##
## This is a feature requested by prophetUK on the forums at phpbb.com. If you
## apply this step the total posts statistic on the forum index will
## increase/decrease as you modify postcounts. By default phpBB bases this
## statistic on the actual number of posts in the database, but having it
## based on all your users' combined postcounts could be desireable. Please
## make a judgement on how you wish to have this statistic calculated, and
## apply the final step if you desire.
##############################################################
## MOD History:
##
## 2004-01-26 - Version 1.0.0
## - Initial Release
##
## 2004-01-26 - Version 1.0.1
## - I had put the name of the wrong MOD in the comments... oops!
##
## 2006-11-23 - Version 1.0.2
## - Added an optional step to change the behaviour of the total posts
## statistic - as requested by prophetUK
##
## 2007-02-06 - Version 1.0.3
## - Added a function to recalculate the user's real postcount (i.e. the
## actual number of posts that user has made) - as requested by adk_tj
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
Attachments
edit_users_postc.zip
修改用户帖子数插件
(2.35 KiB) Downloaded 23 times

newerby
论坛管理员
论坛管理员
Posts: 1293
Joined: 2006-11-10 2:20

Re: [MOD]Edit User's Postcount(修改用户帖子数)

Post by newerby » 2007-10-29 14:25

发现个问题,这个 MOD 装在 pbpbbxs 上修改用户的帖子数后并不按帖子数把该会员自动归入或者退出某个团队(这些团队是按帖子数设定的),这样会导致该用户的权限出现问题。 :embs:

先留着,等 IOsetting 帮看看。

User avatar
IOsetting
论坛管理员
论坛管理员
Posts: 3647
Joined: 2006-10-17 1:48

Re: [MOD]Edit User's Postcount(修改用户帖子数)

Post by IOsetting » 2007-10-29 17:16

对于安装了自动加入/退出用户组MOD的phpBB2, 还需要做如下的改动才能实现修改帖子数时自动修正用户所在组, 否则只有在用户再次发表/编辑/删除文章时才会修正其所在组.

打开admin/admin_users.php
找到

Code: Select all

if( isset($rename_user) )
在前面添加

Code: Select all

//////////////////////////////
				$sql = "SELECT ug.user_id, g.group_id as g_id, u.user_posts, u.user_allow_ag, g.group_count, g.group_count_max 
					FROM ".USERS_TABLE." u, " . GROUPS_TABLE . " g 
						LEFT JOIN ". USER_GROUP_TABLE." ug ON g.group_id=ug.group_id AND ug.user_id=$user_id 
					WHERE u.user_id=$user_id 
						AND g.group_single_user=0 
						AND g.group_count_enable=1 
						AND g.group_moderator<>$user_id";
				if ( !($result = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Error geting users post stat', '', __LINE__, __FILE__, $sql);
				}
				while ($group_data = $db->sql_fetchrow($result))
				{
					$user_already_added = (empty($group_data['user_id'])) ? FALSE : TRUE; 
					$user_add = ($group_data['group_count'] <= $group_data['user_posts'] && $group_data['group_count_max'] >= $group_data['user_posts'] && $user_id!=ANONYMOUS) ? TRUE : FALSE; 
					$user_remove = ($group_data['group_count'] > $group_data['user_posts'] || $group_data['group_count_max'] < $group_data['user_posts']) ? TRUE : FALSE;
					if ($user_add && !$user_already_added && $group_data['user_allow_ag'] == 1)
					{
						//user join a autogroup
						$sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) 
							VALUES (".$group_data['g_id'].", $user_id, '0')";
						if ( !($db->sql_query($sql)) )
						{
							message_die(GENERAL_ERROR, 'Error insert users, group count', '', __LINE__, __FILE__, $sql);
						}
					} else
					if ( $user_already_added && $user_remove OR $group_data['user_allow_ag'] == 0)
					{
						//remove user from auto group
						$sql = "DELETE FROM " . USER_GROUP_TABLE . " 
							WHERE group_id=".$group_data['g_id']." 
								AND user_id=$user_id";
						if ( !($db->sql_query($sql)) )
						{
							message_die(GENERAL_ERROR, 'Could not remove users, group count', '', __LINE__, __FILE__, $sql);
						}
					}
				}
				//////////////////////////////

newerby
论坛管理员
论坛管理员
Posts: 1293
Joined: 2006-11-10 2:20

Re: [MOD]Edit User's Postcount(修改用户帖子数)

Post by newerby » 2007-10-29 17:22

谢谢 IOsetting 了,这是非常不错的 MOD ,特别推荐一下,可作为技术性论坛震慑恶意灌水的工具。 8-)

Locked