<?php

class Intense_Social_Icon extends Intense_Shortcode {

	function __construct() {
        parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'Social Icon', 'intense' );
		$this->description = __( 'Be social by adding social icons using the social icon shortcode. Use icons from Font Awesome, Vector Social Media, or use your own. Add links and control the size of the icons.', 'intense' );
		$this->category = __( 'Elements', 'intense' );
		$this->show_preview = true;
		$this->map_visual_composer = false;		
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		if ( !isset( $label ) ) $label = $type;
		if ( isset( $onclick ) ) $onclick = ' onclick="' . $onclick . '" ';
		$id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

        $color = intense_get_plugin_color( $color );

        if ( is_numeric( $link ) ) {
        	$link = get_permalink( $link );
        }

        if ( !empty( $link_rel ) ) $link_rel = ' rel="' . $link_rel . '"';

		$output = '<a' . $id . $link_rel . ' class="intense ' . $type . ' social-link' . ( !empty( $class ) ? ' ' . $class : '' ) . '" href="' . $link . '" target="' . $link_target . '" rel="external nofollow" title="' . $label . '" style="color: ' . $color . '; text-decoration: none;  display: inline-block; padding: 5px;"' . $onclick . '>';

		if ( $mode == "image" ) {
			$output .= '<img width="' . $size . '" height="' . $size . '" src="' . INTENSE_PLUGIN_URL . '/assets/img/social/PNG/32px/' . str_replace( " ", "-", mb_strtolower( $type ) ) . '.png" alt="' . $label . '" />';
		} else if ( $mode == "custom" ) {
			if ( is_numeric( $image ) ) {
				$photo = Intense_Photo_Source::get_wordpress_photo( $image, 'square75' );				
				$imageurl = $photo['url'];
			} else if ( !empty( $image ) ) {
				$imageurl = $image;
			}

			$output .= '<img style="height:' . $size . 'px;" src="' . $imageurl . '" alt="' . $label . '" />';
		} else {			
			$output .= intense_run_shortcode( 'intense_icon', array( 'type' => $type, 'color' => $color , 'size' => ( $size <= 5 ? $size : null ), 'width' => ( $size > 5 ? $size : null ), ) );
		}

		$output .= '</a>';

		return $output;
	}	
}
