<?php
/**
 * Clients Custom Post
 *
 * @package All In One Custom Post
 * @since All In One Custom Post 7.0.0 
 */
if ( !defined( 'ABSPATH' ) ) exit;

// Register custom post clients
function vr_register_post_clients() {

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

	register_taxonomy(
		'vr_clients_categories',
		'vr_clients',
		array(
			'labels' => array( 
				'name' 				=> __( 'Clients 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_clients_tags',
		'vr_clients',
		array(
			'labels' => array( 
				'name' 				=> __( 'Clients 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_clients' );
$vr_clients_metabox = new VP_Metabox( plugin_dir_path( __FILE__ ) . 'clients_metabox.php' );

// Clients Shortcode
function vr_shortcode_clients( $atts ) {

	extract( shortcode_atts( array( 
		'id' 				=> '',
		'posts_per_page' 	=> -1,
		'message'			=> 'We are committed to the <strong>Client Service</strong>',
		'category'			=> '',
		'module' 			=> '',
		'column'			=> '',
		'animation'			=> '',
		'animation'			=> 'ani'
	), $atts ) );

	global $wp_query;
	$wp_query = new WP_Query( array( 
		'p'					    => esc_attr( $id ),
		'posts_per_page' 	    => esc_attr( $posts_per_page ),
		'vr_clients_categories'	=> esc_attr( $category ),
		'post_type' 		    => 'vr_clients',
		'post_status'		    => 'publish',
		'orderby'			    => 'date'
	) );
	
	if ( $module == 'slider' ) { $column = 'col-md-12'; }
	if ( $animation != '' ) { $animation = 'data-animation="' . $animation . '"'; $ani = 'fx-start'; }
	
	ob_start(); ?>

	<?php if ( $module == 'slider' ) : ?>

		<div class="client-slider clearfix <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<div class="slider-body">
				<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
					<div class="slider-item">

						<article class="client-grid column-equal">
							<a href="<?php echo esc_url( vp_metabox( 'vr_clients.url' ) ); ?>">
								<?php if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) : ?>
									<img src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 320, 200, true, true, true ) ); ?>" width="320" height="200" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
								<?php endif; ?>
							</a>
						</article>
						
					</div>
				<?php endwhile; ?>
			</div>
		</div>

	<?php elseif ( $module == 'group' ) : ?>

		<div class="client-group clearfix <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<div class="client-head"><h3><?php echo wp_filter_kses( $message ); ?></h3></div>
			<div class="client-body">
			<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
				<div class="client-item vr-col col-xs-3 <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
					<a href="<?php esc_url( vp_metabox( 'vr_clients.url' ) ); ?>">
						<img src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 320, 200, true, true, true ) ); ?>" width="320" height="200" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
					</a>
				</div>
			<?php endwhile; ?>
			</div>
		</div>

	<?php else : ?>

		<div class="row row-equal fx">
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
		
			<article class="client-grid column-equal  <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
				<a href="<?php echo esc_url( vp_metabox( 'vr_clients.url' ) ); ?>">
					<?php if ( ( function_exists( 'has_post_thumbnail' ) ) && ( has_post_thumbnail() ) ) : ?>
						<img src="<?php echo esc_url( aio_resize( aio_src( get_the_ID() ), 320, 200, true, true, true ) ); ?>" width="320" height="200" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
					<?php endif; ?>
				</a>
			</article>
			
		<?php endwhile; ?>
		</div>

	<?php endif; ?>
	
	<?php
	wp_reset_query();
	$html = ob_get_clean();
	return $html;
}
add_shortcode( 'shortcode_clients', 'vr_shortcode_clients' );

/*
 * EOF
 */