<?php

/**
 * 
 *
 * @version $Id$
 * @copyright 2003 
 **/

class rhceib_frontend {
	var $template = '';
	function rhceib_frontend(){
		global $rhc_plugin; 
		if('1'==$rhc_plugin->get_option('enable_events_in_blogroll','1',true)){
			add_filter( 'pre_get_posts', array(&$this,'pre_get_posts') );
		}
		/*
		$this->template = $rhc_plugin->get_option('rhc_eib_template','',true);
		if(!empty($this->template)){
			add_filter('the_content', array(&$this,'the_content'), 999999, 1);
		}
		*/
	}
	
	function the_content($content){
		global $post;
	
		if(is_object($post)&&property_exists($post,'post_type')&&RHC_EVENTS==$post->post_type){
			if( false == $query->query_vars['suppress_filters'] && (is_home() || is_post_type_archive('post')) ){
				if(false!==strpos($this->template,'{content}')){
					$content = str_replace('{content}',$content,$this->template);
				}else{
					$content = $this->template.$content;
				}
			}
		}
		return $content;
	}
	
	function pre_get_posts($query){
		//return $query;
		$post_type = $query->get('post_type');
		if( empty($post_type) || (is_array($post_type) && in_array('post',$post_type)) ){
			if( ( !isset($query->query_vars['suppress_filters']) || (false == $query->query_vars['suppress_filters']) ) && (is_home() || is_post_type_archive('post')) ){
				
				if(empty($post_type)){
					$post_types=array('post',RHC_EVENTS);
				}else if( is_array($post_type) && in_array('post',$post_type) ){
					$post_types = $post_type;
					$post_types[]=RHC_EVENTS;
				}else{
					return $query;
				}

				$query->set( 'post_type',$post_types );
			}		
		}
		
		return $query;
	}
}
?>