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

📄 auth.php

📁 这些都是我以前学习是用到的源码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
			$role_ids[] = $row['role_id'];		}		$db->sql_freeresult($result);		if (sizeof($role_ids))		{			$sql = "DELETE FROM $table				WHERE $forum_sql					AND $ug_id_sql					AND auth_option_id = 0					AND " . $db->sql_in_set('auth_role_id', $role_ids);			$db->sql_query($sql);		}		// Ok, include the any-flag if one or more auth options are set to yes...		foreach ($auth as $auth_option => $setting)		{			if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))			{				$auth[$flag] = ACL_YES;			}		}		$sql_ary = array();		foreach ($forum_id as $forum)		{			$forum = (int) $forum;			if ($role_id)			{				foreach ($ug_id as $id)				{					$sql_ary[] = array(						$id_field			=> (int) $id,						'forum_id'			=> (int) $forum,						'auth_option_id'	=> 0,						'auth_setting'		=> 0,						'auth_role_id'		=> $role_id					);				}			}			else			{				foreach ($auth as $auth_option => $setting)				{					$auth_option_id = (int) $this->option_ids[$auth_option];					if ($setting != ACL_NO)					{						foreach ($ug_id as $id)						{							$sql_ary[] = array(								$id_field			=> (int) $id,								'forum_id'			=> (int) $forum,								'auth_option_id'	=> (int) $auth_option_id,								'auth_setting'		=> (int) $setting							);						}					}				}			}		}		$db->sql_multi_insert($table, $sql_ary);		if ($clear_prefetch)		{			$this->acl_clear_prefetch();		}	}	/**	* Set a role-specific ACL record	*/	function acl_set_role($role_id, $auth)	{		global $db;		// Get any-flag as required		reset($auth);		$flag = key($auth);		$flag = substr($flag, 0, strpos($flag, '_') + 1);				// Remove any-flag from auth ary		if (isset($auth[$flag]))		{			unset($auth[$flag]);		}		// Re-set any flag...		foreach ($auth as $auth_option => $setting)		{			if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))			{				$auth[$flag] = ACL_YES;			}		}		$sql_ary = array();		foreach ($auth as $auth_option => $setting)		{			$auth_option_id = (int) $this->option_ids[$auth_option];			if ($setting != ACL_NO)			{				$sql_ary[] = array(					'role_id'			=> (int) $role_id,					'auth_option_id'	=> (int) $auth_option_id,					'auth_setting'		=> (int) $setting				);			}		}		// If no data is there, we set the any-flag to ACL_NEVER...		if (!sizeof($sql_ary))		{			$sql_ary[] = array(				'role_id'			=> (int) $role_id,				'auth_option_id'	=> $this->option_ids[$flag],				'auth_setting'		=> ACL_NEVER			);		}		// Remove current auth options...		$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '			WHERE role_id = ' . $role_id;		$db->sql_query($sql);		// Now insert the new values		$db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);		$this->acl_clear_prefetch();	}	/**	* Remove local permission	*/	function acl_delete($mode, $ug_id = false, $forum_id = false, $permission_type = false)	{		global $db;		if ($ug_id === false && $forum_id === false)		{			return;		}		$option_id_ary = array();		$table = ($mode == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;		$id_field  = $mode . '_id';		$where_sql = array();		if ($forum_id !== false)		{			$where_sql[] = (!is_array($forum_id)) ? 'forum_id = ' . (int) $forum_id : $db->sql_in_set('forum_id', array_map('intval', $forum_id));		}		if ($ug_id !== false)		{			$where_sql[] = (!is_array($ug_id)) ? $id_field . ' = ' . (int) $ug_id : $db->sql_in_set($id_field, array_map('intval', $ug_id));		}		// There seem to be auth options involved, therefore we need to go through the list and make sure we capture roles correctly		if ($permission_type !== false)		{			// Get permission type			$sql = 'SELECT auth_option, auth_option_id				FROM ' . ACL_OPTIONS_TABLE . "				WHERE auth_option LIKE '" . $db->sql_escape(str_replace('_', "\_", $permission_type)) . "%'";			$sql .= ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc') ? " ESCAPE '\\'" : '';			$result = $db->sql_query($sql);			$auth_id_ary = array();			while ($row = $db->sql_fetchrow($result))			{				$option_id_ary[] = $row['auth_option_id'];				$auth_id_ary[$row['auth_option']] = ACL_NO;			}			$db->sql_freeresult($result);			// First of all, lets grab the items having roles with the specified auth options assigned			$sql = "SELECT auth_role_id, $id_field, forum_id				FROM $table, " . ACL_ROLES_TABLE . " r				WHERE auth_role_id <> 0					AND auth_role_id = r.role_id					AND r.role_type = '{$permission_type}'					AND " . implode(' AND ', $where_sql) . '				ORDER BY auth_role_id';			$result = $db->sql_query($sql);			$cur_role_auth = array();			while ($row = $db->sql_fetchrow($result))			{				$cur_role_auth[$row['auth_role_id']][$row['forum_id']][] = $row[$id_field];			}			$db->sql_freeresult($result);			// Get role data for resetting data			if (sizeof($cur_role_auth))			{				$sql = 'SELECT ao.auth_option, rd.role_id, rd.auth_setting					FROM ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_ROLES_DATA_TABLE . ' rd					WHERE ao.auth_option_id = rd.auth_option_id						AND ' . $db->sql_in_set('rd.role_id', array_keys($cur_role_auth));				$result = $db->sql_query($sql);				$auth_settings = array();				while ($row = $db->sql_fetchrow($result))				{					// We need to fill all auth_options, else setting it will fail...					if (!isset($auth_settings[$row['role_id']]))					{						$auth_settings[$row['role_id']] = $auth_id_ary;					}					$auth_settings[$row['role_id']][$row['auth_option']] = $row['auth_setting'];				}				$db->sql_freeresult($result);				// Set the options				foreach ($cur_role_auth as $role_id => $auth_row)				{					foreach ($auth_row as $f_id => $ug_row)					{						$this->acl_set($mode, $f_id, $ug_row, $auth_settings[$role_id], 0, false);					}				}			}		}		// Now, normally remove permissions...		if ($permission_type !== false)		{			$where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));		}				$sql = "DELETE FROM $table			WHERE " . implode(' AND ', $where_sql);		$db->sql_query($sql);		$this->acl_clear_prefetch();	}	/**	* Assign category to template	* used by display_mask()	*/	function assign_cat_array(&$category_array, $tpl_cat, $tpl_mask, $ug_id, $forum_id, $show_trace = false)	{		global $template, $user, $phpbb_admin_path, $phpEx;		foreach ($category_array as $cat => $cat_array)		{			$template->assign_block_vars($tpl_cat, array(				'S_YES'		=> ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,				'S_NEVER'	=> ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,				'S_NO'		=> ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false,											'CAT_NAME'	=> $user->lang['permission_cat'][$cat])			);			foreach ($cat_array['permissions'] as $permission => $allowed)			{				$template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(					'S_YES'		=> ($allowed == ACL_YES) ? true : false,					'S_NEVER'	=> ($allowed == ACL_NEVER) ? true : false,					'S_NO'		=> ($allowed == ACL_NO) ? true : false,					'UG_ID'			=> $ug_id,					'FORUM_ID'		=> $forum_id,					'FIELD_NAME'	=> $permission,					'S_FIELD_NAME'	=> 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',					'U_TRACE'		=> ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&amp;mode=trace&amp;u=$ug_id&amp;f=$forum_id&amp;auth=$permission") : '',					'UA_TRACE'		=> ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',					'PERMISSION'	=> $user->lang['acl_' . $permission]['lang'])				);			}		}	}	/**	* Building content array from permission rows with explicit key ordering	* used by display_mask()	*/	function build_permission_array(&$permission_row, &$content_array, &$categories, $key_sort_array)	{		global $user;		foreach ($key_sort_array as $forum_id)		{			if (!isset($permission_row[$forum_id]))			{				continue;			}			$permissions = $permission_row[$forum_id];			ksort($permissions);			foreach ($permissions as $permission => $auth_setting)			{				if (!isset($user->lang['acl_' . $permission]))				{					$user->lang['acl_' . $permission] = array(						'cat'	=> 'misc',						'lang'	=> '{ acl_' . $permission . ' }'					);				}							$cat = $user->lang['acl_' . $permission]['cat'];							// Build our categories array				if (!isset($categories[$cat]))				{					$categories[$cat] = $user->lang['permission_cat'][$cat];				}				// Build our content array				if (!isset($content_array[$forum_id]))				{					$content_array[$forum_id] = array();				}				if (!isset($content_array[$forum_id][$cat]))				{					$content_array[$forum_id][$cat] = array(						'S_YES'			=> false,						'S_NEVER'		=> false,						'S_NO'			=> false,						'permissions'	=> array(),					);				}				$content_array[$forum_id][$cat]['S_YES'] |= ($auth_setting == ACL_YES) ? true : false;				$content_array[$forum_id][$cat]['S_NEVER'] |= ($auth_setting == ACL_NEVER) ? true : false;				$content_array[$forum_id][$cat]['S_NO'] |= ($auth_setting == ACL_NO) ? true : false;				$content_array[$forum_id][$cat]['permissions'][$permission] = $auth_setting;			}		}	}	/**	* Use permissions from another user. This transferes a permission set from one user to another.	* The other user is always able to revert back to his permission set.	* This function does not check for lower/higher permissions, it is possible for the user to gain 	* "more" permissions by this.	* Admin permissions will not be copied.	*/	function ghost_permissions($from_user_id, $to_user_id)	{		global $db;		if ($to_user_id == ANONYMOUS)		{			return false;		}		$hold_ary = $this->acl_raw_data($from_user_id, false, false);		if (isset($hold_ary[$from_user_id]))		{			$hold_ary = $hold_ary[$from_user_id];		}				// Key 0 in $hold_ary are global options, all others are forum_ids		// We disallow copying admin permissions		foreach ($this->acl_options['global'] as $opt => $id)		{			if (strpos($opt, 'a_') === 0)			{				$hold_ary[0][$opt] = ACL_NEVER;			}		}		// Force a_switchperm to be allowed		$hold_ary[0]['a_switchperm'] = ACL_YES;		$user_permissions = $this->build_bitstring($hold_ary);		if (!$user_permissions)		{			return false;		}		$sql = 'UPDATE ' . USERS_TABLE . "			SET user_permissions = '" . $db->sql_escape($user_permissions) . "',				user_perm_from = $from_user_id			WHERE user_id = " . $to_user_id;		$db->sql_query($sql);		return true;	}}?>

⌨️ 快捷键说明

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