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

function vr_register_post_projects() {

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

	register_taxonomy(
		'vr_projects_categories',
		'vr_projects',
		array(
			'labels' => array(
				'name' 				=> __( 'Projects 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_projects_tags',
		'vr_projects',
		array(
			'labels' => array(
				'name' 				=> __( 'Projects 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_projects' );
$vr_projects_metabox = new VP_Metabox( plugin_dir_path( __FILE__ ) . 'projects_metabox.php' );

// Projects Shortcode
function vr_shortcode_projects( $atts ) {

	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_projects_categories'    => esc_attr( $category ),
		'post_type' 		        => 'vr_projects',
		'post_status'		        => 'publish',
		'orderby'			        => 'date',
		'order'				        => 'DESC'
	) );

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

	ob_start(); ?>
	
	<?php if ( $module == 'list' ) : ?>
	
		<div class="row row-equal fx">
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
			<article class="project-list column-equal  <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
				<?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="project" data-title="<?php echo wp_strip_all_tags( get_the_title() ); ?>"><i class="fa fa-plus"></i></a>
						</div>
						<img width="110" height="110" src="<?php echo esc_url( aq_resize( aio_src( get_the_ID() ), 110, 110, true, true, true ) ); ?>" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
					</div>
				<?php endif; ?>
				<div class="project-head">
					<?php if ( vp_metabox( 'vr_projects.url' ) != '' ) : ?>
						<h3><a href="<?php echo esc_url( vp_metabox( 'vr_projects.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_projects.description' ) ); ?></p>
				</div>
			</article>
		<?php endwhile; ?>
		</div>
				
	<?php elseif ( $module == 'box-list' ) : ?>
		
		<div class="row row-equal fx">
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
			<article class="project-box-list column-equal  <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
				<div class="inner-hover clearfix">
					<div class="project-head">
						<?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="project" data-title="<?php echo wp_strip_all_tags( get_the_title() ); ?>"><i class="fa fa-plus"></i></a>
								</div>
								<img width="500" height="600" src="<?php echo esc_url( aq_resize( aio_src( get_the_ID() ), 380, 400, true, true, true ) ); ?>" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
							</div>
						<?php endif; ?>
						<?php if ( vp_metabox( 'vr_projects.url' ) == '1' ) : ?>
							<h3><a href="<?php echo esc_url( vp_metabox( 'vr_projects.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; ?>
						</div>
					<span class="label-small label-main"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.client' ) ); ?></span>
					<p><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.description' ) ); ?></p>
					<div class="module-foot">
						<?php if ( vp_metabox( 'vr_projects.url' ) != '' ) : ?>
							<a href="<?php echo esc_url( vp_metabox( 'vr_projects.url' ) ); ?>" class="button-medium button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.button_caption' ) ); ?></a>
						<?php else : ?>
							<a href="#" class="vr-button-medium vr-button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.button_caption' ) ); ?></a>
						<?php endif; ?>
					</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="project-box column-equal  <?php echo wp_strip_all_tags( $column ); ?> <?php echo wp_strip_all_tags( $ani ); ?>" <?php echo $animation; ?>>
				<div class="inner-hover">
				<?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="gallery" data-title="<?php echo wp_strip_all_tags( get_the_title() ); ?>"><i class="fa fa-plus"></i></a>
						</div>
						<img src="<?php echo esc_url( aq_resize( aio_src( get_the_ID() ), 400, 360, true, true, true ) ); ?>" alt="<?php echo wp_strip_all_tags( get_the_title() ); ?>" />
					</div>
				<?php endif; ?>
				<?php if ( vp_metabox( 'vr_projects.url' ) == '1' ) : ?>
					<h3><a href="<?php echo esc_url( vp_metabox( 'vr_projects.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 class="label-small label-main"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.client' ) ); ?></span>
				<p><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.description' ) ); ?></p>
					<div class="project-foot">
						<?php if ( vp_metabox( 'vr_projects.url' ) != '1' ) : ?>
							<a href="<?php echo esc_url( vp_metabox( 'vr_projects.url' ) ); ?>" class="button-medium button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.button_caption' ) ); ?></a>
						<?php else : ?>
							<a href="#" class="button-medium button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_projects.button_caption' ) ); ?></a>
						<?php endif; ?>
					</div>
				</div>
			</article>
		<?php endwhile; ?>
		</div>

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

