<?php 

// Custom Heading
add_shortcode('heading','heading_func');

function heading_func($atts, $content = null){

	extract(shortcode_atts(array(

		'text'		=>	'',

		'tag'		=> 	'',

		'size'		=>	'',

		'color'		=>	'',

		'align'		=>	'',

		'bot'		=>	'',

		'class'		=>	'',

	), $atts));

	$size1 = (!empty($size) ? 'font-size: '.$size.';' : '');

	$color1 = (!empty($color) ? 'color: '.$color.';' : '');

	$align1 = (!empty($align) ? 'text-align: '.$align.';' : '');

	$bot = (!empty($bot) ? 'margin-bottom: '.$bot.';' : '');

	$cl = (!empty($class) ? ' class= "'.$class.'"' : '');

	$html .= '<'.$tag.$cl.' style="' . $size1 . $align1 . $color1 . $bot .'">'. $text .'</'.$tag.'>';

	return $html;

}

// Buttons
add_shortcode('button', 'button_func');
function button_func($atts, $content = null){
	extract(shortcode_atts(array(

		'btntext' 	=> '',

		'btnlink' 	=> '',

		'icon'  	=> '',		

		'style'		=> '',	

	), $atts));

	ob_start(); ?>

	<a class="<?php if($style=='sdark'){echo 'button2 sdark';} ?><?php if($style=='mdark'){echo 'button2 mdark';} ?><?php if($style=='ldark'){echo 'button2 ldark';} ?><?php if($style=='lwhite'){echo 'button2 lwhite';} ?><?php if($style=='mwhite'){echo 'button2 mwhite';} ?><?php if($style=='swhite'){echo 'button2 swhite';} ?><?php if($style=='small'){echo 'vc_button small';} ?><?php if($style=='medium'){echo 'vc_button medium';} ?><?php if($style=='large'){echo 'vc_button large';} ?><?php if($style=='ltransparent'){echo 'button2 large';} ?><?php if($style=='mtransparent'){echo 'button2 medium';} ?><?php if($style=='stransparent'){echo 'button2 small';} ?>" href="<?php echo esc_url($btnlink); ?>"><?php if($icon){ ?><i class="icon-<?php echo esc_attr($icon); ?>"></i><?php } ?><?php echo esc_attr($btntext); ?></a>
	
	<?php return ob_get_clean();
}

// Line solid
add_shortcode('line_solid', 'line_solid_func');
function line_solid_func($atts, $content = null){
	extract(shortcode_atts(array(
		'icon'	=> '',
		'title' => '',
		'style'	=> '',
	), $atts));

	ob_start(); ?>
	<?php if($style=='style1') { ?>
		<div class="i-separator animate clearfix"><i class='icon-<?php echo esc_attr($icon); ?>'></i></div><br>	      
	<?php }if($style=='style2'){ ?>
		<div class="t-separator clearfix"><?php echo htmlspecialchars_decode($title); ?></div>
	<?php } ?>
	<?php

    return ob_get_clean();
}

// Skills

add_shortcode('skills', 'skills_func');

function skills_func($atts, $content = null){

	extract(shortcode_atts(array(

		'title1'	=> 	'',
		'percent1'	=> 	'',
		'title2'	=> 	'',
		'percent2'	=> 	'',
		'title3'	=> 	'',
		'percent3'	=> 	'',
		'title4'	=> 	'',
		'percent4'	=> 	'',
		

	), $atts));
	
	ob_start(); ?>
	
	<div class="progress-bar">
		<?php if($title1){ ?>
		<div class="line" data-title="<?php echo esc_attr($title1); ?>" data-percentage="<?php echo esc_attr($percent1); ?>"></div>
		<?php } ?>
		<?php if($title2){ ?>
		<div class="line" data-title="<?php echo esc_attr($title2); ?>" data-percentage="<?php echo esc_attr($percent2); ?>"></div>
		<?php } ?>
		<?php if($title3){ ?>
		<div class="line" data-title="<?php echo esc_attr($title3); ?>" data-percentage="<?php echo esc_attr($percent3); ?>"></div>
		<?php } ?>
		<?php if($title4){ ?>
		<div class="line" data-title="<?php echo esc_attr($title4); ?>" data-percentage="<?php echo esc_attr($percent4); ?>"></div>
		<?php } ?>
	</div>

    <?php

    return ob_get_clean();

}

// Pricing Table

add_shortcode('pricingtable', 'pricingtable_func');
function pricingtable_func($atts, $content = null){
	extract(shortcode_atts(array(
		'title'		 => '',		
		'price'		 => '',
		'buttontext' => '',
		'link'       => '',		
		'month'      => '',
	), $atts));
	ob_start(); ?>

	<div class="pricing-table">
		<div class="column">
			<div class="title"><?php echo esc_attr($title); ?></div>
			<div class="pricing">
				<span class="price"><?php echo esc_attr($price); ?></span>
				<span class="plan"><?php echo esc_attr($month); ?></span>
			</div>
			<div class="c-body">
				<?php echo htmlspecialchars_decode($content); ?>
			</div>
			<div class="c-foot">
				<a href="<?php echo esc_url($link); ?>" class="button"><?php echo esc_attr($buttontext); ?></a>
			</div>
		</div>
	</div>

	<?php
    return ob_get_clean();
}


//Newsletters
add_shortcode('newsletter_startos', 'newsletter_func');
function newsletter_func($atts, $content = null){
	extract(shortcode_atts(array(		
		'btntext'	=> ''
	), $atts));

	ob_start(); ?>

	<?php
		/**
		 * Detect plugin. For use on Front End only.
		 */
		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

		// check for plugin using plugin name
		if ( is_plugin_active( 'newsletter/plugin.php' ) ) { 
	?>	
	<br/>
	<div id="mc_embed_signup">
		<form id="mc-embedded-subscribe-form" class="newsletters-1" action="<?php echo esc_url( home_url('/') ); ?>wp-content/plugins/newsletter/do/subscribe.php" onsubmit="return newsletter_check(this)">			
			<input name="ne" class="newsletter-email" type="email" data-icon="icon-envelope2" placeholder="<?php _e('Enter your email address', 'startos'); ?>">
			<button type="submit" class="button newsletter-submit d-btn d-btn-secondary d-btn-normal"><?php echo htmlspecialchars_decode($btntext); ?></button>						
		</form>
	</div>

	<script type="text/javascript">
		if (typeof newsletter_check !== "function") {
			window.newsletter_check = function (f) {
			    var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
			    if (!re.test(f.elements["ne"].value)) {
			        alert("The email is not correct");
			        return false;
			    }
			    
			    return true;
			}
		}
	</script>
	
<?php } ?>		

<?php
	return ob_get_clean();
}

// Call To Action Box

add_shortcode('ctabox', 'ctabox_func');

function ctabox_func($atts, $content = null){

	extract(shortcode_atts(array(

		'title'		=> 	'',
		'icon1'		=>  '',
		'btn1'		=> 	'',
		'link1'		=> 	'',
		'icon2'		=>  '',
		'btn2'		=> 	'',
		'link2'		=> 	'',
		
	), $atts));

	ob_start(); ?>
	<section id="sec_download" class="section text-align-center" data-layout="100%" data-cover="true" data-fixed="true" data-parallax="false">
		<h1><?php echo htmlspecialchars_decode($title); ?></h1><br>
		<a class="button medium" href="<?php echo esc_url($link1); ?>"><i class="icon-<?php echo esc_attr($icon1); ?>"></i><?php echo htmlspecialchars_decode($btn1); ?></a>
		<a class="button medium" href="<?php echo esc_url($link2); ?>"><i class="icon-<?php echo esc_attr($icon2); ?>"></i><?php echo htmlspecialchars_decode($btn2); ?></a>
	</section>
    <?php

    return ob_get_clean();

}

