<?php
/*===============================
Shortocde tz-skill-item
===============================*/

function tz_inter_banner($atts)
{
    $tz_type = $tz_title = $tz_subtitle = $tz_align = $tz_bg_banner = $tz_link = $css = '';
    extract(shortcode_atts(array(
        'tz_type' => '1',
        'tz_title' => '',
        'tz_subtitle' => '',
        'tz_align' => '1',
        'tz_bg_banner' => '',
        'css' => '',
        'tz_link' => '',
    ), $atts));
    ob_start();

    $vc_link = vc_build_link($tz_link);

    $tz_img_id = preg_replace('/[^\d]/', '', $tz_bg_banner);
    $tz_url_img = '';

    $tz_images_info = wp_get_attachment_image_src($tz_img_id, $size = 'full');
    if (isset($tz_images_info) && !empty($tz_images_info)) :
        $tz_url_img = $tz_images_info[0];
    endif;

    if ($tz_type == '1') :
        $tz_banner_type = 'tz_type1';
    elseif ($tz_type == '2') :
        $tz_banner_type = 'tz_type2';
    endif;

    if ($tz_align == '1') :
        $tz_align_value = 'tz_left';
    elseif ($tz_align == '2') :
        $tz_align_value = 'tz_center';
    elseif ($tz_align == '3') :
        $tz_align_value = 'tz_right';
    endif;

    $banner_classes = '';
    if (isset($css) && $css != ''):
        $banner_classes .= ' ' . vc_shortcode_custom_css_class($css);
    endif;

    ?>
    <div class="box_banner <?php echo esc_attr($banner_classes); ?> ">

        <div class="tz_banner <?php echo esc_attr($tz_banner_type); ?>">

            <img src="<?php echo esc_url($tz_url_img); ?>" />
            <div class="tz__border">
                <?php if ($tz_link == true && $vc_link['url'] != '') : ?>
                    <a href="<?php echo esc_attr($vc_link['url']) ?>"
                       target="<?php echo esc_attr($vc_link['target']); ?>"
                       title="<?php echo esc_attr($vc_link['title']); ?>"></a>
                <?php endif; ?>
                <?php if ($tz_title != '') : ?>
                    <h3 class="tz__title <?php echo $tz_align_value; ?>"><?php echo balanceTags($tz_title); ?></h3>
                <?php endif; ?>
                <?php if ($tz_subtitle != '' && $tz_type == '2') : ?>
                    <p class="tz_subtitle <?php echo $tz_align_value; ?>">
                        <span><?php echo balanceTags($tz_subtitle); ?></span></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <?php
    return ob_get_clean();
}

add_shortcode('tz_inter_banner', 'tz_inter_banner');
?>
