📄 functions_phpbb20.php
字号:
$row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $founder_id = phpbb_user_id($row['user_id']); // Set a founder admin ... we'll assume it's the first user with admin level access $sql = 'UPDATE ' . USERS_TABLE . ' SET user_type = ' . USER_FOUNDER . " WHERE user_id = $founder_id"; $db->sql_query($sql); } // Grab forum auth information $sql = "SELECT * FROM {$convert->src_table_prefix}forums"; $result = $db->sql_query($sql); $forum_access = array(); while ($row = $db->sql_fetchrow($result)) { $forum_access[] = $row; } $db->sql_freeresult($result); // Grab user auth information from 2.0.x board $sql = "SELECT ug.user_id, aa.* FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}user_group ug, {$convert->src_table_prefix}groups g WHERE g.group_id = aa.group_id AND g.group_single_user = 1 AND ug.group_id = g.group_id"; $result = $db->sql_query($sql); $user_access = array(); while ($row = $db->sql_fetchrow($result)) { $user_access[$row['forum_id']][] = $row; } $db->sql_freeresult($result); // Grab group auth information $sql = "SELECT g.group_id, aa.* FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g WHERE g.group_id = aa.group_id AND g.group_single_user <> 1"; $result = $db->sql_query($sql); $group_access = array(); while ($row = $db->sql_fetchrow($result)) { $group_access[$row['forum_id']][] = $row; } $db->sql_freeresult($result); // Add Forum Access List $auth_map = array( 'auth_view' => array('f_', 'f_list'), 'auth_read' => 'f_read', 'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_search', 'f_postcount'), 'auth_reply' => 'f_reply', 'auth_edit' => 'f_edit', 'auth_delete' => 'f_delete', 'auth_pollcreate' => 'f_poll', 'auth_vote' => 'f_vote', 'auth_announce' => 'f_announce', 'auth_sticky' => 'f_sticky', 'auth_attachments' => 'f_attach', 'auth_download' => 'f_download', ); // Define the ACL constants used in 2.0 to make the code slightly more readable define('AUTH_ALL', 0); define('AUTH_REG', 1); define('AUTH_ACL', 2); define('AUTH_MOD', 3); define('AUTH_ADMIN', 5); // A mapping of the simple permissions used by 2.0 $simple_auth_ary = array( 'public' => array( 'auth_view' => AUTH_ALL, 'auth_read' => AUTH_ALL, 'auth_post' => AUTH_ALL, 'auth_reply' => AUTH_ALL, 'auth_edit' => AUTH_REG, 'auth_delete' => AUTH_REG, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_REG, 'auth_pollcreate' => AUTH_REG, ), 'registered' => array( 'auth_view' => AUTH_ALL, 'auth_read' => AUTH_ALL, 'auth_post' => AUTH_REG, 'auth_reply' => AUTH_REG, 'auth_edit' => AUTH_REG, 'auth_delete' => AUTH_REG, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_REG, 'auth_pollcreate' => AUTH_REG, ), 'registered_hidden' => array( 'auth_view' => AUTH_REG, 'auth_read' => AUTH_REG, 'auth_post' => AUTH_REG, 'auth_reply' => AUTH_REG, 'auth_edit' => AUTH_REG, 'auth_delete' => AUTH_REG, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_REG, 'auth_pollcreate' => AUTH_REG, ), 'private' => array( 'auth_view' => AUTH_ALL, 'auth_read' => AUTH_ACL, 'auth_post' => AUTH_ACL, 'auth_reply' => AUTH_ACL, 'auth_edit' => AUTH_ACL, 'auth_delete' => AUTH_ACL, 'auth_sticky' => AUTH_ACL, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_ACL, 'auth_pollcreate' => AUTH_ACL, ), 'private_hidden' => array( 'auth_view' => AUTH_ACL, 'auth_read' => AUTH_ACL, 'auth_post' => AUTH_ACL, 'auth_reply' => AUTH_ACL, 'auth_edit' => AUTH_ACL, 'auth_delete' => AUTH_ACL, 'auth_sticky' => AUTH_ACL, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_ACL, 'auth_pollcreate' => AUTH_ACL, ), 'moderator' => array( 'auth_view' => AUTH_ALL, 'auth_read' => AUTH_MOD, 'auth_post' => AUTH_MOD, 'auth_reply' => AUTH_MOD, 'auth_edit' => AUTH_MOD, 'auth_delete' => AUTH_MOD, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_MOD, 'auth_pollcreate' => AUTH_MOD, ), 'moderator_hidden' => array( 'auth_view' => AUTH_MOD, 'auth_read' => AUTH_MOD, 'auth_post' => AUTH_MOD, 'auth_reply' => AUTH_MOD, 'auth_edit' => AUTH_MOD, 'auth_delete' => AUTH_MOD, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_MOD, 'auth_pollcreate' => AUTH_MOD, ), ); if ($mode == 'start') { user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS); user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS); // Selecting from old table $auth_sql = 'SELECT '; $auth_sql .= (!empty($config['increment_user_id'])) ? 'user_id + 1 as user_id' : 'user_id'; $auth_sql .= ', {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1'; user_group_auth('administrators', $auth_sql); // Put administrators into global moderators group too... $auth_sql = 'SELECT '; $auth_sql .= (!empty($config['increment_user_id'])) ? 'user_id + 1 as user_id' : 'user_id'; $auth_sql .= ', {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1'; user_group_auth('global_moderators', $auth_sql); } else if ($mode == 'first') { // Go through all 2.0.x forums (we saved those ids for reference) foreach ($forum_access as $forum) { $new_forum_id = (int) $forum['forum_id']; // Administrators have full access to all forums whatever happens mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL'); $matched_type = ''; foreach ($simple_auth_ary as $key => $auth_levels) { $matched = 1; foreach ($auth_levels as $k => $level) { if ($forum[$k] != $auth_levels[$k]) { $matched = 0; } } if ($matched) { $matched_type = $key; break; } } switch ($matched_type) { case 'public': mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED'); mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS'); mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT'); break; case 'registered': mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY'); mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT'); // no break; case 'registered_hidden': mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS'); break; case 'private': case 'private_hidden': case 'moderator': case 'moderator_hidden': default: // The permissions don't match a simple set, so we're going to have to map them directly // No post approval for all, in 2.0.x this feature does not exist mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES); mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES); // Go through authentication map foreach ($auth_map as $old_auth_key => $new_acl) { // If old authentication key does not exist we continue // This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array if (!isset($forum[$old_auth_key])) { continue; } // Now set the new ACL correctly switch ($forum[$old_auth_key]) { // AUTH_ALL case AUTH_ALL: mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES); mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES); break; // AUTH_REG case AUTH_REG: mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES); break; // AUTH_ACL case AUTH_ACL: // Go through the old group access list for this forum if (isset($group_access[$forum['forum_id']])) { foreach ($group_access[$forum['forum_id']] as $index => $access) { // We only check for ACL_YES equivalence entry if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1) { mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES); } } } if (isset($user_access[$forum['forum_id']])) { foreach ($user_access[$forum['forum_id']] as $index => $access) { // We only check for ACL_YES equivalence entry if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1) { mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES); } } } break; // AUTH_MOD case AUTH_MOD: if (isset($group_access[$forum['forum_id']])) { foreach ($group_access[$forum['forum_id']] as $index => $access) { // We only check for ACL_YES equivalence entry if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1) { mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES); } } } if (isset($user_access[$forum['forum_id']])) { foreach ($user_access[$forum['forum_id']] as $index => $access) { // We only check for ACL_YES equivalence entry if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1) { mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES); } } } break; } } break; } } } else if ($mode == 'second') { // Assign permission roles and other default permissions // guests having u_download and u_search ability $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) SELECT ' . get_group_id('guests') . ', 0, auth_option_id, 0, 1 FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option IN ('u_', 'u_download', 'u_search')"); // administrators/global mods having full user features mass_auth('group_role', 0, 'administrators', 'USER_FULL'); mass_auth('group_role', 0, 'global_moderators', 'USER_FULL'); // By default all converted administrators are given standard access (the founder still have full access) mass_auth('group_role', 0, 'administrators', 'ADMIN_STANDARD'); // All registered users are assigned the standard user role mass_auth('group_role', 0, 'registered', 'USER_STANDARD'); mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD'); // Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group) mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL'); // And now those who have had their avatar rights removed get assigned a more restrictive role $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users WHERE user_allowavatar = 0 AND user_id > 0'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR'); } $db->sql_freeresult($result); // And the same for those who have had their PM rights removed $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users WHERE user_allow_pm = 0 AND user_id > 0'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM'); } $db->sql_freeresult($result); } else if ($mode == 'third') { // And now the moderators // We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions foreach ($user_access as $forum_id => $access_map) { $forum_id = (int) $forum_id; foreach ($access_map as $access) { if (isset($access['auth_mod']) && $access['auth_mod'] == 1) { mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD'); mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD'); } } } foreach ($group_access as $forum_id => $access_map) { $forum_id = (int) $forum_id; foreach ($access_map as $access) { if (isset($access['auth_mod']) && $access['auth_mod'] == 1) { mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD'); mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD'); } } } // We grant everyone readonly access to the categories to ensure that the forums are visible $sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql); $parent_forums = $forums = array(); while ($row = $db->sql_fetchrow($result)) { if ($row['parent_id'] == 0) { mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL'); $parent_forums[] = $row; } else { $forums[] = $row; } } $db->sql_freeresult($result); global $auth; // Let us see if guests/registered users have access to these forums... foreach ($parent_forums as $row) { // Get the children $branch = $forum_ids = array(); foreach ($forums as $key => $_row) { if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id']) { $branch[] = $_row; $forum_ids[] = $_row['forum_id']; continue; } } if (sizeof($forum_ids)) { // Now make sure the user is able to read these forums $hold_ary = $auth->acl_group_raw_data(get_group_id('guests'), 'f_list', $forum_ids); if (!empty($hold_ary)) { mass_auth('group', $row['forum_id'], 'guests', 'f_list', ACL_YES); mass_auth('group', $row['forum_id'], 'registered', 'f_list', ACL_YES); } } } }}/*** Set primary group.* Really simple and only based on user_level (remaining groups will be assigned later)*/function phpbb_set_primary_group($user_level){ global $convert_row; if ($user_level == 1) { return get_group_id('administrators'); }/* else if ($user_level == 2) { return get_group_id('global_moderators'); } else if ($user_level == 0 && $convert_row['user_active'])*/ else if ($convert_row['user_active']) { return get_group_id('registered'); } return 0;}/*** Convert the group name, making sure to avoid conflicts with 3.0 special groups
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -