All pastes #89054 Raw Edit

k4st

public php v1 · immutable
#89054 ·published 2006-07-15 18:34 UTC
rendered paste body
class k4CanDoTag extends FATemplateTag{	function parse(&$context, &$renderer, &$node) 	{		$this->requireAttributes('object', 'perm');				$user = &$context->get('k4_user');		$perm = $this->getAttribute('perm');		$object = $this->getAttribute('object');				$perm_has_and = strpos($perm, ',');		$perm_has_or = strpos($perm, '|');				$object_has_and = strpos($object, ',');		$object_has_or = strpos($object, '|');				$perms_array = array();		$objects_array = array();				$singleperms = $singleobjects = 0;				if($perm_has_and !== FALSE || $perm_has_or !== FALSE)		{			$glue = $perm_has_and !== FALSE ? ',' : '|';			$perms_array = explode($glue, $perm);		}		else		{			$singleperms = 1;			$perms_array[] = $perm;		}				if($object_has_and !== FALSE || $object_has_or !== FALSE)		{			$glue = $object_has_and !== FALSE ? ',' : '|';			$objects_array = explode($glue, $object);			$multiobjects = TRUE;		}		else		{			$singleobjects = 1;			$objects_array[] = $object;		}				$res = FALSE;				if($singleobjects * $singleperms == 0)		{			foreach($objects_array as $object)			{				$sub_res = FALSE;				foreach($perms_array as $perm)				{					$sub_res = $user->canDo($perm, $object);					if($sub_res && !$perm_has_and)					{						break;					}				}				if($sub_res && !$object_has_and)				{					$res = TRUE;					break;				}			}		}		else		{			$res = $user->canDo($perms_array[0], $objects_array[0]);		}				if($res)		{			return $renderer->doNode($node);		}	}}