*/
if (!defined('TOTAL_SLIDER_REQUIRED_CAPABILITY')) {
    header('HTTP/1.1 403 Forbidden');
    die('<h1>Forbidden</h1>');
}
if (!function_exists('__')) {
    header('HTTP/1.1 403 Forbidden');
    die('<h1>Forbidden</h1>');
}
if (array_key_exists('total-slider-uploader', $_GET) && 'bgimage' == $_GET['total-slider-uploader']) {
    if (!array_key_exists('total-slider-slide-group-template', $_GET) || empty($_GET['total-slider-slide-group-template']) || !array_key_exists('total-slider-slide-group-template-location', $_GET) || empty($_GET['total-slider-slide-group-template-location'])) {
        $crop = array('crop_width' => TOTAL_SLIDER_DEFAULT_CROP_WIDTH, 'crop_height' => TOTAL_SLIDER_DEFAULT_CROP_HEIGHT);
    } else {
        try {
            $t = new Total_Slider_Template($_GET['total-slider-slide-group-template'], $_GET['total-slider-slide-group-template-location']);
            $crop = $t->determine_options();
        } catch (Exception $e) {
            $crop = array('crop_width' => TOTAL_SLIDER_DEFAULT_CROP_WIDTH, 'crop_height' => TOTAL_SLIDER_DEFAULT_CROP_HEIGHT);
        }
    }
    ?>
<!-- a little shimming to prettify the uploader/media library options for Total Slider purposes -->
<style type="text/css">
#media-items .post_title,#media-items .image_alt,#media-items .post_excerpt,#media-items .post_content, #media-items .url, #media-items .align { display:none !important; }
</style>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
	jQuery('.imgedit-response').append('<p style="text-align:center;font-size:12px;color:#909090;"><?php 
    printf(__('Choose ‘Edit Image’ and crop to %d×%d for best results.', 'total-slider'), $crop['crop_width'], $crop['crop_height']);
    ?>
    /**
     * Render an HTML mini-preview of the slide images, for use in the widget selector. TODO UNFINISHED
     *
     * This allows an at-a-glance verification that the selected slide group is the desired slide group.
     *
     * @return void
     */
    public function mini_preview()
    {
        /*
        	* Extract background images from slides.
        	* (Get thumbnail versions?)
        	* Get suggested crop width and height, scale down proportionally to calculate thumbnail size of template
        	* Render thumbnail images against those dimensions
        	* JS to spin through them with some kind of animation?
        	
        	How do we disclaim that this isn't truly WYSIWYG? Is that a problem?
        */
        if (empty($this->template) || empty($this->templateLocation)) {
            if (!$this->load()) {
                return false;
            }
        }
        // load template information
        try {
            $t = new Total_Slider_Template($this->template, $this->templateLocation);
        } catch (Exception $e) {
            if (defined('WP_DEBUG') && WP_DEBUG) {
                printf(__('Unable to render the slide mini-preview: %s (error code %d)', 'total-slider'), $e->getMessage(), $e->getCode());
            }
            return false;
        }
        $template_options = $t->determine_options();
        ?>
<p><strong><?php 
        _e('Template:', 'total-slider');
        ?>
</strong> <?php 
        echo esc_html($t->name());
        ?>
</p><?php 
        $current_slides = get_option('total_slider_slides_' . $this->slug);
        if (false === $current_slides || !is_array($current_slides) || count($current_slides) < 0) {
            ?>
<p><?php 
            _e('There are no slides to show.', 'total-slider');
            ?>
</p><?php 
            return true;
        }
        ?>
<div class="total-slider-mini-preview">
		<ul><?php 
        foreach ($current_slides as $idx => $slide) {
            if (is_numeric($slide['background']) && intval($slide['background']) == $slide['background']) {
                // background references an attachment ID
                $image = wp_get_attachment_image_src(intval($slide['background']), 'thumbnail');
                $image = $image[0];
            } else {
                $image = $slide['background'];
            }
            ?>
<li><img src="<?php 
            echo esc_url($image);
            ?>
" alt="<?php 
            echo esc_attr($slide['title']);
            ?>
" title="<?php 
            echo esc_attr($slide['title']);
            ?>
" width="100" height="32" /></li><?php 
        }
        ?>
		</ul>
		</div><?php 
    }