<?php
// **********************************************************************// 
// ! Shortcodes
// **********************************************************************// 

// **********************************************************************// 
// ! WooCommerce featured slider
// **********************************************************************// 
add_shortcode('etheme_featured', 'etheme_featured_shortcodes');
function etheme_featured_shortcodes($atts, $content=null){
    global $wpdb;
    if ( !class_exists('Woocommerce') ) return false;
    
    extract(shortcode_atts(array( 
        'shop_link' => 1,
        'limit' => 50,
        'categories' => '',
        'title' => __('Featured Products', WFT_DOMAIN)
    ), $atts)); 
    
    $key = '_featured';
    

    if(!class_exists('Woocommerce')) return;

    $args = apply_filters('woocommerce_related_products_args', array(
        'post_type'             => 'product',
        'meta_key'              => $key,
        'meta_value'            => 'yes',
        'ignore_sticky_posts'   => 1,
        'no_found_rows'         => 1,
        'posts_per_page'        => $limit
    ) );
    
      // Narrow by categories
      if ( $categories != '' ) {
          $categories = explode(",", $categories);
          $gc = array();
          foreach ( $categories as $grid_cat ) {
              array_push($gc, $grid_cat);
          }
          $gc = implode(",", $gc);
          $args['category_name'] = $gc;
          $pt = array('product');

          $taxonomies = get_taxonomies('', 'object');
          $args['tax_query'] = array('relation' => 'OR');
          foreach ( $taxonomies as $t ) {
              if ( in_array($t->object_type[0], $pt) ) {
                  $args['tax_query'][] = array(
                      'taxonomy' => $t->name,//$t->name,//'portfolio_category',
                      'terms' => $categories,
                      'field' => 'id',
                  );
              }
          }
      }
      
    ob_start();
    etheme_create_slider($args,$title, $shop_link);
    $output = ob_get_contents();
    ob_end_clean();
    
    return $output;
}

add_shortcode('etheme_new', 'etheme_new_shortcodes');
function etheme_new_shortcodes($atts, $content=null){
    global $wpdb;
    if ( !class_exists('Woocommerce') ) return false;
    
    extract(shortcode_atts(array( 
        'shop_link' => 1,
        'limit' => 50,
        'categories' => '',
        'title' => __('Latest Products', WFT_DOMAIN)
    ), $atts)); 
    
    $key = 'product_new';
    
    
    if(!class_exists('Woocommerce')) return;

    $args = array(
        'post_type'             => 'product',
        'meta_key'              => $key,
        'meta_value'            => 'enable',
        'ignore_sticky_posts'   => 1,
        'no_found_rows'         => 1,
        'posts_per_page'        => $limit
    );
    
      // Narrow by categories
      if ( $categories != '' ) {
          $categories = explode(",", $categories);
          $gc = array();
          foreach ( $categories as $grid_cat ) {
              array_push($gc, $grid_cat);
          }
          $gc = implode(",", $gc);
          $args['category_name'] = $gc;
          $pt = array('product');

          $taxonomies = get_taxonomies('', 'object');
          $args['tax_query'] = array('relation' => 'OR');
          foreach ( $taxonomies as $t ) {
              if ( in_array($t->object_type[0], $pt) ) {
                  $args['tax_query'][] = array(
                      'taxonomy' => $t->name,
                      'terms' => $categories,
                      'field' => 'id',
                  );
              }
          }
      }
      
    ob_start();
    etheme_create_slider($args,$title, $shop_link);
    $output = ob_get_contents();
    ob_end_clean();
    
    return $output;
}


add_shortcode('template_url', 'etheme_template_url_shortcode');
function etheme_template_url_shortcode(){
    return get_template_directory_uri();
}

add_shortcode('base_url', 'etheme_base_url_shortcode');
function etheme_base_url_shortcode(){
    return home_url();
}


// **********************************************************************// 
// ! Recent posts shortcodes
// **********************************************************************// 


add_shortcode('recent_posts', 'etheme_recent_posts_shortcode');
function etheme_recent_posts_shortcode($atts){
    $a = shortcode_atts( array(
       'title' => 'Recent Posts',
       'limit' => 10,
       'cat' => '',
       'imgwidth' => 300,
       'imgheight' => 200,
       'imgcrop' => 1,
       'date' => 0,
       'excerpt' => 0,
       'more_link' => 1
   ), $atts );


    $args = array(
        'post_type'             => 'post',
        'ignore_sticky_posts'   => 1,
        'no_found_rows'         => 1,
        'posts_per_page'        => $a['limit'],
        'cat'                   => $a['cat']
    );

    $crop = ($a['imgcrop'] == 1);

    ob_start();
    etheme_create_posts_slider($args, $a['title'], $a['more_link'], $a['date'], $a['excerpt'], $a['imgwidth'], $a['imgheight'], $crop );
    $output = ob_get_contents();
    ob_end_clean();
    
    return $output;

}

// **********************************************************************// 
// ! Typography Shortcodes
// **********************************************************************// 

// **********************************************************************// 
// ! Buttons
// **********************************************************************// 

add_shortcode('button', 'etheme_btn_shortcode');
function etheme_btn_shortcode($atts){
    $a = shortcode_atts( array(
       'title' => 'Button',
       'url' => '#',
       'icon' => '',
       'style' => ''
   ), $atts );
    $icon = '';
    if($a['icon'] != '') {
        $icon = '<i class="icon-'.$a['icon'].'"></i>';
    }
    return '<a class="button ' . $a['style'] . '" href="' . $a['url'] . '"><span>'. $icon . $a['title'] . '</span></a>';
}


// **********************************************************************// 
// ! Title with subtitle
// **********************************************************************// 

add_shortcode('title', 'etheme_title_shortcode');
function etheme_title_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'heading' => '2',
        'subtitle' => '',
        'align' => 'center',
        'subtitle' => '',
        'line' => 1
    ), $atts);
    $subtitle = '';
    $class = 'title';
    $class .= ' a-'.$a['align'];
    if(!$a['line']) {
        $class .= ' without-line';
    }
    if($a['subtitle'] != '') {
        $class .= ' with-subtitle';
        $subtitle = '<span class="subtitle a-'.$a['align'].'">'.$a['subtitle'].'</span>';
    }

    return '<h'.$a['heading'].' class="'.$class.'"><span>'.$content.'</span></h'.$a['heading'].'>'.$subtitle;
}

// **********************************************************************// 
// ! Animated counter
// **********************************************************************// 

add_shortcode('counter', 'etheme_counter_shortcode');
function etheme_counter_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'init_value' => 1,
        'final_value' => 100,
        'class' => ''
    ), $atts);

    return '<span id="animatedCounter" class="animated-counter '.$a['class'].'" data-value='.$a['final_value'].'>'.$a['init_value'].'</span>';
}



// **********************************************************************// 
// ! Call to action
// **********************************************************************// 

add_shortcode('callto', 'etheme_callto_shortcode');
function etheme_callto_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'btn' => '',
        'style' => '',
        'btn_position' => 'right',
        'link' => ''
    ), $atts);
    $btn = '';
    $class = '';
    $btnClass = '';

    if($a['style'] == 'filled') {
        $btnClass = 'active filled';
    } else if($a['style'] == 'dark') {
        $btnClass = 'white';
    }
    
    if($a['btn'] != '') {
        $btn = '<a href="'.$a['link'].'" class="button '.$btnClass.'">' . $a['btn'] . '</a>';
    }
    
    if($a['style'] != '') {
        $class = 'style-'.$a['style'];
    }

    $output = '';

    $output .= '<div class="cta-block '.$class.'"><div class="table-row">';
        if($a['btn'] != '') {

                if ($a['btn_position'] == 'left') {
                    $output .= '<div class="table-cell button-left">'.$btn.'</div>';
                }
                $output .= '<div class="table-cell">'. do_shortcode($content) .'</div>';

                if ($a['btn_position'] == 'right') {
                    $output .= '<div class="table-cell button-right">'.$btn.'</div>';
                }
            
        } else{
            $output .= '<div class="table-cell">'. do_shortcode($content) .'</div>';
        }
    $output .= '</div></div>';
    
    return $output;
}


