<?php 

class rhc_auw_options {
	var $id;
	function __construct($plugin_id='rhc'){
		$this->id = $plugin_id;
		add_filter("pop-options_{$this->id}",array(&$this,'options'),10,1);		
	}
	
	function options( $t ){
		foreach( $t as $i => $tab ){
			if( $tab->id == 'rhc-custom-types' ){
				$post_types=array();
				foreach(get_post_types(array(/*'public'=> true,'_builtin' => false*/),'objects','and') as $post_type => $pt){
					if(in_array($post_type,array(RHC_EVENTS, 'revision','nav_menu_item')))continue;
					$post_types[$post_type]=$pt;
				} 
				
				$new_options = array();
				foreach( $tab->options as $opt ){
					//TODO: find a more reliable entry point
					if( $opt->type=='subtitle' && $opt->label == __('Automatic Calendar content','rhcauw') ){

//--
						if( count( $post_types ) > 0 ){
							$new_options[]=(object)array(
									'type' 			=> 'subtitle',
									'label'			=> __('Accordion Upcoming Events Widget Metabox','rhcauw')
								);				

							$j=0;
							foreach($post_types as $post_type => $pt){
								$tmp=(object)array(
									'id'	=> 'auw_post_types_'.$post_type,
									'name'	=> 'auw_post_types[]',
									'type'	=> 'checkbox',
									'option_value'=>$post_type,
									'label'	=> (@$pt->labels->name?$pt->labels->name:$post_type),
									'el_properties' => array(),
									'save_option'=>true,
									'load_option'=>true
								);
								if($j==0){
									$tmp->description = sprintf('<p>%s</p>',
										__('Check post types for wich you want to enable the Calendarize It! Accordion Upcoming Events Widget Metabox.','rhcauw')
									);
									$tmp->description_rowspan = count($post_types);
								}				
								
								$new_options[]=$tmp;
								$j++;
							}
						}	
//--
					}
					$new_options[] = $opt;
				}
				$t[$i]->options = $new_options;
				
			}
		}
		return $t;
	}
}


?>