<?php
/****** SHOW POSTS BY CATEGORY AND COUNT ********/

function alc_list_posts( $atts )
{
	extract( shortcode_atts( array(
		'category' => '',
		'title'=>'',
		'limit' => '5',
		'order' => 'DESC',
		'orderby' => 'date',
		'anim'=>'',
		'class'=>''
	), $atts) );
    $anim = empty($anim) ? '' : "animation $anim";
	$return = '';

	$query = array();

	if ( $category != '' )
		$query[] = 'category=' . $category;

	if ( $limit )
		$query[] = 'numberposts=' . $limit;

	if ( $order )
		$query[] = 'order=' . $order;

	if ( $orderby )
		$query[] = 'orderby=' . $orderby;

	$posts_to_show = get_posts( implode( '&', $query ) );
	$showdate = weblusive_get_option('blog_show_date'); 
	$showcomments = weblusive_get_option('blog_show_comments'); 
	$showauthor = weblusive_get_option('blog_show_author'); 
	$showrmtext = weblusive_get_option('blog_show_rmtext'); 
        
		$return = '
		<div class="related-posts blog-section '.$anim.' '.$class.'">';		
		foreach ($posts_to_show as $ps) 
		{
			$numcomments = wp_count_comments($ps->ID);
		
			$day = get_the_time('d', $ps->ID);
			$month = get_the_time('M', $ps->ID);
			$year = get_the_time('Y', $ps->ID);
			$author_id= $ps->post_author;
			$rmtext = (isset($showrmtext)&& !empty($showrmtext)) ? $showrmtext : 'Read More';
			$mediatype = isset($get_meta["_blog_mediatype"]) ? $get_meta["_blog_mediatype"][0] : 'image';
			$videoId = isset($get_meta["_blog_video"]) ? $get_meta["_blog_video"][0] : ''; 
			$autoplay =  isset($get_meta["_blog_videoap"]) ? $get_meta["_blog_videoap"][0] : '0';
			$return.='<div class="col-md-6"><div class="blog-post">
				<div class="post-box">
					<ul class="post-tags">';
						if(!$showdate): 
							$return.='<li><i class="fa fa-calendar-o"></i>
								<a href="'.get_day_link( $year, $month, $day ).'">'.get_the_time( get_option( 'date_format' ), $ps->ID ).'</a>
							</li>';
						endif;
						if(!$showauthor): 
							$return.='<li><i class="fa fa-user"></i><a href="'.get_author_posts_url($author_id).'">'.get_the_author_meta( 'display_name' , $author_id ).'</a></li>';
						endif;
						if( 'open' == $ps->comment_status && !$showcomments) : 
							$return.='<li><a href="'.get_comments_link() .'"><i class="fa fa-comments"></i>'.$numcomments->approved.' '.__('Comments', 'unik').'</a></li>';
						endif;
					$return.='</ul>
					<div class="post-gal">';
						$thumbnail = get_the_post_thumbnail($ps->ID); $postmeta = get_post_custom($ps->ID); 
						if(!empty($thumbnail) && !isset($postmeta['_post_video'])):
							$return.=$thumbnail;
						elseif ( $mediatype == "youtube" && $videoId):
							$return.='<iframe width="280" height="223" src="http://www.youtube.com/embed/'.$videoId.'?autoplay='.$autoplay.'" class="vid iframe-youtube"></iframe>';
						elseif ( $mediatype == "vimeo" && $videoId):
							$return.='<iframe  width="280" height="223" src="http://player.vimeo.com/video/'.$videoId.'?autoplay='.$autoplay.'" class="vid iframe-vimeo"></iframe>';
						elseif ( $mediatype == "dailymotion" && $videoId):
							$return.='<iframe  width="280" height="223" src="http://www.dailymotion.com/embed/video/'.$videoId.'?autoplay='.$autoplay.'" class="vid dailymotion-vimeo"></iframe>';
						elseif ( $mediatype == "veoh" && $videoId):
							$return.='<iframe  width="280" height="223" src="http://www.veoh.com/static/swf/veoh/SPL.swf?videoAutoPlay='.$autoplay.'&permalinkId='.$videoId.'" class="vid iframe-veoh"></iframe>';
						elseif ( $mediatype == "bliptv" && $videoId):
							$return.='<iframe  width="280" height="223" src="http://a.blip.tv/scripts/shoggplayer.html#file=http://blip.tv/rss/flash/'.$videoId.'?autoplay='.$autoplay.'" class="vid iframe-bliptv"></iframe>';
						elseif ( $mediatype == "viddler" && $videoId):
							$return.='<iframe  width="280" height="223" src="http://www.viddler.com/embed/'.$videoId.'e/?f=1&offset=0&autoplay='.$autoplay.'" class="vid iframe-viddler"></iframe>';
						elseif($mediatype== 'slider' && !empty($thumbnail)):
							$return.='<div class="flexslider flexpost">
								<ul class="slides">';
									$argsThumb = array(
										'order'          => 'ASC',
										'post_type'      => 'attachment',
										'post_parent'    => $post->ID,
										'post_mime_type' => 'image',
										'post_status'    => null,
										//'exclude' => get_post_thumbnail_id()
									);
									$attachments = get_posts($argsThumb);
									if ($attachments) {
										foreach ($attachments as $attachment) {
											$return.='<li><img src="'.wp_get_attachment_url($attachment->ID, 'full', false, false).'" alt="'.get_post_meta($attachment->ID, '_wp_attachment_image_alt', true).'" /></li>';
										}
									}
									$return.='
								</ul>
							</div>';
						else:
							$return.='<img src="http://placehold.it/280x223" alt="" />';
						endif;
						$return.='
						<div class="hover-post">
							<a href="'.get_permalink( $ps->ID ).'">'.$rmtext.'</a>
						</div>
					</div>
				</div>
				<h2><a href="'.get_permalink( $ps->ID ).'">'.$ps->post_title.'</a></h2>
			</div></div>';
		}
		$return.='</div>';                

	
	return $return;
}

