⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auth.php

📁 这些都是我以前学习是用到的源码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
			$memberships = group_memberships(false, array_keys($hold_ary), false);			// User is not a member of any group? Bad admin, bad bad admin...			if ($memberships)			{				foreach ($memberships as $row)				{					if ($groups[$row['group_id']]['group_type'] == GROUP_SPECIAL)					{						$user_groups_default[$row['user_id']][] = $user->lang['G_' . $groups[$row['group_id']]['group_name']];					}					else					{						$user_groups_custom[$row['user_id']][] = $groups[$row['group_id']]['group_name'];					}				}			}			unset($memberships, $groups);		}		// If we only have one forum id to display or being in local mode and more than one user/group to display, 		// we switch the complete interface to group by user/usergroup instead of grouping by forum		// To achive this, we need to switch the array a bit		if (sizeof($forum_ids) == 1 || ($local && sizeof($ug_names_ary) > 1))		{			$hold_ary_temp = $hold_ary;			$hold_ary = array();			foreach ($hold_ary_temp as $ug_id => $row)			{				foreach ($row as $forum_id => $auth_row)				{					$hold_ary[$forum_id][$ug_id] = $auth_row;				}			}			unset($hold_ary_temp);			foreach ($hold_ary as $forum_id => $forum_array)			{				$content_array = $categories = array();				$this->build_permission_array($hold_ary[$forum_id], $content_array, $categories, array_keys($ug_names_ary));				$template->assign_block_vars($tpl_pmask, array(					'NAME'			=> ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],					'CATEGORIES'	=> implode('</th><th>', $categories),					'L_ACL_TYPE'	=> $l_acl_type,					'S_LOCAL'		=> ($local) ? true : false,					'S_GLOBAL'		=> (!$local) ? true : false,					'S_NUM_CATS'	=> sizeof($categories),					'S_VIEW'		=> ($mode == 'view') ? true : false,					'S_NUM_OBJECTS'	=> sizeof($content_array),					'S_USER_MODE'	=> ($user_mode == 'user') ? true : false,					'S_GROUP_MODE'	=> ($user_mode == 'group') ? true : false)				);				foreach ($content_array as $ug_id => $ug_array)				{					// Build role dropdown options					$current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;					$s_role_options = '';					foreach ($roles as $role_id => $role_row)					{						$role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);						$title = ($role_description) ? ' title="' . $role_description . '"' : '';						$s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_row['role_name'] . '</option>';					}					if ($s_role_options)					{						$s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;					}					$template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(						'NAME'				=> $ug_names_ary[$ug_id],						'S_ROLE_OPTIONS'	=> $s_role_options,						'UG_ID'				=> $ug_id,						'FORUM_ID'			=> $forum_id)					);					$this->assign_cat_array($ug_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, $show_trace);				}			}		}		else		{			foreach ($ug_names_ary as $ug_id => $ug_name)			{				if (!isset($hold_ary[$ug_id]))				{					continue;				}				$content_array = $categories = array();				$this->build_permission_array($hold_ary[$ug_id], $content_array, $categories, array_keys($forum_names_ary));				$template->assign_block_vars($tpl_pmask, array(					'NAME'			=> $ug_name,					'CATEGORIES'	=> implode('</th><th>', $categories),					'USER_GROUPS_DEFAULT'	=> ($user_mode == 'user' && isset($user_groups_default[$ug_id]) && sizeof($user_groups_default[$ug_id])) ? implode(', ', $user_groups_default[$ug_id]) : '',					'USER_GROUPS_CUSTOM'	=> ($user_mode == 'user' && isset($user_groups_custom[$ug_id]) && sizeof($user_groups_custom[$ug_id])) ? implode(', ', $user_groups_custom[$ug_id]) : '',					'L_ACL_TYPE'			=> $l_acl_type,					'S_LOCAL'		=> ($local) ? true : false,					'S_GLOBAL'		=> (!$local) ? true : false,					'S_NUM_CATS'	=> sizeof($categories),					'S_VIEW'		=> ($mode == 'view') ? true : false,					'S_NUM_OBJECTS'	=> sizeof($content_array),					'S_USER_MODE'	=> ($user_mode == 'user') ? true : false,					'S_GROUP_MODE'	=> ($user_mode == 'group') ? true : false)				);				foreach ($content_array as $forum_id => $forum_array)				{					// Build role dropdown options					$current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;					$s_role_options = '';					foreach ($roles as $role_id => $role_row)					{						$role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);						$title = ($role_description) ? ' title="' . $role_description . '"' : '';						$s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_row['role_name'] . '</option>';					}					if ($s_role_options)					{						$s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;					}					if (!$forum_id)					{						$folder_image = '';					}					else					{						if ($forum_names_ary[$forum_id]['forum_status'] == ITEM_LOCKED)						{							$folder_image = '<img src="images/icon_folder_lock_small.gif" width="19" height="18" alt="' . $user->lang['FORUM_LOCKED'] . '" />';						}						else						{							switch ($forum_names_ary[$forum_id]['forum_type'])							{								case FORUM_LINK:									$folder_image = '<img src="images/icon_folder_link_small.gif" width="22" height="18" alt="' . $user->lang['FORUM_LINK'] . '" />';								break;								default:									$folder_image = ($forum_names_ary[$forum_id]['left_id'] + 1 != $forum_names_ary[$forum_id]['right_id']) ? '<img src="images/icon_folder_sub_small.gif" width="22" height="18" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder_small.gif" width="19" height="18" alt="' . $user->lang['FOLDER'] . '" />';								break;							}						}					}					$template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(						'NAME'				=> ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],						'PADDING'			=> ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],						'FOLDER_IMAGE'		=> $folder_image,						'S_ROLE_OPTIONS'	=> $s_role_options,						'UG_ID'				=> $ug_id,						'FORUM_ID'			=> $forum_id)					);					$this->assign_cat_array($forum_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, $show_trace);				}			}		}	}	/**	* Display permission mask for roles	*/	function display_role_mask(&$hold_ary)	{		global $db, $template, $user, $phpbb_root_path, $phpbb_admin_path, $phpEx;		if (!sizeof($hold_ary))		{			return;		}		// Get forum names		$sql = 'SELECT forum_id, forum_name			FROM ' . FORUMS_TABLE . '			WHERE ' . $db->sql_in_set('forum_id', array_keys($hold_ary));		$result = $db->sql_query($sql);		$forum_names = array();		while ($row = $db->sql_fetchrow($result))		{			$forum_names[$row['forum_id']] = $row['forum_name'];		}		$db->sql_freeresult($result);		foreach ($hold_ary as $forum_id => $auth_ary)		{			$template->assign_block_vars('role_mask', array(				'NAME'				=> ($forum_id == 0) ? $user->lang['GLOBAL_MASK'] : $forum_names[$forum_id],				'FORUM_ID'			=> $forum_id)			);			if (isset($auth_ary['users']) && sizeof($auth_ary['users']))			{				$sql = 'SELECT user_id, username					FROM ' . USERS_TABLE . '					WHERE ' . $db->sql_in_set('user_id', $auth_ary['users']) . '					ORDER BY username_clean ASC';				$result = $db->sql_query($sql);				while ($row = $db->sql_fetchrow($result))				{					$template->assign_block_vars('role_mask.users', array(						'USER_ID'		=> $row['user_id'],						'USERNAME'		=> $row['username'],						'U_PROFILE'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u={$row['user_id']}"))					);				}				$db->sql_freeresult($result);			}			if (isset($auth_ary['groups']) && sizeof($auth_ary['groups']))			{				$sql = 'SELECT group_id, group_name, group_type					FROM ' . GROUPS_TABLE . '					WHERE ' . $db->sql_in_set('group_id', $auth_ary['groups']) . '					ORDER BY group_type ASC, group_name';				$result = $db->sql_query($sql);				while ($row = $db->sql_fetchrow($result))				{					$template->assign_block_vars('role_mask.groups', array(						'GROUP_ID'		=> $row['group_id'],						'GROUP_NAME'	=> ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],						'U_PROFILE'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&amp;g={$row['group_id']}"))					);				}				$db->sql_freeresult($result);			}		}	}	/**	* NOTE: this function is not in use atm	* Add a new option to the list ... $options is a hash of form ->	* $options = array(	*	'local'		=> array('option1', 'option2', ...),	*	'global'	=> array('optionA', 'optionB', ...)	* );	*/	function acl_add_option($options)	{		global $db, $cache;		if (!is_array($options))		{			return false;		}		$cur_options = array();		$sql = 'SELECT auth_option, is_global, is_local			FROM ' . ACL_OPTIONS_TABLE . '			ORDER BY auth_option_id';		$result = $db->sql_query($sql);		while ($row = $db->sql_fetchrow($result))		{			if ($row['is_global'])			{				$cur_options['global'][] = $row['auth_option'];			}			if ($row['is_local'])			{				$cur_options['local'][] = $row['auth_option'];			}		}		$db->sql_freeresult($result);		// Here we need to insert new options ... this requires discovering whether		// an options is global, local or both and whether we need to add an permission		// set flag (x_)		$new_options = array('local' => array(), 'global' => array());		foreach ($options as $type => $option_ary)		{			$option_ary = array_unique($option_ary);			foreach ($option_ary as $option_value)			{				if (!in_array($option_value, $cur_options[$type]))				{					$new_options[$type][] = $option_value;				}				$flag = substr($option_value, 0, strpos($option_value, '_') + 1);				if (!in_array($flag, $cur_options[$type]) && !in_array($flag, $new_options[$type]))				{					$new_options[$type][] = $flag;				}			}		}		unset($options);		$options = array();		$options['local'] = array_diff($new_options['local'], $new_options['global']);		$options['global'] = array_diff($new_options['global'], $new_options['local']);		$options['local_global'] = array_intersect($new_options['local'], $new_options['global']);		$sql_ary = array();		foreach ($options as $type => $option_ary)		{			foreach ($option_ary as $option)			{				$sql_ary[] = array(					'auth_option'	=> $option,					'is_global'		=> ($type == 'global' || $type == 'local_global') ? 1 : 0,					'is_local'		=> ($type == 'local' || $type == 'local_global') ? 1 : 0				);			}		}		$db->sql_multi_insert(ACL_OPTIONS_TABLE, $sql_ary);		$cache->destroy('acl_options');		$this->acl_clear_prefetch();		return true;	}	/**	* Set a user or group ACL record	*/	function acl_set($ug_type, $forum_id, $ug_id, $auth, $role_id = 0, $clear_prefetch = true)	{		global $db;		// One or more forums		if (!is_array($forum_id))		{			$forum_id = array($forum_id);		}		// One or more users		if (!is_array($ug_id))		{			$ug_id = array($ug_id);		}		$ug_id_sql = $db->sql_in_set($ug_type . '_id', array_map('intval', $ug_id));		$forum_sql = $db->sql_in_set('forum_id', array_map('intval', $forum_id));		// Instead of updating, inserting, removing we just remove all current settings and re-set everything...		$table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;		$id_field = $ug_type . '_id';		// Get any flags as required		reset($auth);		$flag = key($auth);		$flag = substr($flag, 0, strpos($flag, '_') + 1);				// This ID (the any-flag) is set if one or more permissions are true...		$any_option_id = (int) $this->option_ids[$flag];		// Remove any-flag from auth ary		if (isset($auth[$flag]))		{			unset($auth[$flag]);		}		// Remove current auth options...		$auth_option_ids = array();		foreach ($auth as $auth_option => $auth_setting)		{			$auth_option_ids[] = (int) $this->option_ids[$auth_option];		}		$sql = "DELETE FROM $table			WHERE $forum_sql				AND $ug_id_sql				AND auth_option_id IN ($any_option_id, " . implode(', ', $auth_option_ids) . ')';		$db->sql_query($sql);		// Remove those having a role assigned... the correct type of course...		$sql = 'SELECT role_id			FROM ' . ACL_ROLES_TABLE . "			WHERE role_type = '" . $db->sql_escape($flag) . "'";		$result = $db->sql_query($sql);		$role_ids = array();		while ($row = $db->sql_fetchrow($result))		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -