<?php

class Intense_Snippet extends Intense_Shortcode {

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

        $this->title = __( 'Snippet', 'intense' );
        $this->description = __( 'Snippets allows you to create content that you can use over and over again throughout your site, without having to redo your work, or copy from one page to another.', 'intense' );
        $this->category = __( 'Elements', 'intense' );
        $this->show_preview = false;
        $this->is_container = false;        
    }

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

        if ( is_numeric( $snippet_id ) ) {
            $snippet = get_post_field( 'post_content', $snippet_id );      
        } else {
            //id will look like: location | relative path/template name
            $parts = explode( " | ", $snippet_id );
            $snippet_location_name = $parts[0];            
            $location_path = intense_get_snippet_location_path( $snippet_location_name );

            // unset the first to remove the location and then put back together so that the name can have a | in it
            unset( $parts[0] ); 
            $snippet_file = implode( " | ", $parts ) . ".php";

            // load snippet from the file
            $snippet = intense_load_plugin_snippet( $location_path . $snippet_file );
        }

        $line_count = substr_count( trim( $snippet ), "\n" );

        //added wpautop so that line breaks are included. Only do this if there are multiple lines.
        if ( $line_count > 0 ) $snippet = wpautop( $snippet );

        return do_shortcode( Intense_Shortcodes::cleaner( $snippet ) );
    }

    public function map_visual_composer() {
        // $this->set_default_options();
        
        // return parent::map_visual_composer();
        return null;
    }
}