<?php



include 'ecm_posttype/posttype.php';



add_theme_support('post-thumbnails');

add_theme_support('html5');

add_image_size('promo_img', 272, 147);

add_image_size('service_img', 210, 149);



add_action('init','ecm_menu_registration');



function ecm_menu_registration(){



		register_nav_menus(array(

				'top_menu'			=> 'Placed top-right corner of header',

				'main_menu'			=> 'Main navigation menu'

			));

}



add_action('init','ecm_sidebar_registration');



function ecm_sidebar_registration(){



	  /**

		* Footer Sidebar

		* @param string|array  Builds Sidebar based off of 'name' and 'id' values.

		*/



		$args = array(

			'name'          => 'Top Sidebar',

			'id'            => 'sidebar-top',

			'description'   => 'Pleased at top sidebar',

			'before_widget' => '<div class="single-widget"><div class="widget-content">',

			'after_widget'  => '</div></div>',

			'before_title'  => '<h3 class="widget-title">',

			'after_title'   => '</h3>'

		);



		register_sidebar( $args );




	   /**

		* Footer Sidebar

		* @param string|array  Builds Sidebar based off of 'name' and 'id' values.

		*/



		$args = array(

			'name'          => 'Footer one',

			'id'            => 'footer-one',

			'description'   => 'Pleased at footer one',

			'before_widget' => '<div class="single-widget"><div class="widget-content">',

			'after_widget'  => '</div></div>',

			'before_title'  => '<h2 class="widget-title">',

			'after_title'   => '</h2>'

		);

	

		register_sidebar( $args );



		$args = array(

			'name'          => 'Footer two',

			'id'            => 'footer-two',

			'description'   => 'Pleased at footer two',

			'before_widget' => '<div class="single-widget"><div class="widget-content">',

			'after_widget'  => '</div></div>',

			'before_title'  => '<h2 class="widget-title">',

			'after_title'   => '</h2>'

		);

	

		register_sidebar( $args );



		$args = array(

			'name'          => 'Footer three',

			'id'            => 'footer-three',

			'description'   => 'Pleased at footer three',

			'before_widget' => '<div class="single-widget"><div class="widget-content">',

			'after_widget'  => '</div></div>',

			'before_title'  => '<h2 class="widget-title">',

			'after_title'   => '</h2>'

		);

	

		register_sidebar( $args );



                $args = array(

                        'name'          => 'Footer four',

                        'id'            => 'footer-four',

                        'description'   => 'Pleased at footer four',

                        'before_widget' => '<div class="single-widget"><div class="widget-content">',

                        'after_widget'  => '</div></div>'

                );

                register_sidebar( $args );



		$args = array(

			'name'          => 'Featured Text Overlay',

			'id'            => 'featured-text-overlay',

			'description'   => 'Placed on top of the featured image',

			'before_widget' => '<span class="new-wrapper"><span>',

			'after_widget'  => '</span></span>'

		);

		register_sidebar( $args );
}




function service_post_qurey(){

	$args = array(

		'post_type'   			=> 'service',
		'post_status' 			=> 'publish',
		'order'               	=> 'ASC'

	);

	$service_query = new WP_Query( $args ); if($service_query->have_posts()): $content = ''; ?>

	<?php $content.= '<div class="tuning-box-area">'; ?>

		<?php while($service_query->have_posts()): $service_query->the_post(); ?>

		<?php $content.= '<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 single-tuning-box">'; ?>
			<?php $content.= '<figure>'; ?>

				<?php if(has_post_thumbnail()): $content.= get_the_post_thumbnail(); endif; ?>

				<?php $content.= '<figcaption>'; ?>

					<?php $content.= '<h2>'. get_the_title() .'</h2>'; ?>

					<?php $content.= '<div class="tuningbox-content">' . get_the_content() . '</div>'; ?>

				<?php $content.= '</figcaption>'; ?>

			<?php $content.= '</figure>'; ?>
		<?php $content.= '</div>'; ?>

		<?php endwhile; ?>

	<?php $content.= '</div>'; ?>

	<?php return $content; ?>

	<?php else: return false; endif; wp_reset_postdata(); 
}



add_shortcode('ecm_service','service_shortcode');



function service_shortcode(){

	$serv_query = service_post_qurey();

	if ( $serv_query ) {

		return $serv_query;

	} else {

		return "";

	}

}





function promotions_post_qurey(){
	$args = array(

		'post_type'			=> 'promotion',

		'post_status'		=> 'publish',

		'posts_per_page'	=> 3,

		'order'				=> 'ASC'

	);

	$promo_query = new WP_Query( $args ); if($promo_query->have_posts()): $html = ''; ?>

	<?php $html.= '<div class="promo-box-area row">'; ?>

		<?php while($promo_query->have_posts()): $promo_query->the_post(); ?>

			<?php $html.= '<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 single-promo-box">'; ?>

				<?php $html.= '<figure>'; ?>

					<?php $html.= '<a href="#" class="thumbnail-link">'; ?>

						<?php if(has_post_thumbnail()): $html.= get_the_post_thumbnail(); endif; ?>

					<?php $html.= '</a>'; ?>

					<?php $html.= '<figcaption>'; ?>

						<?php $html.= '<a href="#">'. get_the_content().'</a>'; ?>

					<?php $html.= '</figcaption>'; ?>

				<?php $html.= '</figure>'; ?>

			<?php $html.= '</div>'; ?>

		<?php endwhile; ?>

	<?php $html.= '</div>'; ?>

	<?php return $html; ?>

	<?php else: return false; endif; wp_reset_postdata();
}



add_shortcode('ecm_promo','promotions_shortcode');


function promotions_shortcode(){

	$prm_qury = promotions_post_qurey();

	if ( $prm_qury ) {

		return $prm_qury;

	} else {

		return "";

	}

}



add_shortcode( 'green_button', 'btn_link_shortcode' );

function btn_link_shortcode($atts){



	shortcode_atts(array(
			'url'			=> !empty($atts['url']) ? $atts['url'] : '#',
			'text'			=> !empty($atts['text']) ? $atts['text'] : 'empty text !' 
		),
		$atts );
	return '<a href="'.$atts['url'].'" class="btn big-btn">'.$atts['text'].'</a>';
}







add_filter('widget_text', 'do_shortcode');
