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

📄 gacl.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			}			/*			 * This query is where all the magic happens.			 * The ordering is very important here, as well very tricky to get correct.			 * Currently there can be  duplicate ACLs, or ones that step on each other toes. In this case, the ACL that was last updated/created			 * is used.			 *			 * This is probably where the most optimizations can be made.			 */			$order_by = array();			$query = '					SELECT		a.id,a.allow,a.return_value					FROM		'. $this->_db_table_prefix .'acl a					LEFT JOIN 	'. $this->_db_table_prefix .'aco_map ac ON ac.acl_id=a.id';			if ($aro_section_value != $this->_group_switch) {				$query .= '					LEFT JOIN	'. $this->_db_table_prefix .'aro_map ar ON ar.acl_id=a.id';			}			if ($axo_section_value != $this->_group_switch) {				$query .= '					LEFT JOIN	'. $this->_db_table_prefix .'axo_map ax ON ax.acl_id=a.id';			}			/*			 * if there are no aro groups, don't bother doing the join.			 */			if (isset($sql_aro_group_ids)) {				$query .= '					LEFT JOIN	'. $this->_db_table_prefix .'aro_groups_map arg ON arg.acl_id=a.id					LEFT JOIN	'. $this->_db_table_prefix .'aro_groups rg ON rg.id=arg.group_id';			}			// this join is necessary to weed out rules associated with axo groups			$query .= '					LEFT JOIN	'. $this->_db_table_prefix .'axo_groups_map axg ON axg.acl_id=a.id';			/*			 * if there are no axo groups, don't bother doing the join.			 * it is only used to rank by the level of the group.			 */			if (isset($sql_axo_group_ids)) {				$query .= '					LEFT JOIN	'. $this->_db_table_prefix .'axo_groups xg ON xg.id=axg.group_id';			}			//Move the below line to the LEFT JOIN above for PostgreSQL's sake.			//AND	ac.acl_id=a.id			$query .= '					WHERE		a.enabled=1						AND		(ac.section_value='. $this->db->quote($aco_section_value) .' AND ac.value='. $this->db->quote($aco_value) .')';			// if we are querying an aro group			if ($aro_section_value == $this->_group_switch) {				// if acl_get_groups did not return an array				if ( !isset ($sql_aro_group_ids) ) {					$this->debug_text ('acl_query(): Invalid ARO Group: '. $aro_value);					return FALSE;				}				$query .= '						AND		rg.id IN ('. $sql_aro_group_ids .')';				$order_by[] = '(rg.rgt-rg.lft) ASC';			} else {				$query .= '						AND		((ar.section_value='. $this->db->quote($aro_section_value) .' AND ar.value='. $this->db->quote($aro_value) .')';				if ( isset ($sql_aro_group_ids) ) {					$query .= ' OR rg.id IN ('. $sql_aro_group_ids .')';					$order_by[] = '(CASE WHEN ar.value IS NULL THEN 0 ELSE 1 END) DESC';					$order_by[] = '(rg.rgt-rg.lft) ASC';				}				$query .= ')';			}			// if we are querying an axo group			if ($axo_section_value == $this->_group_switch) {				// if acl_get_groups did not return an array				if ( !isset ($sql_axo_group_ids) ) {					$this->debug_text ('acl_query(): Invalid AXO Group: '. $axo_value);					return FALSE;				}				$query .= '						AND		xg.id IN ('. $sql_axo_group_ids .')';				$order_by[] = '(xg.rgt-xg.lft) ASC';			} else {				$query .= '						AND		(';				if ($axo_section_value == '' AND $axo_value == '') {					$query .= '(ax.section_value IS NULL AND ax.value IS NULL)';				} else {					$query .= '(ax.section_value='. $this->db->quote($axo_section_value) .' AND ax.value='. $this->db->quote($axo_value) .')';				}				if (isset($sql_axo_group_ids)) {					$query .= ' OR xg.id IN ('. $sql_axo_group_ids .')';					$order_by[] = '(CASE WHEN ax.value IS NULL THEN 0 ELSE 1 END) DESC';					$order_by[] = '(xg.rgt-xg.lft) ASC';				} else {					$query .= ' AND axg.group_id IS NULL';				}				$query .= ')';			}			/*			 * The ordering is always very tricky and makes all the difference in the world.			 * Order (ar.value IS NOT NULL) DESC should put ACLs given to specific AROs			 * ahead of any ACLs given to groups. This works well for exceptions to groups.			 */			$order_by[] = 'a.updated_date DESC';			$query .= '					ORDER BY	'. implode (',', $order_by) . '					';			// we are only interested in the first row			$rs = $this->db->SelectLimit($query, 1);			if (!is_object($rs)) {				$this->debug_db('acl_query');				return FALSE;			}			$row =& $rs->FetchRow();			/*			 * Return ACL ID. This is the key to "hooking" extras like pricing assigned to ACLs etc... Very useful.			 */			if (is_array($row)) {				// Permission granted?				// This below oneliner is very confusing.				//$allow = (isset($row[1]) AND $row[1] == 1);				//Prefer this.				if ( isset($row[1]) AND $row[1] == 1 ) {					$allow = TRUE;				} else {					$allow = FALSE;				}				$retarr = array('acl_id' => &$row[0], 'return_value' => &$row[2], 'allow' => $allow);			} else {				// Permission denied.				$retarr = array('acl_id' => NULL, 'return_value' => NULL, 'allow' => FALSE);			}			/*			 * Return the query that we ran if in debug mode.			 */			if ($debug == TRUE) {				$retarr['query'] = &$query;			}			//Cache data.			$this->put_cache($retarr, $cache_id);		}		$this->debug_text("<b>acl_query():</b> ACO Section: $aco_section_value ACO Value: $aco_value ARO Section: $aro_section_value ARO Value $aro_value ACL ID: ". $retarr['acl_id'] .' Result: '. $retarr['allow']);		return $retarr;	}	/**	* Grabs all groups mapped to an ARO. You can also specify a root_group for subtree'ing.	* @param string The section value or the ARO or ACO	* @param string The value of the ARO or ACO	* @param integer The group id of the group to start at (optional)	* @param string The type of group, either ARO or AXO (optional)	*/	function acl_get_groups($section_value, $value, $root_group=NULL, $group_type='ARO') {		switch(strtolower($group_type)) {			case 'axo':				$group_type = 'axo';				$object_table = $this->_db_table_prefix .'axo';				$group_table = $this->_db_table_prefix .'axo_groups';				$group_map_table = $this->_db_table_prefix .'groups_axo_map';				break;			default:				$group_type = 'aro';				$object_table = $this->_db_table_prefix .'aro';				$group_table = $this->_db_table_prefix .'aro_groups';				$group_map_table = $this->_db_table_prefix .'groups_aro_map';				break;		}		//$profiler->startTimer( "acl_get_groups()");		//Generate unique cache id.		$cache_id = 'acl_get_groups_'.$section_value.'-'.$value.'-'.$root_group.'-'.$group_type;		$retarr = $this->get_cache($cache_id);		if (!$retarr) {			// Make sure we get the groups			$query = '					SELECT 		DISTINCT g2.id';			if ($section_value == $this->_group_switch) {				$query .= '					FROM		' . $group_table . ' g1,' . $group_table . ' g2';				$where = '					WHERE		g1.value=' . $this->db->quote( $value );			} else {				$query .= '					FROM		'. $object_table .' o,'. $group_map_table .' gm,'. $group_table .' g1,'. $group_table .' g2';				$where = '					WHERE		(o.section_value='. $this->db->quote($section_value) .' AND o.value='. $this->db->quote($value) .')						AND		gm.'. $group_type .'_id=o.id						AND		g1.id=gm.group_id';			}			/*			 * If root_group_id is specified, we have to narrow this query down			 * to just groups deeper in the tree then what is specified.			 * This essentially creates a virtual "subtree" and ignores all outside groups.			 * Useful for sites like sourceforge where you may seperate groups by "project".			 */			if ( $root_group != '') {				//It is important to note the below line modifies the tables being selected.				//This is the reason for the WHERE variable.				$query .= ','. $group_table .' g3';				$where .= '						AND		g3.value='. $this->db->quote( $root_group ) .'						AND		((g2.lft BETWEEN g3.lft AND g1.lft) AND (g2.rgt BETWEEN g1.rgt AND g3.rgt))';			} else {				$where .= '						AND		(g2.lft <= g1.lft AND g2.rgt >= g1.rgt)';			}			$query .= $where;			// $this->debug_text($query);			$rs = $this->db->Execute($query);			if (!is_object($rs)) {				$this->debug_db('acl_get_groups');				return FALSE;			}			$retarr = array();			/*			 * Changed by: Louis Landry for Joomla ACL integration			 * 21-Jan-2006			 */			for ($i = 0; $i < count($rs->data); $i++) {				//$retarr[] = $rs->data[$i]['id'];				$retarr[] = reset( $rs->data[$i] );			}			//Cache data.			$this->put_cache($retarr, $cache_id);		}		return $retarr;	}	/**	* Uses PEAR's Cache_Lite package to grab cached arrays, objects, variables etc...	* using unserialize() so it can handle more then just text string.	* @param string The id of the cached object	* @return mixed The cached object, otherwise FALSE if the object identifier was not found	*/	function get_cache($cache_id) {		if ( $this->_caching == TRUE ) {			$this->debug_text("get_cache(): on ID: $cache_id");			if ( is_string($this->Cache_Lite->get($cache_id) ) ) {				return unserialize($this->Cache_Lite->get($cache_id) );			}		}		return false;	}	/**	* Uses PEAR's Cache_Lite package to write cached arrays, objects, variables etc...	* using serialize() so it can handle more then just text string.	* @param mixed A variable to cache	* @param string The id of the cached variable	*/	function put_cache($data, $cache_id) {		if ( $this->_caching == TRUE ) {			$this->debug_text("put_cache(): Cache MISS on ID: $cache_id");			return $this->Cache_Lite->save(serialize($data), $cache_id);		}		return false;	}}?>

⌨️ 快捷键说明

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