// **********************************************************************// 
// ! Dropcap
// **********************************************************************// 

add_shortcode('dropcap', 'etheme_dropcap_shortcode');
function etheme_dropcap_shortcode($atts,$content=null){
    $a = shortcode_atts( array(
       'style' => ''
   ), $atts );
   
    return '<span class="dropcap ' . $a['style'] . '">' . $content . '</span>';
}

// **********************************************************************// 
// ! Blockquote
// **********************************************************************// 

add_shortcode('blockquote', 'etheme_blockquote_shortcode');
function etheme_blockquote_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'align' => 'left',
        'class' => ''
    ), $atts);
    switch($a['align']) {

        case 'right':
            $align = 'fl-r';
        break;
        case 'center':
            $align = 'fl-none';
        break;
        default:
            $align = 'fl-l';        
    }
    $content = wpautop(trim($content));
    return '<blockquote class="' . $align .' '. $a['class'] . '">' . $content . '</blockquote>';
}


// **********************************************************************// 
// ! Checklist
// **********************************************************************// 

add_shortcode('checklist', 'etheme_checklist_shortcode');
function etheme_checklist_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'style' => 'arrow'
    ), $atts);
    switch($a['style']) {
        case 'arrow':
            $class = 'arrow';
        break;
        case 'circle':
            $class = 'circle';
        break;
        case 'star':
            $class = 'star';
        break;
        case 'square':
            $class = 'square';
        break;
        case 'dash':
            $class = 'dash';
        break;
        default:
            $class = 'arrow';
    }
    return '<div class="list list-' . $class . '">' . do_shortcode($content) . '</div	>';
}

// **********************************************************************// 
// ! Columns
// **********************************************************************// 

add_shortcode('et_section', 'etheme_et_section_shortcode');
function etheme_et_section_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'el_class' => '',
        'color_sceheme' => '',
        'section_border' => '',
        'padding' => '',
        'color' => '',
        'content' => '',
        'parallax' => 0,
        'video_poster' => '',
        'video_mp4' => '',
        'video_webm' => '',
        'video_ogv' => '',
        'img' => '',
        'img_src' => '',
        'mt' => '',
        'mb' => '',
        'pt' => '',
        'pb' => ''

    ), $atts);


    $src = '';
    $style = 'style="';
    $video = '';

    if($a['img'] != '') {
        $src = etheme_get_image($a['img']);
    }elseif ($a['img_src'] != '') {
        $src = do_shortcode($a['img_src']);
    }

    if ($src != '') {
        $style .= 'background-image: url('.$src.');';
    }
    if ($a['color'] != '') {
        $style .= 'background-color: '.$a['color'].';';
    }

    if ($a['content'] != '') {
        $content = $a['content'];
    }
    
    $class = '';

    if ($a['parallax']) {
        $class .= 'parallax-section';
    }

    if($a['mt'] != '') {
        $style .= 'margin-top: '.$a['mt'].'px;';
    }

    if($a['mb'] != '') {
        $style .= 'margin-bottom: '.$a['mb'].'px;';
    }

    if($a['pt'] != '') {
        $style .= 'padding-top: '.$a['pt'].'px;';
    }

    if($a['pb'] != '') {
        $style .= 'padding-bottom: '.$a['pb'].'px;';
    }

    $style .= '"';

    if($a['video_mp4'] != '' || $a['video_webm'] != '' || $a['video_ogv'] != '') {
        if($a['video_poster'] != '') { 
            $video_poster = etheme_get_image($a['video_poster']);
            $video .= '
                <div class="section-video-poster" style="background-image: url('.$video_poster.')"></div>
            ';
        }

        $video .= '
        <div class="section-back-video hidden-tablet hidden-phone">
            <video autoplay="autoplay" loop="loop" muted="muted" style="">
                <source src="'.$a['video_mp4'].'" type="video/mp4">
                <source src="'.$a['video_ogv'].'" type="video/ogv">
                <source src="'.$a['video_webm'].'" type="video/webm">
            </video>
        </div>
        <div class="section-video-mask"></div>
        ';
    }



    return '<div class="et_section '.$a['padding'].' '.$a['section_border'].' color-scheme-'.$a['color_sceheme'].' '.$class . ' ' . $a['el_class'] . '" '.$style.'>'.$video.'<div class="container">' . do_shortcode($content) . '</div></div>';
}

add_shortcode('row', 'etheme_row_shortcode');
function etheme_row_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'class' => '',
        'fluid' => 1
    ), $atts);
    
    $class = '';

    if ($a['fluid'] == 1) {
        $class = '-fluid';
    }
    return '<div class="row'.$class . ' ' . $a['class'] . '">' . do_shortcode($content) . '</div>';
}

add_shortcode('column', 'etheme_column_shortcode');
function etheme_column_shortcode($atts, $content = null) {
    $a = shortcode_atts( array(
        'size' => 'one_half',
        'class' => '',
    ), $atts);
    switch($a['size']) {
        case 'one-half':
            $class = 'span6 ';
        break;
        case 'one-third':
            $class = 'span4 ';
        break;
        case 'two-third':
            $class = 'span8 ';
        break;
        case 'one-fourth':
            $class = 'span3 ';
        break;
        case 'three-fourth':
            $class = 'span9 ';
        break;
        default: 
            $class = $a['size'];
        }
        
        $class .= ' '.$a['class'];
        
        return '<div class="' . $class . '">' . do_shortcode($content) . '</div>';
}

// **********************************************************************// 
// ! Toggles
// **********************************************************************// 

add_shortcode('toggle_block', 'etheme_toggle_block_shortcode');
function etheme_toggle_block_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'class' => ''
    ), $atts);
    return '<div class="toggle-block '.$a['class'].'">' . do_shortcode($content) . '</div>';
}

add_shortcode('toggle', 'etheme_toggle_shortcode');

function etheme_toggle_shortcode($atts, $content = null) {
    global $tab_count;
    $a = shortcode_atts(array(
        'title' => 'Tab',
        'class' => '',
        'active' => 0
    ), $atts);
    
    $class = $a['class'];
    $style = '';

    $opener = '<div class="open-this">+</div>';
    
    if ($a['active'] == 1)  {
        $style = ' style="display: block;"';
        $class .= 'opened'; 
        $opener = '<div class="open-this">&ndash;</div>';
    }
    
    $tab_count++;
    
    return '<div class="toggle-element"><a href="#" class="toggle-title ' . $class . '">' . $opener . $a['title'] . '</a><div class="toggle-content" ' . $style . '>' . do_shortcode($content) . '</div></div>';
}

// **********************************************************************// 
// ! Tabs
// **********************************************************************// 

add_shortcode('tabs', 'etheme_tabs_shortcode');
function etheme_tabs_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'class' => ''
    ), $atts);
    return '<div class="tabs '.$a['class'].'">' . do_shortcode($content) . '</div>';
}

add_shortcode('tab', 'etheme_tab_shortcode');

function etheme_tab_shortcode($atts, $content = null) {
    global $tab_count;
    $a = shortcode_atts(array(
        'title' => 'Tab',
        'class' => '',
        'active' => 0
    ), $atts);
    
    $class = $a['class'];
    $style = '';
    
    if ($a['active'] == 1)  {
        $style = ' style="display: block;"';
        $class .= 'opened'; 
    }
    
    $tab_count++;
    
    return '<a href="#tab_'.$tab_count.'" id="tab_'.$tab_count.'" class="tab-title ' . $class . '">' . $a['title'] . '</a><div id="content_tab_'.$tab_count.'" class="tab-content" ' . $style . '>' . do_shortcode($content) . '</div>';
}


// **********************************************************************// 
// ! Dividers
// **********************************************************************// 

add_shortcode('hr','etheme_hr_shortcode');

function etheme_hr_shortcode($atts) {
    $a = shortcode_atts(array(
        'class' => ''   
    ),$atts);
    
    return '<hr class="divider '.$a['class'].'"/>';
}


// **********************************************************************// 
// ! Tooltip
// **********************************************************************// 

