You are here

insert_shadowbox.module in Shadowbox 8

Same filename and directory in other branches
  1. 7.4 insert_shadowbox/insert_shadowbox.module

File

insert_shadowbox/insert_shadowbox.module
View source
<?php

define('INSERT_SHADOWBOX_ICOPATH', drupal_get_path('module', 'file_shadowbox') . "/images/icos/");

/**
 * Implementation of hook_insert_styles().
 */
function insert_shadowbox_insert_styles() {
  $insert_styles = array();
  $image_styles = image_styles();
  foreach ($image_styles as $style) {
    $insert_styles['shadowbox_' . $style['name']] = array(
      'label' => 'shadowbox: ' . t($style['name']),
    );
  }
  return $insert_styles;
}

/*
 * Implementation of hook_insert_content().
 */
function insert_shadowbox_insert_content($item, $style, $widget) {
  $style_name = preg_replace('/^shadowbox_/', '', $style['name']);
  $rel = "shadowbox";
  $path = INSERT_SHADOWBOX_ICOPATH . 'generic.png';
  $class = 'sb-insert sb-image sb-individual';
  switch ($widget['type']) {
    case 'image_image':
      $path = $item['uri'];
      $alt = isset($item['alt']) ? $item['alt'] : "";
      $title = isset($item['title']) ? $item['title'] : "";
      $class = 'image-' . $style_name . ' sb-insert sb-image sb-individual';
      break;
    case 'file_generic':
      $title = isset($item['description']) ? $item['description'] : '';
      $alt = $title;
      $width = variable_get('shadowbox_video_width', 640);
      $height = variable_get('shadowbox_video_height', 360);
      switch ($item['filemime']) {
        case 'video/mp4':
        case 'video/x-flv':
          $path = INSERT_SHADOWBOX_ICOPATH . 'flv.png';
          $style_name = '';
          $rel = 'shadowbox; player=flv; width=' . $width . '; height=' . $height;
          break;
        case 'video/quicktime':
          $path = INSERT_SHADOWBOX_ICOPATH . 'mov.png';
          $style_name = '';
          $rel = 'shadowbox; player=flv; width=' . $width . '; height=' . $height;
          break;
        case 'application/x-shockwave-flash':
          $path = INSERT_SHADOWBOX_ICOPATH . 'swf.png';
          $style_name = '';
          $rel = 'shadowbox; player=swf; width=' . $width . '; height=' . $height;
          break;
        default:
          if (strstr($item['filemime'], 'image/')) {
            $path = $item['uri'];
          }
          else {
            $style_name = '';
            $rel = '';
          }
      }
      break;
    default:
      break;
  }
  $image = array(
    'path' => $path,
    'alt' => $alt,
    'title' => $title,
    'image_style' => $style_name,
  );
  return theme('shadowbox_formatter', array(
    'innerHTML' => theme('shadowbox_thumbnail', $image),
    'title' => $title,
    'url' => file_create_url($item['uri']),
    'rel' => $rel,
    'class' => 'sb-insert sb-image sb-individual',
  ));
}