<?php
/**
 * Created by entiri.
 * @Author: Miroslav Bohovic
 * @Date: 1.10.2013
 * License: entiri s.r.o.
 * Licence URI: http://www.entiri.com
 */

class entiri_sc_Tabs extends entiri_BaseShortcode implements entiri_IShortcode
{
	/**
	 * Name of shortcode group
	 * @var string
	 */
	public static $group = 'Togglable';

	/**
	 * Name of shortcode
	 * @var string
	 */
	public static $shortCode = 'tabs';

	/**
	 * Title for shortcode
	 * @var string
	 */
	public static $title = 'Togglable tabs - tab';

	/**
	 * Image for shortcode, if exist
	 * @var string
	 */
	public static $image = 'tabtable.png';

	/**
	 * Description for shortcode
	 * @var string
	 */
	public static $desc = 'Add item for dynamic tab.';

	/**
	 * Type of shorcode
	 * <code>
	 * 0 = [tag (attributes) ]
	 * 1 = [tag (attributes) ] (content) [/tag]
	 * </code>
	 * @var int
	 */
	public static $uni = 1;

	/**
	 * Default values
	 */
	/** @var string */
	private static $fieldTitle = '';
	/** @var string  */
	private static $fieldHighlight = '';
	/** @var string  */
	private static $fieldLink = '';
	/** @var bool */
	private static $fieldActive = true;

	/**
	 * @return array
	 */
	public function fields()
	{
		$fields = array(
			'title' => array(
				'title' => __('Title', THEME_NAME),
				'desc' => __('Title for tab.', THEME_NAME),
				'type' => 'text',
				'std' => self::$fieldTitle
			),
			'highlight' => array(
				'title' => __('Highlight', THEME_NAME),
				'desc' => __('Highlight text in tab.', THEME_NAME),
				'type' => 'text',
				'std' => self::$fieldHighlight
			),
			'link' => array(
				'title' => __('Link', THEME_NAME),
				'desc' => __('Web link tabe.', THEME_NAME),
				'type' => 'text',
				'std' => self::$fieldLink
			),
			'active' => array(
				'title' => __('Active', THEME_NAME),
				'desc' => __('Mark tab as active. (will be displayed).', THEME_NAME),
				'type' => 'select',
				'options' => array(true => 'Yes', false => 'No'),
				'std' => self::$fieldActive
			)
		);
		return $fields;
	}

	/**
	 * @param null $atts
	 * @param null $content
	 * @return string
	 */
	public function get($atts = null, $content = null)
	{
		$ex_atts = $this->extract_atts($this->fields());
		if (!empty($ex_atts)) {
			extract(shortcode_atts($ex_atts, $atts));
		}
		$uniq = uniqid('tabtable-');
		$x = isset($GLOBALS['tab_count']) ? $GLOBALS['tab_count'] : 0;
		$title = isset($title) ? $title : self::$fieldTitle;
		$highlight = isset($highlight) ? $highlight : self::$fieldHighlight;
		$link = isset($link) ? $link : self::$fieldLink;
		$active = isset($active) ? $active : '';
		$GLOBALS['tabs'][$x] = array(
			'uniq' => $uniq,
			'title' => $title,
			'highlight' => $highlight,
			'link' => $link,
			'active' => $active,
			'content' => $content
		);
		$GLOBALS['tab_count']++;
	}
}