add_shortcode('list_posts', 'alc_list_posts');
/***********************************/
vc_map( array(
   "name" => __("Unik Blog listing", "unik"),
   "base" => "list_posts",
   "class" => "",
   "icon" => "icon-wpb-my_bloglist",
   'admin_enqueue_css' => array(get_template_directory_uri().'/vc_templates/shortcodes.css'),
   "category" => __('Content', "unik"),
   "params" => array(
       array(
         "type" => "dropdown",
         "class" => "",
         "heading" => __("Animation", "unik"),
         "param_name" => "anim",
         "value" => array( "None"=>"", "bounce"=>"bounce", "flash"=>"flash", "pulse"=>"pulse", "shake"=>"shake", "swing"=>"swing", "tada"=>"tada", "wobble"=>"wobble", "bounceIn"=>"bounceIn", "bounceInDown"=>"bounceInDown", "bounceInLeft"=>"bounceInLeft", "bounceInRight"=>"bounceInRight", "bounceInUp"=>"bounceInUp", "bounceOut"=>"bounceOut", "bounceOutDown"=>"bounceOutDown", "bounceOutLeft"=>"bounceOutLeft", "bounceOutRight"=>"bounceOutRight", "bounceOutUp"=>"bounceOutUp", "fadeIn"=>"fadeIn", "fadeInDown"=>"fadeInDown", "fadeInDownBig"=>"fadeInDownBig", "fadeInLeft"=>"fadeInLeft", "fadeInLeftBig"=>"fadeInLeftBig", "fadeInRight"=>"fadeInRight", "fadeInRightBig"=>"fadeInRightBig", "fadeInUp"=>"fadeInUp", "fadeInUpBig"=>"fadeInUpBig", "fadeOut"=>"fadeOut", "fadeOutDown"=>"fadeOutDown", "fadeOutDownBig"=>"fadeOutDownBig", "fadeOutLeft"=>"fadeOutLeft", "fadeOutLeftBig"=>"fadeOutLeftBig", "fadeOutRight"=>"fadeOutRight", "fadeOutRightBig"=>"fadeOutRightBig", "fadeOutUp"=>"fadeOutUp", "fadeOutUpBig"=>"fadeOutUpBig", "flip"=>"flip", "flipInX"=>"flipInX", "flipInY"=>"flipInY", "flipOutX"=>"flipOutX", "flipOutY"=>"flipOutY", "lightSpeedIn"=>"lightSpeedIn", "lightSpeedOut"=>"lightSpeedOut", "rotateIn"=>"rotateIn", "rotateInDownLeft"=>"rotateInDownLeft", "rotateInDownRight"=>"rotateInDownRight", "rotateInUpLeft"=>"rotateInUpLeft", "rotateInUpRight"=>"rotateInUpRight", "rotateOut"=>"rotateOut", "rotateOutDownLeft"=>"rotateOutDownLeft", "rotateOutDownRight"=>"rotateOutDownRight", "rotateOutUpLeft"=>"rotateOutUpLeft", "rotateOutUpRight"=>"rotateOutUpRight",  "hinge"=>"hinge", "rollIn"=>"rollIn", "rollOut"=>"rollOut", "zoomIn"=>"zoomIn","zoomInDown"=>"zoomInDown", "zoomInLeft"=>"zoomInLeft","zoomInRight"=>"zoomInRight","zoomInUp"=>"zoomInUp","zoomOut"=>"zoomOut", "zoomOutLeft"=>"zoomOutLeft", "zoomOutRight"=>"zoomOutRight","zoomOutUp"=>"zoomOutUp"),
         "description" => __(" Animation.", "unik")
      ),
      array(
         "type" => "textfield",
         
         "class" => "",
         "heading" => __("items limit", "unik"),
         "param_name" => "limit",
          "value"=>"5"
      ),
       array(
         "type" => "textfield",
         
         "class" => "",
         "heading" => __("Category", "unik"),
         "param_name" => "category",
         "description"=>__("Specify category Id or leave blank to display items from all categories.", "unik")
      ),
      array(
         "type" => "dropdown",
         
         "class" => "",
         "heading" => __("Post Order", "unik"),
         "param_name" => "order",
         "value"=>array("Descending"=>"DESC", "Ascending"=>"ASC")
      ),
       array(
         "type" => "dropdown",
         
         "class" => "",
         "heading" => __("Order by", "unik"),
         "param_name" => "orderby",
         "value"=>array("Date"=>"date", "ID"=>"id", "Author"=>"author","Title"=>"title","Number of comments"=>"comment_count","Randomly"=>"rand")
      ),
       array(
         "type" => "textfield",
         "class" => "",
         "heading" => __("Extra class", "unik"),
         "param_name" => "class",
         "description" => __(' Extra class name', "unik")
      ),
   )
) );
/*************************************************/
?>