<?php
if ( !defined( 'ABSPATH' ) ) exit;

/**
 * Staffs Register
 *
 * @package All In One Custom Post
 * @since All In One Custom Post 1.0.0 
 */
function vr_register_post_staffs() {

	register_post_type( 'vr_staffs',
	array(
		'menu_icon' 	=> 'dashicons-businessman',
		'supports' 		=> array( 'title', 'thumbnail', 'author' ),
		'public' 		=> true,
		'show_ui' 		=> true,
		'labels'        => array(
			'name'                	=> __( 'Staffs', PLUGIN_NAME ),
			'singular_name'       	=> __( 'Staff', PLUGIN_NAME ),
			'add_new'             	=> __( 'Add New Staff', PLUGIN_NAME ),
			'add_new_item'        	=> __( 'Add New Staff', PLUGIN_NAME ),
			'menu_name'           	=> __( 'Staffs', PLUGIN_NAME ),
			'parent_item_colon'   	=> __( 'Parent Staff', PLUGIN_NAME ),
			'all_items'           	=> __( 'All Staffs', PLUGIN_NAME ),
			'view_item'           	=> __( 'View Staff', PLUGIN_NAME ),
			'edit_item'           	=> __( 'Edit Staff', PLUGIN_NAME ),
			'update_item'         	=> __( 'Update Staff', PLUGIN_NAME ),
			'search_items'        	=> __( 'Search Staff', PLUGIN_NAME ),
			'not_found' 			=> __(  'No Staff found', PLUGIN_NAME ),
			'not_found_in_trash'	=> __(  'No Staff found in Trash', PLUGIN_NAME ),
			'parent' 				=> __(  'Parent Staff', PLUGIN_NAME ),
		)
	));

	register_taxonomy(
		'vr_staffs_categories',
		'vr_staffs',
		array(
			'labels' => array(
				'name' 				=> __( 'Staffs Categories', PLUGIN_NAME ),
				'singular_name' 	=> __( 'Category', PLUGIN_NAME ),
				'search_items'  	=> __( 'Search Categories', PLUGIN_NAME ),
				'all_items' 		=> __( 'All Categories', PLUGIN_NAME ),
				'parent_item' 		=> __( 'Parent Category', PLUGIN_NAME ),
				'parent_item_colon' => __( 'Parent Category:', PLUGIN_NAME ),
				'edit_item' 		=> __( 'Edit Category', PLUGIN_NAME ),
				'update_item' 		=> __( 'Update Category', PLUGIN_NAME ),
				'add_new_item' 		=> __( 'Add New Category', PLUGIN_NAME ),
				'new_item_name'		=> __( 'New Category Name', PLUGIN_NAME ),
				'menu_name' 		=> __( 'Categories', PLUGIN_NAME ),
			 ),
			'hierarchical'	=> true,
			'public' 		=> true,
			'rewrite' 		=> true
		)
	);

	register_taxonomy(
		'vr_staffs_tags',
		'vr_staffs',
		array(
			'labels' => array(
				'name' 				=> __( 'Staffs Tags', PLUGIN_NAME ),
				'singular_name' 	=> __( 'Tag', PLUGIN_NAME ),
				'search_items'  	=> __( 'Search Tags', PLUGIN_NAME ),
				'all_items' 		=> __( 'All Tags', PLUGIN_NAME ),
				'parent_item' 		=> __( 'Parent Tag', PLUGIN_NAME ),
				'parent_item_colon'	=> __( 'Parent Tag:', PLUGIN_NAME ),
				'edit_item' 		=> __( 'Edit Tag', PLUGIN_NAME ),
				'update_item' 		=> __( 'Update Tag', PLUGIN_NAME ),
				'add_new_item' 		=> __( 'Add New Tag', PLUGIN_NAME ),
				'new_item_name' 	=> __( 'New Tag Name', PLUGIN_NAME ),
				'menu_name' 		=> __( 'Tags', PLUGIN_NAME ),
			 ),
			'hierarchical'	=> false,
			'public'		=> true,
			'rewrite'		=> true
		)
	);

}
add_action( 'init', 'vr_register_post_staffs' );
$vr_staffs_metabox = new VP_Metabox( plugin_dir_path( __FILE__ ) . 'staffs_metabox.php' );

