You are here

function scald_file_scald_prerender in Scald File Provider 7

Implements hook_scald_prerender().

File

./scald_file.module, line 297
Scald File is a Scald Atom Provider for Files.

Code

function scald_file_scald_prerender($atom, $context, $options, $mode) {
  if ($mode == 'atom') {
    if ($context === 'sdl_library_item') {
      $scald_thumbnail = field_get_items('scald_atom', $atom, 'scald_thumbnail');
      if (empty($scald_thumbnail)) {
        $atom->rendered->thumbnail_transcoded_url = file_create_url($atom->thumbnail_source);
      }
    }
    else {
      $config = scald_context_config_load($context);
      $file = isset($atom->base_entity) ? $atom->base_entity : file_load($atom->base_id);
      $transcoder = '';
      if (isset($config->transcoder[$atom->type]['*'])) {
        $transcoder = $config->transcoder[$atom->type]['*'];
      }
      if (module_exists('pdf') && !empty($transcoder) && strpos($transcoder, 'pdf') !== FALSE && $file->filemime === 'application/pdf') {
        $theme = preg_match('/^file_field_pdf_/', $transcoder) ? str_replace('file_field_pdf_', 'pdf_formatter_', $transcoder) : 'pdf_formatter_default';
        $atom->rendered->player = theme($theme, array(
          'file' => $file,
        ));
      }
      else {
        $scald_thumbnail = field_get_items('scald_atom', $atom, 'scald_thumbnail');
        if (!empty($transcoder) && !empty($scald_thumbnail) && preg_match('/^style-(.*)$/', $transcoder, $match)) {
          $style_name = $match[1];
          $preset = image_style_load($style_name);
          $thumbnail_source = image_style_url($preset['name'], $atom->thumbnail_source);
        }
        else {
          $thumbnail_source = $atom->thumbnail_source;
        }
        $atom->rendered->player = theme('scald_file_render', array(
          'vars' => array(
            'context' => $context,
            'file_source' => $atom->file_source,
            'file_size' => format_size($atom->base_entity->filesize),
            'thumbnail_source' => $thumbnail_source,
            'file_title' => check_plain($atom->title),
          ),
        ));
      }
    }
  }
}