<?php

class TiguMetaboxes {
	public function __construct()
	{
		add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
		add_action('save_post', array($this, 'save_meta_boxes'));
	}
	public function add_meta_boxes()
	{
        $this->add_meta_box('post_general','Featured Image', 'post');
		
		
	}
	public function add_meta_box($id, $label, $post_type)
	{
	    add_meta_box( 
	        'tiguan_' . $id,
	        $label,
	        array($this, $id),
	        $post_type,'normal' , 'high'
	    );
	}
	public function save_meta_boxes($post_id)
	{
		if(defined( 'DOING_AUTOSAVE') && DOING_AUTOSAVE) {
			return;
		}
		
		foreach($_POST as $key => $value) {
			update_post_meta($post_id, $key, $value);
		}
	}
	
	public function post_general()
	{		
		include 'post-metaboxes.php';
	}

	
	public function select($id, $label, $options, $desc = '')
	{
		global $post;
		
		if (empty($html)) $html = '<div class="review grid">';
			$html .= '<div class="field">';
				$html .= '<select class="small" id="tiguan_' . $id . '" name="tiguan_' . $id . '">';
				foreach($options as $key => $option) {
					if(get_post_meta($post->ID, 'tiguan_' . $id, true) == $key) {
						$selected = 'selected="selected"';
					} else {
						$selected = '';
					}
					
					$html .= '<option ' . $selected . 'value="' . $key . '">' . $option . '</option>';
				}
				$html .= '</select>';
				if($desc) {
					$html .= '<p>' . $desc . '</p>';
				}
			$html .= '</div>';
		$html .= '</div>';
		
		echo $html;
	}
	
}

$metaboxes = new TiguMetaboxes;