add_shortcode('tooltip', 'etheme_tooltip_shortcode');
function etheme_tooltip_shortcode($atts,$content=null){
    $a = shortcode_atts( array(
       'position' => 'top',
       'text' => '',
       'class' => '',
       'link' => '#'
   ), $atts );
   
    return '<a href="'.$a['link'].'" class="'.$a['class'].'" rel="tooltip" data-placement="'.$a['position'].'" data-original-title="'.$a['text'].'">'.$content.'</a>';
}

// **********************************************************************// 
// ! Vimeo Video
// **********************************************************************// 

add_shortcode('vimeo', 'etheme_vimeo_shortcode');
function etheme_vimeo_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'src' => '',
        'height' => '500',
        'width' => '900'
    ), $atts);
    if ($a['src'] == '') return;
    return '<div class="vimeo-video" style="width=:' . $a['width'] . 'px; height:' . $a['height'] . 'px;"><iframe width="' . $a['width'] . '" height="' . $a['height'] . '" src="' . $a['src'] . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>';
}

// **********************************************************************// 
// ! Youtube Video
// **********************************************************************// 

add_shortcode('youtube', 'etheme_youtube_shortcode');
function etheme_youtube_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'src' => '',
        'height' => '500',
        'width' => '900'
    ), $atts);
    if ($a['src'] == '') return;
    return '<div class="youtube-video" style="width=:' . $a['width'] . 'px; height:' . $a['height'] . 'px;"><iframe width="' . $a['width'] . '" height="' . $a['height'] . '" src="' . $a['src'] . '" frameborder="0" allowfullscreen></iframe></div>';
}

// **********************************************************************// 
// ! QR Code
// **********************************************************************// 

add_shortcode('qrcode', 'etheme_qrcode_shortcode');
function etheme_qrcode_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'size' => '128',
        'self_link' => 0,
        'title' => 'QR Code',
        'lightbox' => 0,
        'class' => ''
    ), $atts);

    return generate_qr_code($content,$a['title'],$a['size'],$a['class'],$a['self_link'],$a['lightbox']);
}

// **********************************************************************// 
// ! Google Maps
// **********************************************************************// 

add_shortcode('gmaps', 'etheme_gmaps_shortcode');
function etheme_gmaps_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
            'title' => '',
            'address' => 'London',
            'height' => 400,
            'width' => 800,
            'type' => 'roadmap',
            'zoom' => 14
        ), $atts);
        if ($a['address'] == '') return;
        $rand = rand(100,1000);
        wp_enqueue_script('google.maps', 'http://maps.google.com/maps/api/js?sensor=false');
        wp_enqueue_script('gmap', get_template_directory_uri().'/js/jquery.gmap.min.js');
        
        $output = '';
        
        if ($a['title'] != '') $output = '<h2>'. $a['title'] .'</h2>';
        
        $output .= '<div id="map'.$rand.'" style="height:'.$a['height'].'px;" class="gmap">'."\r\n";
        $output .= '<p>Enable your JavaScript!</p>."\r\n"';
        $output .= '</div>'."\r\n";
        $output .= '<script type="text/javascript">'."\r\n";
        $output .= 'jQuery(document).ready(function(){'."\r\n";
        $output .= 'var $map = jQuery("#map'.$rand.'");'."\r\n";
        $output .= 'if( $map.length ) {'."\r\n";
        $output .= '$map.gMap({'."\r\n";
        $output .= 'address: "'.$a['address'].'",'."\r\n";
        $output .= 'maptype: "'.$a['type'].'",'."\r\n";
        $output .= 'zoom: '.$a['zoom'].','."\r\n";
        $output .= 'markers: [';
        $output .= '{ "address" : "'.$a['address'].'" }'."\r\n";
        $output .= ']'."\r\n";
        $output .= '});'."\r\n";
        $output .= '}'."\r\n";
        $output .= '});'."\r\n";
        $output .= '</script>';
        
        return $output;
}

// **********************************************************************// 
// ! Share This Product
// **********************************************************************// 

add_shortcode('share', 'wft_share_shortcode');
function wft_share_shortcode($atts, $content = null) {
	extract(shortcode_atts(array(
		'title'  => __('Social', WFT_DOMAIN),
	), $atts));
	global $post;
    $html = '';
	$permalink = get_permalink($post->ID);
	$image =  etheme_get_image( get_post_thumbnail_id($post->ID), 150,150,true);
	$post_title = rawurlencode(get_the_title($post->ID)); 
	if($title) $html .= '<div class="share-title"><h4>'.$title.'</h4></div>';
	$html .= '
	   <div class="socialsplugins_wrapper">
            <div class="facebook_button">
        		<iframe src="//www.facebook.com/plugins/like.php?href=' . urlencode($permalink) . '&amp;width&amp;layout=button_count&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=21&amp;appId=609838709082531" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
            </div>
            <div class="twitter_button">
				<iframe scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.1379634856.html#_=1379949792265&amp;count=horizontal&amp;id=twitter-widget-0&amp;lang=en&amp;original_referer=' . urlencode($permalink) . '&amp;text=' . $post_title . '&amp;url=' . urlencode($permalink) . '&amp;via=' . home_url() . '" class="twitter-share-button twitter-count-horizontal" style="width: 109px; height: 20px;" title="Twitter Tweet Button" data-twttr-rendered="true"></iframe><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
			</div>
			<div class="pinit_button">

				&nbsp;&nbsp;<a count-layout="Horizontal" class="pin-it-button" href="http://pinterest.com/pin/create/button/">
					<img alt="Pin it" src="//assets.pinterest.com/images/PinExt.png"></a>
			</div>
       </div>
	';



	return $html;
}

// **********************************************************************// 
// ! Google Charts
// **********************************************************************// 

add_shortcode('googlechart', 'etheme_googlechart_shortcode');
function etheme_googlechart_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'title' => '',
        'labels' => '',
        'data' => '',
        'type' => 'pie2d',
        'data_colours' => ''
    ), $atts);
    
    switch($a['type']) {
        case 'pie':   
            $type = 'p3';
        break;
        case 'pie2d':   
            $type = 'p';
        break;
        case 'line':   
            $type = 'lc';
        break;
        case 'xyline':   
            $type = 'lxy';
        break;
        case 'scatter':   
            $type = 's';
        break;
    }
    
    $output = '';
    if ($a['title'] != '') $output = '<h2>'. $a['title'] .'</h2>';
    $output .= '<div class="googlechart">';
    $output .= '<img src="http://chart.apis.google.com/chart?cht='.$type.'&chd=t:'.$a['data'].'&chtt=&chl='.$a['labels'].'&chs=600x250&chf=bg,s,65432100&chco='.$a['data_colours'].'" />';
    $output .= '</div>';
    return $output;
}

// **********************************************************************// 
// ! Icon
// **********************************************************************// 

add_shortcode('icon', 'etheme_icon_shortcode');
function etheme_icon_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'name' => 'circle-blank',
        'size' => '',
        'style' => '',
        'color' => '',
        'hover' => 0,
        'class' => ''
    ), $atts);
    
    if($a['hover'] == 1 ) {
        $a['name'] .= ' hover-icon';
    }
    
    return '<i class="icon-'.$a['name'].' ' . $a['class'] . '" style="color:'.$a['color'].'; font-size:'.$a['size'].'px; '.$a['style'].'"></i>';
}

// **********************************************************************// 
// ! Image
// **********************************************************************// 

add_shortcode('image', 'etheme_image_shortcode');
function etheme_image_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
        'src' => '',
        'alt' => '',
        'height' => '',
        'width' => '',
        'class' => ''
    ), $atts);
    
    return '<img src="'.$a['src'].'" alt="'.$a['alt'].'" height="'.$a['height'].'" width="'.$a['width'].'" class="'.$a['class'].'" />';
}

// **********************************************************************// 
// ! Team Member
// **********************************************************************// 