// Our Team
add_shortcode('team', 'team_func');
function team_func($atts, $content = null){
	extract(shortcode_atts(array(
		'photo'		=> 	'',
		'name'		=>	'',
		'job'		=>	'',		
		'icon1'		=>	'',
		'icon2'		=>	'',
		'icon3'		=>	'',
		'icon4'		=>	'',
		'url1'		=>	'',
		'url2'		=>	'',
		'url3'		=>	'',
		'url4'		=>	'',
	), $atts));

	$img = wp_get_attachment_image_src($photo,'full');
	$img = $img[0];

	$icon11 = (!empty($icon1) ? '<a href="'.esc_url($url1).'" target="_blank" class="icon-'.esc_attr($icon1).'"></a>' : '');
	$icon22 = (!empty($icon2) ? '<a href="'.esc_url($url2).'" target="_blank" class="icon-'.esc_attr($icon2).'"></a>' : '');
	$icon33 = (!empty($icon3) ? '<a href="'.esc_url($url3).'" target="_blank" class="icon-'.esc_attr($icon3).'"></a>' : '');
	$icon44 = (!empty($icon4) ? '<a href="'.esc_url($url4).'" target="_blank" class="icon-'.esc_attr($icon4).'></a>' : '');

	ob_start(); ?>

	<div class="team" data-animate="true">
		<div class="person">
			<div class="img">
				<img src="<?php echo esc_url($img); ?>" alt="" />				
				<div class="social-links">
					<?php echo htmlspecialchars_decode($icon11); ?>
	                <?php echo htmlspecialchars_decode($icon22); ?>
	                <?php echo htmlspecialchars_decode($icon33); ?>
	                <?php echo htmlspecialchars_decode($icon44); ?>
				</div>
			</div>
			<div class="name"><?php echo htmlspecialchars_decode($name); ?></div>
			<div class="title"><?php echo htmlspecialchars_decode($job); ?></div>
		</div>
	</div>
	<?php

    return ob_get_clean();
}



// Fun Facts

add_shortcode('facts', 'facts_func');

function facts_func($atts, $content = null){

	extract(shortcode_atts(array(

		'icon'		=> '',
		'title'		=> '',
		'color'		=>	'',
		'number'	=> '',
		'border'	=>	'',

	), $atts));

		$color1 = (!empty($color) ? 'color: '.$color.';' : '');

	ob_start(); ?>
	
	<div class="child-element counter clearfix">
		<div class="<?php if($border=='yes'){echo 'count';}else{echo 'counts';} ?> icon-<?php echo esc_attr($icon); ?>" data-value="<?php echo esc_attr($number); ?>"></div>
		<p class="title-count" style="<?php echo esc_attr($color1); ?>"><?php echo esc_attr($title); ?></p>	
	</div>	
	
    <?php

    return ob_get_clean();

}

// Slider(use)
add_shortcode('slider', 'slider_func');

function slider_func($atts, $content = null){

	extract(shortcode_atts(array(

		'gallery'		=> '',
		

	), $atts));

	ob_start(); ?>
	
	<div class="child-element carousel">
		<?php 

			$img_ids = explode(",",$gallery);

			foreach( $img_ids AS $img_id ){

			$meta = wp_prepare_attachment_for_js($img_id);

			$caption = $meta['caption'];			

			$image_src = wp_get_attachment_image_src($img_id,''); ?>
			<?php if($caption){ ?>
				<div class="item"><a href="<?php echo esc_url($caption); ?>" data-lightbox-gallery="gallery1"><img src="<?php echo esc_url($image_src[0]); ?>" alt=""></a></div>
			<?php }else{ ?>
				<div class="item"><img src="<?php echo esc_attr($image_src[0]); ?>" alt=""></div>
			<?php } ?>
		<?php } ?>
	</div>
    <?php

    return ob_get_clean();

}

// Services Box

add_shortcode('services', 'services_func');

