<?php
/**
* @package Krown
* @subpackage Krown
* @since Krown 1.0
*/
//==========================================
// Team Meta Box
//==========================================
class team_meta_box_plugin {
  function __construct() {
    add_action( 'add_meta_boxes', array( $this, 'our_team_meta_box' ) );
  }
  function our_team_meta_box()
	{
		add_meta_box('our_schedule', __('Extra Information', 'evential'), 'our_team_meta_action', 'team', 'advanced', 'high' );
	}
}
new team_meta_box_plugin();

function our_team_meta_action($post) { ?>
    <?php $designation = get_post_meta($post->ID, 'designation', true); ?>
    <div class="meta_tr"><div class="meta_lable">Designation</div><div class="meta_field"><input type="text" name="designation" value="<?php echo esc_attr($designation); ?>"></div></div>
    <?php $facebook = get_post_meta($post->ID, 'facebook', true); ?>
    <div class="meta_tr"><div class="meta_lable">Facebook</div><div class="meta_field"><input type="text" name="facebook" value="<?php echo esc_url($facebook); ?>"></div></div>
    <?php $linkedin = get_post_meta($post->ID, 'linkedin', true); ?>
    <div class="meta_tr"><div class="meta_lable">Linked In</div><div class="meta_field"><input type="text" name="linkedin" value="<?php echo esc_url($linkedin); ?>"></div></div>
    <?php $google = get_post_meta($post->ID, 'google', true); ?>
    <div class="meta_tr"><div class="meta_lable">Google Plus</div><div class="meta_field"><input type="text" name="google" value="<?php echo esc_url($google); ?>"></div></div>
    <?php $twitter = get_post_meta($post->ID, 'twitter', true); ?>
    <div class="meta_tr"><div class="meta_lable">Twitter</div><div class="meta_field"><input type="text" name="twitter" value="<?php echo esc_url($twitter); ?>"></div></div>
    <div class="clr"></div>
<?php 
}

add_action( 'save_post', 'save_team_extra_info' );
function save_team_extra_info($post_ID)
{
    global $post;
    if(isset($_POST))
    {
        if(isset($_POST['designation']))
        {
            update_post_meta( $post_ID, 'designation', strip_tags($_POST['designation']) );
        }
        if(isset($_POST['facebook']))
        {
            update_post_meta( $post_ID, 'facebook', strip_tags($_POST['facebook']) );
        }
        if(isset($_POST['linkedin']))
        {
            update_post_meta( $post_ID, 'linkedin', strip_tags($_POST['linkedin']) );
        }
        if(isset($_POST['google']))
        {
            update_post_meta( $post_ID, 'google', strip_tags($_POST['google']) );
        }
        if(isset($_POST['twitter']))
        {
            update_post_meta( $post_ID, 'twitter', strip_tags($_POST['twitter']) );
        }
        
    }
}
//==========================================
// Portfolio Details Meta Box
//==========================================
class portfolio_meta_box_plugin {
  function __construct() {
    add_action( 'add_meta_boxes', array( $this, 'our_portfolio_meta_box' ) );
  }
  function our_portfolio_meta_box()
	{
		add_meta_box('our_schedule', __('Details Information', 'evential'), 'our_portfolio_meta_action', 'portfolio', 'advanced', 'high' );
	}
}
new portfolio_meta_box_plugin();

function our_portfolio_meta_action($post) { ?>
    <?php $company = get_post_meta($post->ID, 'company', true); ?>
    <div class="meta_tr"><div class="meta_lable">Company</div><div class="meta_field"><input type="text" name="company" value="<?php echo esc_attr($company); ?>"></div></div>
	
    <?php $budget = get_post_meta($post->ID, 'budget', true); ?>
    <div class="meta_tr"><div class="meta_lable">Budget</div><div class="meta_field"><input type="text" name="budget" value="<?php echo esc_attr($budget); ?>"></div></div>
	
    <?php $website = get_post_meta($post->ID, 'website', true); ?>
    <div class="meta_tr"><div class="meta_lable">Website</div><div class="meta_field"><input type="text" name="website" value="<?php echo esc_attr($website); ?>"></div></div>
<?php 
}

add_action( 'save_post', 'save_portfolio_extra_info' );
function save_portfolio_extra_info($post_ID)
{
    global $post;
    if(isset($_POST))
    {
        if(isset($_POST['company']))
        {
            update_post_meta( $post_ID, 'company', strip_tags($_POST['company']) );
        }
        if(isset($_POST['budget']))
        {
            update_post_meta( $post_ID, 'budget', strip_tags($_POST['budget']) );
        }
        if(isset($_POST['website']))
        {
            update_post_meta( $post_ID, 'website', strip_tags($_POST['website']) );
        }
    }
}
?>
<?php 
//==========================================
// Portfolio Meta Box
//==========================================

add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add()
{
	add_meta_box( 'my-meta-box-id', 'Width Settings', 'cd_meta_box_cb', 'portfolio', 'side', 'high' );
}

function cd_meta_box_cb( $post )
{
	$values = get_post_custom( $post->ID );
	$text = isset( $values['my_meta_box_text'] ) ? esc_attr( $values['my_meta_box_text'][0] ) : '';
	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
	?>
	<p>
		<label for="my_meta_box_text">Set Width Class</label>
		<input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo esc_attr($text); ?>" /><br/>
		<small>ie: width-x2 (if you want to set big image)</small>
	</p>
	<?php	
}


add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
	// Bail if we're doing an auto save
	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
	
	// if our nonce isn't there, or we can't verify it, bail
	if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
	
	// if our current user can't edit this post, bail
	//if( !current_user_can( 'edit_posts' ) ) return;
	
	// now we can actually save the data
	$allowed = array( 
		'a' => array( // on allow a tags
			'href' => array() // and those anchords can only have href attribute
		)
	);
	
	// Probably a good idea to make sure your data is set
	if( isset( $_POST['my_meta_box_text'] ) )
		update_post_meta( $post_id, 'my_meta_box_text', wp_kses( $_POST['my_meta_box_text'], $allowed ) );
		
}