add_shortcode('team_member', 'wft_team_member_shortcode');
function wft_team_member_shortcode($atts, $content = null) {
	$a = shortcode_atts(array(
		'class' => '',
		'type' => 1,
		'name' => '',
		'email' => '',
		'twitter' => '',
		'facebook' => '',
		'skype' => '',
		'linkedin' => '',
		'instagram' => '',
		'pinterest' => '',
		'gplus' => '',
		'position' => '',
		'content' => '',
		'img' => '',
		'img_src' => '',
		'img_size' => '',
		'img_class' => ''
	), $atts);

	$src = '';

	if ( $a['img_size'] ) {
		$img_size = explode('x', $a['img_size']);

		if ( !empty($img_size) ) {
			$width = $img_size[0];
			$height = $img_size[1];
		}
	}

	if ( $a['img'] != '' ) {
		$src = etheme_get_image($a['img'], $width, $height);
	} elseif ( $a['img_src'] != '' ) {
		$src = do_shortcode($a['img_src']);
	}
    
	$html = '';

	$html .= '<div class="thumbnail team-member-box '.$a['class'].'">';

	// horizontal display type
	if ( $a['type'] == 2 ) {
		$html .= '<div class="row-fluid">';
	}

	if ( $src != '' ) {
		$src = str_replace('__template_url__', get_template_directory_uri(), $src);

		if ( $a['type'] == 2 ) {
			$html .= '<div class="span6"><div class="aligncenter_tablet">';
			$html .= '<img src="'.$src.'" class="'.$a['img_class'].'">';
			$html .= '</div></div>';
		} else {
			$html .= '<img src="'.$src.'" class="'.$a['img_class'].'">';
		}


	}

	if ( $a['type'] == 2 ) {
		$html .= '<div class="span6">';
	}

	$html .= '<div class="info">';

	if ( $a['name'] ) {
		$html .= '<div class="name">' . $a['name'] . '</div>';
	}

	if ( $a['position'] ) {
		$html .= '<div class="position">' . $a['position'] . '</div>';
	}

	if ( $a['email'] ) {
		$html .= '<div class="email"><a href="mailto:' . $a['email'] . '" target="_top">' . $a['email'] . '</a></div>';
	}

	$html .= '<div class="divider"></div>';

	if ( $a['content'] ) {
		$content = $a['content'];
	}
	$html .= '<p>' . $content . '</p><br/>';

	if ($a['facebook'] != '') {
		$html .= '<a href="'.$a['facebook'].'" class="icon-facebook-rect icon-color squared"></a>&nbsp;&nbsp;';
	}
	if ($a['twitter'] != '') {
		$html .= '<a href="'.$a['twitter'].'" class="icon-twitter-bird icon-color squared"></a>&nbsp;&nbsp;';
	}
	if ($a['pinterest'] != '') {
		$html .= '<a href="'.$a['pinterest'].'" class="icon-pinterest icon-color squared"></a>&nbsp;&nbsp;';
	}
	if ($a['linkedin'] != '') {
		$html .= '<a href="'.$a['linkedin'].'" class="icon-linkedin icon-color squared"></a>&nbsp;&nbsp;';
	}
	if ($a['gplus'] != '') {
		$html .= '<a href="'.$a['gplus'].'" class="icon-gplus icon-color squared"></a>&nbsp;&nbsp;';
	}
	if ($a['skype'] != '') {
		$html .= '<a href="'.$a['skype'].'" class="icon-skype icon-color squared"></a>&nbsp;&nbsp;';
	}

	$html .= '</div></div>';

	if ( $a['type'] == 2 ) {
		$html .= '</div></div>';
	}

	return $html;
}


// **********************************************************************// 
// ! Banner With mask
// **********************************************************************// 

add_shortcode('banner','etheme_banner_shortcode');

function etheme_banner_shortcode($atts, $content) {
    $image = $mask = '';
    $a = shortcode_atts(array(
        'valign'  => 'top',
        'class'  => '',
        'link'  => '',
        'hover'  => '',
        'content'  => '',  
        'font_style'  => '',  
        'img' => '',
        'img_src' => '',
        'img_size' => '270x170'
    ), $atts);

    $src = '';

    $img_size = explode('x', $a['img_size']);

    $width = $img_size[0];
    $height = $img_size[1];

    if($a['img'] != '') {
        $src = etheme_get_image($a['img'], $width, $height);
    }elseif ($a['img_src'] != '') {
        $src = do_shortcode($a['img_src']);
    }

    
    return '<div class="banner '.$a['class'].' banner-font-'.$a['font_style'].' hover-'.$a['hover'].'" style="height:'.$height.'px;"><a href="'.$a['link'].'"><div class="banner-content">'.do_shortcode($content).'</div><div class="banner-bg parallax" style="background-image:url('.$src.'); "></div></a></div>';
}

// **********************************************************************// 
// ! Progress Bar
// **********************************************************************// 

add_shortcode('progress','etheme_progress_shortcode');

function etheme_progress_shortcode($atts) {
    $a = shortcode_atts(array(
        'complete' => '',
        'color' => '',
        'title'    => ''    
    ),$atts);

    $style = '';
    
    if($a['complete'] > 100) {
        $a['complete'] = 100;
    }elseif($a['complete'] < 0) {
        $a['complete'] = 0;
    }

    if ($a['color'] != '') {
        $style = 'background-color:'.$a['color'];
    }
    
    return '<div class="progress-bars"><div class="progress-bar" data-width="'.$a['complete'].'" style="'.$style.'"><span>'.$a['title'].'</span><div></div></div></div>';
}



// **********************************************************************// 
// ! Google Font
// **********************************************************************// 

add_shortcode('googlefont','etheme_googlefont_shortcode');
$registerd_fonts = array();

function etheme_googlefont_shortcode($atts, $content = null) {
	global $registerd_fonts;
    $a = shortcode_atts(array(
        'name' => 'Open Sans',
        'size' => '',
        'color' => '',
        'class' => ''
    ),$atts);
    $google_name = str_replace(" ", "+", $a['name']);
    if (!in_array($google_name, $registerd_fonts)) {
    	$registerd_fonts[] = $google_name;
	    ?>
	    <link rel='stylesheet'  href='http://fonts.googleapis.com/css?family=<?php echo $google_name; ?>' type='text/css' media='all' />
	    <?php
    }
    
    //wp_enqueue_style($google_name,"http://fonts.googleapis.com/css?family=".$google_name);
    return '<span class="google-font '.$a['class'].'" style="font-family:'.$a['name'].'; color:'.$a['color'].'; font-size:'.$a['size'].'px;">'.do_shortcode($content).'</span>';
}

// **********************************************************************// 
// ! Pricing Tables
// **********************************************************************// 

add_shortcode('ptable','etheme_ptable_shortcode');

function etheme_ptable_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'class' => '',
        'content' => ''
    ),$atts);
    return '<div class="price-table '.$a['class'].'">'.do_shortcode($content.$a['content']).'</div>';
}

// **********************************************************************// 
// ! Single post
// **********************************************************************// 

add_shortcode('single_post','etheme_featured_post_shortcode');