function services_func($atts, $content = null){

	extract(shortcode_atts(array(

		'icon'		=> 	'',

		'title'		=> 	'',

		'border'	=>	'',

	), $atts));



	ob_start(); ?>
	<div class="child-element content-box clearfix">
		<div class="<?php if($border=='yes'){echo 'box';}else{echo 'boxes';} ?>">
			<div class="box-icon icon-<?php echo esc_attr($icon); ?>"></div>
			<h3 class="box-title"><?php echo htmlspecialchars_decode($title); ?></h3>
			<div class="box-content"><?php echo htmlspecialchars_decode($content); ?></div>
		</div>
	</div>


	<?php



    return ob_get_clean();

}


// Testimonials

add_shortcode('testimonial', 'testimonial_func');

function testimonial_func($atts, $content = null){

	extract(shortcode_atts(array(

		'number'	=> '',

	), $atts));	

	ob_start(); ?>

	<div class="child-element testimonials" >
		<?php 
			$number1 = (!empty($number)) ? $number : 3;
			$args = array(   
				'post_type' => 'testimonial',
				'posts_per_page' => $number,	

			);  
			$testimonial = new WP_Query($args);	
			if($testimonial->have_posts()):
			$i = 0;				
			while ($testimonial -> have_posts()) : $testimonial -> the_post();
			$job = get_post_meta(get_the_ID(),'_cmb_job', true);
		?>
		<div class="testimonial">
			<div class="text"><?php the_content(); ?></div>
			<img src="<?php echo wp_get_attachment_url(get_post_thumbnail_id()); ?>" alt="">
			<?php if($job){ ?><span class="name"><?php the_title(); ?></span><?php } ?>
			<span class="title"><?php echo htmlspecialchars_decode($job); ?></span>
		</div>	
		<?php $i++; endwhile;?>
		<?php wp_reset_postdata(); ?>
	 	<?php endif; ?> 	
	</div>

    <?php



    return ob_get_clean();

}





// Clients Logo

add_shortcode('logos', 'logos_func');

function logos_func($atts, $content = null){

	extract(shortcode_atts(array(

		'gallery'		=> 	'',
		

	), $atts));

	
	ob_start(); ?>

	
            <div class="child-element clients">
              	<?php 

				$img_ids = explode(",",$gallery);

				foreach( $img_ids AS $img_id ){

				$meta = wp_prepare_attachment_for_js($img_id);

				$caption = $meta['caption'];

				$title = $meta['title'];

				$image_src = wp_get_attachment_image_src($img_id,''); ?>
	            
	                <div class="client"><a href="<?php echo esc_url($caption); ?>" title="<?php echo esc_url($title); ?>"><img src="<?php echo esc_url($image_src[0]); ?>" alt=""></a></div>
	            
	            <?php } ?>     

	        </div>
	     

	<?php

    return ob_get_clean();

}

// Social
add_shortcode('social', 'social_func');

function social_func($atts, $content = null){

	extract(shortcode_atts(array(

		
		'link1'		=>	'',
		
		'link2'		=>	'',
		
		'link3'		=>	'',
		
		'link4'		=>	'',
		
		'link5'		=>	'',
		
		'link6'		=>	'',
		
		'link7'		=>	'',
		
		'link8'		=>	'',
		
		'link9'		=>	'',
		
		'link10'	=>	'',

	), $atts));

	
	ob_start(); ?>            
	     
	    <div class="social-links text-align-center">
			<?php if($link1) { ?>
            <a target="_blank" href="<?php echo esc_url($link1); ?>" class="icon-twitter"></a>
            <?php } ?>
            <?php if($link2) { ?>
            <a target="_blank" href="<?php echo esc_url($link2); ?>" class="icon-github"></a>
            <?php } ?>
            <?php if($link3) { ?>
            <a target="_blank" href="<?php echo esc_url($link3); ?>" class="icon-dribbble"></a>
            <?php } ?>
            <?php if($link4) { ?>
            <a target="_blank" href="<?php echo esc_url($link4); ?>" class="icon-linkedin"></a>
            <?php } ?>
            <?php if($link5) { ?>
            <a target="_blank" href="<?php echo esc_url($link5); ?>" class="icon-behance"></a>
            <?php } ?>
            <?php if($link6) { ?>
            <a target="_blank" href="<?php echo esc_url($link6); ?>" class="icon-facebook"></a>
            <?php } ?>
            <?php if($link7) { ?>
            <a target="_blank" href="<?php echo esc_url($link7); ?>" class="icon-instagram"></a>
            <?php } ?>
            <?php if($link8) { ?>
            <a target="_blank" href="<?php echo esc_url($link8); ?>" class="icon-youtube"></a>
            <?php } ?>
            <?php if($link9) { ?>
            <a target="_blank" href="<?php echo esc_url($link9); ?>" class="icon-skype"></a>
            <?php } ?>
            <?php if($link10) { ?>
            <a target="_blank" href="<?php echo esc_url($link10); ?>" class="icon-google"></a>
            <?php } ?>
		</div>

	<?php

    return ob_get_clean();

}

