Pastoid

Scope RPN

The page you are looking at now is at this URL: http://pastoid.com/awz

This paste was last updated on April 28, 2009 at 1:00 pm.

Pasted Coderaw

<?php
 
function check_scope_criteria($criteria)
{
	$stack = array();
	foreach($criteria as $crit) {
		if(is_array($crit)) {
			$value = false;
			switch($crit[0]) {
				case 'request':
					$value = URL::get_matched_rule()->name == $crit[1];
					break;
				case 'token':
					if(isset($crit[2])) {
						$value = User::identify()->can($crit[1], $crit[2]);
					}
					else {
						$value = User::identify()->can($crit[1]);
					}
					break;
				default:
					$value = Plugins::filter('scope_criteria_value', $value, $crit[1], $crit[2]);
					break;
			}
			$stack[] = $value;
		}
		else {
			switch($crit) {
				case 'not':
					$stack[] = ! array_pop($stack);
					break;
				case 'or':
					$value1 = array_pop($stack);
					$value2 = array_pop($stack);
					$stack[] = $value1 || $value2;
					break;
				case 'and':
					$value1 = array_pop($stack);
					$value2 = array_pop($stack);
					$stack[] = $value1 && $value2;
					break;
				default:
					Plugins::act('scope_criteria_operator', $stack, $crit);
					break;
			}
		}
	}
	return array_pop($stack);
}
 
	public function theme_area($theme, $area, $scope = null)
	{
		// This array would normally come from the database via:
		// $scopes = $this->get_scopes($area);
		$scopes = array(
			'editors' => array(
				array('request', 'display_post'),
				'and',
				array('token', 'post_entry', 'edit'),
			),
		);
 
		$active_scope = '';
		foreach($scopes as $scope_name => $scope_criteria) {
			if($this->check_scope_criteria($scope_criteria)) {
				$active_scope = $scope_name;
				break;
			}
		}
 
		$area_blocks = $this->get_blocks($area, $active_scope, $theme);
 
		$this->area = $area;
		$begin = '';
		$begin = Plugins::filter('area_begin', $begin, $area, $this);
 
		$output = '';
		foreach($area_blocks as $block_instance_id => $block) {
			Plugins::act('block_content_' . $block->type, $block);
			$output .= implode( '', $this->content_return($block));
		}
 
		$this->area = '';
		$end = '';
		$end = Plugins::filter('area_end', $end, $area, $this);
 
		$output = $begin . $output . $end;
 
		return $output;
	}
 
?>
 

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 13
search.live.com 2
Is this paste spam?
<Hide