function etheme_featured_post_shortcode($atts) {
    $a = shortcode_atts(array(
        'title' => '',
        'id' => '',
        'class' => '',
        'more_posts' => 1
    ),$atts);
    $limit = 1;
    $width = 300;
    $height = 300;
    $lightbox = etheme_get_option('blog_lightbox');
    $blog_slider = etheme_get_option('blog_slider');
    $posts_url = get_permalink(get_option('page_for_posts'));
    $args = array(
        'p'                     => $a['id'],
        'post_type'             => 'post',
        'ignore_sticky_posts'   => 1,
        'no_found_rows'         => 1,
        'posts_per_page'        => $limit
    );

    $the_query = new WP_Query( $args ); 
    ob_start();
    ?>

    <?php if ( $the_query->have_posts() ) : ?>

        <?php while ( $the_query->have_posts() ) : $the_query->the_post();  $postId = get_the_ID(); ?>

            <div class="featured-posts <?php echo $a['class']; ?>">
                <?php if ($a['title'] != ''): ?>
                    <h3 class="title a-left"><span><?php echo $a['title']; ?></span></h3>
                    <?php if ($a['more_posts']): ?>
                            <?php echo '<a href="'.$posts_url.'" class="show-all-posts hidden-tablet hidden-phone">'.__('View more posts', WFT_DOMAIN).'</a>'; ?>
                    <?php endif ?>
                <?php endif ?>
                <div class="featured-post row-fluid">
                    <div class="span6">
                        <?php 
                            $width = etheme_get_option('blog_page_image_width');
                            $height = etheme_get_option('blog_page_image_height');
                            $crop = etheme_get_option('blog_page_image_cropping');
                        ?>

                        <?php $images = etheme_get_images($width,$height,$crop); ?>

                        <?php if (count($images)>0 && has_post_thumbnail()): ?>
                            <div class="post-images nav-type-small<?php if (count($images)>1): ?> images-slider<?php endif; ?>">
                                <ul class="slides">
                                    <?php if(!$blog_slider): ?>
                                        <li><a href="<?php the_permalink(); ?>"><img src="<?php echo $images[0]; ?>"></a></li>
                                    <?php else: ?>
                                        <?php foreach ($images as $key => $value): ?>
                                            <li><a href="<?php the_permalink(); ?>"><img src="<?php echo $value; ?>"></a></li>
                                        <?php endforeach ?>
                                    <?php endif; ?>
                                </ul>
                                <?php if (count($images) == 1 || !$blog_slider): ?>
                                    <div class="blog-mask">
                                        <div class="mask-content">
                                            <?php if($lightbox): ?><a href="<?php echo etheme_get_image(get_post_thumbnail_id($postId)); ?>" rel="lightbox"><i class="icon-resize-full"></i></a><?php endif; ?>
                                            <a href="<?php the_permalink(); ?>"><i class="icon-link"></i></a>
                                        </div>
                                    </div>
                                <?php endif ?>
                            </div>
                            <?php if($blog_slider): ?>
                                <script type="text/javascript">
                                    jQuery('.post-images').flexslider({
                                        animation: "slide",
                                        slideshow: false,
                                        animationLoop: false,
                                        controlNav: false
                                    });
                                </script>   
                            <?php endif; ?>
                        <?php endif ?>
                    </div>
                    <div class="span6">
                        <h4 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                        <div class="post-info">
                            <span class="posted-on">
                                <?php _e('Posted on', WFT_DOMAIN) ?>
                                <?php the_time(get_option('date_format')); ?> 
                                <?php _e('at', WFT_DOMAIN) ?>
                                <?php the_time(get_option('time_format')); ?>
                            </span> 
                            <span class="posted-by"> <?php _e('by', WFT_DOMAIN);?> <?php the_author_posts_link(); ?></span>
                        </div>
                        <div class="post-description">
                            <?php the_excerpt(); ?>
                            <a href="<?php the_permalink(); ?>" class="button read-more"><?php _e('Read More', WFT_DOMAIN) ?></a>
                        </div>
                    </div>
                </div>
            </div>

        <?php endwhile; ?>

        <?php wp_reset_postdata(); ?>

    <?php else:  ?>

        <p><?php _e( 'Sorry, no posts matched your criteria.', WFT_DOMAIN ); ?></p>

    <?php endif; ?>

    <?php
    $output = ob_get_contents();
    ob_end_clean();

    return $output;

}

// **********************************************************************// 
// ! Static Block Shortcode
// **********************************************************************// 

add_shortcode('block','etheme_block_shortcode');

function etheme_block_shortcode($atts) {
    $a = shortcode_atts(array(
        'class' => '',
        'id' => ''
    ),$atts);

    return et_get_block($a['id']);
}

// **********************************************************************// 
// ! Recent posts widget shortcode 
// **********************************************************************// 

add_shortcode('et_recent_posts_widget','etheme_recent_posts_widget_shortcode');

function etheme_recent_posts_widget_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'title' => '', 
        'number' => 5
    ),$atts);
    
    $widget = new Etheme_Recent_Posts_Widget();

    $args = array(
        'before_widget' => '<div class="sidebar-widget etheme_widget_recent_entries">',
        'after_widget' => '</div><!-- //sidebar-widget -->',
        'before_title' => '<h4 class="widget-title">',
        'after_title' => '</h4>',
        'widget_id' => 'etheme_widget_recent_entries',
    ); 
    $instance = array(
        'title' => $a['title'],
        'number' => $a['number']
    );

    ob_start();
    $widget->widget($args, $instance);
    $output = ob_get_contents();
    ob_end_clean();
    
    return $output;
}

// **********************************************************************// 
// ! Recent comments widget shortcode 
// **********************************************************************// 

add_shortcode('et_recent_comments','etheme_recent_comments_shortcode');

function etheme_recent_comments_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'title' => '', 
        'number' => 5
    ),$atts);
    
    $widget = new Etheme_Recent_Comments_Widget();

    $args = array(
        'before_widget' => '<div class="sidebar-widget etheme_widget_recent_comments">',
        'after_widget' => '</div><!-- //sidebar-widget -->',
        'before_title' => '<h4 class="widget-title">',
        'after_title' => '</h4>',
        'widget_id' => 'etheme_widget_recent_comments',
    ); 
    $instance = array(
        'title' => $a['title'],
        'number' => $a['number']
    );

    ob_start();
    $widget->widget($args, $instance);
    $output = ob_get_contents();
    ob_end_clean();
    
    return $output;
}


// **********************************************************************// 
// ! Icon Box
// **********************************************************************// 

add_shortcode('icon_box','etheme_icon_box_shortcode');

function etheme_icon_box_shortcode($atts, $content = null) {
    $a = shortcode_atts(array(
        'title' => '', 
        'icon' => 'bolt', 
        'icon_position' => 'left',
        'color' => '', 
        'text' => ''
    ),$atts);
    
    $output = '';
    $output .= '<div class="block-with-ico ico-position-'.$a['icon_position'].'">';
        $output .= '<i class="icon-'.$a['icon'].'" style="color:'.$a['color'].'"></i>';
        $output .= '<h5>'.$a['title'].'</h5>';
        $output .= do_shortcode($content).do_shortcode($a['text']);
    $output .= '</div>';

    
    return $output;
}

// **********************************************************************// 
// ! Add Shortcodes Buttons to editor
// **********************************************************************// 

function etheme_add_shortcodes_buttons() {
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     return;
   if ( get_user_option('rich_editing') == 'true') {
     add_filter('mce_external_plugins', 'shortcodes_tinymce_plugin');
     add_filter('mce_buttons_3', 'register_shortcodes_button');
   }
}

function etheme_add_shortcodes_buttons2() {
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     return;
   if ( get_user_option('rich_editing') == 'true') {
     add_filter('mce_external_plugins', 'shortcodes_tinymce_plugin2');
     add_filter('mce_buttons_4', 'register_shortcodes_button2');
   }
}

add_action('init', 'etheme_add_shortcodes_buttons');
add_action('init', 'etheme_add_shortcodes_buttons2');

function register_shortcodes_button($buttons) {
   array_push($buttons, "et_featured", "et_new_products", "et_button", "et_blockquote", "et_list", "eth_dropcap", "et_alert", "et_progress", "et_ptable");
   return $buttons;
}

