<?php

class Intense_Divider extends Intense_Shortcode {

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

		global $intense_visions_options;

		$this->title = __( 'Divider', 'intense' );
		$this->description = __( 'Adds a divider that can be used to separate content. There are several different divider types to choose from. Some of the dividers have multiple colors that can be set. A divider can show at the top or bottom of an element. The parent element needs to have a <strong>relative</strong> position CSS style.', 'intense' );
		$this->category = __( 'Layout', 'intense' );
		$this->show_preview = false;
	}

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

		if ( !empty($atts['type']) && $atts['type'][0] != '.' && $atts['type'][0] != '~' ) {
			global $intense_divider;

			$minified = ( INTENSE_DEBUG ? "" : "min." );

			$intense_divider = $atts;

			if ( empty( $intense_divider['id'] ) ) {
				$intense_divider['id'] = 'divider_' . rand();
			}			

			if ( !empty( $intense_divider['class'] ) ) {
				$intense_divider['class'] = ' ' . $intense_divider['class'];
			} else {
				$intense_divider['class'] = '';
			}

			if ( empty( $intense_divider['primary_color'] ) ) $intense_divider['primary_color'] = "#fff";
			if ( empty( $intense_divider['secondary_color'] ) ) $intense_divider['secondary_color'] = $intense_divider['primary_color'];
			if ( empty( $intense_divider['tertiary_color'] ) ) $intense_divider['tertiary_color'] = $intense_divider['primary_color'];

			$intense_divider['primary_color'] = intense_get_plugin_color( $intense_divider['primary_color'] );
			$intense_divider['secondary_color'] = intense_get_plugin_color( $intense_divider['secondary_color'] );
			$intense_divider['tertiary_color'] = intense_get_plugin_color( $intense_divider['tertiary_color'] );

			ob_start();

			if ( file_exists( INTENSE_PLUGIN_FOLDER .'/shortcodes/divider/dividers/' . $atts['type'] . '.php' ) ) {
				require INTENSE_PLUGIN_FOLDER .'/shortcodes/divider/dividers/' . $atts['type'] . '.php';

				$output = ob_get_contents();

				ob_end_clean();

				$css_path = INTENSE_PLUGIN_FOLDER .'/shortcodes/divider/css/' . $atts['type'] . '.' . $minified . 'css';
			
				if ( empty( $GLOBALS['IntensePluginInlineStyle'][ 'divider_' . $atts['type'] ] ) && file_exists( $css_path ) ) {
					$GLOBALS['IntensePluginInlineStyle'][ 'divider_' . $atts['type'] ] = file_get_contents( $css_path );	
				}
			}

			return $output;
		}
	}
}
