<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function shrk_sc_socialicons( $atts ) {

	global $shrk_options;
	$icons = '';

	extract( shortcode_atts(array(
		'class'       => '',
		'link_colors' => 'normal', 
		'new_window'  => false,
		'css'         => ''
	), $atts) );  

	$social_networks = apply_filters( 'shrk-social-network-icons' , array(
		'facebook'   => 'ion-social-facebook',
		'twitter'    => 'ion-social-twitter',
		'googleplus' => 'ion-social-googleplus',
		'google'     => 'ion-social-google',
		'dribbble'   => 'ion-social-dribbble',
		'github'     => 'ion-social-github',
		'instagram'  => 'ion-social-instagram',
		'foursquare' => 'ion-social-foursquare',
		'pinterest'  => 'ion-social-pinterest',
		'tumblr'     => 'ion-social-tumblr',
		'wordpress'  => 'ion-social-wordpress',
		'reddit'     => 'ion-social-reddit',
		'buffer'     => 'ion-social-buffer',
		'skype'      => 'ion-social-skype',
		'linkedin'   => 'ion-social-linkedin',
		'vimeo'      => 'ion-social-vimeo',
		'youtube'    => 'ion-social-youtube',
		'rss'        => 'ion-social-rss',
		)
	);

	foreach ($social_networks as $network => $icon) {
		if ( !empty( $shrk_options['social_'.$network.'_url'] ) ) {
			$icons .= '<li><a href="' . esc_url( $shrk_options['social_'.$network.'_url'] ) . '" ' . ($new_window ? 'target="_blank"' : '') . '><i class="' . esc_attr( $icon ) . '"></i></a></li>';
		}
	}

	if ( $link_colors == 'inverted' ) {
		$class .= ' inv-link-colors';
	}

	if ( function_exists( 'vc_shortcode_custom_css_class') ) {
		$class .= ' ' . apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class( $css, ' ' ), 'shrk_banner', $atts );
	}

	if ( !empty($icons) ) {
		return '<ul class="shrk-social-icons ' . esc_attr( $class ) . '">' . $icons . '</ul>';
	} else {
		return '<span>Social networks not specified.</span>';
	}
}

add_action( 'init', function () {
	add_shortcode('socialicons', 'shrk_sc_socialicons');
});


add_filter( 'shrk_filter_vc_mappings', function ( $shrk_vc_shortcodes ) {

	$shrk_vc_shortcodes["socialicons"] = array(
		"name"                    => esc_html__("Social Icons", 'dvl-uxshop-shortcodes'), 
		"category"                => esc_html__('Theme Specific', 'dvl-uxshop-shortcodes'),
		"description"             => esc_html__('Show the social icons configured in the theme options.', 'dvl-uxshop-shortcodes'),
		"base"                    => "socialicons",
		"icon"                    => "icon-wpb-shrk",
		"show_settings_on_create" => false,
		"params"                  => array(
			array(
				'type'       => 'dropdown',
				'heading'    => esc_html__('Link colors', 'dvl-uxshop-shortcodes'),
				'param_name' => 'link_colors',
				'value'      => array(
					esc_html__( 'Main Color / Secondary on hover', 'dvl-uxshop-shortcodes' ) => 'normal',
					esc_html__( 'Secondary Color / Main on hover', 'dvl-uxshop-shortcodes' ) => 'inverted',
					)
				),
			array(
				'type'       => 'css_editor',
				'heading'    => __( 'Css', 'dvl-uxshop-shortcodes' ),
				'param_name' => 'css',
				'group'      => __( 'Design options', 'dvl-uxshop-shortcodes' ),
				),
			),
	);

	return $shrk_vc_shortcodes;
} );

?>