function shortcodes_tinymce_plugin($plugin_array) {
   if(class_exists('WooCommerce')){
	   $plugin_array['et_featured'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
	   $plugin_array['et_new_products'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   }
   $plugin_array['et_button'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_blockquote'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_list'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['eth_dropcap'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   //$plugin_array['et_tooltip'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   //$plugin_array['et_iblock'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_alert'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_progress'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_ptable'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   return $plugin_array;
}

function register_shortcodes_button2($buttons) {
   array_push($buttons, "et_row", "et_column1_2", "et_column1_3", "et_column1_4", "et_column3_4", "et_column2_3", "et_tabs", "et_gmaps", "et_icon", "et_tm");
   return $buttons;
}

function shortcodes_tinymce_plugin2($plugin_array) {
   $plugin_array['et_row'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_column1_2'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_column1_3'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_column2_3'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_column1_4'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_column3_4'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_tabs'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   //$plugin_array['et_vimeo'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   //$plugin_array['et_youtube'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_gmaps'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_icon'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   $plugin_array['et_tm'] = get_template_directory_uri().'/framework/js/editor_plugin.js';
   return $plugin_array;
}

function etheme_refresh_mce($ver) {
  $ver += 3;
  return $ver;
}

add_filter( 'tiny_mce_version', 'etheme_refresh_mce');

add_shortcode('wft_product_slider', 'wft_product_slider');
function wft_product_slider( $atts ) {

	global $woocommerce_loop, $product_slide_size;

	extract(shortcode_atts(array(
		'type' => 'featured',
		'per_page' 	=> '12',
		'columns' 	=> '4',
		'title' => '',
		'size' => '2',
		'with_descr' => '1',
		//'orderby' => 'date',
		//'order' => 'desc'
	), $atts));

	$product_slide_size = $size;

	ob_start();

	//$products = new WP_Query( $args );
	switch ($type) {
		case 'featured':
			$products = get_featured_products($per_page);
			break;
		case 'sale':
			$products = get_sale_products($per_page);
			break;
		case 'bestsellers':
			$products = get_best_selling_products($per_page);
			break;
		case 'top_rated':
			$products = get_top_rated_products($per_page);
			break;
		case 'recent':
			$products = get_recent_products($per_page);
			break;
		case 'related':
			$products = get_related_products($per_page);
			break;
		default:
			$products = get_featured_products($per_page);
			break;
	}

	$woocommerce_loop['columns'] = $columns;

	if ( $products && $products->have_posts() ) {

		if ( $title ) {
			echo '<h2>' . $title . '</h2>';
		}

		echo '<div class="carousel es-carousel-wrapper '. (( $with_descr == 1 ) ? 'style1' : 'style0') .'">
				<div class="es-carousel">
					<div class="row '. (( $with_descr == 1 ) ? 'small_with_description' : '') .'">
						<div class="product_outer carousel_items">';

		while ( $products->have_posts() ) {

			$products->the_post();

			woocommerce_get_template_part( 'content', 'product' );

		} // end of the loop.

		//woocommerce_product_loop_end();
		echo '</div></div></div></div>';

	}

	wp_reset_postdata();


	return '<div class="woocommerce">' . ob_get_clean() . '</div>';
}

if ( function_exists('is_plugin_active') && is_plugin_active( 'woocommerce-multilingual/wpml-woocommerce.php' ) ) {

	function wft_wpml_currency_switcher($atts) {

		global $woocommerce;

		// format tags
		// Name     - %name
		// Symbol   - %symbol
		// Code     - $code

		extract( shortcode_atts( array(
			'format' => '(%symbol) %name',
		), $atts ) );

		include_once(home_url() .'/wp-content/plugins/woocommerce-multilingual/inc/multi-currency-support.class.php');

		$mc_obj = new WCML_Multi_Currency_Support;

		$wc_currencies = get_woocommerce_currencies();

		$exchange_rates = $mc_obj->get_exchange_rates();

		$current_currency = $mc_obj->get_client_currency();
		wc_enqueue_js("
			jQuery('.currency_switcher_value').click(function() {

				jQuery('#ajax_loader').show();
				var currency = jQuery(this).attr('data-currency');

				//jQuery('this').find();

				var data = {action: 'wcml_switch_currency', currency: currency, context: 'frontend'}
				jQuery.ajax({
					url: woocommerce_params.ajax_url,
					method: 'POST',
					data: data,
					complete: function(response) {
						jQuery('#ajax_loader').hide();
						//jQuery('.wcml_currency_switcher').removeAttr('disabled');
						//jQuery('#ajax_loader').hide();
						location.reload();
					}
				});

			});
		");

		echo '<span class="link_label">Currency:</span>';

		?>

		<div class="fadelink currency_switcher">

			<a href="#" class="current_currency"><?php echo $wc_currencies[$current_currency]; ?></a>

			<div class="ul_wrapper" style="display: none;">
				<ul>
					<?php foreach ( $exchange_rates as $currency => $rate ) {

						$currency_format = preg_replace(array('#%name#', '#%symbol#', '#%code#'),
							array($wc_currencies[$currency], get_woocommerce_currency_symbol($currency), $currency), $format);
						?>

						<li class="currency_switcher_value" data-currency="<?php echo $currency; ?>">
							<a href="#"><?php echo $currency_format; ?></a>
						</li>

					<?php } //endforeach; ?>

				</ul>
			</div>

		</div>

		<?php

	}

	add_shortcode('wft_wpml_currency_switcher', 'wft_wpml_currency_switcher');
}

function wft_youtube_video($atts) {

	extract( shortcode_atts( array(
		'id' => '',
		'thumb' => false
	), $atts ) );

	$thumb = (bool) $thumb;

	if ( $thumb ) {
		?>


		<a class="video" href="http://www.youtube.com/watch?v=<?php echo $id; ?>"><i class=" icon-link"></i></a>



		<?php
	} else {

	}

}
add_shortcode('wft_youtube_video', 'wft_youtube_video');

function wft_breadcrumbs() {
	woocommerce_breadcrumb();
}
add_shortcode('wft_breadcrumbs', 'wft_breadcrumbs');

function wft_video_section($atts, $content = null) {

	$a = shortcode_atts( array(
		'title' => '',
		'el_class' => '',
		'content' => '',
		'video_mp4' => '',
	), $atts);

	$css_class = 'videoWrapperFull';
	if ( $a['el_class'] ) {
		$css_class .= ' ' . $a['el_class'];
	}

	$output = '<div class="' . $css_class . '">';
	$output .= '<div class="video-hover"></div>';
	$output .= '<div class="video-hover-color"></div>';
	$output .= '<div class="video-text">';

	if ( $a['title'] ) {
		$output .= '<div class="title">' . $a['title'] . '</div>';
	}

	$output .= do_shortcode($content).do_shortcode($a['content']);
	$output .= '</div>';

	if ( $a['video_mp4'] ) {

		$src = str_replace('__template_url__', get_template_directory_uri(), $a['video_mp4']);
		$output .= '<video style="width: 100%; height: 100%; min-height:407px;" controls="controls" preload="auto" src="' . $src . '"  loop="true" autoplay="true"></video>';
	}

	$output .= '</div>';


	return $output;
}
add_shortcode('wft_video_section', 'wft_video_section');

// **********************************************************************//
// ! Alert Boxes
// **********************************************************************//
function wft_alert($atts, $content = null) {
	$a = shortcode_atts(array(
		'title' => __('Warning', 'buyshop'),
		'type' => 'warning',
		'message' => '',
		'close' => 1
	), $atts);

	$output = '<div class="alert alert-'. $a['type'] .' alert-dismissable">';

	if ( $a['close'] ) {
		$output .= '<button data-dismiss="alert" class="close" type="button">×</button>';
	}

	if ( $a['title'] ) {
		$output .= '<h3>' . $a['title'] . '</h3>';
	}

	if ( $content ) {
		$output .= do_shortcode($content);
	}

	$output .= $a['message'];

	$output .= '</div>';

	return $output;

}
add_shortcode('alert', 'wft_alert');

function wft_blog_slider($atts, $content = null) {
	$a = shortcode_atts(array(
		'title' => __('FROM THE BLOG', 'buyshop'),
		'span_size' => 6,
		'numberposts' => 10,
		'offset' => 0,
		'category' => 0,
		'orderby' => 'post_date',
		'order' => 'DESC',
		'include' => '',
		'exclude' => '',
		'meta_key' => '',
		'meta_value' =>'',
		'post_type' => 'post',
		'post_status' => 'publish',
		'suppress_filters' => true
	), $atts);

	$posts = wp_get_recent_posts( $a, ARRAY_A );

	$output = '';

	if ( !empty($posts) ) {
		add_filter('post_thumbnail_html', 'wft_blog_slider_image_filter', 10, 5);
		if ( $a['title'] ) {
			$output .= '<h3 class="padding">' . $a['title'] . '</h3>';
		}

		$half_size = (int) ($a['span_size'] / 2);

		$output .= '<div class="carousel es-carousel-wrapper style2 from-blog">
				<div class="es-carousel">
				  <div class="row">
					<div class="carousel_items">';

		foreach ( $posts as $p ) {

			$content = explode('<!--more-->', $p['post_content']);

			$images = etheme_get_images($width = null, $height = null, $crop = true, $p['ID'] );

			$output .= '
				<div class="span' . (int) $a['span_size'] . ' carousel_item">
                    <div class="row">';

			if ( !empty($images) ) {
			  $output .= '<div class="span' . $half_size . '">
							<a href="' . get_permalink($p['ID']) . '"><img src="' . $images[0] . '"  alt="" class="img-rounded animate flip" /></a>
						  </div>';
			}

			$output .= '<div class="span' . (!empty($images) ? $half_size : $a['span_size']) . '">
                        <h4>' . $p['post_title'] . '</h4>
                        <p><a href="' . get_comments_link($p['ID']) . '">' . $p['comment_count'] . ' ' . __('Comments', WFT_DOMAIN) . '</a></p>
                        <p>' . $content[0] . '</p>
                      </div>
                    </div>
                </div>';
		}
		remove_filter('post_thumbnail_html', 'wft_blog_slider_image_filter', 10);

		$output .= '</div></div></div></div>';
	}
	return $output;
}
add_shortcode('blog_slider', 'wft_blog_slider');

add_shortcode('products_isotope_listing', 'wft_products_isotope_listing');
function wft_products_isotope_listing($atts) {

	global $product_slide_size;

	$a = shortcode_atts(array(
		'per_page' 	=> '12',
		'title' => '',
		'size' => '3',
		'with_descr' => '1',
		'filter' => true,
	), $atts);

	$product_slide_size = $a['size'];
	$per_page = (int) $a['per_page'];
	ob_start();
	$products = get_recent_products($per_page);

	if ( $products->have_posts() ) {

		//woocommerce_product_loop_start();

		if ( $a['title'] ) {
			echo '<h2>' . $a['title'] . '</h2>';
		}

		if ( $a['filter'] ) {

			echo '<section class="filters-by-category clearfix">
					<ul class="option-set" data-option-key="filter">
					  <li><a href="#filter" data-option-value="*" class="selected" data-per-page="' . $per_page . '">'. __('all', WFT_DOMAIN) . '</a></li>
					  <li><a href="#filter" data-option-value=".featured" data-per-page="' . $per_page . '">'. __('FEATURED', WFT_DOMAIN) . '</a></li>
					  <li><a href="#filter" data-option-value=".new_product" data-per-page="' . $per_page . '">'. __('NEW PRODUCTS', WFT_DOMAIN) . '</a></li>
					  <li><a href="#filter" data-option-value=".sale" data-per-page="' . $per_page . '">'. __('ON SALE', WFT_DOMAIN) . '</a></li>
					</ul>
				  </section>';

		}

		echo '<div class="row isotope-outer '. (( $a['with_descr'] == 1 ) ? 'big_with_description' : '') .'">';

		while ( $products->have_posts() ) {

			$products->the_post();

			woocommerce_get_template_part( 'content', 'product' );

		} // end of the loop.

		echo '</div>';

	}

	wp_reset_postdata();

	return '<div class="woocommerce">' . ob_get_clean() . '</div>';

}

if ( ! function_exists( 'woothemes_testimonials_shortcode' ) ) {
	/**
	 * The shortcode function.
	 * @since  1.0.0
	 * @param  array  $atts    Shortcode attributes.
	 * @param  string $content If the shortcode is a wrapper, this is the content being wrapped.
	 * @return string          Output using the template tag.
	 */
	function woothemes_testimonials_shortcode ( $atts, $content = null ) {
		$args = (array)$atts;

		$defaults = array(
			'limit' => 5,
			'orderby' => 'menu_order',
			'order' => 'DESC',
			'interval' => 10000,
			'id' => 0,
			'display_author' => true,
			'display_avatar' => true,
			'display_url' => true,
			'effect' => 'fade', // Options: 'fade', 'none'
			'pagination' => false,
			'echo' => true,
			'size' => 50,
			'type' => 'slider',
			'navigation' => false,
			'category' => 0,
			'title' => '',
			'before' => '',
			'after' => '',
			'before_title' => '<h1 class="aligncenter">',
			'after_title' => '</h1>',
			'columns' => 2,
			'parallax' => false,
			'parallax_size' => 8,
			'parallax_class' => ''
		);

		$args = shortcode_atts( $defaults, $atts );

		// Make sure we return and don't echo.
		$args['echo'] = false;

		// Fix integers.
		if ( isset( $args['limit'] ) ) $args['limit'] = intval( $args['limit'] );
		if ( isset( $args['id'] ) ) $args['id'] = intval( $args['id'] );
		if ( isset( $args['size'] ) &&  ( 0 < intval( $args['size'] ) ) ) $args['size'] = intval( $args['size'] );
		if ( isset( $args['category'] ) && is_numeric( $args['category'] ) ) $args['category'] = intval( $args['category'] );

		// Fix booleans.
		foreach ( array( 'display_author', 'display_url', 'pagination', 'display_avatar' ) as $k => $v ) {
			if ( isset( $args[$v] ) && ( 'true' == $args[$v] ) ) {
				$args[$v] = true;
			} else {
				$args[$v] = false;
			}
		}

		return woothemes_testimonials( $args );
	} // End woothemes_testimonials_shortcode()
}

if ( ! function_exists( 'woothemes_testimonials' ) ) {
	/**
	 * Display or return HTML-formatted testimonials.
	 * @param  string/array $args  Arguments.
	 * @since  1.0.0
	 * @return string
	 */
	function woothemes_testimonials ( $args = '' ) {
		global $post;

		$defaults = array(
			'limit' => 5,
			'orderby' => 'menu_order',
			'interval' => 10000,
			'order' => 'DESC',
			'id' => 0,
			'display_author' => true,
			'display_avatar' => true,
			'display_url' => true,
			'pagination' => false,
			'echo' => true,
			'size' => 50,
			'title' => '',
			'before' => '',
			'after' => '',
			'before_title' => '',
			'after_title' => '',
			'type' => 'slider',
			'columns' => 2,
			'navigation' => false,
			'category' => 0,
			'parallax' => false,
			'parallax_size' => 8,
			'parallax_class' => ''
		);

		$img_size = 40;

		$args = wp_parse_args( $args, $defaults );

		// Allow child themes/plugins to filter here.
		$args = apply_filters( 'woothemes_testimonials_args', $args );
		$html = '';

		do_action( 'woothemes_testimonials_before', $args );

		// The Query.
		$query = woothemes_get_testimonials( $args );

		$class = 'cbp-qtrotator';

		if($args['type'] == 'slider') {
			$class = 'carousel-testimonials';
		} elseif($args['type'] == 'grid') {
			$img_size = 120;
			$class = 'testimonial-grid testimonials';
		}

		// The Display.
		if ( ! is_wp_error( $query ) && is_array( $query ) && count( $query ) > 0 ) {

			if ( $args['parallax'] ) {
				$html .= '<div class="parallax-block parallax ' . esc_html($args['parallax_class']) . '">
							  <div class="container">
								<div class="row">
								  <div class="span'. (int) $args['parallax_size'] .' offset2">';

			}

			$html .= $args['before'] . "\n";
			if ( '' != $args['title'] ) {
				$html .= $args['before_title'] . esc_html( $args['title'] ) . $args['after_title'] . "\n";
			}


			$html .= '<div  class="'.$class.'">' . "\n" . '<div class="quotes">&#8220;</div>' . "\n";

			// Begin templating logic.

			if($args['type'] == 'slider') {
				$tpl = '<li id="quote-%%ID%%" class="cbp-qtcontent %%CLASS%%"><p class="testimonials-text">%%TEXT%%</p><p><span class="testimonial-author">%%AUTHOR%%</span></p></li>';

			} elseif($args['type'] == 'grid') {
				$tpl = '<div id="quote-%%ID%%" class="cbp-qtcontent %%CLASS%%"> %%AVATAR%% <blockquote class="testimonials-text">%%TEXT%%</blockquote> <div class="testimonial-author">%%AUTHOR%%</div> <div class="clear"></div></div>';
			}
			$tpl = apply_filters( 'woothemes_testimonials_item_template', $tpl, $args );

			$count = 0;

			if ($args['type'] == 'grid') {
				$html .= '<div class="testimonials-row">';
			} elseif ($args['type'] == 'slider') {
				$html .= '<div class="flexslider"><ul class="slides">';
			}

			foreach ( $query as $post ) { $count++;
				$template = $tpl;

				$css_class = 'quote';
				if ( 1 == $count ) { $css_class .= ' first'; }
				if ( count( $query ) == $count ) { $css_class .= ' last'; }

				setup_postdata( $post );

				$author = '';
				$author_text = '';

				// If we need to display the author, get the data.
				if ( ( get_the_title( $post ) != '' ) && true == $args['display_author'] ) {
					$author .= '<cite class="author">';

					$author_name = get_the_title( $post );

					$author .= '<strong>'.$author_name.'</strong>';

					if ( isset( $post->byline ) && '' != $post->byline ) {
						$author .= ' <span class="excerpt">' . $post->byline . '</span><!--/.excerpt-->' . "\n";
					}

					if ( true == $args['display_url'] && '' != $post->url ) {
						$author .= ' <span class="url"><a href="' . esc_url( $post->url ) . '">' . $post->url . '</a></span><!--/.excerpt-->' . "\n";
					}

					$author .= '</cite><!--/.author-->' . "\n";

					// Templating engine replacement.
					$template = str_replace( '%%AUTHOR%%', $author, $template );
				} else {
					$template = str_replace( '%%AUTHOR%%', '', $template );
				}

				// Templating logic replacement.
				$template = str_replace( '%%ID%%', get_the_ID(), $template );
				$template = str_replace( '%%CLASS%%', esc_attr( $css_class ), $template );

				if ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] ) {
					$image = '<img src="' . etheme_get_image(false, $img_size, $img_size) . '">';
					$template = str_replace( '%%AVATAR%%', '<a class="avatar-link">' . $image . '</a>', $template );
				} else {
					$template = str_replace( '%%AVATAR%%', '', $template );
				}

				// Remove any remaining %%AVATAR%% template tags.
				$template = str_replace( '%%AVATAR%%', '', $template );

				$content = apply_filters( 'woothemes_testimonials_content', get_the_content(), $post );
				$template = str_replace( '%%TEXT%%', $content, $template );

				// Assign for output.
				$html .= $template;

				if ($count%$args['columns'] == 0 && count( $query ) != $count && $args['type'] == 'grid') {
					$html .= '</div><div class="testimonials-row">';
				}
			}
			if ($args['type'] == 'grid') {
				$html .= '</div><!--testimonials-row-->';
			} elseif ( $args['type'] == 'slider' ) {
				$html .= '</ul></div><!--testimonials-flexslider-->';
			}



			wp_reset_postdata();


			if ( $args['pagination'] == true && count( $query ) > 1 && $args['effect'] != 'none' ) {
				$html .= '<div class="pagination">' . "\n";
				$html .= '<a href="#" class="btn-prev">' . apply_filters( 'woothemes_testimonials_prev_btn', '&larr; ' . __( 'Previous', WFT_DOMAIN ) ) . '</a>' . "\n";
				$html .= '<a href="#" class="btn-next">' . apply_filters( 'woothemes_testimonials_next_btn', __( 'Next', WFT_DOMAIN ) . ' &rarr;' ) . '</a>' . "\n";
				$html .= '</div><!--/.pagination-->' . "\n";
			}
			$html .= '<div class="fix"></div>' . "\n";
			if ($args['navigation']) {
				$html .= '<div class="cbp-next"><i class="icon-angle-right"></i></div>' . "\n";
				$html .= '<div class="cbp-prev"><i class="icon-angle-left"></i></div>' . "\n";
			}
			$html .= '</div><!--/.testimonials-->' . "\n";
			$html .= $args['after'] . "\n";

			if ( $args['parallax'] ) {
				$html .= '</div></div></div></div>';
			}
		}

		// Allow child themes/plugins to filter here.
		$html = apply_filters( 'woothemes_testimonials_html', $html, $query, $args );

		if ( $args['echo'] != true ) { return $html; }

		// Should only run is "echo" is set to true.
		echo $html;

		do_action( 'woothemes_testimonials_after', $args ); // Only if "echo" is set to true.
	} // End woothemes_testimonials()
}

if ( !shortcode_exists('woocommerce_lost_password') ) {
	function wft_lost_password() {
		global $post;

		// arguments to pass to template
		$args = array( 'form' => 'lost_password' );

		// process reset key / login from email confirmation link
		if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {

			$user = self::check_password_reset_key( $_GET['key'], $_GET['login'] );

			// reset key / login is correct, display reset password form with hidden key / login values
			if( is_object( $user ) ) {
				$args['form'] = 'reset_password';
				$args['key'] = esc_attr( $_GET['key'] );
				$args['login'] = esc_attr( $_GET['login'] );
			}
		} elseif ( isset( $_GET['reset'] ) ) {
			wc_add_notice( __( 'Your password has been reset.', 'woocommerce' ) . ' <a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Log in', 'woocommerce' ) . '</a>' );
		}

		wc_get_template( 'myaccount/form-lost-password.php', $args );
	}
	add_shortcode('woocommerce_lost_password', 'wft_lost_password');
}

if ( !function_exists('wft_brands_slider') ) {
	function wft_brands_slider($atts) {
		$a = shortcode_atts(array(
			'title' => __('Brands', WFT_DOMAIN),
			'block_class' => 'brands_block',
			'block_id' => ''
		), $atts);

		$output = '';

		if ( $a['title'] ) {
			$output .= '<h3>' . $a['title'] . '</h3>';
		}

		$output .= '<div class="brands_block ' . $a['block_class'] . '" ' . ( $a['block_id'] ? 'id="' . $a['block_id'] . '"' : '' ) . '>';

		$brands = get_product_brands();

		if ( !empty($brands) ) {
			wp_enqueue_script('jcarousel');
			wp_enqueue_script('wft-brands-slider');

			$output .= '<ul class="jcarousel-skin-brands">';
			foreach ( $brands as $brand ) {

				$output .= '<li>';
				$output .= '<a href="' . get_term_link( $brand->slug, 'brand') . '">';

				$thumbnail_id 	= absint( get_woocommerce_term_meta( $brand->term_id, 'thumbnail_id', true ) );
				if ($thumbnail_id) {
					$output .= '<img src="' . etheme_get_image( $thumbnail_id ) . '" alt="' . $brand->name . '" title="' . $brand->name . '" />';
				}

				$output .= '</a>';
				$output .= '</li>';

			}
			$output .= '</ul>';

		} else {
			$output .= '<p>' . __('There are no brands found', WFT_DOMAIN) . '</p>';
		}

		$output .= '</div>';

		return $output;
	}
}
add_shortcode('wft_brands_slider', 'wft_brands_slider');

if ( !function_exists('wft_simple_related_products') ) {
	function wft_simple_related_products($atts) {
		$a = shortcode_atts(array(
			'title' => __('Related Products', WFT_DOMAIN),
			'per_page' => 9,
			'vertical' => true
		), $atts);

		$output = '';

		if ( $a['title'] ) {
			$output .= '<h3>' . $a['title'] . '</h3>';
		}

		$output .= '<div class="flexslider' . ($a['vertical'] ? ' vertical' : '') . '">';

		$products = get_related_products((int) $a['per_page']);

		if ( $products && $products->have_posts() ) {

			$output .= '<ul class="slides">';

			$posts = $products->get_posts();

			foreach ( $posts as $p ) {

				$output .= '<li>';

				$output .= '<a href="' . esc_url( apply_filters( 'the_permalink', get_permalink($p->ID) ) ) . '">';

				if ( has_post_thumbnail() ) {
					$output .= get_the_post_thumbnail( $p->ID, 'shop_single' );
				} else {

					$attachment_ids = $p->get_gallery_attachment_ids();

					if ( $attachment_ids ) {
						$output .= '<img alt="" src="' . wft_get_attachment_thumb_url($attachment_ids[0], 'shop_single') . '" />';
					} elseif ( woocommerce_placeholder_img_src() ) {
						$output .= woocommerce_placeholder_img( 'shop_single' );
					}
				}

				$output .= '</a>';

				$output .= '</li>';

			}
			$output .= '</ul>';

			wp_reset_postdata();
		}

		$output .= '</div>';

		return $output;
	}
}
add_shortcode('wft_related_products', 'wft_simple_related_products');