<?php

class Intense_Person extends Intense_Shortcode {

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

		global $intense_visions_options;

		$this->title = __( 'Person', 'intense' );
		$this->description = __( 'The person shortcode shows a person with a name, title, image, social networks, and a description. The person shortcode is perfect for showing your team members, clients, authors, guests, and more. Besides the information about the person, you can also set the border radius (rounded corners) of the image and add a shadow.
			<br><br>
			The layouts for the person shortcode are templates that can be customized to suite your needs. There are several predefined templates with more to come.', 'intense' );
		$this->category = __( 'Layout', 'intense' );
		$this->show_preview = true;
		$this->preview_content = __( 'Person Content', 'intense' );
		$this->is_container = true;
	}

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

		global $intense_person, $intense_person_custom_social;

		if ( is_numeric( $image ) ) {
			$imageid = $image;
		} else if ( !empty( $image ) ) {
			$imageurl = $image;
		}

		if ( isset( $imageposition ) ) {
			$template = $imageposition;
		}

		global $intense_person_custom_social;
		global $intense_person_social_size;

		$intense_person_custom_social = array();

		if ( empty( $custom_social ) ) {
			// render shortcodes so that the custom social
			// icons can be gathered together
			do_shortcode( $content );
		} else {
			$custom_social_items = explode( ',', $custom_social );

			foreach ( $custom_social_items as $social ) {
				$splitsocial = explode( '|', $social );

				if ( is_numeric( $splitsocial[2] ) ) {
					$photo = Intense_Photo_Source::get_wordpress_photo( $splitsocial[2], $social_size );
					$splitsocial[2] = $photo['url'];
				}

				if ( $splitsocial[0] != '' || $splitsocial[1] != '' ) {
					$link = $splitsocial[1];

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

					$intense_person_custom_social[] = array(
						'title' => $splitsocial[0],
						'link' => $link,
						'image' => $splitsocial[2],
					);
				}
			}
		}

		$custom_social = $intense_person_custom_social;

		$intense_person = array(
			'template' => $template,
			'imageid' => $imageid,
			'imageurl' => $imageurl,
			'imageshadow' => $imageshadow,
			'border_radius' => $border_radius,
			'size' => $size,
			'name' => $name,
			'social_target' => $social_target,
			'social_rel' => $social_rel,
			'title' => $title,
			'facebook' => $facebook,
			'twitter' => $twitter,
			'linkedin' => $linkedin,
			'dribbble' => $dribbble,
			'googleplus' => $googleplus,
			'instagram' => $instagram,
			'tumblr' => $tumblr,
			'pinterest' => $pinterest,
			'spotify' => $spotify,
			'youtube' => $youtube,
			'content' => do_shortcode( $content ),			
			'social_size' => $social_size,
			'custom_social'  => $custom_social
		);

		return intense_get_template( '/person/' . $template . '.php' );
	}
}
