<?php

class Intense_Lightbox extends Intense_Shortcode {

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

    global $intense_visions_options;

    $this->title = __( 'Lightbox', 'intense' );
    $this->description = __( 'Add images, videos, html and iframe content within the lightbox shortcode. Lightboxes are modal dialogs that appear over the webpage content. They are sometimes referred to as popups. There are many different lightbox types to choose from.', 'intense' );
    $this->category = __( 'Elements', 'intense' );
    $this->show_preview = false;
    $this->is_container = true;    
  }

  function shortcode( $atts, $content = null ) {
    require_once INTENSE_PLUGIN_FOLDER . '/inc/tools/lightboxes.php';
    
    global $intense_visions_options;
    extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

    $output = '';
    $id = rand();

    if ( is_numeric( $url ) ) {
      $url = get_permalink( $url );
    }

    $lightbox = Intense_Lightboxes::create( $type, '#intense-lightbox-' . $id . ' a' );

    $output .= '<span id="intense-lightbox-' . $id . '" class="intense lightbox">';

    switch ( $content_type ) {
    case 'html':
      $output .= $lightbox->get_html( do_shortcode( $content ), $html_element  );
      $output .= '<script>jQuery(function($) { $("#' . $html_element . '").wrap("<div style=\'display:none\'>"); ' . $lightbox->get_html_script() . '});</script>';
      $output .= '<style type="text/css">' . $lightbox->get_css() . '</style>';
      break;
    case 'image':
      if ( is_numeric( $image ) ) {
        $photo = Intense_Photo_Source::get_wordpress_photo( $image, $image_size );
        $display_image = $photo['url'];        
        $full_size = ( isset( $intense_visions_options['intense_photosource_full_size'] ) ? $intense_visions_options['intense_photosource_full_size'] : 'large' );
        $photo = Intense_Photo_Source::get_wordpress_photo( $image, $full_size );
        $full_size_image = $photo['url'];
      } else if ( !empty( $image ) ) {
          $full_size_image = $image;
        }

      $output .= '<script>jQuery(function($) {' . $lightbox->get_image_script() . '});</script>';
      $output .= $lightbox->get_image( $grouping, $title, $description, $full_size_image, '<img src="' . $display_image . '">' );
      $output .= '<style type="text/css">' . $lightbox->get_css() . '</style>';
      break;
    case 'iframe':
      $output .= $lightbox->get_iframe( do_shortcode( $content ), $url );
      $output .= '<script>jQuery(function($) { ' . $lightbox->get_iframe_script() . '});</script>';
      $output .= '<style type="text/css">' . $lightbox->get_css() . '</style>';
      break;
    }

    $output .= '</span>';

    return $output;
  }
}