// Staffs Shortcode
function vr_shortcode_staffs( $atts, $content = null ) {
	
	extract( shortcode_atts( array(
		'id' 				=> '',
		'posts_per_page' 	=> -1,
		'category'			=> '',
		'module' 			=> '',
		'column' 			=> '',
		'ani'				=> '',
		'animation'			=> ''
	 ), $atts ) );

	global $wp_query;
	$wp_query = new WP_Query( array(
		'p'					    => esc_attr( $id ),
		'posts_per_page' 	    => esc_attr( $posts_per_page ),
		'vr_staffs_categories'  => esc_attr( $category ),
		'post_type' 		    => 'vr_staffs',
		'post_status'		    => 'publish',
		'orderby'			    => 'date'
	) );

	if ( $animation != '' ) { $animation = 'data-animation="' . $animation . '"'; $ani = 'fx-start'; }
	
	ob_start(); ?>

			<?php if ( $module == 'widget' ) : ?>
			
				<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
					<article class="staff-widget">
						<div class="thumbnail">
							<img src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 400, 420, true, true, true ) ); ?>" width="400" height="420" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
						</div>
						<?php if ( vp_metabox( 'vr_staffs.url' ) != '' ) : ?>
							<h3><a href="<?php echo esc_url( vp_metabox( 'vr_staffs.url' ) ); ?>"><?php echo wp_strip_all_tags( get_the_title() ); ?></a></h3>
						<?php else : ?>
							<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
						<?php endif; ?>
						<p><?php echo wp_strip_all_tags( vp_metabox( 'vr_staffs.position' ) ); ?></p>
					</article>
				<?php endwhile; ?>
				
			<?php elseif ( $module == 'list' ) : ?>
				
				<div class="row row-equal fx">
				<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
					<article class="staff-list column-equal clearfix <?php echo wp_strip_all_tags( $column ); ?> <?php echo wp_strip_all_tags( $ani ); ?>" <?php echo $animation; ?>>
						<div class="inner clearfix">
							<?php if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) : ?>
								<div class="thumbnail fx-hover">
									<div class="fx-hover-back"></div>
									<div class="fx-hover-icon">
										<a class="icon-medium icon-main" href="<?php echo esc_url( aio_src( get_the_ID() ) ); ?>" data-lightbox="staff" data-title="<?php echo wp_strip_all_tags( get_the_title() ); ?>"><i class="fa fa-search"></i></a>
									</div>
									<img width="600" height="500" src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 600, 500, true, true, true ) ); ?>" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
								</div>
							<?php endif; ?>
							<div class="staff-body">
							<?php if ( vp_metabox( 'vr_staffs.url' ) != '' ) : ?>
								<h3><a href="<?php echo esc_url( vp_metabox( 'vr_staffs.url' ) ); ?>"><?php echo wp_strip_all_tags( get_the_title() ); ?></a></h3>
							<?php else : ?>
								<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
							<?php endif; ?>
							<span><?php echo wp_strip_all_tags( vp_metabox( 'vr_staffs.position' ) ); ?></span>
							<div class="staff-foot">
								<?php if ( vp_metabox( 'vr_staffs.social_facebook' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_facebook' ) ); ?>" class="button-icon button-facebook"><i class="fa fa-facebook"></i></a><?php endif; ?>
								<?php if ( vp_metabox( 'vr_staffs.social_twitter' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_twitter' ) ); ?>" class="button-icon button-twitter"><i class="fa fa-twitter"></i></a><?php endif; ?>
								<?php if ( vp_metabox( 'vr_staffs.social_googleplus' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_googleplus' ) ); ?>" class="button-icon button-googleplus"><i class="fa fa-google-plus"></i></a><?php endif; ?>
								<?php if ( vp_metabox( 'vr_staffs.social_linkedin' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_linkedin' ) ); ?>" class="button-icon button-linkedin"><i class="fa fa-linkedin"></i></a><?php endif; ?>
								<?php if ( vp_metabox( 'vr_staffs.social_email' ) != '' ) : ?><a target="_blank" href="mailto:<?php echo sanitize_email( vp_metabox( 'vr_staffs.social_email' ) ); ?>" class="button-icon button-email"><i class="fa fa-envelope"></i></a><?php endif; ?>
							</div>
							<p><?php echo wp_strip_all_tags( vp_metabox( 'vr_staffs.description' ) ); ?></p>
							</div>
						</div>
					</article>
				<?php endwhile; ?>
				</div>

			<?php else : ?>
					
				<div class="row row-equal fx">
				<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
				<article class="staff-grid column-equal  <?php echo wp_strip_all_tags( $column ); ?> <?php echo wp_strip_all_tags( $ani ); ?>" <?php echo $animation; ?>>
					<div class="inner">
						<?php if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) : ?>
							<figure class="thumbnail fx-hover">
								<div class="fx-hover-back"></div>
								<div class="fx-hover-icon">
									<a class="icon-medium icon-main" href="<?php echo esc_url( aio_src( get_the_ID() ) ); ?>" data-lightbox="staff" data-title="<?php echo wp_strip_all_tags( get_the_title() ); ?>"><i class="fa fa-search"></i></a>
								</div>
								<img width="600" height="400" src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 600, 400, true, true, true ) ); ?>" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
							</figure>
						<?php endif; ?>
						<?php if ( vp_metabox( 'vr_staffs.url' ) != '' ) : ?>
							<h3><a href="<?php echo esc_url( vp_metabox( 'vr_staffs.url' ) ); ?>"><?php echo wp_strip_all_tags( get_the_title() ); ?></a></h3>
						<?php else : ?>
							<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
						<?php endif; ?>
						<span><?php echo wp_strip_all_tags( vp_metabox( 'vr_staffs.position' ) ); ?></span>
						<div class="staff-foot">
							<?php if ( vp_metabox( 'vr_staffs.social_facebook' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_facebook' ) ); ?>" class="button-icon button-facebook"><i class="fa fa-facebook"></i></a><?php endif; ?>
							<?php if ( vp_metabox( 'vr_staffs.social_twitter' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_twitter' ) ); ?>" class="button-icon button-twitter"><i class="fa fa-twitter"></i></a><?php endif; ?>
							<?php if ( vp_metabox( 'vr_staffs.social_googleplus' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_googleplus' ) ); ?>" class="button-icon button-googleplus"><i class="fa fa-google-plus"></i></a><?php endif; ?>
							<?php if ( vp_metabox( 'vr_staffs.social_linkedin' ) != '' ) : ?><a target="_blank" href="<?php echo esc_url( vp_metabox( 'vr_staffs.social_linkedin' ) ); ?>'" class="button-icon button-linkedin"><i class="fa fa-linkedin"></i></a><?php endif; ?>
							<?php if ( vp_metabox( 'vr_staffs.social_email' ) != '' ) : ?><a target="_blank" href="mailto:<?php echo sanitize_email( vp_metabox( 'vr_staffs.social_email' ) ); ?>" class="button-icon button-email"><i class="fa fa-envelope"></i></a><?php endif; ?>
						</div>
					</div>
				</article>
				<?php endwhile; ?>
				</div>

			<?php endif; ?>

	<?php
	wp_reset_query();
	$html = ob_get_clean();
	return $html;
}
add_shortcode( 'shortcode_staffs', 'vr_shortcode_staffs' );
