You are here

function scald_dnd_library_scald_render in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 modules/library/scald_dnd_library/scald_dnd_library.module \scald_dnd_library_scald_render()

Implements hook_scald_render.

File

scald_dnd_library/scald_dnd_library.module, line 119
Scald DnD Library

Code

function scald_dnd_library_scald_render($atom, $context, $options = array()) {
  if ($atom->rendered->file_transcoded_url) {
    $path = $atom->rendered->file_transcoded_url;
  }
  else {
    $path = $atom->rendered->thumbnail_source_url;
  }
  $attributes = array();
  if ($context == 'sdl_library_item') {
    $path .= strpos($path, '?') !== FALSE ? '&' : '?';
    $path .= 'dnd_id=' . $atom->sid;
    $attributes += array(
      'class' => 'drop',
      'draggable' => 'TRUE',
    );
  }
  elseif ($context == 'sdl_preview') {
    $path .= strpos($path, '?') !== FALSE ? '&' : '?';
    $path .= 'dnd_id=' . $atom->sid;
    $attributes += array(
      'class' => 'drop',
    );
  }
  else {
    $attributes += array(
      'class' => 'dnd-dropped',
    );
  }

  // Try to get the image size.
  if ($atom->rendered->file_transcoded_url && $atom->file_transcoded) {
    list($width, $height, $type, $attr) = @getimagesize($atom->file_transcoded);
  }
  elseif ($atom->thumbnail_source) {
    list($width, $height, $type, $attr) = @getimagesize($atom->thumbnail_source);
  }
  if ($width && $height) {
    $attributes += array(
      'width' => $width,
      'height' => $height,
    );
  }
  $image = "<img src='{$path}' alt='' " . drupal_attributes($attributes) . ' />';
  switch ($context) {
    case 'sdl_preview':
      $render = theme('sdl_preview_item', $atom, $image);
      break;
    case 'sdl_library_item':
      $render = theme('sdl_library_item', $atom, $image);
      break;
    default:
      $render = theme('sdl_editor_item', $atom->rendered, $image);
  }
  return $render;
}