// Icons
add_shortcode('icons', 'icons_func');

function icons_func($atts, $content = null){

	extract(shortcode_atts(array(
	
		'icon'		=>	'',
		'style' 	=>	'',
		'animate'	=> '',

	), $atts));

	
	ob_start(); ?>            
	     
	    <i class="icon-<?php echo esc_attr($icon); ?> <?php if($style=='small'){echo 'small';} ?><?php if($style=='medium'){echo 'medium';} ?><?php if($style=='squaresmall'){echo 'square small';} ?><?php if($style=='circlemedium'){echo 'circle medium';} ?><?php if($style=='circlelarge'){echo 'circle large';} ?> <?php if($animate=='yes'){echo 'animate';} ?>"></i>

	<?php

    return ob_get_clean();

}

// Google Map



add_shortcode('ggmap','ggmap_func');

function ggmap_func($atts, $content = null){

    extract( shortcode_atts( array(

	  'idmap'		=> 'map-1',

	  'height'		=> '',	

      'lat'   		=> '',

      'long'	  	=> '',

      'zoom'		=> '',

	  'icon'		=> '',

   ), $atts ) );

   

   $img = wp_get_attachment_image_src($image,'full');

   $img = $img[0];

   

   $icon1 = wp_get_attachment_image_src($icon,'full');

   $icon1 = $icon1[0];

   		

    ob_start(); ?>

    	 

    
    <div height="<?php echo esc_attr($height); ?>" class="map" id="<?php echo esc_attr($idmap); ?>" data-x="<?php echo esc_js($lat);?>" data-y="<?php echo esc_js($long);?>" data-zoom="<?php echo esc_js($zoom);?>" data-marker="<?php echo esc_js($icon1);?>"></div>


    <script type="text/javascript">

    (function($){

		"use strict";

		var styleArray = [{"featureType":"all","stylers":[{"saturation":-100},{"gamma":0.5}]}];

		if ($('body').data('skin') == 'dark') {
			styleArray = [{"stylers":[{"hue":"#ff1a00"},{"invert_lightness":true},{"saturation":-100},{"lightness":33},{"gamma":0.5}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#2D333C"}]}];
		};

		$('.map').each(function(){

			var $this     = $(this),
				x         = ($this.attr('data-x')) ? $this.data('x') : <?php echo esc_js($lat);?>,
				y         = ($this.attr('data-y')) ? $this.data('y') : <?php echo esc_js($long);?>,
				z         = ($this.attr('data-zoom')) ? parseInt($this.data('zoom')) : <?php echo esc_js($zoom);?>;

			var options = {
				center     : new google.maps.LatLng(x, y),
				zoom       : z, 
				mapTypeId  : google.maps.MapTypeId.ROADMAP,
				styles     : styleArray,
				scrollwheel: false
			};

			var map    = new google.maps.Map(document.getElementById($this.attr('id')), options);

			if ($this.attr('data-marker')) {
				var marker = new google.maps.Marker({ position: new google.maps.LatLng(x,y), map: map, icon: $this.data('marker')});
			};

		});

	})(jQuery); 	

   	</script>

<?php



    return ob_get_clean();



}