<?php

class Intense_Blockquote extends Intense_Shortcode {

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

        global $intense_visions_options;

        $this->title = __( 'Blockquote', 'intense' );
        $this->description = __( 'Blockquotes are useful for showing quoted text within a section of text. Often they are used within blog posts but they can also be useful within pages. Blockquotes can be set to take the full width or can be used as a pull quote that only take up part of the width.', 'intense' );
        $this->category = __( 'Typography', 'intense' );
        $this->show_preview = true;
        $this->preview_content = __( "Blockquote Text", 'intense' );
        $this->vc_map_content = 'textarea_html';       
    }

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

        $align = '';
        $authorText = '';
        $radius = '';
        $margin = '';

        if ( !empty( $border_radius ) ) {
            $radius = ' border-radius:' . $border_radius . ';';
        }

        if ( !empty( $width ) ) {
            $width = ' width:' . $width . ';';
            $align = ' pull-left';
            $margin = ' margin: 0 20px 20px 0;';
        }

        if ( $rightalign ) {
            $align = ' pull-right';

            if ( !empty( $width ) ) {
                $margin = ' margin: 0 0 20px 20px;';
            }
        }

        $color = intense_get_plugin_color( $color );
        $font_color = intense_get_plugin_color( $font_color );

        if ( $font_color == '' ) {
            $font_color = intense_get_contract_color( $color );
        }

        if ( !empty( $border_color ) ) {
            $border_color = intense_get_plugin_color( $border_color );
            $border_color = " border-color: " . $border_color . ';';
        }

        if ( $author != '' ) {
            if ( $author_link != '' ) {
                if ( is_numeric( $author_link ) ) {
                    $author_link = get_permalink( $author_link );
                }

                $authorText = '<a href="' . $author_link . '" target="_blank" style="text-decoration: none;"><small style="padding-top: 10px;">' . $author . '</small></a>';
            } else {
                $authorText = '<small style="padding-top:10px;">' . $author . '</small>';
            }
        }

        $id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

        $css = "background: " . $color  . "; color: " . $font_color . ";" . $radius . $width . $margin . $border_color;
        $extra_class = $align . ( !empty( $class ) ? ' ' . $class : '' ); 

        if ( isset( $atts['get_css'] ) && $atts['get_css'] ) {
            return array(
                'css' => $css,
                'base_classes' => 'intense',
                'extra_classes' => $extra_class
            );
        }  

        return "<blockquote" . $id . " style='" . $css . "' class='intense" . $extra_class . "'>" . do_shortcode( $content ) . ( $authorText != "" ? $authorText : "" ) . "</blockquote>";
    }
}
