Exemplo n.º 1
0
		/**
		 * Check a given id to see if it is OK to show
		 *
		 * Called upon by _show_item()
		 * Calls on further_checks_on_entity()
		 *
		 * @todo check to see if the order of the checking is appropriate... it seems a little wonky
		 * @param integer $id Reason Entity ID
		 * @return mixed false if not OK, the entity object if OK
		 */
		function check_id( $id )
		{
			// assume that if it's in the list it's OK
			if(!empty($this->items[$id]))
				return $this->items[$id];
			
			$e = new entity ( $id );
			if(in_array($id,$this->ok_ids))
			{
				return $e;
			}
			elseif(in_array($id, $this->not_ok_ids))
			{
				return false;
			}
			elseif( $e->get_values()
				&& $e->get_value('type')
				&& $e->get_value('type') == $this->type
				&& $e->get_value('state') == 'Live'
				&& ( !$this->params['limit_to_current_site'] || $e->owned_or_borrowed_by( $this->parent->site_id ) )
				&& $this->further_checks_on_entity( $e )
			 )
			 {
			 	$this->ok_ids[] = $id;
				return $e;
			}
			elseif(array_key_exists($id,$this->ids))
			{
				$this->ok_ids[] = $id;
				return $e;
			}
			else
			{
				$this->not_ok_ids[] = $id;
				http_response_code(404);
				// 404s, even internal ones, don't need to go into the error log ... commenting this out to reduce error log spam.
				//if(!empty($_SERVER['HTTP_REFERER']))
				//{
				//	$parts = parse_url($_SERVER['HTTP_REFERER']);
				//	if($parts['host'] == HTTP_HOST_NAME) // probably can't do anything about it if the link is offsite...
				//		trigger_error('ID given does not correspond to an appropriate entity. Referer: '.$_SERVER['HTTP_REFERER']);
				//}
				return false;
			}
		}